Package pyffi :: Package object_models :: Module editable
[hide private]
[frames] | no frames]

Source Code for Module pyffi.object_models.editable

  1  """Implements abstract editor base classes. 
  2   
  3  These abstract base classes provide an abstract layer for editing data in a 
  4  graphical user interface. 
  5   
  6  @todo: Make these into true abstract base classes, and implement and use the 
  7      get_editor_value and set_editor_value functions in non-abstract derived 
  8      classes. 
  9  """ 
 10   
 11  # ***** BEGIN LICENSE BLOCK ***** 
 12  # 
 13  # Copyright (c) 2007-2011, Python File Format Interface 
 14  # All rights reserved. 
 15  # 
 16  # Redistribution and use in source and binary forms, with or without 
 17  # modification, are permitted provided that the following conditions 
 18  # are met: 
 19  # 
 20  #    * Redistributions of source code must retain the above copyright 
 21  #      notice, this list of conditions and the following disclaimer. 
 22  # 
 23  #    * Redistributions in binary form must reproduce the above 
 24  #      copyright notice, this list of conditions and the following 
 25  #      disclaimer in the documentation and/or other materials provided 
 26  #      with the distribution. 
 27  # 
 28  #    * Neither the name of the Python File Format Interface 
 29  #      project nor the names of its contributors may be used to endorse 
 30  #      or promote products derived from this software without specific 
 31  #      prior written permission. 
 32  # 
 33  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 34  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 35  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 36  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 37  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 38  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 39  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 40  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 41  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 42  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
 43  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 44  # POSSIBILITY OF SUCH DAMAGE. 
 45  # 
 46  # ***** END LICENSE BLOCK ***** 
 47   
48 -class EditableBase(object):
49 """The base class for all delegates."""
50 - def get_editor_value(self):
51 """Return data as a value to initialize an editor with. 52 Override this method. 53 54 :return: A value for the editor. 55 :rtype: any (whatever is appropriate for the particular 56 implementation of the editor) 57 """ 58 raise NotImplementedError
59
60 - def set_editor_value(self, editorvalue):
61 """Set data from the editor value. Override this method. 62 63 :param editorvalue: The value of the editor. 64 :type editorvalue: any (whatever is appropriate for the particular 65 implementation of the editor) 66 """ 67 raise NotImplementedError
68
69 -class EditableSpinBox(EditableBase):
70 """Abstract base class for data that can be edited with a spin box that 71 contains an integer. Override get_editor_minimum and get_editor_maximum to 72 set the minimum and maximum values that the spin box may contain. 73 74 Requirement: get_editor_value must return an ``int``, set_editor_value 75 must take an ``int``. 76 """
77 - def get_editor_value(self):
78 return self.get_value()
79
80 - def set_editor_value(self, editorvalue):
81 self.set_value(self, editorvalue)
82
83 - def get_editor_minimum(self):
84 return -0x80000000
85
86 - def get_editor_maximum(self):
87 return 0x7fffffff
88
89 -class EditableFloatSpinBox(EditableSpinBox):
90 """Abstract base class for data that can be edited with a spin box that 91 contains a float. Override get_editor_decimals to set the number of decimals 92 in the editor display. 93 94 Requirement: get_editor_value must return a ``float``, set_editor_value 95 must take a ``float``. 96 """ 97
98 - def get_editor_decimals(self):
99 return 5
100
101 -class EditableLineEdit(EditableBase):
102 """Abstract base class for data that can be edited with a single line 103 editor. 104 105 Requirement: get_editor_value must return a ``str``, set_editor_value 106 must take a ``str``. 107 """ 108 pass
109
110 -class EditableTextEdit(EditableLineEdit):
111 """Abstract base class for data that can be edited with a multiline editor. 112 113 Requirement: get_editor_value must return a ``str``, set_editor_value 114 must take a ``str``. 115 """ 116 pass
117
118 -class EditableComboBox(EditableBase):
119 """Abstract base class for data that can be edited with combo boxes. 120 This can be used for for instance enum types. 121 122 Requirement: get_editor_value must return an ``int``, set_editor_value 123 must take an ``int`` (this integer is the index in the list of keys). 124 """ 125
126 - def get_editor_keys(self):
127 """Tuple of strings, each string describing an item.""" 128 return ()
129
130 -class EditableBoolComboBox(EditableComboBox):
131 """Class for data that can be edited with a bool combo box. 132 133 Requirement: get_value must return a ``bool``, set_value must take a ``bool``. 134 """
135 - def get_editor_keys(self):
136 return ("False", "True")
137
138 - def set_editor_value(self, editorvalue):
139 if editorvalue == 0: 140 self.set_value(False) 141 elif editorvalue == 1: 142 self.set_value(True) 143 else: 144 raise ValueError("no value for index %i" % editorvalue)
145
146 - def get_editor_value(self):
147 return 1 if self.get_value() else 0
148