[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8474 - trunk/gnue-common/src/logic
From: |
reinhard |
Subject: |
[gnue] r8474 - trunk/gnue-common/src/logic |
Date: |
Thu, 18 May 2006 09:59:02 -0500 (CDT) |
Author: reinhard
Date: 2006-05-18 09:59:02 -0500 (Thu, 18 May 2006)
New Revision: 8474
Added:
trunk/gnue-common/src/logic/usercode.py
Removed:
trunk/gnue-common/src/logic/actions.py
Modified:
trunk/gnue-common/src/logic/GTrigger.py
Log:
Prepared common base class for triggers and actions.
Modified: trunk/gnue-common/src/logic/GTrigger.py
===================================================================
--- trunk/gnue-common/src/logic/GTrigger.py 2006-05-18 14:14:23 UTC (rev
8473)
+++ trunk/gnue-common/src/logic/GTrigger.py 2006-05-18 14:59:02 UTC (rev
8474)
@@ -21,15 +21,10 @@
#
# $Id$
-import string
-from xml.sax import saxutils
-
-from gnue.common.apps import errors, GDebug
-from gnue.common.definitions.GObjects import GObj
-from gnue.common.definitions.GRootObj import GRootObj
-from gnue.common.definitions.GParserHelpers import GContent
+from gnue.common.apps import errors
from gnue.common.formatting import GTypecast
+from gnue.common.logic.usercode import UserCode
from gnue.common.logic import language
__all__ = ['InvalidTriggerTypeError', 'InvalidTriggerFiredError', 'GTrigger',
@@ -69,16 +64,13 @@
# <trigger>
# =============================================================================
-class GTrigger(GObj):
+class GTrigger(UserCode):
# -------------------------------------------------------------------------
# Attributes
# -------------------------------------------------------------------------
- name = None
type = None
- language = None
- file = None
src = None
@@ -88,21 +80,8 @@
def __init__(self, parent=None):
- GObj.__init__(self, parent, 'GCTrigger')
+ UserCode.__init__(self, parent, 'GCTrigger')
- self._xml_content_as_cdata_ = gConfig('StoreTriggersAsCDATA')
-
- # Find the next GRootObj. This can be, for example, either a <form> or
- # a <dialog> within a <form>. This most be done because every dialog
- # has its own global trigger namespace and its own trigger dictionary.
- parent = self.getParent()
- while not isinstance(parent, GRootObj) \
- and parent.getParent() is not None:
- parent = parent.getParent()
- self.__root = parent
-
- self.__function = None
-
self._inits = [self.__initialize]
@@ -125,22 +104,12 @@
if self.getParent():
self.getParent().associateTrigger(self.type, self)
else:
- self.__root._triggerDictionary[self.name] = self
+ self._root._triggerDictionary[self.name] = self
if self.src is None:
- execution_context = language.create_execution_context(
- language = self.language,
- name = repr(self),
- local_namespace = {},
- global_namespace = self.__root._triggerns,
- builtin_namespace = {})
+ self._compile(['self'])
- self.__function = execution_context.build_function(
- name = self.getDescription(),
- parameters = ['self'],
- code = self.getChildrenAsContent())
-
# -------------------------------------------------------------------------
# Run the trigger code
# -------------------------------------------------------------------------
@@ -151,9 +120,9 @@
# function can have a parameter "self".
if __self.src is not None:
- __self.__root._triggerDictionary[__self.src](*args, **params)
- elif __self.__function is not None:
- __self.__function(*args, **params)
+ __self._root._triggerDictionary[__self.src](*args, **params)
+ else:
+ __self._run(*args, **params)
# -------------------------------------------------------------------------
@@ -167,7 +136,7 @@
if self.type == 'NAMED':
return self.name
else:
- return string.upper(self.type)
+ return self.type.upper()
# =============================================================================
Deleted: trunk/gnue-common/src/logic/actions.py
===================================================================
--- trunk/gnue-common/src/logic/actions.py 2006-05-18 14:14:23 UTC (rev
8473)
+++ trunk/gnue-common/src/logic/actions.py 2006-05-18 14:59:02 UTC (rev
8474)
@@ -1,424 +0,0 @@
-# GNU Enterprise Common Library - Menus And Toolbars
-#
-# Copyright 2000-2006 Free Software Foundation
-#
-# This file is part of GNU Enterprise.
-#
-# GNU Enterprise is free software; you can redistribute it
-# and/or modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation; either
-# version 2, or (at your option) any later version.
-#
-# GNU Enterprise is distributed in the hope that it will be
-# useful, but WITHOUT ANY WARRANTY; without even the implied
-# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-# PURPOSE. See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public
-# License along with program; see the file COPYING. If not,
-# write to the Free Software Foundation, Inc., 59 Temple Place
-# - Suite 330, Boston, MA 02111-1307, USA.
-#
-# $Id: GDataSource.py 8315 2006-03-31 17:14:37Z reinhard $
-
-"""
-Classes for the menu and toolbar object trees.
-"""
-
-from gnue.common.definitions import GObjects
-from gnue.common.formatting import GTypecast
-
-__all__ = ['GAction', 'GMenu', 'GMenuItem', 'GToolbar', 'GToolButton']
-
-
-# =============================================================================
-# <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, object_type = "GCAction"):
- """
- Create a GAction instance.
- """
- GObjects.GObj.__init__(self, parent, object_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, object_type):
- """
- Create a GCommander instance.
- """
- GObjects.GObj.__init__(self, parent, object_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>
-# =============================================================================
-
-class GMenu(GObjects.GObj):
- """
- A Menu that can either be the menu bar, a context menu, or a submenu.
- """
-
- # -------------------------------------------------------------------------
- # Attributes
- # -------------------------------------------------------------------------
-
- name = None
- label = None
-
-
- # -------------------------------------------------------------------------
- # Constructor
- # -------------------------------------------------------------------------
-
- def __init__(self, parent = None, object_type = "GCMenu"):
- """
- Create a GMenu instance.
- """
- GObjects.GObj.__init__(self, parent, object_type)
-
-
-# =============================================================================
-# <menuitem>
-# =============================================================================
-
-class GMenuItem(GCommander):
- """
- An item in a menu that fires an action when selected.
- """
-
- # -------------------------------------------------------------------------
- # Constructor
- # -------------------------------------------------------------------------
-
- def __init__(self, parent = None, object_type = "GCMenuItem"):
- """
- Create a GMenuItem instance.
- """
- GCommander.__init__(self, parent, object_type)
-
-
-# =============================================================================
-# <toolbar>
-# =============================================================================
-
-class GToolbar(GObjects.GObj):
- """
- A Toolbar containing L{GToolButton} buttons.
- """
-
- # -------------------------------------------------------------------------
- # Attributes
- # -------------------------------------------------------------------------
-
- name = None
-
-
- # -------------------------------------------------------------------------
- # Constructor
- # -------------------------------------------------------------------------
-
- def __init__(self, parent = None, object_type = "GCToolbar"):
- """
- Create a GToolbar instance.
- """
- GObjects.GObj.__init__(self, parent, object_type)
-
-
-# =============================================================================
-# <toolbutton>
-# =============================================================================
-
-class GToolButton(GCommander):
- """
- A button in a toolbar that fires an action when selected.
- """
-
- # -------------------------------------------------------------------------
- # Constructor
- # -------------------------------------------------------------------------
-
- def __init__(self, parent = None, object_type = "GCToolButton"):
- """
- Create a GToolButton instance.
- """
- GCommander.__init__(self, parent, object_type)
-
-
-# =============================================================================
-# XML Element dictionary
-# =============================================================================
-
-def get_xml_elements(updates):
- """
- Return the XML Element dictionary for the objects defined in this module.
- """
-
- checktype(updates, dict)
-
- xml_elements = {
- '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"),
- 'BaseClass' : GMenu,
- 'ParentTags' : None,
- 'Attributes' : {
- 'name': {
- 'Label' : u_("Name"),
- 'Description': u_("Name of this element"),
- 'Typecast' : GTypecast.name,
- 'Required' : True,
- 'Unique' : True},
- 'label': {
- 'Label' : u_("Label"),
- 'Description': u_("Text to use if this is a submenu"),
- 'Typecast' : GTypecast.text}}},
- 'menuitem': {
- 'Description': u_(
- "A menu item that fires a trigger when selected"),
- 'BaseClass' : GMenu,
- 'ParentTags' : ['menu'],
- '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 to display besides this menu item"),
- 'Typecast' : GTypecast.name},
- 'label': {
- 'Label' : u_("Label"),
- 'Description': u_("Text to use for this menu item"),
- 'Typecast' : GTypecast.text},
- 'description': {
- 'Label' : u_("Description"),
- 'Description': u_(
- "Text to display in the status bar for this menu "
- "item"),
- 'Typecast' : GTypecast.text},
- 'action': {
- 'Label' : u_("Action"),
- 'Description': u_(
- "Name of the trigger to run whenever this menu "
- "item is selected"),
- 'Typecast' : GTypecast.name,
- 'References' : 'trigger.name'},
- 'enabled': {
- 'Label' : u_("Enabled"),
- 'Description': u_(
- "Determines whether this menu item will be "
- "enabled by default"),
- 'Typecast' : GTypecast.boolean,
- 'Default' : False}}},
- 'toolbar': {
- 'Description': u_("A toolbar containing tool buttons"),
- 'BaseClass' : GToolbar,
- 'ParentTags' : None,
- 'Attributes' : {
- 'name': {
- 'Label' : u_("Name"),
- 'Description': u_("Name of this element"),
- 'Typecast' : GTypecast.name,
- 'Required' : True,
- 'Unique' : True}}},
- 'toolbutton': {
- 'Description': u_("A button on a toolbar"),
- 'BaseClass' : GToolButton,
- 'ParentTags' : ['toolbar'],
- '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 to display on the button"),
- 'Typecast' : GTypecast.name},
- 'label': {
- 'Label' : u_("Label"),
- 'Description': u_("Text to display on the button"),
- 'Typecast' : GTypecast.text},
- 'description': {
- 'Label' : u_("Description"),
- 'Description': u_(
- "Text to display in a tooltip window"),
- 'Typecast' : GTypecast.text},
- 'action': {
- 'Label' : u_("Action"),
- 'Description': u_(
- "Name of the trigger to run whenever this button "
- "is clicked"),
- 'Typecast' : GTypecast.name,
- 'References' : 'trigger.name'},
- 'enabled': {
- 'Label' : u_("Enabled"),
- 'Description': u_(
- "Determines whether this button will be enabled "
- "by default"),
- 'Typecast' : GTypecast.boolean,
- 'Default' : False}}}}
-
- for alteration in updates.keys():
- xml_elements[alteration].update(updates[alteration])
-
- return xml_elements
Copied: trunk/gnue-common/src/logic/usercode.py (from rev 8473,
trunk/gnue-common/src/logic/actions.py)
===================================================================
--- trunk/gnue-common/src/logic/actions.py 2006-05-18 14:14:23 UTC (rev
8473)
+++ trunk/gnue-common/src/logic/usercode.py 2006-05-18 14:59:02 UTC (rev
8474)
@@ -0,0 +1,509 @@
+# GNU Enterprise Common Library - Triggers, Actions, Menus, And Toolbars
+#
+# Copyright 2000-2006 Free Software Foundation
+#
+# This file is part of GNU Enterprise.
+#
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id$
+
+"""
+Classes for all the object trees that handle user code: Triggers, Actions,
+Menus, and Toolbars
+"""
+
+from gnue.common.definitions import GObjects, GRootObj
+from gnue.common.formatting import GTypecast
+
+from gnue.common.logic import language
+
+__all__ = ['GAction', 'GMenu', 'GMenuItem', 'GToolbar', 'GToolButton']
+
+
+# =============================================================================
+# Abstract parent class for action and trigger
+# =============================================================================
+
+class UserCode(GObjects.GObj):
+ """
+ A Piece of user defined code.
+
+ This class is the abstract base class for L{GAction} and
+ L{GTrigger.GTrigger} and implements most of the things related to compiling
+ and executing code that was provided in a form/report/whatever definition.
+ """
+
+ # -------------------------------------------------------------------------
+ # Attributes
+ # -------------------------------------------------------------------------
+
+ name = None
+ language = None
+ file = None
+
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, parent=None, object_type=None):
+ """
+ Initialize a UserCode instance.
+ """
+
+ GObjects.GObj.__init__(self, parent, object_type)
+
+ self._xml_content_as_cdata_ = gConfig('StoreTriggersAsCDATA')
+
+ # Find the next GRootObj. This can be, for example, either a <form> or
+ # a <dialog> within a <form>. This most be done because every dialog
+ # has its own global trigger namespace and its own trigger dictionary.
+ parent = self.getParent()
+ while not isinstance(parent, GRootObj.GRootObj) \
+ and parent.getParent() is not None:
+ parent = parent.getParent()
+ self._root = parent # also used by GTrigger
+
+ self.__function = None
+
+
+ # -------------------------------------------------------------------------
+ # Compile program code
+ # -------------------------------------------------------------------------
+
+ def _compile(self, parameters):
+ """
+ Compile the code.
+ """
+
+ execution_context = language.create_execution_context(
+ language = self.language,
+ name = repr(self),
+ local_namespace = {},
+ global_namespace = self._root._triggerns,
+ builtin_namespace = {})
+
+ self.__function = execution_context.build_function(
+ name = self.getDescription(),
+ parameters = parameters,
+ code = self.getChildrenAsContent())
+
+
+ # -------------------------------------------------------------------------
+ # Run program code
+ # -------------------------------------------------------------------------
+
+ def _run(__self, *args, **params):
+ """
+ Run the code.
+ """
+
+ # We call our own self parameter "__self" here so that the user
+ # function can have a parameter "self".
+
+ if __self.__function is not None:
+ __self.__function(*args, **params)
+
+
+# =============================================================================
+# <action>
+# =============================================================================
+
+class GAction(UserCode):
+ """
+ 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
+ # -------------------------------------------------------------------------
+
+ icon = None
+ label = None
+ description = None
+ enabled = True
+
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, parent = None, object_type = "GCAction"):
+ """
+ Create a GAction instance.
+ """
+ UserCode.__init__(self, parent, object_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, object_type):
+ """
+ Create a GCommander instance.
+ """
+ GObjects.GObj.__init__(self, parent, object_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>
+# =============================================================================
+
+class GMenu(GObjects.GObj):
+ """
+ A Menu that can either be the menu bar, a context menu, or a submenu.
+ """
+
+ # -------------------------------------------------------------------------
+ # Attributes
+ # -------------------------------------------------------------------------
+
+ name = None
+ label = None
+
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, parent = None, object_type = "GCMenu"):
+ """
+ Create a GMenu instance.
+ """
+ GObjects.GObj.__init__(self, parent, object_type)
+
+
+# =============================================================================
+# <menuitem>
+# =============================================================================
+
+class GMenuItem(GCommander):
+ """
+ An item in a menu that fires an action when selected.
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, parent = None, object_type = "GCMenuItem"):
+ """
+ Create a GMenuItem instance.
+ """
+ GCommander.__init__(self, parent, object_type)
+
+
+# =============================================================================
+# <toolbar>
+# =============================================================================
+
+class GToolbar(GObjects.GObj):
+ """
+ A Toolbar containing L{GToolButton} buttons.
+ """
+
+ # -------------------------------------------------------------------------
+ # Attributes
+ # -------------------------------------------------------------------------
+
+ name = None
+
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, parent = None, object_type = "GCToolbar"):
+ """
+ Create a GToolbar instance.
+ """
+ GObjects.GObj.__init__(self, parent, object_type)
+
+
+# =============================================================================
+# <toolbutton>
+# =============================================================================
+
+class GToolButton(GCommander):
+ """
+ A button in a toolbar that fires an action when selected.
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, parent = None, object_type = "GCToolButton"):
+ """
+ Create a GToolButton instance.
+ """
+ GCommander.__init__(self, parent, object_type)
+
+
+# =============================================================================
+# XML Element dictionary
+# =============================================================================
+
+def get_xml_elements(updates):
+ """
+ Return the XML Element dictionary for the objects defined in this module.
+ """
+
+ checktype(updates, dict)
+
+ xml_elements = {
+ '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"),
+ 'BaseClass' : GMenu,
+ 'ParentTags' : None,
+ 'Attributes' : {
+ 'name': {
+ 'Label' : u_("Name"),
+ 'Description': u_("Name of this element"),
+ 'Typecast' : GTypecast.name,
+ 'Required' : True,
+ 'Unique' : True},
+ 'label': {
+ 'Label' : u_("Label"),
+ 'Description': u_("Text to use if this is a submenu"),
+ 'Typecast' : GTypecast.text}}},
+ 'menuitem': {
+ 'Description': u_(
+ "A menu item that fires a trigger when selected"),
+ 'BaseClass' : GMenu,
+ 'ParentTags' : ['menu'],
+ '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 to display besides this menu item"),
+ 'Typecast' : GTypecast.name},
+ 'label': {
+ 'Label' : u_("Label"),
+ 'Description': u_("Text to use for this menu item"),
+ 'Typecast' : GTypecast.text},
+ 'description': {
+ 'Label' : u_("Description"),
+ 'Description': u_(
+ "Text to display in the status bar for this menu "
+ "item"),
+ 'Typecast' : GTypecast.text},
+ 'action': {
+ 'Label' : u_("Action"),
+ 'Description': u_(
+ "Name of the trigger to run whenever this menu "
+ "item is selected"),
+ 'Typecast' : GTypecast.name,
+ 'References' : 'trigger.name'},
+ 'enabled': {
+ 'Label' : u_("Enabled"),
+ 'Description': u_(
+ "Determines whether this menu item will be "
+ "enabled by default"),
+ 'Typecast' : GTypecast.boolean,
+ 'Default' : False}}},
+ 'toolbar': {
+ 'Description': u_("A toolbar containing tool buttons"),
+ 'BaseClass' : GToolbar,
+ 'ParentTags' : None,
+ 'Attributes' : {
+ 'name': {
+ 'Label' : u_("Name"),
+ 'Description': u_("Name of this element"),
+ 'Typecast' : GTypecast.name,
+ 'Required' : True,
+ 'Unique' : True}}},
+ 'toolbutton': {
+ 'Description': u_("A button on a toolbar"),
+ 'BaseClass' : GToolButton,
+ 'ParentTags' : ['toolbar'],
+ '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 to display on the button"),
+ 'Typecast' : GTypecast.name},
+ 'label': {
+ 'Label' : u_("Label"),
+ 'Description': u_("Text to display on the button"),
+ 'Typecast' : GTypecast.text},
+ 'description': {
+ 'Label' : u_("Description"),
+ 'Description': u_(
+ "Text to display in a tooltip window"),
+ 'Typecast' : GTypecast.text},
+ 'action': {
+ 'Label' : u_("Action"),
+ 'Description': u_(
+ "Name of the trigger to run whenever this button "
+ "is clicked"),
+ 'Typecast' : GTypecast.name,
+ 'References' : 'trigger.name'},
+ 'enabled': {
+ 'Label' : u_("Enabled"),
+ 'Description': u_(
+ "Determines whether this button will be enabled "
+ "by default"),
+ 'Typecast' : GTypecast.boolean,
+ 'Default' : False}}}}
+
+ for alteration in updates.keys():
+ xml_elements[alteration].update(updates[alteration])
+
+ return xml_elements
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8474 - trunk/gnue-common/src/logic,
reinhard <=