[mousetrap/gnome3-wip: 79/240] Add moustrap.gui.Gui to collect public mousetrap.gui functions.
- From: Heidi Ellis <heidiellis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mousetrap/gnome3-wip: 79/240] Add moustrap.gui.Gui to collect public mousetrap.gui functions.
- Date: Mon, 8 Sep 2014 15:19:12 +0000 (UTC)
commit ff48eb98b71f8af692b64872f789a9cd5446383c
Author: Stoney Jackson <dr stoney gmail com>
Date: Thu Jun 12 10:37:51 2014 -0400
Add moustrap.gui.Gui to collect public mousetrap.gui functions.
src/mousetrap/gui.py | 28 +++++++++++++++-------------
src/mousetrap/main.py | 8 ++++----
2 files changed, 19 insertions(+), 17 deletions(-)
---
diff --git a/src/mousetrap/gui.py b/src/mousetrap/gui.py
index 470b850..780cb14 100644
--- a/src/mousetrap/gui.py
+++ b/src/mousetrap/gui.py
@@ -63,19 +63,21 @@ def _cvimage_to_pixbuf(cvimage):
)
-_WINDOWS = {}
-def show_image(window_name, image):
- '''Displays image in window named by window_name.
- May reuse named windows.
- '''
- if window_name not in _WINDOWS:
- _WINDOWS[window_name] = ImageWindow(window_name)
- _WINDOWS[window_name].draw(image)
-
-
-def start():
- '''Start handling events.'''
- Gtk.main()
+class Gui(object):
+ def __init__(self):
+ self._windows = {}
+
+ def show_image(self, window_name, image):
+ '''Displays image in window named by window_name.
+ May reuse named windows.
+ '''
+ if window_name not in self._windows:
+ self._windows[window_name] = ImageWindow(window_name)
+ self._windows[window_name].draw(image)
+
+ def start(self):
+ '''Start handling events.'''
+ Gtk.main()
class Pointer(object):
diff --git a/src/mousetrap/main.py b/src/mousetrap/main.py
index c51ddd3..2f15093 100644
--- a/src/mousetrap/main.py
+++ b/src/mousetrap/main.py
@@ -2,8 +2,7 @@ from gi.repository import GObject
from gi.repository import Gtk
from mousetrap.vision import Camera, NoseLocator
-from mousetrap.gui import Pointer
-import mousetrap.gui as gui
+from mousetrap.gui import Pointer, Gui
FPS = 5
@@ -19,10 +18,11 @@ class Main(object):
self.locator = NoseLocator()
self.pointer = Pointer()
self.screen = Gtk.Window().get_screen()
+ self.gui = Gui()
def run(self):
self.timeout_id = GObject.timeout_add(INTERVAL, self.on_timeout, None)
- gui.start()
+ self.gui.start()
def on_timeout(self, user_data):
self.image = self.camera.read_image()
@@ -47,7 +47,7 @@ class Main(object):
self.pointer.set_position((x_screen, y_screen))
except Exception as exception:
print exception.args[0]
- gui.show_image('diff', self.image)
+ self.gui.show_image('diff', self.image)
return True
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]