Changeset 1179

Show
Ignore:
Timestamp:
03/08/10 16:17:24 (5 months ago)
Author:
erikj
Message:

add some docstring generation code

Location:
trunk/camelot
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/camelot/types/__init__.py

    r1153 r1179  
    9999   
    100100    eg: ``['08', 'AB']`` is stored as ``08.AB`` 
     101     
     102    .. image:: ../_static/editors/CodeEditor_editable.png 
    101103    """ 
    102104     
     
    154156      rating = Field(camelot.types.Rating()) 
    155157       
    156   .. image:: ../_static/rating.png""" 
     158  .. image:: ../_static/editors/StarEditor_editable.png 
     159""" 
    157160     
    158161    impl = types.Integer 
     
    162165  rendered in a rich text editor.   
    163166   
    164   .. image:: ../_static/richtext.png""" 
     167    .. image:: ../_static/editors/RichTextEditor_editable.png 
     168""" 
    165169     
    166170    impl = types.UnicodeText 
     
    199203    class MovieType(Entity): 
    200204      color = Field(camelot.types.Color()) 
    201    
    202   .. image:: ../_static/color.png 
    203    
     205 
     206  .. image:: ../_static/editors/ColorEditor_editable.png   
    204207   
    205208  The colors are stored in the database as strings  
     
    255258                                              index=True, required=True, default='planning') 
    256259   
    257   .. image:: ../_static/enumeration.png   
     260  .. image:: ../_static/editors/ChoicesEditor_editable.png   
    258261  """ 
    259262     
     
    312315      script = Field(camelot.types.File(upload_to='script')) 
    313316       
    314   .. image:: ../_static/file_delegate.png 
     317  .. image:: ../_static/editors/FileEditor_editable.png 
    315318    """ 
    316319     
     
    361364  the files stored should be images. 
    362365   
    363   .. image:: ../_static/image.png   
     366  .. image:: ../_static/editors/ImageEditor_editable.png 
    364367    """ 
    365368   
  • trunk/camelot/view/controls/delegates/__init__.py

    r1150 r1179  
    11 
    2 """Camelot includes a number of Qt delegates, most of them are used as default 
    3 delegates for the various sqlalchemy and camelot field types. 
    4  
    5 Some delegates take specific arguments into account for their construction. 
    6 All :attr:`field_attributes` specified for a certain field will be propagated 
    7 towards the constructor of the delegate. 
    8 """ 
    92 
    103from delegatemanager import DelegateManager 
     
    3730from notedelegate import NoteDelegate 
    3831from labeldelegate import LabelDelegate 
     32 
     33doc = """Camelot includes a number of Qt delegates, most of them are used as default 
     34delegates for the various sqlalchemy and camelot field types. 
     35 
     36Some delegates take specific arguments into account for their construction. 
     37All :attr:`field_attributes` specified for a certain field will be propagated 
     38towards the constructor of the delegate.  Some of them will be used by the delegate 
     39itself, others will be used by the editor, created by the delegate. 
     40 
     41""" 
     42 
     43custom_delegates = list(CustomDelegate.__subclasses__()) 
     44custom_delegates.sort(key=lambda d:d.__name__) 
     45for custom_delegate in custom_delegates: 
     46    doc = doc + custom_delegate.__name__ + '\n' + '-'*len(custom_delegate.__name__) + '\n' 
     47    if hasattr(custom_delegate, '__doc__'): 
     48        doc = doc + custom_delegate.__doc__ + '\n' 
     49     
     50print doc 
     51 
     52__doc__ = doc 
  • trunk/camelot/view/controls/delegates/comboboxdelegate.py

    r1085 r1179  
    109109                         unicode(value)) 
    110110        painter.restore() 
    111  
    112  
    113 class ComboBoxEditorDelegate(ComboBoxDelegate): 
    114     """Delegate for combobox which makes sure that the editor (of the combobox) 
    115 is visible even if it isn't selected""" 
    116  
    117     def __init__(self, choices, parent=None, editable=True, **kwargs): 
    118         ComboBoxDelegate.__init__(self, parent, choices, editable, **kwargs) 
    119  
    120     def setEditorData(self, editor, index): 
    121         value = variant_to_pyobject(index.data(Qt.EditRole)) 
    122  
    123         def create_choices_getter(model, row): 
    124  
    125             def choices_getter(): 
    126                 print 'in set editor data', self.choices(None) 
    127                 return list(self.choices(None)) 
    128  
    129             return choices_getter 
    130  
    131         #editor.set_value(value) 
    132         post(create_choices_getter(index.model(),index.row()), 
    133              editor.set_choices) 
    134  
    135     def setModelData(self, editor, model, index): 
    136         return None 
    137         #model.setData(index, create_constant_function(editor.get_value())) 
    138  
    139     def paint(self, painter, option, index): 
    140         """adapted from booldelegate""" 
    141  
    142         painter.save() 
    143         self.drawBackground(painter, option, index) 
    144         #checked = index.model().data(index, Qt.EditRole).toString().__str__() 
    145         value = index.model().data(index, Qt.DisplayRole).toString().__str__() 
    146         #c = index.model().data(index, Qt.BackgroundRole) 
    147         #background_color = QtGui.QColor(c) 
    148         background_color = QtGui.QColor(Qt.blue) 
    149  
    150         #check_option = QtGui.QStyleOptionComboBox() 
    151         #check_option = QtGui.QStyleOptionButton() 
    152         check_option = QtGui.QStyleOptionMenuItem() 
    153         #check_option.OptionType = QStyleOption.SO_ComboBox 
    154  
    155         #check_option.text = QString('choice')     
    156      
    157 class ComboBoxEditorDelegate(ComboBoxDelegate):   
    158      
    159     editor = editors.ChoicesEditor 
    160      
    161     """  
    162         Delegate for combobox which makes sure that the editor (of the combobox) is visible 
    163         even if it isn't selected 
    164     """ 
    165     def __init__(self, choices, parent=None, editable=True, **kwargs): 
    166          ComboBoxDelegate.__init__(self, parent, choices, editable, **kwargs) 
    167           
    168     def setEditorData(self, editor, index): 
    169         value = variant_to_pyobject(index.data(Qt.EditRole)) 
    170  
    171         def create_choices_getter(model, row): 
    172            
    173           def choices_getter(): 
    174  
    175             return list(self.choices(None)) 
    176            
    177           return choices_getter 
    178          
    179         #editor.set_value(value) 
    180         post(create_choices_getter(index.model(),index.row()), editor.set_choices) 
    181      
    182     def setModelData(self, editor, model, index): 
    183         return None 
    184         #model.setData(index, create_constant_function(editor.get_value())) 
    185      
    186     """ adapted from booldelegate """      
    187     def paint(self, painter, option, index): 
    188         painter.save() 
    189         self.drawBackground(painter, option, index) 
    190         #checked = index.model().data(index, Qt.EditRole).toString().__str__() 
    191         value = index.model().data(index, Qt.DisplayRole).toString().__str__() 
    192         print "index value in delegate", value 
    193          
    194         #background_color = QtGui.QColor(index.model().data(index, Qt.BackgroundRole)) 
    195         background_color = QtGui.QColor(Qt.blue) 
    196          
    197         #check_option = QtGui.QStyleOptionComboBox() 
    198         #check_option = QtGui.QStyleOptionButton() 
    199         check_option = QtGui.QStyleOptionMenuItem() 
    200         #check_option.OptionType = QStyleOption.SO_ComboBox 
    201          
    202         #check_option.text = QString('choice') 
    203          
    204         rect = QtCore.QRect(option.rect.left(), 
    205                             option.rect.top(), 
    206                             option.rect.width(), 
    207                             option.rect.height()) 
    208  
    209         #check_option.rect = rect 
    210         check_option.palette = option.palette 
    211          
    212         #if (option.state & QtGui.QStyle.State_Selected): 
    213         #  painter.fillRect(option.rect, option.palette.highlight()) 
    214         #elif not self.editable: 
    215         #  painter.fillRect(option.rect, option.palette.window()) 
    216         #else: 
    217         painter.fillRect(option.rect, background_color) 
    218            
    219         #if checked: 
    220           #check_option.state = option.state | QtGui.QStyle.State_On 
    221           #check_option.state = QtGui.QStyle.State_On 
    222         #else: 
    223       #check_option.state = option.state | QtGui.QStyle.State_Off 
    224           #check_option.state = QtGui.QStyle.State_On 
    225            
    226         check_option.state = QtGui.QStyle.State_DownArrow   
    227            
    228         QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_MenuBarItem, 
    229                                                check_option, 
    230                                                painter) 
    231          
    232         QtGui.QApplication.style().drawItemText(painter, rect, 0, option.palette, True, QString(value)) 
    233         painter.restore() 
    234  
    235               
    236 class TestComboBoxDelegate(QItemDelegate): 
    237  
    238  
    239     def __init__(self, choices, parent = None): 
    240  
    241         QItemDelegate.__init__(self, parent) 
    242         self.choices = choices 
    243  
    244      
    245     def createEditor(self, parent, option, index): 
    246         editor = QComboBox( parent ) 
    247         i = 0 
    248         for choice in self.choices: 
    249             editor.insertItem(i, unicode(choice), QVariant(QString(choice))) 
    250             i = i + 1 
    251         return editor 
    252  
    253     def setEditorData( self, comboBox, index ): 
    254         value = index.model().data(index, Qt.DisplayRole).toInt() 
    255         comboBox.setCurrentIndex(value[0]) 
    256  
    257     def setModelData(self, editor, model, index): 
    258         value = editor.currentIndex() 
    259         model.setData( index, editor.itemData( value, Qt.DisplayRole ) ) 
    260  
    261     def updateEditorGeometry( self, editor, option, index ): 
    262  
    263         editor.setGeometry(option.rect) 
    264         rect = QtCore.QRect(option.rect.left(), 
    265                             option.rect.top(), 
    266                             option.rect.width(), 
    267                             option.rect.height()) 
    268  
    269         #check_option.rect = rect 
    270         check_option.palette = option.palette 
    271  
    272         #if (option.state & QtGui.QStyle.State_Selected): 
    273         #    painter.fillRect(option.rect, option.palette.highlight()) 
    274         #elif not self.editable: 
    275         #    painter.fillRect(option.rect, option.palette.window()) 
    276         #else: 
    277         #    painter.fillRect(option.rect, background_color) 
    278  
    279         #if checked: 
    280         #    check_option.state = option.state | QtGui.QStyle.State_On 
    281         #else: 
    282         #    check_option.state = option.state | QtGui.QStyle.State_Off 
    283         check_option.state = QtGui.QStyle.State_DownArrow 
    284  
    285         QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_MenuBarItem, 
    286                                                check_option, 
    287                                                painter) 
    288  
    289         QtGui.QApplication.style().drawItemText(painter, 
    290                                                 rect, 
    291                                                 0, 
    292                                                 option.palette, 
    293                                                 True, 
    294                                                 QString('choice')) 
    295  
    296         painter.restore() 
    297  
    298  
    299 class TestComboBoxDelegate(QItemDelegate): 
    300  
    301     def __init__(self, choices, parent=None): 
    302         QItemDelegate.__init__(self, parent) 
    303         self.choices = choices 
    304  
    305     def createEditor(self, parent, option, index): 
    306         editor = QComboBox(parent) 
    307         i = 0 
    308         for choice in self.choices: 
    309             editor.insertItem(i, unicode(choice), QVariant(QString(choice))) 
    310             i = i + 1 
    311         return editor 
    312  
    313     def setEditorData(self, comboBox, index): 
    314         value = index.model().data(index, Qt.DisplayRole).toInt() 
    315         comboBox.setCurrentIndex(value[0]) 
    316  
    317     def setModelData(self, editor, model, index): 
    318         value = editor.currentIndex() 
    319         model.setData(index, editor.itemData(value, Qt.DisplayRole)) 
    320  
    321     def updateEditorGeometry(self, editor, option, index): 
    322         editor.setGeometry(option.rect) 
  • trunk/camelot/view/controls/delegates/customdelegate.py

    r1086 r1179  
    4646.. image:: ../_static/delegates/%s_unselected_disabled.png 
    4747.. image:: ../_static/delegates/%s_unselected_editable.png 
     48 
    4849.. image:: ../_static/delegates/%s_selected_disabled.png 
    4950.. image:: ../_static/delegates/%s_selected_editable.png 
    50 """%(name, name, name, name) 
     51 
     52"""%(name, name, name, name,) 
     53 
     54    if 'editor' in dct: 
     55        dct['__doc__'] = dct['__doc__'] + '.. image:: ../_static/editors/%s_editable.png'%dct['editor'].__name__ + '\n' 
     56         
     57    if '__init__' in dct: 
     58        dct['__doc__'] = dct['__doc__'] + 'Field attributes supported by this delegate : \n' 
     59        import inspect 
     60        args, _varargs, _varkw,  _defaults = inspect.getargspec(dct['__init__']) 
     61        for arg in args: 
     62            if arg not in ['self', 'parent']: 
     63                dct['__doc__'] = dct['__doc__'] + '\n * %s'%arg 
    5164    return type(name, bases, dct) 
    5265 
  • trunk/camelot/view/controls/delegates/labeldelegate.py

    r1150 r1179  
    3232             
    3333        QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_CheckBox, 
    34                                                check_option, 
     34                                               checked, 
    3535                                               painter) 
    3636        painter.restore() 
  • trunk/camelot/view/field_attributes.py

    r1175 r1179  
    3434from controls import delegates 
    3535from camelot.core import constants 
    36 from camelot.core.utils import ugettext as _ 
    3736from camelot.view.utils import ( 
    3837    bool_from_string, 
     
    279278    row = row_format%(field_type.__name__, delegate.__name__, '.. image:: ../_static/editors/%s_editable.png'%(delegate.editor.__name__)) 
    280279    doc += row + """ 
    281   """ + row_separator + """ 
    282   """ 
     280""" + row_separator + """ 
     281""" 
    283282 
    284283doc += """