Exemplo n.º 1
0
class Application(Gtk.Application):
	def __init__(self):
		Gtk.Application.__init__(self,
			application_id="app.qrencode-gtk",
			flags=Gio.ApplicationFlags.FLAGS_NONE)
		
		GLib.set_application_name("QR code") # ?
		
		Gdk.threads_init()
        	
		self.connect("shutdown", self.handle_action_quit, None)
        	
	def do_activate(self):
	
		self.window = Window(self)
		self.add_window(self.window)

		self.encoder = Encoder()
		
		self.window.encoder = self.encoder
		self.encoder.window = self.window
		
		self.window.show_all()
		self.encoder.start()

	def do_startup(self):
		Gtk.Application.do_startup(self)

		# TODO: Menu?
		"""
		menu = Gio.Menu()
		menu.append("About", "app.about")
		menu.append("Quit", "app.quit")
		self.set_app_menu(menu)

		action_about = Gio.SimpleAction.new("about", None)
		action_about.connect("activate", self.handle_action_about)
		self.add_action(action_about)

		action_quit = Gio.SimpleAction.new("quit", None)
		action_quit.connect("activate", self.handle_action_quit)
		self.add_action(action_quit)
		"""
	
	def handle_action_quit(self, action, parameter):		
		if self.encoder.lock.acquire(True, 0.5):
			self.encoder.running = False
			self.encoder.doencode.set()
			self.encoder.lock.release()
			self.encoder.join()
		self.window.close()
		self.quit()

	"""
Exemplo n.º 2
0
	def do_activate(self):
	
		self.window = Window(self)
		self.add_window(self.window)

		self.encoder = Encoder()
		
		self.window.encoder = self.encoder
		self.encoder.window = self.window
		
		self.window.show_all()
		self.encoder.start()