/usr/share/pyshared/mousetrap/app/main.py is in gnome-mousetrap 0.4-2ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | # -*- coding: utf-8 -*-
# MouseTrap
#
# Copyright 2009 Flavio Percoco Premoli
#
# This file is part of mouseTrap.
#
# MouseTrap is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License v2 as published
# by the Free Software Foundation.
#
# mouseTrap 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 mouseTrap. If not, see <http://www.gnu.org/licenses/>.
"""MouseTrap's main script."""
__id__ = "$Id$"
__version__ = "$Revision$"
__date__ = "$Date$"
__copyright__ = "Copyright (c) 2008 Flavio Percoco Premoli"
__license__ = "GPLv2"
####################### TAKEN FROM ORCA'S CODE ###################
# We're going to force the name of the app to "mousetrap" so pygtk
# will end up showing us as "mousetrap" to the AT-SPI. If we don't
# do this, the name can end up being "-c". See Orca's bug 364452 at
# http://bugzilla.gnome.org/show_bug.cgi?id=364452 for more
# information.
import sys
sys.argv[0] = "mousetrap"
import gobject
import debug
import getopt
import environment as env
from mousetrap.ocvfw import pocv
from ui.i18n import _
from ui.main import MainGui
from ui.scripts import get_script_class
from lib import httpd, dbusd, settings
class Controller():
"""
MouseTrap's Controller Class
"""
def __init__(self):
"""
The MouseTrap controller init class
Arguments:
- self: The main object pointer.
"""
# We don't want to load the settings each time we need them. do we?
self.cfg = None
self.loop = gobject.MainLoop()
self.httpd = httpd.HttpdServer(20433)
self.dbusd = dbusd.DbusServer()
def start(self):
"""
Starts the modules, views classes.
Arguments:
- self: The main object pointer.
"""
if self.cfg is None:
conf_created, self.cfg = settings.load()
self.proc_args()
if not self.dbusd.start():
self.httpd.start()
if self.cfg.getboolean("main", "startCam"):
# Lets start the module
idm = pocv.get_idm(self.cfg.get("main", "algorithm"))
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)
debug.info("mousetrap", "Idm loaded and started")
# Lets build the interface
self.itf = MainGui(self)
self.itf.build_interface()
self.itf.load_addons()
if conf_created:
from ui import settings_gui
settings_gui.showPreffGui(self)
debug.info("mousetrap", "MouseTrap's Interface Built and Loaded")
gobject.threads_init()
self.loop.run()
def proc_args(self):
"""
Process the startup flags
Arguments:
- self: The main object pointer.
"""
arguments = sys.argv[1:]
if len(arguments) == 1:
arguments = arguments[0].split()
env.flags = dict((key[0], {"section" : sec}) for sec in self.cfg.sections()
for key in self.cfg.items(sec))
try:
# ? for help
# e for enable
# d for disable
# t for mouse tiemout
opts, args = getopt.getopt(
arguments,
"?hve:d:s:",
["help",
"version",
"enable=",
"disable=",
"set="])
for opt, val in opts:
key = False
# This will change the default video device input
if opt in ("-s", "--set"):
key, value = val.strip().split("-")
if opt in ("-e", "--enable"):
key, value = [val.strip(), "True"]
if opt in ("-d", "--disable"):
key, value = [val.strip(), "False"]
if key in env.flags:
self.cfg.set(env.flags[key]["section"], key, value)
elif key:
self.usage()
self.quit(2)
if opt in ("-v", "--version"):
print(env.version)
self.quit(0)
# This will show the usage of mouseTrap
if opt in ("-?", "-h", "--help"):
self.usage()
self.quit(0)
except getopt.GetoptError, err:
print str(err)
self.usage()
self.quit(2)
pass
def usage(self):
"""
Prints the usage
Arguments:
- self: The main object pointer
"""
print( _("Usage: mouseTrap [OPTION...]"))
# '-?, --help' that is used to display usage information.
#
print( "-?, -h, --help " + \
_(" Show this help message"))
# Option:
# '-i' that is used to set the input camera index. E.g: -i 0
print( "-s, --set " + \
_(" Sets new value to Non Boolean options E.g -s inputDevIndex-1"))
# Options:
# -e, --enable Allow the users to enable modules not permantly
print( "-e, --enable=[" \
+ "main-window" + "|" \
+ "cam") + "]",
print( _(" Enable the selected options"))
# Options:
# -d, --disable Allow the users to disable modules not permanently.
print( "-d, --disable=[" \
+ "main-window" + "|" \
+ "cam" + "]"),
print( _(" Disable the selected options"))
# Options:
# -t --timeout To change the mouse timeout not permanently.
print( "-v, --version " + \
_(" Shows mouseTrap version"))
print( _("\nReport bugs to flaper87@flaper87.org"))
def script(self):
"""
Returns the main script class object.
Arguments:
- self: The main object pointer.
"""
return get_script_class(self.cfg.get("scripts", "name"))()
def update_frame(self):
"""
Updates the User Interface frame with the latest capture.
Arguments:
- self: The main object pointer.
"""
self.itf.update_frame(self.idm.get_capture(), self.idm.get_pointer())
return True
def update_pointers(self):
"""
Gets the new mouse pointer position based on the las calcs.
Arguments:
- self: The main object pointer.
"""
self.itf.script.update_items(self.idm.get_pointer())
return True
def quit(self, exitcode=1):
"""
Quits mouseTrap and all its process
Arguments:
- self: The main object pointer.
- exitcode: The exitcode number. It helps to handle some quit events.
"""
sys.exit(exitcode)
|