def _construct_page(self): # zbar panel setup self.zbar = zbarpygtk.Gtk() self.zbar.connect("decoded-text", self._decoded) self.zbar.set_video_device(self.vdev) self.zbar.set_video_enabled(True) self.zbar.set_size_request(*SIZE) hbox = gtk.HBox(spacing=10) vbox = gtk.VBox(spacing=10) hbox.add(self.zbar) hbox.add(vbox) # message area self._msg_event = gtk.EventBox() self._msg_lbl = gtk.Label("MSG") self._msg_lbl.set_width_chars(35) self._msg_lbl.set_line_wrap(True) self._msg_event.add(self._msg_lbl) vbox.add(self._msg_event) # wristband and abort buttons self._wristband_btn = gtk.Button( "WRISTBANDED\n(wristband crimped on user)") self._wristband_btn.connect("clicked", self._wristband_click) vbox.add(self._wristband_btn) self._abort_btn = gtk.Button("ABORT\n(forget current user)") self._abort_btn.connect("clicked", self._abort_click) vbox.add(self._abort_btn) # cheeky spacing vbox.add(gtk.Label("")) # another vbox to squash some parts of the manual check area vbox2 = gtk.VBox(spacing=10) vbox2.add(gtk.Label("")) vbox2.add(gtk.Label("Manually Check username:"******"activate", self._manual_click) vbox2.add(self._manual_entry) self._manual_btn = gtk.Button("Check") self._manual_btn.connect("clicked", self._manual_click) vbox2.add(self._manual_btn) vbox.add(vbox2) return hbox
open_file = None video_device = None if len(sys.argv) > 1: video_device = sys.argv[1] # threads *must* be properly initialized to use zbarpygtk gtk.gdk.threads_init() gtk.gdk.threads_enter() window = gtk.Window() window.set_title("test_pygtk") window.set_border_width(8) window.connect("destroy", gtk.main_quit) zbar = zbarpygtk.Gtk() zbar.connect("decoded-text", decoded) # video device list combo box video_list = gtk.combo_box_new_text() video_list.connect("changed", video_changed) # enable/disable status button status_button = gtk.ToggleButton("closed") status_image = gtk.image_new_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_BUTTON) status_button.set_image(status_image) status_button.set_sensitive(False) # bind status button state and video state status_button.connect("toggled", status_button_toggled) zbar.connect("notify::video-enabled", video_enabled)
def read_card_id(self): d = gtk.Dialog() d.add_buttons(gtk.STOCK_CANCEL, 2) self.code = None def set_status_label(opened, enabled): """update status button label to reflect indicated state.""" if not opened: label = "closed" elif enabled: label = "enabled" else: label = "disabled" status_button.set_label(label) def status_button_toggled(button): """callback invoked when the status button changes state (interactively or programmatically). ensures the zbar widget video streaming state is consistent and updates the display of the button to represent the current state """ opened = zbar.get_video_opened() active = status_button.get_active() if opened and (active != zbar.get_video_enabled()): zbar.set_video_enabled(active) set_status_label(opened, active) if active: status_image.set_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_BUTTON) else: status_image.set_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_BUTTON) def video_enabled(zbar, param): """callback invoked when the zbar widget enables or disables video streaming. updates the status button state to reflect the current video state """ enabled = zbar.get_video_enabled() if status_button.get_active() != enabled: status_button.set_active(enabled) def video_opened(zbar, param): """callback invoked when the zbar widget opens or closes a video device. also called when a device is closed due to error. updates the status button state to reflect the current video state """ opened = zbar.get_video_opened() status_button.set_sensitive(opened) set_status_label(opened, zbar.get_video_enabled()) def decoded(zbar, data): print "decoded" self.code = data d.destroy() pass zbar = zbarpygtk.Gtk() zbar.connect("decoded-text", decoded) # enable/disable status button status_button = gtk.ToggleButton("closed") status_image = gtk.image_new_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_BUTTON) status_button.set_image(status_image) status_button.set_sensitive(False) # bind status button state and video state status_button.connect("toggled", status_button_toggled) zbar.connect("notify::video-enabled", video_enabled) zbar.connect("notify::video-opened", video_opened) zbar.set_video_device("/dev/video0") zbar.set_size_request(1280, 720) zbar.show() d.vbox.pack_start(zbar) ret = d.run() d.destroy() print ret return self.code