Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Poirier <simpoir@gmail.com>2009-12-06 22:56:25 (GMT)
committer Simon Poirier <simpoir@gmail.com>2009-12-06 23:05:41 (GMT)
commit7008603df84f0ba868c14151939eae986cd1def0 (patch)
tree8e2102e3942d6e03e3046cbdc0ad6be2531fa491
parentcd743b7800481d6607222d1d21ab50afb58747ee (diff)
inspect widgets through probe
-rw-r--r--addons/fetchwidget.py50
-rw-r--r--tutorius/creator.py14
-rw-r--r--tutorius/propwidgets.py39
3 files changed, 90 insertions, 13 deletions
diff --git a/addons/fetchwidget.py b/addons/fetchwidget.py
new file mode 100644
index 0000000..4339a01
--- /dev/null
+++ b/addons/fetchwidget.py
@@ -0,0 +1,50 @@
+# Copyright (C) 2009, Tutorius.org
+#
+# This program 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 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+"""
+This addons aims to give the creator the means to fetch a widget address.
+"""
+
+from sugar.tutorius.filters import EventFilter
+from sugar.tutorius.properties import TUAMProperty
+
+class FetchWidget(EventFilter):
+ """
+ Property containter to be able to fetch TUamProperty from the tutorius
+ service. Mandatory assignation will be done by the probe so we can
+ inspect the application through DBUS.
+ """
+ # widget address property
+ widaddr = TUAMProperty("0")
+
+ def __init__(self, widaddr=None):
+ """
+ Constructor - Change a widget color
+ @param widaddr: the widget address (UAM)
+ """
+ EventFilter.__init__(self)
+
+ if widaddr:
+ self.widaddr = widaddr
+
+__event__ = {
+ "name" : FetchWidget.__name__,
+ "display_name" : "Fetch Widget",
+ "icon" : "",
+ "class" : FetchWidget,
+ "mandatory_props" : ["widaddr"],
+ "test" : True,
+}
+
diff --git a/tutorius/creator.py b/tutorius/creator.py
index 9413186..f7f9752 100644
--- a/tutorius/creator.py
+++ b/tutorius/creator.py
@@ -264,6 +264,16 @@ class Creator(Object):
action_type = self._propedit.actions_list[path][ToolBox.ICON_NAME]
LOGGER.debug("Creator :: Adding an action = %s"%(action_type))
action = addon.create(action_type)
+
+ # force mandatory props
+ meta = addon.get_addon_meta(action_type)
+ for propname in meta['mandatory_props']:
+ prop = getattr(type(action), propname)
+ prop.widget_class.run_dialog(self._overview.win,
+ action,
+ propname,
+ probe_mgr=self._probe_mgr)
+
return_cb = partial(self._action_installed_cb, action)
self._probe_mgr.install(action,
action_installed_cb=return_cb,
@@ -327,6 +337,7 @@ class Creator(Object):
self._probe_mgr.update(address,
action,
is_editing=True)
+ self._propedit.action = action
def _action_refresh_cb(self, widget, evt, action):
"""
@@ -558,7 +569,8 @@ class ToolBox(object):
#Value field
prop = getattr(type(action), propname)
propedit = prop.widget_class(self.__parent, action, propname,
- self._refresh_action_cb)
+ self._refresh_action_cb,
+ probe_mgr=default_creator()._probe_mgr)
self._propedits.append(propedit)
row.pack_end(propedit.widget)
diff --git a/tutorius/propwidgets.py b/tutorius/propwidgets.py
index 7e78ba4..eb756fe 100644
--- a/tutorius/propwidgets.py
+++ b/tutorius/propwidgets.py
@@ -192,18 +192,22 @@ class PropWidget(object):
Base Class for property editing widgets.
Subclasses should implement create_widget, run_dialog and refresh_widget
"""
- def __init__(self, parent, edit_object, prop_name, changed_callback=None):
+ def __init__(self, parent, edit_object, prop_name, changed_callback=None,
+ probe_mgr=None):
"""Constructor
@param parent parent widget
@param edit_object TPropContainer being edited
@param prop_name name of property being edited
@param changed_callback optional callable to call on value changes
+ @type probe_mgr: ProbeMgr instance or None
+ @param probe_mgr: the probe manager to use to inspect activities
"""
self._parent = parent
self._edit_object = edit_object
self._propname = prop_name
self._widget = None
self._changed_cb = changed_callback
+ self._probe_mgr = probe_mgr
############################################################
# Begin Properties
@@ -254,13 +258,14 @@ class PropWidget(object):
return widget
@classmethod
- def run_dialog(cls, parent, obj_prop, propname):
+ def run_dialog(cls, parent, obj_prop, propname, probe_mgr=None):
"""
Class Method.
Prompts the user for changing an object's property
@param parent widget
@param obj_prop TPropContainer to edit
@param propname name of property to edit
+ @param probe_mgr a ProbeMgr instance for activity inspection
"""
raise NotImplementedError()
@@ -318,13 +323,14 @@ class StringPropWidget(PropWidget):
self.widget.get_buffer().set_text(str(self.obj_prop)) #unicode() ?
@classmethod
- def run_dialog(cls, parent, obj_prop, propname):
+ def run_dialog(cls, parent, obj_prop, propname, probe_mgr=None):
"""
Class Method.
Prompts the user for changing an object's property
@param parent widget
@param obj_prop TPropContainer to edit
@param propname name of property to edit
+ @param probe_mgr a ProbeMgr instance for activity inspection
"""
dlg = TextInputDialog(parent,
text="Mandatory property",
@@ -380,8 +386,8 @@ class UAMPropWidget(PropWidget):
"""Allows editing an UAM property with a widget chooser"""
def _show_uam_chooser(self, widget):
"""show the UAM chooser"""
- selector = WidgetSelector(self.parent)
- self.obj_prop = selector.select()
+ evt = self._probe_mgr.create_event('FetchWidget')
+ self.obj_prop = evt.widaddr
self.notify()
def create_widget(self, init_value=None):
@@ -401,17 +407,24 @@ class UAMPropWidget(PropWidget):
self.widget.set_label(self.obj_prop)
@classmethod
- def run_dialog(cls, parent, obj_prop, propname):
+ def run_dialog(cls, parent, obj_prop, propname, probe_mgr=None):
"""
Class Method.
Prompts the user for changing an object's property
@param parent widget
@param obj_prop TPropContainer to edit
@param propname name of property to edit
- """
- selector = WidgetSelector(parent)
- value = selector.select()
- setattr(obj_prop, propname, selector.select())
+ @param probe_mgr a ProbeMgr instance for activity inspection
+ """
+ if probe_mgr:
+ evt = probe_mgr.create_event('FetchWidget')
+ setattr(obj_prop, propname, evt.widaddr)
+ elif parent:
+ selector = WidgetSelector(parent)
+ value = selector.select()
+ setattr(obj_prop, propname, selector.select())
+ else:
+ raise RuntimeError('No parent or probe_mgr passed for inspection.')
class EventTypePropWidget(PropWidget):
"""Allows editing an EventType property"""
@@ -422,13 +435,14 @@ class EventTypePropWidget(PropWidget):
self.widget.set_text(str(self.obj_prop))
@classmethod
- def run_dialog(cls, parent, obj_prop, propname):
+ def run_dialog(cls, parent, obj_prop, propname, probe_mgr=None):
"""
Class Method.
Prompts the user for changing an object's property
@param parent widget
@param obj_prop TPropContainer to edit
@param propname name of property to edit
+ @param probe_mgr a ProbeMgr instance for activity inspection
"""
try:
dlg = SignalInputDialog(parent,
@@ -478,12 +492,13 @@ class IntArrayPropWidget(PropWidget):
children[i].set_text(str(value[i]))
@classmethod
- def run_dialog(cls, parent, obj_prop, propname):
+ def run_dialog(cls, parent, obj_prop, propname, probe_mgr=None):
"""
Class Method.
Prompts the user for changing an object's property
@param parent widget
@param obj_prop TPropContainer to edit
@param propname name of property to edit
+ @param probe_mgr a ProbeMgr instance for activity inspection
"""
pass