Example #1
0
class App:
	def __init__(self,port=35353, debug=False):
		gnome.program_init("Dreadmill UI", "1.0")
		client = gnome.ui.master_client()
		command = os.path.normpath(os.path.join(os.getcwd(), sys.argv[0]))
		client.set_restart_style(gnome.ui.RESTART_IF_RUNNING)
		try: client.set_restart_command([command] + sys.argv[1:])
		except TypeError:
			client.set_restart_command(len(sys.argv), [command] + sys.argv[1:])
		client.connect('die', self.die)
		client.connect('save-yourself',  self.save_state)

		self.dreadmill = Dreadmill(port=port, debug=debug)
		self.history = History(self.dreadmill)
		
		# create window
		self.control_window = ControlWindow(self.dreadmill, self)
		# add app indicator
		self.indicator = Indicator(self.dreadmill, self)
		
		# hook callback for IO
		gobject.io_add_watch(self.dreadmill.get_socket(), gobject.IO_IN, self.prod_dreadmill, None)
		gobject.timeout_add_seconds(3, self.dreadmill.ping)

	def prod_dreadmill(self, source, condition, misc=None):
		self.dreadmill.socket_ready()
		return True

	def show_control_window(self):
		self.control_window.show()

	def main(self):
		gtk.main()

	def get_distance_today(self):
		return self.history.get_distance_today()

	def destroy(self):
		self.history.sync()
		self.history.close()
		gtk.main_quit()

	def die(self, *args):
		self.destroy()

	def save_state(self, *args):
		self.history.sync()
Example #2
0
	def __init__(self,port=35353, debug=False):
		gnome.program_init("Dreadmill UI", "1.0")
		client = gnome.ui.master_client()
		command = os.path.normpath(os.path.join(os.getcwd(), sys.argv[0]))
		client.set_restart_style(gnome.ui.RESTART_IF_RUNNING)
		try: client.set_restart_command([command] + sys.argv[1:])
		except TypeError:
			client.set_restart_command(len(sys.argv), [command] + sys.argv[1:])
		client.connect('die', self.die)
		client.connect('save-yourself',  self.save_state)

		self.dreadmill = Dreadmill(port=port, debug=debug)
		self.history = History(self.dreadmill)
		
		# create window
		self.control_window = ControlWindow(self.dreadmill, self)
		# add app indicator
		self.indicator = Indicator(self.dreadmill, self)
		
		# hook callback for IO
		gobject.io_add_watch(self.dreadmill.get_socket(), gobject.IO_IN, self.prod_dreadmill, None)
		gobject.timeout_add_seconds(3, self.dreadmill.ping)