[mousetrap] Added addons handler with CPU addon
- From: Flavio Percoco <flaper src gnome org>
- To: svn-commits-list gnome org
- Subject: [mousetrap] Added addons handler with CPU addon
- Date: Tue, 23 Jun 2009 17:42:33 -0400 (EDT)
commit 6f1d9afc688afe07cf1cd7129648d5eea01babeb
Author: Flavio Percoco Premoli <flaper87 gmail com>
Date: Sun Jun 21 23:35:08 2009 +0200
Added addons handler with CPU addon
src/mousetrap/environment.py.in | 3 +
src/mousetrap/lib/settings.py | 34 ++++++++++++++++
src/mousetrap/mousetrap.py | 5 +-
src/mousetrap/ui/main.py | 34 ++++++++++------
src/mousetrap/ui/settings_gui.py | 81 ++++++++++++++++++++++++++++++++++++++
5 files changed, 143 insertions(+), 14 deletions(-)
---
diff --git a/src/mousetrap/environment.py.in b/src/mousetrap/environment.py.in
index 1cc7eb6..be120d4 100644
--- a/src/mousetrap/environment.py.in
+++ b/src/mousetrap/environment.py.in
@@ -30,6 +30,9 @@ import sys
import os
import gtk
+## MouseTrap's PID
+pid = os.getpid()
+
## mouseTrap Version
version = "@MOUSETRAP_VERSION@"
diff --git a/src/mousetrap/lib/settings.py b/src/mousetrap/lib/settings.py
index 161a1d3..55a7e06 100755
--- a/src/mousetrap/lib/settings.py
+++ b/src/mousetrap/lib/settings.py
@@ -34,8 +34,41 @@ import mousetrap.environment as env
class Settings( ConfigParser.ConfigParser ):
def optionxform( self, optionstr ):
+ """
+ Keeps the options cases instead of
+ converting them in lowercase.
+
+ Arguments:
+ - self: The main object pointer.
+ - optionstr: The option string.
+ """
return optionstr
+ def getList(self, section, option):
+ """
+ Gets a section parsed as string
+ and returns it as list
+
+ Arguments:
+ - self: The main object pointer.
+ - section: The section where option is.
+ - option: The needed option value.
+ """
+ return [ val for val in self.get(section, option).split("|") if val != "" ]
+
+ def setList(self, section, option, arr):
+ """
+ Sets a new list type option.
+
+ Arguments:
+ - self: The main object pointer.
+ - section: The section where option will be.
+ - option: The option to set.
+ - arr: The List to transform in string.
+ """
+
+ self.set(section, option, "|".join(arr))
+
def write_first(self, conf_file):
"""
Writes the first configuration file in case it doesn't exists.
@@ -63,6 +96,7 @@ class Settings( ConfigParser.ConfigParser ):
conf.write("\ndebugLevel = 10")
conf.write("\nalgorithm = forehead")
conf.write("\nstartCam = True")
+ conf.write("\naddon = ")
conf.write("\n\n[mouse]")
conf.write("\ndefClick = b1c")
diff --git a/src/mousetrap/mousetrap.py b/src/mousetrap/mousetrap.py
index e36e2e2..898dd73 100644
--- a/src/mousetrap/mousetrap.py
+++ b/src/mousetrap/mousetrap.py
@@ -83,12 +83,13 @@ class Controller():
self.idm = idm.Module(self)
self.idm.set_capture(self.cfg.getint("cam", "inputDevIndex"))
- #gobject.timeout_add(150, self.update_frame)
- #gobject.timeout_add(50, self.update_pointers)
+ gobject.timeout_add(150, self.update_frame)
+ gobject.timeout_add(50, self.update_pointers)
# Lets build the interface
self.itf = MainGui(self)
self.itf.build_interface()
+ self.itf.load_addons()
gobject.threads_init()
self.loop.run()
diff --git a/src/mousetrap/ui/main.py b/src/mousetrap/ui/main.py
index 05904d9..d7b3557 100644
--- a/src/mousetrap/ui/main.py
+++ b/src/mousetrap/ui/main.py
@@ -32,6 +32,7 @@ import dialogs
import settings_gui
import mousetrap.debug as debug
import mousetrap.environment as env
+from mousetrap.addons import cpu
class MainGui( gtk.Window ):
"""
@@ -124,18 +125,6 @@ class MainGui( gtk.Window ):
#expander.connect('notify::expanded', self.expanded_cb)
self.vBox.pack_start(self.map_expander)
-# hBox = gtk.HBox()
-# showMapper = gtk.CheckButton( _("Start Point Mapper: ") )
-# showMapper.set_active( self.settings.getboolean( "gui", "showPointMapper" ) )
-# showMapper.connect("toggled", lambda x: self.mapper.show()
-# if x.get_active() else self.mapper.hide())
-# hBox.pack_start( showMapper, False, False )
-#
-# showCapture = gtk.CheckButton( _("Show Capture: ") )
-# showCapture.set_active( self.settings.getboolean( "gui", "showCapture" ) )
-# showCapture.connect("toggled", lambda x: self.capture.show()
-# if x.get_active() else self.capture.hide())
-# hBox.pack_start( showCapture, False, False )
#
# flipButton = gtk.Button( _("Flip Image") )
# flipButton.connect("clicked", self.recalcPoint, "flip" )
@@ -148,10 +137,31 @@ class MainGui( gtk.Window ):
# self.vBox.pack_end(hBox, False, False )
#
# self.buttonsBox.show_all()
+
+ self.statusbar = gtk.Statusbar()
+ self.statusbar_id = self.statusbar.get_context_id("statusbar")
+
+ self.vBox.pack_start(self.statusbar, True, True)
+
self.vBox.show_all()
self.add(self.vBox)
self.show()
+ def load_addons(self):
+ """
+ Loads the enabled addons
+
+ Arguments:
+ - self: The main object pointer.
+ """
+
+ for add in self.cfg.getList("main", "addon"):
+ tmp = __import__("mousetrap.addons.%s" % add,
+ globals(), locals(),[''])
+
+ setattr(self, add, tmp.Addon(self.ctr))
+
+
def update_frame(self, img, point):
"""
Updates the image
diff --git a/src/mousetrap/ui/settings_gui.py b/src/mousetrap/ui/settings_gui.py
old mode 100755
new mode 100644
index 3c62925..3c4c384
--- a/src/mousetrap/ui/settings_gui.py
+++ b/src/mousetrap/ui/settings_gui.py
@@ -32,6 +32,7 @@ import dialogs
from i18n import _
from ocvfw import pocv
import mousetrap.environment as env
+from mousetrap.addons.handler import AddonsHandler
class PreffGui( gtk.Window ):
"""
@@ -54,6 +55,7 @@ class PreffGui( gtk.Window ):
self.ctr = controller
self.cfg = self.ctr.cfg
+ self.adds = AddonsHandler(self.ctr)
self.preffWidgets = dict()
def setWindowsIcon( self ):
@@ -99,6 +101,7 @@ class PreffGui( gtk.Window ):
self.main_gui_tab()
self.cam_tab()
self.algorithm_tab()
+ self.addons_tab()
self.mouseTab()
self.debug_tab()
@@ -264,6 +267,68 @@ class PreffGui( gtk.Window ):
frame.show()
self.noteBook.insert_page(frame, gtk.Label( _("Algorithm") ) )
+
+ def addons_tab( self ):
+ """
+ The cam module Preff Tab.
+
+ Arguments:
+ - self: The main object pointer.
+ """
+
+ frame = gtk.Frame()
+
+ algo_box = gtk.VBox( spacing = 6 )
+
+ liststore = gtk.ListStore(bool, str, str, str)
+
+ conf_button = gtk.Button(stock=gtk.STOCK_PREFERENCES)
+ conf_button.connect('clicked', self.show_alg_pref, liststore)
+ conf_button.set_sensitive(False)
+
+ tree_view = gtk.TreeView(liststore)
+ tree_view.connect("cursor-changed", self._tree_view_click, conf_button)
+
+ toggle_cell = gtk.CellRendererToggle()
+ toggle_cell.connect( 'toggled', self._enable_disable_addon, liststore)
+ toggle_cell.set_property('activatable', True)
+
+ name_cell = gtk.CellRendererText()
+ desc_cell = gtk.CellRendererText()
+
+ toggle_column = gtk.TreeViewColumn(_('Active'), toggle_cell)
+ name_column = gtk.TreeViewColumn(_('Name'))
+ desc_column = gtk.TreeViewColumn(_('Description'))
+
+ for add in self.adds.get_addons_list():
+ add_inf = self.adds.get_addon_inf(add)
+ state = False
+ if add_inf["name"].lower() in self.cfg.getList("main", "addon"):
+ state = True
+ liststore.append([state, add_inf["name"], add_inf["dsc"], add_inf["stgs"]])
+
+ tree_view.append_column(toggle_column)
+ tree_view.append_column(name_column)
+ tree_view.append_column(desc_column)
+
+ name_column.pack_start(name_cell, True)
+ desc_column.pack_start(desc_cell, True)
+
+ toggle_column.add_attribute( toggle_cell, "active", 0 )
+ toggle_column.set_max_width(30)
+ #toggle_column.set_attributes( toggle_cell, background=2 )
+ name_column.set_attributes(name_cell, text=1)
+ desc_column.set_attributes(desc_cell, text=2)
+
+ algo_box.pack_start(tree_view)
+ algo_box.pack_start(conf_button, False, False)
+
+ algo_box.show_all()
+
+ frame.add( algo_box )
+ frame.show()
+
+ self.noteBook.insert_page(frame, gtk.Label( _("Addons") ) )
def mouseTab( self ):
"""
@@ -411,6 +476,22 @@ class PreffGui( gtk.Window ):
else:
model[pth][0] = False
+ def _enable_disable_addon(self, cell, path, model):
+ """
+ ListStore RadioButton Value Changer.
+ """
+
+ model[path][0] = not model[path][0]
+
+ cur = self.cfg.getList("main", "addon")
+
+ if model[path][1] in cur:
+ cur.remove(model[path][1].lower())
+ else:
+ cur.append(model[path][1].lower())
+
+ self.cfg.setList("main", "addon", cur)
+
def _checkToggled( self, widget, section, option ):
"""
Sets the new value in the settings object for the toggled checkbox
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]