Package mcbase :: Package widgets :: Module mcpushbutton
[hide private]
[frames] | no frames]

Source Code for Module mcbase.widgets.mcpushbutton

 1  # -*- coding: utf-8 -*- 
 2   
 3  ############################################################################ 
 4  # mcpushbutton.py 
 5  # 
 6  # MOCOP  push button widget 
 7  # 
 8  # (C) 2008 Likya Software Ltd. 
 9  ############################################################################ 
10   
11  from PyQt4.Qt import * 
12   
13  from mcwidget import MCWidget 
14  from mc import MC 
15   
16 -class MCPushButton(QPushButton, MCWidget):
17 ''' 18 push button, which is used in MC views 19 '''
20 - def __init__(self, *args):
21 ''' 22 Disables the default action of the button, saves the background 23 color, determines the focus color. 24 ''' 25 QPushButton.__init__(self, *args) 26 MCWidget.__init__(self) 27 self._normalPalette = QPalette(self.palette()) 28 self._focusPalette = QPalette(self.palette()) 29 self._focusPalette.setColor(QPalette.Button, MC.FOCUS_BACKGROUND_COLOR)
30
31 - def focusInEvent(self, e):
32 QPushButton.focusInEvent(self, e) 33 self.setPalette(self._focusPalette)
34
35 - def focusOutEvent(self, e):
36 QPushButton.focusOutEvent(self, e) 37 self.setPalette(self._normalPalette)
38
39 - def keyPressEvent(self, event):
40 ''' 41 Overrides the Key events of the PushButton 42 43 The clicked() signal is emitted when return is pressed. Therefore, 44 the slot connected to the mouse clicked signal will be executed. 45 There is no need to connect it manually several times. 46 ''' 47 if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return: 48 self.animateClick() 49 elif event.key() == Qt.Key_Up or event.key() == Qt.Key_Left: 50 self.focusNextPrevChild(False) 51 elif event.key() == Qt.Key_Down or event.key() == Qt.Key_Right: 52 self.focusNextPrevChild(True) 53 else: 54 QPushButton.keyPressEvent(self, event)
55