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

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

  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  """left navigation pane""" 
 29   
 30  import logging 
 31  logger = logging.getLogger( 'camelot.view.controls.navpane' ) 
 32   
 33  from PyQt4.QtCore import Qt 
 34  from PyQt4 import QtGui, QtCore 
 35   
 36  from camelot.view.model_thread import post 
 37  from camelot.action import addActions, createAction 
 38  from camelot.view.controls.modeltree import ModelItem, ModelTree 
 39  from appscheme import scheme 
 40   
 41  QT_MAJOR_VERSION = float( '.'.join( str( QtCore.QT_VERSION_STR ).split( '.' )[0:2] ) ) 
 42   
 43  _ = lambda x:x 
 44   
 45  from camelot.view.controls.user_translatable_label import UserTranslatableLabel 
 46   
47 -class PaneCaption( UserTranslatableLabel ):
48 """Navigation pane Caption"""
49 - def __init__( self, 50 text, 51 textbold = True, 52 textindent = 3, 53 width = 160, 54 height = 32, 55 objectname = 'PaneCaption', 56 parent = None ):
57 58 super(UserTranslatableLabel, self).__init__(text, parent) 59 60 if textbold: 61 self.textbold() 62 63 font = self.font() 64 font.setPointSize( font.pointSize() + 2 ) 65 self.setFont( font ) 66 67 self.setIndent( textindent ) 68 69 self.setObjectName( objectname ) 70 71 style = """ 72 QLabel#PaneCaption { 73 margin: 3px 0 0 3px; 74 border: 1px solid %s; 75 color: %s; 76 background-color: %s; 77 } 78 """ % ( scheme.bordercolor(), 79 scheme.captiontextcolor(), 80 scheme.captionbackground() ) 81 82 self.setStyleSheet( style ); 83 self.setFixedHeight( height ) 84 self.resize( width, height )
85
86 - def textbold( self ):
87 font = self.font() 88 font.setBold( True ) 89 font.setPointSize( font.pointSize() + 1 ) 90 self.setFont( font )
91 92
93 -class PaneButton( QtGui.QWidget ):
94 """Custom made navigation pane pushbutton""" 95
96 - def __init__( self, 97 text, 98 buttonicon = '', 99 textbold = True, 100 textleft = True, 101 width = 160, 102 height = 32, 103 objectname = 'PaneButton', 104 parent = None, 105 index = 0 ):
106 107 QtGui.QWidget.__init__( self, parent ) 108 109 if textleft: 110 option = QtGui.QBoxLayout.LeftToRight 111 else: 112 option = QtGui.QBoxLayout.RightToLeft 113 self.layout = QtGui.QBoxLayout( option ) 114 self.layout.setSpacing( 0 ) 115 self.layout.setContentsMargins( 3, 0, 0, 0 ) 116 117 if buttonicon: 118 self.icon = QtGui.QLabel() 119 self.icon.setPixmap( QtGui.QPixmap( buttonicon ) ) 120 self.layout.addWidget( self.icon ) 121 122 self.label = UserTranslatableLabel(text, parent) 123 124 self.layout.addWidget( self.label, 2 ) 125 126 self.setLayout( self.layout ) 127 128 if textbold: 129 self.textbold() 130 131 self.setObjectName( objectname ) 132 133 self.stylenormal = """ 134 QWidget#PaneButton * { 135 margin: 0; 136 padding-left: 3px; 137 color : %s; 138 border-color : %s; 139 background-color : %s; 140 } 141 """ % ( scheme.textcolor(), 142 scheme.bordercolor(), 143 scheme.normalbackground() ) 144 145 self.stylehovered = """ 146 QWidget#PaneButton * { 147 margin: 0; 148 padding-left: 3px; 149 color : %s; 150 background-color : %s; 151 } 152 """ % ( scheme.textcolor(), 153 scheme.hoveredbackground() ) 154 155 self.styleselected = """ 156 QWidget#PaneButton * { 157 margin: 0; 158 padding-left: 3px; 159 color : %s; 160 background-color : %s; 161 } 162 """ % ( scheme.selectedcolor(), 163 scheme.selectedbackground() ) 164 165 self.styleselectedover = """ 166 QWidget#PaneButton * { 167 margin: 0; 168 padding-left: 3px; 169 color : %s; 170 background-color : %s; 171 } 172 """ % ( scheme.selectedcolor(), 173 scheme.selectedbackground( inverted = True ) ) 174 175 self.setStyleSheet( self.stylenormal ) 176 self.setFixedHeight( height ) 177 self.resize( width, height ) 178 self.selected = False 179 self.index = index
180
181 - def textbold( self ):
182 font = self.label.font() 183 font.setBold( True ) 184 self.label.setFont( font )
185
186 - def enterEvent( self, event ):
187 if self.selected: 188 self.setStyleSheet( self.styleselectedover ) 189 else: 190 self.setStyleSheet( self.stylehovered )
191
192 - def leaveEvent( self, event ):
193 if self.selected: 194 self.setStyleSheet( self.styleselected ) 195 else: 196 self.setStyleSheet( self.stylenormal )
197
198 - def mousePressEvent( self, event ):
199 if self.selected: 200 return 201 else: 202 self.selected = True 203 self.setStyleSheet( self.styleselectedover ) 204 # Python shortcut SIGNAL, any object can be passed 205 self.emit( QtCore.SIGNAL( 'indexselected' ), 206 ( self.index, self.label.text() ) )
207 208 350 357 363