[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8405 - trunk/gnue-common/src/logic
From: |
reinhard |
Subject: |
[gnue] r8405 - trunk/gnue-common/src/logic |
Date: |
Fri, 14 Apr 2006 06:06:30 -0500 (CDT) |
Author: reinhard
Date: 2006-04-14 06:06:30 -0500 (Fri, 14 Apr 2006)
New Revision: 8405
Modified:
trunk/gnue-common/src/logic/actions.py
Log:
Basic skeleton for actions, menus, and toolbars.
issue79 in-progress
Modified: trunk/gnue-common/src/logic/actions.py
===================================================================
--- trunk/gnue-common/src/logic/actions.py 2006-04-14 01:12:45 UTC (rev
8404)
+++ trunk/gnue-common/src/logic/actions.py 2006-04-14 11:06:30 UTC (rev
8405)
@@ -29,6 +29,132 @@
# =============================================================================
+# <action>
+# =============================================================================
+
+class GAction(GObjects.GObj):
+ """
+ A piece of code that can be run by the user.
+
+ Actions are pieces of code that can be arbitarily run by the user.
+
+ Actions can be bound to a button, a toolbar button, a menu item, or a
+ trigger. Each action is available in the global namespace in all
+ action/trigger code and can be run explicitly by calling its L{run} method.
+
+ It is possible to assign an icon, a label and a description to an action,
+ which will then be used for all attached buttons, menu items, and toolbar
+ buttons, unless these elements override that information.
+
+ It is possible to enable/disable an action, which will automatically
+ enable/disable all attached buttons, menu items, and toolbar buttons.
+ """
+
+ # -------------------------------------------------------------------------
+ # Attributes
+ # -------------------------------------------------------------------------
+
+ name = None
+ icon = None
+ label = None
+ description = None
+ language = None
+ file = None
+ enabled = True
+
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, parent = None, type = "GCAction"):
+ """
+ Create a GAction instance.
+ """
+ GObjects.GObj.__init__(self, parent, type)
+
+ # Trigger support
+ _triggerGlobal = True
+ _triggerFunctions = {
+ 'run': {
+ 'function': self.__trigger_run}}
+ _triggerProperties = {
+ 'enabled': {
+ 'get': self.__trigger_get_enabled,
+ 'set': self.__trigger_set_enabled}}
+
+
+ # -------------------------------------------------------------------------
+ # Trigger functions
+ # -------------------------------------------------------------------------
+
+ def __trigger_run(self):
+ # TODO
+ pass
+
+ # -------------------------------------------------------------------------
+
+ def __trigger_get_enabled(self):
+ return self.enabled
+
+ # -------------------------------------------------------------------------
+
+ def __trigger_set_enabled(self, value):
+ self.enabled = value
+
+
+# =============================================================================
+# Abstract parent class for all objects that can fire an action
+# =============================================================================
+
+class GCommander(GObjects.GObj):
+ """
+ Any object that is bound to an action.
+ """
+
+ # -------------------------------------------------------------------------
+ # Attributes
+ # -------------------------------------------------------------------------
+
+ name = None
+ icon = None
+ label = None
+ description = None
+ action = None
+ enabled = True
+
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, parent, type):
+ """
+ Create a GCommander instance.
+ """
+ GObjects.GObj.__init__(self, parent, type)
+
+ # Trigger support
+ _triggerProperties = {
+ 'enabled': {
+ 'get': self.__trigger_get_enabled,
+ 'set': self.__trigger_set_enabled}}
+
+
+ # -------------------------------------------------------------------------
+ # Trigger functions
+ # -------------------------------------------------------------------------
+
+ def __trigger_get_enabled(self):
+ return self.enabled
+
+ # -------------------------------------------------------------------------
+
+ def __trigger_set_enabled(self, value):
+ self.enabled = value
+
+
+# =============================================================================
# <menu>
# =============================================================================
@@ -38,6 +164,14 @@
"""
# -------------------------------------------------------------------------
+ # Attributes
+ # -------------------------------------------------------------------------
+
+ name = None
+ label = None
+
+
+ # -------------------------------------------------------------------------
# Constructor
# -------------------------------------------------------------------------
@@ -52,48 +186,123 @@
# <menuitem>
# =============================================================================
-class GMenuItem(GObjects.GObj):
+class GMenuItem(GCommander):
"""
- An item in a menu that fires a trigger when selected.
+ An item in a menu that fires an action when selected.
"""
# -------------------------------------------------------------------------
# Constructor
# -------------------------------------------------------------------------
- def __init__(self, parent = None, type = "GCMenu"):
+ def __init__(self, parent = None, type = "GCMenuItem"):
"""
Create a GMenuItem instance.
"""
GObjects.GObj.__init__(self, parent, type)
- # trigger support
- self._triggerProperties = {
- 'enabled': {
- 'get':self.__trigger_get_enabled,
- 'set':self.__trigger_set_enabled}}
+# =============================================================================
+# <toolbar>
+# =============================================================================
+class GToolbar(GObjects.GObj):
+ """
+ A Toolbar containing L{GToolButton} buttons.
+ """
+
# -------------------------------------------------------------------------
- # Trigger functions
+ # Attributes
# -------------------------------------------------------------------------
- def __trigger_get_enabled(self):
- return self.enabled
+ name = None
+
# -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
- def __trigger_set_enabled(self, value):
- self.enabled = value
+ def __init__(self, parent = None, type = "GCToolbar"):
+ """
+ Create a GToolbar instance.
+ """
+ GObjects.GObj.__init__(self, parent, type)
# =============================================================================
+# <toolbutton>
+# =============================================================================
+
+class GToolButton(GCommander):
+ """
+ A button in a toolbar that fires an action when selected.
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, parent = None, type = "GCToolButton"):
+ """
+ Create a GToolButton instance.
+ """
+ GObjects.GObj.__init__(self, parent, type)
+
+
+# =============================================================================
# XML Element dictionary
# =============================================================================
def getXMLelements(updates = {}):
xmlElements = {
+ 'action': {
+ 'Description' : u_(
+ "A piece of code that can be bound to a button, a menu "
+ "item, a toolbar button or a trigger."),
+ 'BaseClass' : GAction,
+ 'ParentTags' : None,
+ 'Importable' : True,
+ 'MixedContent' : True,
+ 'KeepWhitespace': True,
+ 'Attributes' : {
+ 'name': {
+ 'Label' : u_("Name"),
+ 'Description': u_("Name of this element"),
+ 'Typecast' : GTypecast.name,
+ 'Required' : True,
+ 'Unique' : True},
+ 'icon': {
+ 'Label' : u_("Icon"),
+ 'Description': u_("Icon assigned with this action"),
+ 'Typecast' : GTypecast.name},
+ 'label': {
+ 'Label' : u_("Label"),
+ 'Description': u_("Short text to use for this action"),
+ 'Typecast' : GTypecast.text},
+ 'description': {
+ 'Label' : u_("Description"),
+ 'Description': u_("Long text to use for this action"),
+ 'Typecast' : GTypecast.text},
+ 'language': {
+ 'Label' : u_("Language"),
+ 'Description': u_(
+ "Programming language the code is written in"),
+ 'Typecast' : GTypecast.name,
+ 'ValueSet' : {
+ 'python': {'Label': "Python"}},
+ 'Default' : 'python'},
+ 'file': {
+ 'Label' : u_("Source file"),
+ 'Description': u_(
+ "External file containing the source code"),
+ 'Typecast' : GTypecast.text},
+ 'enabled': {
+ 'Label' : u_("Enabled"),
+ 'Description': u_(
+ "Determines whether this action can be run"),
+ 'Typecast' : GTypecast.boolean,
+ 'Default' : False}}},
'menu': {
'Description': u_(
"A menu or submenu containing menu items and/or submenus"),
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8405 - trunk/gnue-common/src/logic,
reinhard <=