Package Camelot :: Package camelot :: Package view :: Package controls :: Module inheritance
[frames] | no frames]

Source Code for Module Camelot.camelot.view.controls.inheritance

  1  #  ============================================================================
 
  2  #
 
  3  #  Copyright (C) 2007-2008 Conceptive Engineering bvba. All rights reserved.
 
  4  #  www.conceptive.be / project-camelot@conceptive.be
 
  5  #
 
  6  #  This file is part of the Camelot Library.
 
  7  #
 
  8  #  This file may be used under the terms of the GNU General Public
 
  9  #  License version 2.0 as published by the Free Software Foundation
 
 10  #  and appearing in the file LICENSE.GPL included in the packaging of
 
 11  #  this file.  Please review the following information to ensure GNU
 
 12  #  General Public Licensing requirements will be met:
 
 13  #  http://www.trolltech.com/products/qt/opensource.html
 
 14  #
 
 15  #  If you are unsure which license is appropriate for your use, please
 
 16  #  review the following information:
 
 17  #  http://www.trolltech.com/products/qt/licensing.html or contact
 
 18  #  project-camelot@conceptive.be.
 
 19  #
 
 20  #  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
 21  #  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
 22  #
 
 23  #  For use of this library in commercial applications, please contact
 
 24  #  project-camelot@conceptive.be
 
 25  #
 
 26  #  ============================================================================
 
 27  
 
 28  """Controls related to visualizing object hierarchy""" 
 29  
 
 30  import logging 
 31  
 
 32  logger = logging.getLogger( 'camelot.view.controls.inheritance' ) 
 33  
 
 34  from PyQt4 import QtGui 
 35  from PyQt4 import QtCore 
 36  
 
 37  from camelot.view.controls.modeltree import ModelTree, ModelItem 
 38  from camelot.view.model_thread import post 
 39  
 
 40  QT_MAJOR_VERSION = float( '.'.join( str( QtCore.QT_VERSION_STR ).split( '.' )[0:2] ) ) 
 41  
 
 42  
 
43 -class SubclassItem( ModelItem ):
44 - def __init__( self, parent, admin ):
47
48 -class SubclassTree( ModelTree ):
49 """Widget to select subclasses of a certain entity, where the 50 subclasses are represented in a tree 51 52 emits subclassClicked when a subclass has been selected 53 """ 54
55 - def __init__( self, admin, parent ):
56 header_labels = ['Types'] 57 ModelTree.__init__( self, header_labels, parent ) 58 self.setSizePolicy( QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding ) 59 #self.setSelectionBehavior(QtGui.QAbstractItemView.SelectItems) 60 self.admin = admin 61 self.subclasses = [] 62 post( self.admin.get_subclass_tree, self.setSubclasses ) 63 self.connect( self, 64 QtCore.SIGNAL( 'clicked(const QModelIndex&)' ), 65 self.emitSubclassClicked )
66
67 - def setSubclasses( self, subclasses ):
68 logger.debug( 'setting subclass tree' ) 69 self.subclasses = subclasses 70 71 def append_subclasses(class_item, subclasses): 72 for subclass_admin, subsubclasses in subclasses: 73 subclass_item = SubclassItem(class_item, subclass_admin) 74 self.modelitems.append(subclass_item) 75 append_subclasses(subclass_item, subsubclasses)
76 77 if len( subclasses ): 78 self.clear_model_items() 79 top_level_item = SubclassItem( self, self.admin ) 80 self.modelitems.append( top_level_item ) 81 append_subclasses(top_level_item, subclasses) 82 top_level_item.setExpanded( True ) 83 self.setMaximumWidth( self.fontMetrics().width( ' ' )*70 ) 84 else: 85 self.setMaximumWidth( 0 )
86
87 - def emitSubclassClicked( self, index ):
88 logger.debug( 'subclass clicked at position %s' % index.row() ) 89 item = self.itemFromIndex( index ) 90 self.emit( QtCore.SIGNAL( 'subclassClicked' ), item.admin )
91
92 -class SubclassDialog( QtGui.QDialog ):
93 """A dialog requesting the user to select a subclass""" 94
95 - def __init__( self, parent, admin ):
96 QtGui.QDialog.__init__( self, parent ) 97 layout = QtGui.QVBoxLayout() 98 subclass_tree = SubclassTree( admin, self ) 99 layout.addWidget( subclass_tree ) 100 layout.addStretch( 1 ) 101 self.setLayout( layout ) 102 self.selected_subclass = None 103 self.connect( subclass_tree, QtCore.SIGNAL( 'subclassClicked' ), self.subclassClicked )
104
105 - def subclassClicked( self, admin ):
106 self.selected_subclass = admin 107 self.accept()
108