Package camelot :: Package camelot :: Package view :: Package controls :: Module inheritance
[hide private]
[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 os 
31  import logging 
32  
 
33  logger = logging.getLogger('camelot.view.controls.inheritance') 
34  
 
35  from PyQt4 import QtGui 
36  from PyQt4 import QtCore 
37  from PyQt4.QtCore import Qt 
38  
 
39  import settings 
40  from camelot.view.controls.modeltree import ModelTree 
41  from camelot.view.controls.modeltree import ModelItem 
42  
 
43  QT_MAJOR_VERSION = float('.'.join(str(QtCore.QT_VERSION_STR).split('.')[0:2])) 
44  
 
45  
 
46 -class SubclassItem(ModelItem):
47 - def __init__(self, parent, admin):
48 super(SubclassItem, self).__init__(parent, [admin.getName()]) 49 self.admin = admin
50 51
52 -class SubclassTree(ModelTree):
53 """Widget to select subclasses of a certain entity, where the 54 subclasses are represented in a tree 55 56 emits subclasssClicked when a subclass has been selected 57 """ 58
59 - def __init__(self, admin, parent):
60 header_labels = ['Types'] 61 super(SubclassTree, self).__init__(header_labels, parent) 62 self.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) 63 #self.setSelectionBehavior(QtGui.QAbstractItemView.SelectItems) 64 self.admin = admin 65 self.subclasses = [] 66 self.mt = admin.getModelThread() 67 self.mt.post(lambda: self.admin.getSubclasses(), 68 lambda subclasses: self.setSubclasses(subclasses)) 69 self.connect(self, 70 QtCore.SIGNAL('clicked(const QModelIndex&)'), 71 self.emitSubclassClicked)
72
73 - def setSubclasses(self, subclasses):
74 logger.debug('setting subclass tree') 75 76 self.subclasses = subclasses 77 if len(subclasses) > 1: 78 self.clear_model_items() 79 top_level_item = SubclassItem(self, self.admin) 80 self.modelitems.append(top_level_item) 81 for cls in subclasses: 82 item = SubclassItem(top_level_item, cls) 83 self.modelitems.append(item) 84 top_level_item.setExpanded(True) 85 else: 86 self.setMaximumWidth(0)
87
88 - def emitSubclassClicked(self, index):
89 logger.debug('subclass clicked at position %s' % index.row()) 90 item = self.itemFromIndex(index) 91 self.emit(QtCore.SIGNAL('subclasssClicked'), item.admin)
92