[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8490 - in trunk: gnue-common/src/logic gnue-forms/src/uidrivers/
From: |
reinhard |
Subject: |
[gnue] r8490 - in trunk: gnue-common/src/logic gnue-forms/src/uidrivers/wx26/widgets |
Date: |
Mon, 12 Jun 2006 09:07:22 -0500 (CDT) |
Author: reinhard
Date: 2006-06-12 09:07:22 -0500 (Mon, 12 Jun 2006)
New Revision: 8490
Modified:
trunk/gnue-common/src/logic/usercode.py
trunk/gnue-forms/src/uidrivers/wx26/widgets/menuitem.py
Log:
Added possibility to dynamically enable/disable menu items.
issue79 in-progress
Modified: trunk/gnue-common/src/logic/usercode.py
===================================================================
--- trunk/gnue-common/src/logic/usercode.py 2006-06-08 12:28:54 UTC (rev
8489)
+++ trunk/gnue-common/src/logic/usercode.py 2006-06-12 14:07:22 UTC (rev
8490)
@@ -161,6 +161,9 @@
"""
UserCode.__init__(self, parent, object_type)
+ #: Commanders attached to this action
+ self.__commanders = []
+
# Trigger support
self._triggerGlobal = True
self._triggerFunctions = {
@@ -210,8 +213,25 @@
def __trigger_set_enabled(self, value):
self.enabled = value
+ for commander in self.__commanders:
+ commander.update_status()
+ # -------------------------------------------------------------------------
+ # Register commander attached to this action
+ # -------------------------------------------------------------------------
+
+ def register_commander(self, commander):
+ """
+ Registers a commander that is attached to this action.
+
+ Whenever this action is enabled or disabled, it will automatically
+ enable/disable all commanders attached to it.
+ """
+
+ self.__commanders.append(commander)
+
+
# =============================================================================
# Abstract parent class for all objects that can fire an action
# =============================================================================
@@ -246,6 +266,12 @@
#: L{GAction} object linked to this commander.
self.__action = None
+ #: Whether the UI widget is enabled or not. The UIxxx implementations
+ #: read this variable on initialisation; if at some point the UI
+ #: widgets are initialized with parameters, this variable can be made
+ #: private.
+ self._ui_enabled = False
+
# Trigger support
_triggerProperties = {
'enabled': {
@@ -270,6 +296,10 @@
parent = parent.getParent()
self.__action = parent._actions[self.action]
+ # Register ourselves to the action so we get notified of action
+ # enables/disables
+ self.__action.register_commander(self)
+
# Copy icon, label and description from action object if not set
# here. We can safely do this here because designer doesn't run
# this code.
@@ -280,7 +310,11 @@
if self.description is None:
self.description = self.__action.description
+ # Set a variable to determine whether the UI widget should be
+ # enabled or not.
+ self._ui_enabled = self.enabled and self.__action.enabled
+
# -------------------------------------------------------------------------
# Trigger functions
# -------------------------------------------------------------------------
@@ -292,9 +326,40 @@
def __trigger_set_enabled(self, value):
self.enabled = value
+ self.update_status()
# -------------------------------------------------------------------------
+ # Update enabled/disabled status
+ # -------------------------------------------------------------------------
+
+ def update_status(self):
+ """
+ Update the enabled/disabled status of the commander.
+
+ The attached action calls this function whenever its enabled/disabled
+ status changes, so the commander can adjust the status of the user
+ interface element.
+ """
+
+ if self.__action is not None:
+ new_ui_enabled = self.enabled and self.__action.enabled
+ else:
+ new_ui_enabled = False
+
+ if new_ui_enabled != self._ui_enabled:
+ # FIXME: This relies on the object having an uiWidget assigned.
+ # Either GCommander should be a descendant of GFObj (and thus be
+ # moved to gnue-forms), or the UI buildup should be moved to
+ # common.
+ if new_ui_enabled:
+ self.uiWidget.do_enable()
+ else:
+ self.uiWidget.do_disable()
+ self._ui_enabled = new_ui_enabled
+
+
+ # -------------------------------------------------------------------------
# Fire the commander
# -------------------------------------------------------------------------
@@ -456,7 +521,7 @@
'Description': u_(
"Determines whether this action can be run"),
'Typecast' : GTypecast.boolean,
- 'Default' : False}}},
+ 'Default' : True}}},
'menu': {
'Description': u_(
"A menu or submenu containing menu items and/or submenus"),
@@ -513,7 +578,7 @@
"Determines whether this menu item will be "
"enabled by default"),
'Typecast' : GTypecast.boolean,
- 'Default' : False}}},
+ 'Default' : True}}},
'toolbar': {
'Description': u_("A toolbar containing tool buttons"),
'BaseClass' : GToolbar,
@@ -562,7 +627,7 @@
"Determines whether this button will be enabled "
"by default"),
'Typecast' : GTypecast.boolean,
- 'Default' : False}}}}
+ 'Default' : True}}}}
for alteration in updates.keys():
xml_elements[alteration].update(updates[alteration])
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/menuitem.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/menuitem.py 2006-06-08
12:28:54 UTC (rev 8489)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/menuitem.py 2006-06-12
14:07:22 UTC (rev 8490)
@@ -45,23 +45,28 @@
"""
if self._gfObject.label is not None:
- result = wx.MenuItem(event.container, wx.ID_ANY,
+ widget = wx.MenuItem(event.container, wx.ID_ANY,
self._gfObject.label, self._gfObject.description or u"")
if self._gfObject.icon:
image = wx.Image(self._gfObject.icon, wx.BITMAP_TYPE_PNG)
- result.SetBitmap(image.ConvertToBitmap())
+ widget.SetBitmap(image.ConvertToBitmap())
- wx.EVT_MENU(wx.GetApp(), result.GetId(), self.__on_menu)
+ wx.EVT_MENU(wx.GetApp(), widget.GetId(), self.__on_menu)
- event.container.AppendItem(result)
+ event.container.AppendItem(widget)
+
+ if not self._gfObject._ui_enabled:
+ widget.Enable(False)
else:
- result = None
+ widget = None
event.container.AppendSeparator()
- return result
+ self.__widget = widget
+ return widget
+
# -------------------------------------------------------------------------
# Events
# -------------------------------------------------------------------------
@@ -71,6 +76,21 @@
self._gfObject.fire()
+ # -------------------------------------------------------------------------
+ # Enable/disable menu item
+ # -------------------------------------------------------------------------
+
+ def do_enable(self):
+ if self.__widget is not None:
+ self.__widget.Enable(True)
+
+ # -------------------------------------------------------------------------
+
+ def do_disable(self):
+ if self.__widget is not None:
+ self.__widget.Enable(False)
+
+
# =============================================================================
# Configuration data
# =============================================================================
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8490 - in trunk: gnue-common/src/logic gnue-forms/src/uidrivers/wx26/widgets,
reinhard <=