Repository navigation
Expand file tree
/
Copy pathcmdaction.py
More file actions
66 lines (53 loc) · 1.61 KB
/
Copy pathcmdaction.py
File metadata and controls
66 lines (53 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'''
Created on May 12, 2010
@author: gertwin
'''
# This is only needed for Python v2 but is harmless for Python v3.
#import sip
#sip.setapi('QString', 2)
from PyQt4 import QtCore, QtGui
class CmdAction(QtGui.QAction):
'''
Derived action class to hold a command name.
The FunctionHandler class handles signals emitted by this class.
'''
def __init__(self, command, icon, text, parent, function_handler):
'''
Parameters:
command: name of the command.
function_handler: reference to the function_handler object.
'''
if not icon is None:
super(CmdAction, self).__init__(icon, text, parent, triggered=self._actionHandler)
else:
super(CmdAction, self).__init__(text, parent, triggered=self._actionHandler)
# command name
self.__command = command
# function handler
self.__function_handler = function_handler
# visible
self.__visible=True
return
def show(self):
"""
show the command
"""
self.setEnabled(True)
def hide(self):
"""
hide the command
"""
self.setEnabled(False)
@property
def command(self):
"""
get the command name
"""
return self.__command
def _actionHandler(self):
'''
All actions are handled by the function handler.
From the function handler the command call-back is called.
'''
self.__function_handler.evaluate(self.__command)
return