[mousetrap/gnome3-wip: 80/240] Encapsulate screen access into moustrap.gui.Gui.
- From: Heidi Ellis <heidiellis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mousetrap/gnome3-wip: 80/240] Encapsulate screen access into moustrap.gui.Gui.
- Date: Mon, 8 Sep 2014 15:19:17 +0000 (UTC)
commit 9ef80e33866b026aa407d8e4887a0804360add88
Author: Stoney Jackson <dr stoney gmail com>
Date: Thu Jun 12 10:49:06 2014 -0400
Encapsulate screen access into moustrap.gui.Gui.
src/mousetrap/gui.py | 5 +++++
src/mousetrap/main.py | 10 +++-------
2 files changed, 8 insertions(+), 7 deletions(-)
---
diff --git a/src/mousetrap/gui.py b/src/mousetrap/gui.py
index 780cb14..8cdb04c 100644
--- a/src/mousetrap/gui.py
+++ b/src/mousetrap/gui.py
@@ -79,6 +79,11 @@ class Gui(object):
'''Start handling events.'''
Gtk.main()
+ def get_screen_width(self):
+ return Gtk.Window().get_screen().get_width()
+
+ def get_screen_height(self):
+ return Gtk.Window().get_screen().get_height()
class Pointer(object):
def __init__(self):
diff --git a/src/mousetrap/main.py b/src/mousetrap/main.py
index 2f15093..0352bd3 100644
--- a/src/mousetrap/main.py
+++ b/src/mousetrap/main.py
@@ -1,6 +1,4 @@
from gi.repository import GObject
-from gi.repository import Gtk
-
from mousetrap.vision import Camera, NoseLocator
from mousetrap.gui import Pointer, Gui
@@ -17,7 +15,6 @@ class Main(object):
self.camera.set_dimensions(300, 200)
self.locator = NoseLocator()
self.pointer = Pointer()
- self.screen = Gtk.Window().get_screen()
self.gui = Gui()
def run(self):
@@ -35,10 +32,9 @@ class Main(object):
image_height = self.image.get_height()
x_percent = 1.0 * location['x'] / image_width
y_percent = 1.0 * location['y'] / image_height
- screen = Gtk.Window().get_screen()
- x_screen = x_percent * screen.get_width()
- y_screen = y_percent * screen.get_width()
- half_width = screen.get_width() / 2
+ x_screen = x_percent * self.gui.get_screen_width()
+ y_screen = y_percent * self.gui.get_screen_height()
+ half_width = self.gui.get_screen_width() / 2
x_screen = (-1 * (x_screen - half_width)) + half_width
print 'Pointer location in screen:' + \
str({'x':x_screen, 'y':y_screen})
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]