SF.net SVN: fclient: [630] trunk/fclient/src/fclient/lib/qt4ex/lib/actions. py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-07-15 23:43:59
|
Revision: 630
http://fclient.svn.sourceforge.net/fclient/?rev=630&view=rev
Author: jUrner
Date: 2008-07-15 16:44:05 -0700 (Tue, 15 Jul 2008)
Log Message:
-----------
new class to tame actions a bit
Added Paths:
-----------
trunk/fclient/src/fclient/lib/qt4ex/lib/actions.py
Added: trunk/fclient/src/fclient/lib/qt4ex/lib/actions.py
===================================================================
--- trunk/fclient/src/fclient/lib/qt4ex/lib/actions.py (rev 0)
+++ trunk/fclient/src/fclient/lib/qt4ex/lib/actions.py 2008-07-15 23:44:05 UTC (rev 630)
@@ -0,0 +1,114 @@
+#TODO: not yet completely implemented
+
+
+from PyQt4 import QtCore, QtGui
+#******************************************************************************
+#
+#******************************************************************************
+class Action(QtGui.QAction):
+
+ def __init__(self, text, parent, userData=None):
+ QtGui.QAction.__init__(self, text, parent)
+ self._userData = userData
+
+ def userData(self):
+ return self._userData
+
+ def setUserData(self, data):
+ self._userData = data
+
+
+#******************************************************************************
+#
+#******************************************************************************
+
+class ActionsBase(QtCore.QObject):
+
+ def __init__(self, parent):
+ QtCore.QObject.__init__(self, parent)
+ self._actions = []
+ self._actionNames = []
+ self._dummyGroups = [] # cheat a bit to always trigger SIGNAL('triggered(QAction*)')
+
+ def action(self,
+ name=None,
+ text=None,
+ group=None,
+ trigger=None,
+ isCheckable=False,
+ isChecked=False,
+ isEnabled=True,
+ userData=None,
+ ):
+ if group is None:
+ group = QtGui.QActionGroup(self.parent())
+ self._dummyGroups.append(group) #TODO: is this necessary?
+ act = Action(text, group, userData=userData)
+ group.addAction(act)
+ if trigger is not None:
+ self.parent().connect(group, QtCore.SIGNAL('triggered(QAction*)'), trigger)
+ else:
+ act = Action(text, group, userData=userData)
+ group.addAction(act)
+
+ act.setObjectName(name)
+ if isCheckable:
+ act.setCheckable(True)
+ act.setChecked(isChecked)
+ act.setEnabled(isEnabled)
+
+ self._registerAction(name, act)
+ return act
+
+
+ def group(self, parent=None, name=None, trigger=None, isExclusive=False):
+ if parent is None:
+ parent = self.parent()
+ group = QtGui.QActionGroup(parent)
+ group.setObjectName(name)
+ if trigger is not None:
+ self.parent().connect(group, QtCore.SIGNAL('triggered(QAction*)'), trigger)
+ group.setExclusive(isExclusive)
+
+ self._registerAction(name, group)
+ return group
+
+
+ def _registerAction(self, name, obj):
+ if name in self._actionNames:
+ raise valueError('action with that name already exists: %r' % name)
+ self._actionNames.append(name)
+ self._actions.append(obj)
+
+
+ def __getitem__(self, name):
+ return self._actions[self._actionNames.index(name)]
+
+
+ def get(self, name, default=None):
+ if name in self._actionNames:
+ return self[name]
+ return default
+
+
+
+def foo(a):
+ print a
+
+ gr = QtGui.QActionGroup(None)
+ gr.connect(gr, QtCore.SIGNAL('triggered(QAction*)'), foo)
+
+
+ a = QtGui.QAction(gr)
+ gr.addAction(a)
+
+ a.trigger()
+
+
+
+
+
+
+
+
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|