def __init__(self, icon): Window.__init__(self, WINDOW_TOPLEVEL) self.set_property("skip-taskbar-hint", True) self.set_property("destroy-with-parent", True) self.set_modal(True) self.set_position(WIN_POS_CENTER) self.vbox = VBox(False, 0) self.terminal = terminal() self.terminal.connect("child-exited", lambda _: self.close_button.show()) self.terminal.show() self.close_button = Button(stock=STOCK_CLOSE) self.close_button.connect("clicked", lambda _: self.destroy()) self.vbox.pack_start(self.terminal, False, False, 0) self.vbox.pack_start(self.close_button, False, False, 0) self.vbox.show() self.add(self.vbox) self.set_icon(pixbuf_new_from_file(icon))
def setupWindow(self): self.window_title = "Bibud" self.window = Window() self.window.show() self.window.connect("destroy-event", self.browser_quit) self.window.resize(1024, 768) self.window.set_title(self.window_title)
def __init__(self, name='MenuVBoxWindow'): Window.__init__(self) self.set_name(name) self.vbox = VBox() self.add(self.vbox) self.menubar = SimpleMenuBar() self.vbox.pack_start(self.menubar, FALSE, FALSE, 0) self.vbox.show() self.show()
def __init__(self, name='MenuVBoxWindow'): Window.__init__(self) self.set_name(name) self.vbox = VBox() self.add(self.vbox) self.menubar = SimpleMenuBar() self.vbox.pack_start(self.menubar, False, False, 0) self.vbox.show() self.show()
def __init__(self, cbox=None, name='CommandWindow'): Window.__init__(self) self.set_name(name) self.vbox = cbox if cbox is None: self.vbox = CommandBox() self.add(self.vbox) self.tbar = self.vbox.tbar self.menubar = self.vbox.menubar self.show()
def __init__(self): Window.__init__(self) self.vbox = VBox() self.button_box = HBox() self.listbox = TwinCList() self.vbox.add(self.listbox) self.add(self.vbox) self.vbox.show() self.show() self.set_size_request(300, 200) self.listbox.set_position(140)
def __init__(self, to_upgrade, icon): Window.__init__(self, WINDOW_TOPLEVEL) self.set_property("skip-taskbar-hint", True) self.set_property("modal", True) self.set_property("destroy-with-parent", True) self.set_position(WIN_POS_CENTER) self.set_default_size (300, 300) self.set_icon(pixbuf_new_from_file(icon)) self._setup_tree(to_upgrade) self._setup_layout()
def __init__(self, queues, icon): Window.__init__(self, WINDOW_TOPLEVEL) self.set_property("skip-taskbar-hint", True) self.set_property("destroy-with-parent", True) self.set_modal(True) self.connect("delete-event", self._stop_closing) self.set_position(WIN_POS_CENTER) self.set_icon(pixbuf_new_from_file(icon)) self._setup_trees(queues) self._setup_layout() self.queues = queues
def __init__(self): from gtk import Window,WINDOW_TOPLEVEL,Button,Label,HBox,Entry,VBox,VSeparator self.window = Window(WINDOW_TOPLEVEL) self.window.set_title("Slideshow") self.window.connect("delete_event", self.delete_event) self.window.set_border_width(10) self.vbox = VBox(False, 0) self.window.add(self.vbox) self.hbox1 = HBox(False, 0) self.vbox.pack_start(self.hbox1, True, True, 1) self.hbox = HBox(False, 0) self.vbox.pack_start(self.hbox, False, False, 1) self.hbox2 = HBox(False, 0) self.vbox.pack_start(self.hbox2, True, True, 1) self.label = Label('Identifikační číslo:') self.hbox.pack_start(self.label, False, False, 1) self.label.show() self.editable = Entry() self.editable.connect('key_press_event', self.key_press_event) self.hbox.pack_start(self.editable, True, True, 1) self.editable.show() self.button = Button("Začít") self.button.connect("clicked", self.callback) self.button.set_receives_default(True) self.button.set_can_focus(True) self.hbox.pack_start(self.button, False, False, 1) self.button.show() self.hbox1.show() self.hbox.show() self.hbox2.show() self.vbox.show() self.window.show()
def __init__(self, title=TITLE, level=WINDOW_TOPLEVEL, on_exit=None): self.title = title self.grabbing = False self.events = [] self.rgb = WHITE_RGB self.on_exit = on_exit self.window = Window(level) self.window.set_title(title) self.window.set_resizable(True) self.window.add_events(POINTER_MOTION_MASK) self.window.set_default_size(350, 150) self.colors = [] grab_btn = Button('Grab') grab_btn.connect_object('clicked', self.toggle_grab, self.window) self.grab_btn = grab_btn exit_btn = Button('Exit') exit_btn.connect_object('clicked', self.destroy, self.window) drawing = DrawingArea() drawing.connect_object('expose_event', self.do_expose, self.window) self.drawing = drawing label = Label(rgb_to_string(WHITE_RGB)) self.label = label table = Table(2, 2, True) table.attach(self.drawing, 0, 1, 0, 1) table.attach(label, 0, 1, 1, 2) table.attach(grab_btn, 1, 2, 0, 1) table.attach(exit_btn, 1, 2, 1, 2) self.window.add(table)
def setupWindow(self): self.window_title = "Bibud" self.window = Window() self.window.show() self.window.connect("destroy-event", self.browser_quit) self.window.resize(1024,768) self.window.set_title(self.window_title)
def __init__(self, mensaje="Completado", titulo="Progreso", progreso=0): m = unicode(mensaje, 'latin-1') t = unicode(titulo, 'latin-1') Window.__init__(self) self.set_title(t.encode('utf-8')) self.vbox = gtk.VBox() self.add(self.vbox) hbox = gtk.HBox(False, 8) hbox.set_border_width(8) self.vbox.pack_start(hbox, False, False, 0) stock = gtk.image_new_from_stock(gtk.STOCK_DIALOG_QUESTION, gtk.ICON_SIZE_DIALOG) hbox.pack_start(stock, False, False, 0) self.barra = gtk.ProgressBar() self.barra.set_text(m.encode('utf-8')) self.barra.set_fraction(progreso) hbox.pack_start(self.barra, True, True, 0) self.show_all() self.show()
def __init__(self, mensaje = "Completado", titulo = "Progreso", progreso = 0): m = unicode(mensaje, 'latin-1') t = unicode(titulo, 'latin-1') Window.__init__(self) self.set_title(t.encode('utf-8')) self.vbox = gtk.VBox() self.add(self.vbox) hbox = gtk.HBox(False, 8) hbox.set_border_width(8) self.vbox.pack_start(hbox, False, False, 0) stock = gtk.image_new_from_stock( gtk.STOCK_DIALOG_QUESTION, gtk.ICON_SIZE_DIALOG) hbox.pack_start(stock, False, False, 0) self.barra = gtk.ProgressBar() self.barra.set_text(m.encode('utf-8')) self.barra.set_fraction(progreso) hbox.pack_start(self.barra, True, True, 0) self.show_all() self.show()
def initXdbox(self): self.xdbox = Window() try: self.xdbox.set_title(str(self.node)) except: pass vbox = VBox() self.xdbox.expr = MDSplusExprWidget() vbox.pack_start(self.xdbox.expr, True, True, 20) close = Button(stock=STOCK_CLOSE) close.connect("clicked", self.xdbox_close) redo = Button(stock=STOCK_REDO) redo.connect("clicked", self.xdbox_redo) cancel = Button(stock=STOCK_CANCEL) cancel.connect("clicked", self.xdbox_cancel) hbox = HBox() hbox.pack_start(close, False, False, 20) hbox.pack_start(redo, False, False, 20) hbox.pack_start(cancel, False, False, 20) vbox.pack_start(hbox, False, False, 20) self.xdbox.add(vbox) self.xdbox.expr.set_text(self.node_value())
class SimpleTransactionEditor(object): def __init__(self, trans, transid, plugin, gui_parent, change_register_function, book): """Sub classes should not override this __init__ but instead implement simple_init_before_show() to hook in at the right time """ self.trans = trans self.transid = transid self.plugin = plugin self.gui_parent = gui_parent self.change_register_function = change_register_function self.book = book # An offscreen place for the transaction's GUI to hide while not in use. self.hide_parent = Window() self.hide_parent.hide() self.mainvbox = VBox() self.hide_parent.add(self.mainvbox) self.simple_init_before_show() self.mainvbox.show_all() self.mainvbox.reparent(self.gui_parent) def simple_init_before_show(self): """Create the GUI for this type of BoKeep transaction. Widgets can be added to the "self.mainvbox" object.""" raise Exception("simple_init_before_show must be overrided by " "sub classes of SimpleTransactionEditor") def detach(self): """Detach the BoKeep transaction's GUI from the visible window and attach it to a hidden window. Sub classes overriding this are recommended to do their own work first, and then delegate back up to this original detach so it may do the widget reparenting work""" self.mainvbox.reparent(self.hide_parent)
def main(): print 'answer', input_entry_dialog("who what?", 'edit me') gtk_info_message("hi there missy") w = Window() w.resize(200, 200) w.connect( "delete-event", main_quit ) vbox = VBox() w.add(vbox) ONE_DAY = timedelta(days=1) existing_list = [PersistentList(test_program_return_new_row())] model, tv, tv_vbox = \ create_editable_type_defined_listview_and_model( ( ('date', date,), ('choose-me', (True, str, 'yo', 'hi', 'me', 'fun') ), # end choose-me tuple ('choose-me-only', (False, str, 'yo', 'hi', 'me', 'fun') ), # end choose-me-only tuple ('choose-me-num', (False, int, 1, 2, 3, 4) ), # end choose-num tuple ('description', str), ('count', int), ('file_path', {'type': file, 'file_type':FILE_CHOOSER_ACTION_SELECT_FOLDER} ), ('choose-me-date', (False, date, date.today() - ONE_DAY, date.today(), date.today() + ONE_DAY ) ), ('choose-me-obj', (False, (None, TestProgType(), TestProgType()), 'None', 'obj 1', 'obj 2' ) ), ('choose-me-Decimal', (True, Decimal, '3.1', '3.4') ), ), # end type tuple test_program_return_new_row, existing_list, test_prog_list_changed, False ) # create_editable_type_defined_listview_and_model vbox.pack_start( tv_vbox ) w.show_all() gtk_main()
def __init__(self): Window.__init__(self) self.aboutDialog = None self.mainVBox = MainVBox() self.set_title('Grafer') self.set_border_width(2) self.add(self.mainVBox) self.connect('destroy', Callbacks.mainWindow_destroy, None) self.mainVBox.mainMenu.menuAbout.connect('activate', Callbacks.menuAbout_activate, self) self.mainVBox.mainMenu.menuNew.connect('activate', Callbacks.menuNew_activate, self) self.mainVBox.mainMenu.menuClose.connect('activate', Callbacks.menuClose_activate, self) self.maximize() self.show_all()
def __init__ (self, title): Window.__init__(self) self.set_title(title) self.set_border_width(5) self.set_app_paintable(True) calendar = Calendar() testItem1 = SimpleItem('Hello') testItem2 = SimpleItem('This is Cool', '#b81919', '8f1b1b') toolBox = VBox(False, 5) toolBox.pack_start(testItem1, False, False, 0) toolBox.pack_start(testItem2, False, False, 0) mainBox = HBox(False, 5) mainBox.pack_start(toolBox, False, False, 0) mainBox.pack_start(calendar, False, False, 0) self.add(mainBox) self.maximize() self.connect('expose-event', self.expose, None) self.connect('destroy', main_quit)
def __init__(self): Window.__init__(self) self.model = ListStore(str, str) self.aboutWindow = None self.helper = Helper(None) self.set_title('Gnome Custom Shortcuts') self.set_icon_from_file(join(data_path, 'icon.svg')) self.set_border_width(5) self.set_size_request(400, 400) list = TreeView() list.append_column(TreeViewColumn('')) list.append_column(TreeViewColumn('Command')) list.append_column(TreeViewColumn('Shortcut')) closeButton = Button(None, STOCK_CLOSE) aboutButton = Button(None, STOCK_ABOUT) buttonsBox = HButtonBox() buttonsBox.pack_start(aboutButton, False, False, 0) buttonsBox.pack_start(Label(''), True, True, 0) buttonsBox.pack_start(closeButton, False, False, 0) box = VBox(False, 5) box.pack_start(list, True, True, 0) box.pack_start(buttonsBox, False, False, 0) self.connect('destroy', main_quit, None) closeButton.connect('clicked', main_quit, None) aboutButton.connect('clicked', self.show_about, None) self.add(box) self.show_all()
def __init__(self, trans, transid, plugin, gui_parent, change_register_function, book): """Sub classes should not override this __init__ but instead implement simple_init_before_show() to hook in at the right time """ self.trans = trans self.transid = transid self.plugin = plugin self.gui_parent = gui_parent self.change_register_function = change_register_function self.book = book # An offscreen place for the transaction's GUI to hide while not in use. self.hide_parent = Window() self.hide_parent.hide() self.mainvbox = VBox() self.hide_parent.add(self.mainvbox) self.simple_init_before_show() self.mainvbox.show_all() self.mainvbox.reparent(self.gui_parent)
def initXdbox(self): self.xdbox=Window() try: self.xdbox.set_title(str(self.node)) except: pass vbox=VBox() self.xdbox.expr=MDSplusExprWidget() vbox.pack_start(self.xdbox.expr,True,True,20) close=Button(stock=STOCK_CLOSE) close.connect("clicked",self.xdbox_close) redo=Button(stock=STOCK_REDO) redo.connect("clicked",self.xdbox_redo) cancel=Button(stock=STOCK_CANCEL) cancel.connect("clicked",self.xdbox_cancel) hbox=HBox() hbox.pack_start(close,False,False,20) hbox.pack_start(redo,False,False,20) hbox.pack_start(cancel,False,False,20) vbox.pack_start(hbox,False,False,20) self.xdbox.add(vbox) self.xdbox.expr.set_text(self.node_value())
class multipage_glade_editor(object): def __init__(self, trans, transid, plugin, gui_parent, change_register_function, book, display_mode=TRANSACTION_ALL_EDIT_FIRST_TIME, transaction_edit_finished_function=null_function): self.trans = trans self.transid = transid self.plugin = plugin self.gui_parent = gui_parent self.change_register_function = change_register_function self.book = book self.display_mode = display_mode self.transaction_edit_finished_function = ( null_function if display_mode not in HEADLESS_MODES else transaction_edit_finished_function ) self.hide_parent = Window() self.hide_parent.hide() self.mainvbox = VBox() self.hide_parent.add(self.mainvbox) config = self.trans.get_configuration_and_provide_on_load_hook() config_module_name = self.plugin.config_module_name if not config_valid(config): # even in the case of a broken config, we should still # display all of the data we have available... self.mainvbox.pack_start(Label("no configuration")) elif not self.trans.can_safely_proceed_with_config_module(config): # should display all data that's available instead of just # this label # # and should give # user an overide option where they either pick an old config # for one time use or just blow out the memory of having used # a different config... # # should also print the checksum itself so they know # what they need... # # perhaps eventually we even put in place some archival support # for saving old glade and config files and then code into the # the transaction -- hey, code you need to be editable is # over here.. # # now hopefully there is no marking of this transaction dirty # in this mode and the extra safegaurds we put into # MultipageGladeTransaction don't get activated self.mainvbox.pack_start( Label("out of date configuration. data is read only here for " "the safety of your old information, last adler " "CRC was %s" % self.trans.config_crc_cache )) else: # if the safety cache was relied on before we need to tell the # backend that the transaction is actually dirty, # and now that we know that we have a workable config, # there's a chance that we'll actually be able to avoid # relying on the cache this time if self.trans.get_safety_cache_was_used(): self.change_register_function() self.page_label = Label("") (x_align, y_align) = self.page_label.get_alignment() self.page_label.set_alignment(0.0, y_align) self.mainvbox.pack_start(self.page_label, expand=False) # establish maincontainer, which is where the actual glade # pages are put by attach_current_page # # The order of placement here is important, we place this # after page_label has already been added to main # and we also need to do this prior to attach_current_page # being called, as it depends on self.maincontainer being # there # # when we're in headless mode the maincontainer can just be # the mainvbox itself # # but, outside headless mode we save screen real-estate and # place a scrolled window (which becomes the maincontainer) # inside the mainvbox and the glade by glade pages end up # in there instead (again, in attach_current_page) if display_mode in HEADLESS_MODES: self.maincontainer = self.mainvbox else: self.maincontainer = Viewport() sw = ScrolledWindow() sw.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC) sw.add( self.maincontainer) self.mainvbox.pack_start(sw) self.glade_pages = [ self.__setup_page(glade_file, top_glade_element) for glade_file, top_glade_element in config.pages ] self.glade_pages_by_ident_index = dict( ( (key, self.glade_pages[i]) for i, key in enumerate(config.pages) ) # end generator expression ) # end dict self.__setup_auto_widgets() self.current_page = 0 self.attach_current_page() button_hbox = HBox() self.mainvbox.pack_end(button_hbox, expand=False) self.nav_buts = dict( (Button(), i) for i in range(2) ) for but, i in self.nav_buts.iteritems(): but.set_property('use-stock', True) but.set_label( STOCK_GO_BACK if i == GLADE_BACK_NAV else STOCK_GO_FORWARD ) button_hbox.pack_start(but, expand=False) but.connect("clicked", self.nav_but_clicked) config.gui_initialization_hook( self, self.trans, self.plugin, self.book) self.mainvbox.show_all() self.mainvbox.reparent(self.gui_parent) def page_is_current(self, page): # assumption is that config is fine and we're on a page assert( hasattr(self, 'glade_pages_by_ident_index') and True ) return \ self.glade_pages_by_ident_index[page] == self.current_widget_dict def __setup_page(self, glade_file, top_glade_element): widget_dict = {} # this should come from the config, seeing how we're setting up # our stuff manually event_handlers_dict = {} load_glade_file_get_widgets_and_connect_signals( glade_file, top_glade_element, widget_dict, event_handlers_dict ) widget_dict[top_glade_element].hide() return widget_dict def __setup_auto_widgets(self): # go through each page for key, widget_dict in self.glade_pages_by_ident_index.iteritems(): # go through each widget for widget_name, widget in widget_dict.iteritems(): widget_key = (key, widget_name) # determine if the current widget is one that we can take # care of automatically saving, we do this with a linear # search through a table of eligible types, # where the first element of each entry is Widget class # # Once we have a match do one of the following # * Change the widget from the existing stored stage # * Establish new state from some default # The next two entries in the table # (change_widget_from_state, new_state_from_widget) # provide functions to do this # # Lastly, we establish event handlers for this widget using # the last element in the table for (cls, change_widget_from_state, new_state_from_widget, establish_event_handlers) in ( # start table (Entry, lambda w, wk: w.set_text(self.trans.get_widget_state(wk)), lambda w: '', lambda w: w.connect("changed", self.entry_changed), ), # Entry (Calendar, self.__change_calendar_from_saved_version, get_current_date_of_gtkcal, lambda w: w.connect( "day_selected", self.calendar_changed ), ), # Calendar (CheckButton, lambda w, wk: w.set_active(self.trans.get_widget_state(wk)), get_state_of_checkbutton, lambda w: w.connect("toggled", self.checkbutton_changed), ), # CheckButton ): # end of table and for declartion # does the widget match the type in the current table entry? if isinstance(widget, cls): # use the three remaining functions in the table # as appropriate if self.trans.has_widget_state( widget_key ): change_widget_from_state(widget, widget_key) else: self.trans.update_widget_state( widget_key, new_state_from_widget(widget) ) establish_event_handlers(widget) def __change_calendar_from_saved_version(self, widget, widget_key): set_current_date_of_gtkcal(widget, self.trans.get_widget_state( widget_key ) ) def attach_current_page(self): config = self.plugin.get_configuration(allow_reload=False) self.current_widget_dict = self.glade_pages[self.current_page] self.current_window = self.current_widget_dict[ config.pages[self.current_page][TOP_WIDGET] ] self.current_top_vbox = self.current_window.child self.current_top_vbox.reparent( self.maincontainer) self.page_label.set_text( "page %s of %s" %( self.current_page + 1, len(config.pages) ) ) self.update_auto_labels() def detach_current_page(self): # put the spawn back to wence it came self.current_top_vbox.reparent( self.current_window) def detach(self): if hasattr(self, 'current_page'): self.detach_current_page() self.mainvbox.reparent(self.hide_parent) def page_change_acceptable_by_input_valid(self): bad_fields = ', '.join( widget_name for widget_name, widget in self.current_widget_dict.iteritems() if not self.widget_valid(widget_name, widget) ) if bad_fields == '': return True else: # this is kind of primiative, it would be better to # just highlight them by inserting red lights or something gtk_error_message("The following fields are invalid %s" % bad_fields ) return False def __current_page_ident(self): config = self.plugin.get_configuration(allow_reload=False) return config.pages[self.current_page] def __entry_widget_is_check_excempt(self, widget_name): config = self.plugin.get_configuration(allow_reload=False) return (self.__current_page_ident(), widget_name) in \ config.non_decimal_check_labels def widget_valid(self, widget_name, widget): config = self.plugin.get_configuration(allow_reload=False) if isinstance(widget, Entry) and \ not self.__entry_widget_is_check_excempt(widget_name): try: entry_to_decimal_convert( widget.get_text(), widget_name, self.__current_page_ident(), config) except EntryTextToDecimalConversionFail: return False # this covers not only the else case on the first if, but the # the case with the above try, except passes without exception return True def nav_but_clicked(self, but, *args): config = self.plugin.get_configuration(allow_reload=False) old_page = self.current_page delta = -1 if self.nav_buts[but] == GLADE_BACK_NAV else 1 new_page = old_page + delta # reject a change outside the acceptable range.. and hmm, # perhaps this event handler should never even run under those # conditions because we should really just grey the buttons if not (new_page < 0 or new_page == len(self.glade_pages)) and \ self.page_change_acceptable_by_input_valid() and \ config.page_change_acceptable(self.trans, old_page, new_page): # intentionally done before the page is actually attached, # that's what we mean by pre config.page_pre_change_config_hooks(self.trans, old_page, new_page) self.detach_current_page() self.current_page = new_page self.attach_current_page() # intentionally done after the page is actually attached, # that's what we mean by post config.page_post_change_config_hooks(self.trans, old_page, new_page) entry_changed = make_widget_changed_func(lambda w: w.get_text() ) calendar_changed = make_widget_changed_func(get_current_date_of_gtkcal) checkbutton_changed = make_widget_changed_func(get_state_of_checkbutton) def update_auto_labels(self): config = self.plugin.get_configuration(allow_reload=False) # this function should never be called if the config hasn't been # checked out as okay assert( hasattr(config, 'auto_update_labels') ) for page, label_name, label_source_func in config.auto_update_labels: if self.page_is_current(page): try: label_text = str(label_source_func( self.trans.widget_states, config)) except EntryTextToDecimalConversionFail, e: label_text = '' except WidgetFindError, no_find_e: label_text = str(no_find_e) self.current_widget_dict[label_name].set_text(label_text)
def __init__(self, trans, transid, plugin, gui_parent, change_register_function, book, display_mode=TRANSACTION_ALL_EDIT_FIRST_TIME, transaction_edit_finished_function=null_function): self.trans = trans self.transid = transid self.plugin = plugin self.gui_parent = gui_parent self.change_register_function = change_register_function self.book = book self.display_mode = display_mode self.transaction_edit_finished_function = ( null_function if display_mode not in HEADLESS_MODES else transaction_edit_finished_function ) self.hide_parent = Window() self.hide_parent.hide() self.mainvbox = VBox() self.hide_parent.add(self.mainvbox) config = self.trans.get_configuration_and_provide_on_load_hook() config_module_name = self.plugin.config_module_name if not config_valid(config): # even in the case of a broken config, we should still # display all of the data we have available... self.mainvbox.pack_start(Label("no configuration")) elif not self.trans.can_safely_proceed_with_config_module(config): # should display all data that's available instead of just # this label # # and should give # user an overide option where they either pick an old config # for one time use or just blow out the memory of having used # a different config... # # should also print the checksum itself so they know # what they need... # # perhaps eventually we even put in place some archival support # for saving old glade and config files and then code into the # the transaction -- hey, code you need to be editable is # over here.. # # now hopefully there is no marking of this transaction dirty # in this mode and the extra safegaurds we put into # MultipageGladeTransaction don't get activated self.mainvbox.pack_start( Label("out of date configuration. data is read only here for " "the safety of your old information, last adler " "CRC was %s" % self.trans.config_crc_cache )) else: # if the safety cache was relied on before we need to tell the # backend that the transaction is actually dirty, # and now that we know that we have a workable config, # there's a chance that we'll actually be able to avoid # relying on the cache this time if self.trans.get_safety_cache_was_used(): self.change_register_function() self.page_label = Label("") (x_align, y_align) = self.page_label.get_alignment() self.page_label.set_alignment(0.0, y_align) self.mainvbox.pack_start(self.page_label, expand=False) # establish maincontainer, which is where the actual glade # pages are put by attach_current_page # # The order of placement here is important, we place this # after page_label has already been added to main # and we also need to do this prior to attach_current_page # being called, as it depends on self.maincontainer being # there # # when we're in headless mode the maincontainer can just be # the mainvbox itself # # but, outside headless mode we save screen real-estate and # place a scrolled window (which becomes the maincontainer) # inside the mainvbox and the glade by glade pages end up # in there instead (again, in attach_current_page) if display_mode in HEADLESS_MODES: self.maincontainer = self.mainvbox else: self.maincontainer = Viewport() sw = ScrolledWindow() sw.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC) sw.add( self.maincontainer) self.mainvbox.pack_start(sw) self.glade_pages = [ self.__setup_page(glade_file, top_glade_element) for glade_file, top_glade_element in config.pages ] self.glade_pages_by_ident_index = dict( ( (key, self.glade_pages[i]) for i, key in enumerate(config.pages) ) # end generator expression ) # end dict self.__setup_auto_widgets() self.current_page = 0 self.attach_current_page() button_hbox = HBox() self.mainvbox.pack_end(button_hbox, expand=False) self.nav_buts = dict( (Button(), i) for i in range(2) ) for but, i in self.nav_buts.iteritems(): but.set_property('use-stock', True) but.set_label( STOCK_GO_BACK if i == GLADE_BACK_NAV else STOCK_GO_FORWARD ) button_hbox.pack_start(but, expand=False) but.connect("clicked", self.nav_but_clicked) config.gui_initialization_hook( self, self.trans, self.plugin, self.book) self.mainvbox.show_all() self.mainvbox.reparent(self.gui_parent)
return False def _on_toggled(self, button): if button.get_active(): self._do_show_popup() else: self._do_hide_popup() def _on_expose(self, widget, event): self._update_popup_geometry() if __name__ == '__main__': btn = PopupWidgetButton(label='TestMe', widget=gtk.Button('Click me')) hb = gtk.HBox() hb.pack_start(gtk.Button('Left'), expand=False, fill=False) hb.pack_start(btn, expand=False, fill=False) hb.pack_start(gtk.Button('Right'), expand=False, fill=False) vb = gtk.VBox() vb.pack_start(hb, expand=False, fill=False) from gtk import Window wnd = Window() wnd.set_size_request(400, 300) wnd.set_title('Pop-up Window Button Test') wnd.add(vb) wnd.connect('destroy', lambda *args: gtk.main_quit()) wnd.show_all() gtk.main()
self.form = GeoForm() self.result = GeoResult() self.pack_start(self.form, False) self.pack_start(self.result) self.login = GeoCaching() self.search = None self.form.connect('search', self.do_search) def do_search(self, widget, lat, long): self.search = self.login.search_lat_long(lat, long) for row in self.search.results: self.result.add_cache(row) self.result.show_all() if __name__ == '__main__': W = Window() S = Search() W.connect('destroy', main_quit) W.set_title("Search for caches") W.set_size_request(300, 200) W.add(S) W.show_all() main()
class PointAndPick(object): def __init__(self, title=TITLE, level=WINDOW_TOPLEVEL, on_exit=None): self.title = title self.grabbing = False self.events = [] self.rgb = WHITE_RGB self.on_exit = on_exit self.window = Window(level) self.window.set_title(title) self.window.set_resizable(True) self.window.add_events(POINTER_MOTION_MASK) self.window.set_default_size(350, 150) self.colors = [] grab_btn = Button('Grab') grab_btn.connect_object('clicked', self.toggle_grab, self.window) self.grab_btn = grab_btn exit_btn = Button('Exit') exit_btn.connect_object('clicked', self.destroy, self.window) drawing = DrawingArea() drawing.connect_object('expose_event', self.do_expose, self.window) self.drawing = drawing label = Label(rgb_to_string(WHITE_RGB)) self.label = label table = Table(2, 2, True) table.attach(self.drawing, 0, 1, 0, 1) table.attach(label, 0, 1, 1, 2) table.attach(grab_btn, 1, 2, 0, 1) table.attach(exit_btn, 1, 2, 1, 2) self.window.add(table) def show(self): self.window.show_all() def destroy(self, *args, **kwargs): self.window.hide_all() self.window.do_destroy(self.window) if self.on_exit: self.on_exit() def toggle_grab(self, *args, **kwargs): """Toggle pointer grabbing""" { True: self.ungrab, False: self.grab }[self.grabbing]() def grab(self): """Grab pointer""" if pointer_grab(self.window.window, True, GRAB_MASK) == GRAB_SUCCESS: self.grabbing = True self.grab_btn.set_label('Ungrab') e = [ ('motion_notify_event', self.motion_notify_event), ('button_press_event', self.button_press_event) ] self.events = [ self.window.connect(n, h) for n, h in e ] def ungrab(self): """Ungrab pointer""" pointer_ungrab() while self.events: self.window.disconnect(self.events.pop()) self.grabbing = False self.grab_btn.set_label('Grab') def do_expose(self, *args, **kwargs): """Expose the window""" gc_obj = self.drawing.window.new_gc() gc_obj.set_foreground(SYS_COLORMAP.alloc_color('black')) self.drawing.window.draw_rectangle(gc_obj, False, 10, 10, 100, 100) self.draw_color() def draw_color(self): """Drag the color box with the pixel under the mouse pointer""" gc_obj = self.drawing.window.new_gc() gc_obj.set_foreground(SYS_COLORMAP.alloc_color(rgb_to_string(self.rgb), True)) self.drawing.window.draw_rectangle(gc_obj, True, 11, 11, 99, 99) def motion_notify_event(self, win, event): """Mouse motion_notify_event handler""" pixbuf = Pixbuf(COLORSPACE_RGB, False, 8, 1, 1) root = get_default_root_window() xcoord, ycoord = event.get_root_coords() from_draw = pixbuf.get_from_drawable(root, root.get_colormap(), int(xcoord), int(ycoord), 0, 0, 1, 1) pixel = from_draw.get_pixels_array()[0][0] self.rgb = (pixel[0], pixel[1], pixel[2]) self.draw_color() self.label.set_label(rgb_to_string(self.rgb).upper()) def button_press_event(self, *args, **kwargs): """Mouse button_press_event handler""" self.ungrab()
def __init__(self, screen, maxWindowSize = None ): self._screen = screen # Objecto do tipo pygame.Surface que vai ser desenhado no screen self._surface = None # Tupla com o número de colunas e linhas que a grelha vai ter. É calculado posteriormente self._tableSize = () # Tupla com o tamanho da janela. -este tamanho é calculado consuate os dados da gridList e tem como máximo self.maxWindowSize self._windowSize = () # Tupla com o tamanho da surface- este tamanho é calculado consuate os dados da gridList self._surfaceSize = () # Posição apartir da qual a self._surface é desenhada no self._screen self._surfOffSet = (0, 0) # Tamanho máximo da janela. Se exceder este tamanho entra em funcionamento de slide if ( maxWindowSize != None ): self._maxWindowSize = maxWindowSize else: # Vê a resolução que está a ser utilizada win = Window() scr = win.get_screen() # O height é a altura sem contar com as possíveis barras. O 100 é um remendo para dar o desconto das # possíveis barras self._maxWindowSize = ( scr.get_width(), scr.get_height() - 100 ) del win del scr # Flag que indica se deve ou não fazer slide horizontal self._doHSlide = False # Flag que indica se deve ou não fazer slide vertical self._doVSlide = False # Cursor que é mostrado na janela. É carregado apartir do metodo 'create' self._cursor = None # Lista apartir da qual a grelha vai ser criada # Ex. de uma batalha com duas rondas e dois robots #[ ['Robot1', 0, 0, 0, 0, 0, 0, 1.0], ['Robot2', 0, 0, 0, 3, 0, 0, 0.0], ['Robot3', 0, 15, 0, 1, 1, 0, 1.1] ] self._gridList = [] # Margem esquerda(em pixeis) self._leftMargin = 30 # Margem direita(em pixeis) self._rightMargin = 30 # Margem superior(em pixeis) self._topMargin = 40 # Margem inferior(em pixeis) self._bottomMargin = 20 # Nome da batalha que vai aparecer como titulo na janela self._battleName = "" # battleName já rederizado self._title = None self._titleColor = (193, 5, 0) self._textColor = (255, 199, 0) self._backGroundColor = (27, 62, 80) self._headerColor = (193, 5, 0) self._TITLE_FONT = pygame.font.SysFont( pygame.font.get_default_font(), 32, bold = True, italic = False ) self._HEADER_FONT = pygame.font.SysFont( pygame.font.get_default_font(), 18, bold = True, italic = False ) self._TEXT_FONT = pygame.font.SysFont( pygame.font.get_default_font(), 16, bold = False, italic = False ) # Espaço entre o texto da grelha e as linhas(em pixeis) self._columnPitch = 10 # Espaço entre cada linha da grelha(em pixeis) self._rowPitch = 10 # Guarda a altura em que o ultimo componente foi desenhado entre cada fase de desenho da grelha self._yLocation = 0 # Lista que guarda a largura de cada coluna self._columnsWidthList = [] # Texto para o cabeçalho da tabela # Apesar de quando o cabeçalho é desenhado na surface ser feito o encoding para utf-8, quando se faz o calculo # da largura do texto, a medida não é a correcta porque não está a fazer os calculos com com a string com o # encoding correcto. Para evitar isso, a solução mais rápida foi adicionar logo aqui o enconding correcto. # Futuramente, se for feito o sistema de multi-linguas, este terá de ter suporte unicode! self.transDict = { "robotName": "Nome", "kills": u"Destruídos", "deaths": u"Destruído", "damageCaused": "Danos Causados", "damage": "Danos Sufridos", "totalShots": "Tiros Disparados", "goodShots": "Tiros Certeiros", "accuracy": "Pontaria(%)", "won": "Venceu", "totalScore": u"Pontuação" }
self.add_with_viewport(self.vbox) HasRecordBox.__init__(self, self.vbox, data, name=name) self.vbox.show() self.show() self.vbox.set_events(BUTTON_PRESS_MASK) class CommandBox(VBox, HasMenuBar): def __init__(self, name="CommandBox"): VBox.__init__(self) self.set_name(name) self.tbar = HandleToolbar() self.menubar = SimpleMenuBar() self.pack_start(self.menubar, FALSE, FALSE, 0) self.pack_end(self.tbar, FALSE, FALSE, 0) self.show() if __name__ == "__main__": import paella.gtk from gtk import mainloop, mainquit from paella.base.util import file2str from gtk import Window tt = TextTemplater(file2str("/etc/debconf.conf")) win = Window() win.add(tt) win.show() win.connect("destroy", mainquit) mainloop()
def __init__(self,node=None,value=None): Window.__init__(self) MDSplusWidget.__init__(self) if node is not None: self.node=node else: self.value=value hbtop=HBox(homogeneous=False) self.on=CheckButton(label="On") self.parent_on=CheckButton(label="Parent") self.parent_on.set_sensitive(False) self.path=MDSplusPathWidget() if node is not None: self.path._node=self._node hbtags=HBox(homogeneous=False) self.tags=Entry() self.tags.set_width_chars(60) expression_menu=self.dtype_menu(tuple(),varname='dtype_expression',no_show=True) axis_menu=self.dtype_menu(('Range',),varname='dtype_axis',no_show=True) window_menu=self.dtype_menu(('Window',),varname='dtype_window',no_show=True) dispatch_menu=self.dtype_menu(('Dispatch',),varname='dtype_dispatch',no_show=True) action_menu=self.dtype_menu(('Action',),varname='dtype_action',no_show=True) task_menu=self.dtype_menu(('Method','Routine'),varname='dtype_task',no_show=True) any_menu=self.dtype_menu(('Range','Window','Dispatch','Action','Method','Routine'),varname='dtype_any',no_show=True) menus=(self.dtype_expression,self.dtype_axis,self.dtype_dispatch,self.dtype_action,self.dtype_task,self.dtype_window,self.dtype_any) hbtop.pack_start(self.on,False,False,10) hbtop.pack_start(self.parent_on,False,False,10) hbtop.pack_start(self.path,False,False,0) hbtags.pack_start(Label("Tags:"),False,False,10) hbtags.pack_start(self.tags,False,False,0) self.action=MDSplusActionWidget() self.windoww=MDSplusWindowWidget() self.sequential=MDSplusSequentialWidget() self.expression=MDSplusExpressionWidget() self.method=MDSplusMethodWidget() self.routine=MDSplusRoutineWidget() self.dispatch=MDSplusDispatchWidget() self.range=MDSplusRangeWidget() self.widgets=(self.action,self.sequential,self.expression,self.method,self.routine,self.dispatch,self.range,self.windoww) self.ok=Button(stock=STOCK_OK) self.cancel=Button(stock=STOCK_CANCEL) self.redo=Button(stock=STOCK_REDO) self.ok.connect("clicked",self.do_ok) self.cancel.connect("clicked",self.do_cancel) self.redo.connect("clicked",self.do_redo) hb2=HBox() hb2.add(self.ok) hb2.add(self.redo) hb2.add(self.cancel) vb=VBox(homogeneous=False) vb.set_border_width(10) vb.pack_start(hbtop,False,False,0) vb.pack_start(hbtags,False,False,0) vb.pack_start(expression_menu,False,False,0) vb.pack_start(axis_menu,False,False,0) vb.pack_start(window_menu,False,False,0) vb.pack_start(dispatch_menu,False,False,0) vb.pack_start(action_menu,False,False,0) vb.pack_start(task_menu,False,False,0) vb.pack_start(any_menu,False,False,0) for w in self.widgets: w.set_no_show_all(True) vb.pack_start(w,False,False,0) vb.pack_start(hb2,False,False,20) self.add(vb) self.do_redo(self.redo) self.putOnApply = True self.nidOffset = -1
class Base(object): def __init__(self): from gtk import Window,WINDOW_TOPLEVEL,Button,Label,HBox,Entry,VBox,VSeparator self.window = Window(WINDOW_TOPLEVEL) self.window.set_title("Slideshow") self.window.connect("delete_event", self.delete_event) self.window.set_border_width(10) self.vbox = VBox(False, 0) self.window.add(self.vbox) self.hbox1 = HBox(False, 0) self.vbox.pack_start(self.hbox1, True, True, 1) self.hbox = HBox(False, 0) self.vbox.pack_start(self.hbox, False, False, 1) self.hbox2 = HBox(False, 0) self.vbox.pack_start(self.hbox2, True, True, 1) self.label = Label('Identifikační číslo:') self.hbox.pack_start(self.label, False, False, 1) self.label.show() self.editable = Entry() self.editable.connect('key_press_event', self.key_press_event) self.hbox.pack_start(self.editable, True, True, 1) self.editable.show() self.button = Button("Začít") self.button.connect("clicked", self.callback) self.button.set_receives_default(True) self.button.set_can_focus(True) self.hbox.pack_start(self.button, False, False, 1) self.button.show() self.hbox1.show() self.hbox.show() self.hbox2.show() self.vbox.show() self.window.show() def delete_event(self, widget, event, data=None): gtk.main_quit() return False def key_press_event(self, widget, event): from gtk.gdk import keyval_from_name,keyval_name if event.keyval in (keyval_from_name('Return'),keyval_from_name('KP_Enter')): self.callback(widget) def _getFilePaths(self, fileTypes, recursive=True): import os import re from sys import argv pt = re.compile(r'.*([%(0)s][^%(0)s]*)'%{'0':os.path.extsep}) path = [a for m,a in ((pt.match(os.path.basename(a)),a) for a in argv[1:]) if m and m.group(1) in fileTypes] if not path: path = '/home/pi/img/*.jpg' if isinstance(path, str): ## Returns list containing paths of files in /path/ that are of a file type in /fileTypes/, ## if /recursive/ is False subdirectories are not checked. paths = [] if recursive: for root, folders, files in os.walk(path, followlinks=True): for file in files: for fileType in fileTypes: if file.endswith(fileType): paths.append(os.path.join(root, file)) else: for item in os.listdir(path): for fileType in fileTypes: if item.endswith(fileType): paths.append(os.path.join(root, item)) return paths elif iterable(path): return path else: return [] def _init_cb(self,trans): from threading import Thread if not iterable(trans): trans = trans, callbacks = [] for name,cb in trans: t = Thread(target=cb, name='%sThread'%name) t.daemon = True t.start() callbacks.append(cb.enqueue) def wrap(msg): for cb in callbacks: if not cb(msg): return False return True return wrap def callback(self, widget): from slideshow import SlideShow from trans import Message,GpioTransceiver,JsonTransceiver if not self.editable.get_text(): return False img_cbs = self._init_cb([('ImgGpioCallback',GpioTransceiver(24)),('ImgJsonCallback',JsonTransceiver('img.json'))]) kp_cbs = self._init_cb([('KpGpioCallback',GpioTransceiver(26,bcd=False)),('KpJsonCallback',JsonTransceiver('kp.json'))]) def ordfnc(path): from numpy.random import permutation gray = path[0] result = [] for p in permutation(path[1:]): result.append(p) result.append(gray) return result slide = SlideShow( path=self._getFilePaths(('.jpg', '.jpeg', '.png')), transition='None', fullscreen=True, delay=5, order=ordfnc, principal=self.editable.get_text(), img_callback = img_cbs, kp_callback = kp_cbs, ) self.editable.set_text('') slide() def __call__(self): gtk.main()
def __init__(self, node=None, value=None): Window.__init__(self) MDSplusWidget.__init__(self) if node is not None: self.node = node else: self.value = value hbtop = HBox(homogeneous=False) self.on = CheckButton(label="On") self.parent_on = CheckButton(label="Parent") self.parent_on.set_sensitive(False) self.path = MDSplusPathWidget() if node is not None: self.path._node = self._node hbtags = HBox(homogeneous=False) self.tags = Entry() self.tags.set_width_chars(60) expression_menu = self.dtype_menu(tuple(), varname="dtype_expression", no_show=True) axis_menu = self.dtype_menu(("Range",), varname="dtype_axis", no_show=True) window_menu = self.dtype_menu(("Window",), varname="dtype_window", no_show=True) dispatch_menu = self.dtype_menu(("Dispatch",), varname="dtype_dispatch", no_show=True) action_menu = self.dtype_menu(("Action",), varname="dtype_action", no_show=True) task_menu = self.dtype_menu(("Method", "Routine"), varname="dtype_task", no_show=True) any_menu = self.dtype_menu( ("Range", "Window", "Dispatch", "Action", "Method", "Routine"), varname="dtype_any", no_show=True ) menus = ( self.dtype_expression, self.dtype_axis, self.dtype_dispatch, self.dtype_action, self.dtype_task, self.dtype_window, self.dtype_any, ) hbtop.pack_start(self.on, False, False, 10) hbtop.pack_start(self.parent_on, False, False, 10) hbtop.pack_start(self.path, False, False, 0) hbtags.pack_start(Label("Tags:"), False, False, 10) hbtags.pack_start(self.tags, False, False, 0) self.action = MDSplusActionWidget() self.windoww = MDSplusWindowWidget() self.sequential = MDSplusSequentialWidget() self.expression = MDSplusExpressionWidget() self.method = MDSplusMethodWidget() self.routine = MDSplusRoutineWidget() self.dispatch = MDSplusDispatchWidget() self.range = MDSplusRangeWidget() self.widgets = ( self.action, self.sequential, self.expression, self.method, self.routine, self.dispatch, self.range, self.windoww, ) self.ok = Button(stock=STOCK_OK) self.cancel = Button(stock=STOCK_CANCEL) self.redo = Button(stock=STOCK_REDO) self.ok.connect("clicked", self.do_ok) self.cancel.connect("clicked", self.do_cancel) self.redo.connect("clicked", self.do_redo) hb2 = HBox() hb2.add(self.ok) hb2.add(self.redo) hb2.add(self.cancel) vb = VBox(homogeneous=False) vb.set_border_width(10) vb.pack_start(hbtop, False, False, 0) vb.pack_start(hbtags, False, False, 0) vb.pack_start(expression_menu, False, False, 0) vb.pack_start(axis_menu, False, False, 0) vb.pack_start(window_menu, False, False, 0) vb.pack_start(dispatch_menu, False, False, 0) vb.pack_start(action_menu, False, False, 0) vb.pack_start(task_menu, False, False, 0) vb.pack_start(any_menu, False, False, 0) for w in self.widgets: w.set_no_show_all(True) vb.pack_start(w, False, False, 0) vb.pack_start(hb2, False, False, 20) self.add(vb) self.do_redo(self.redo) self.putOnApply = True self.nidOffset = -1
from moodlight import moodlight_list, moodlight_get from gtk import Window, ColorSelection, main def makeChanger(moodlight): def cChanged(c): colour = c.get_current_color() r, g, b = (colour.red >> 8, colour.green >> 8, colour.blue >> 8) #print("(%s, %s, %s)" % (r, g, b)) moodlight.setRGB(r, g, b) return cChanged for umi in moodlight_list(): moodlight = moodlight_get(umi) w = Window() w.set_title(umi) c = ColorSelection() c.connect('color-changed', makeChanger(moodlight)) w.add(c) w.show_all() # Enter mainloop main()
class Dan: def __init__(self): self.url = "http://www.bibud.com" self.setupWindow() self.setupBrowser() main() def setupWindow(self): self.window_title = "Bibud" self.window = Window() self.window.show() self.window.connect("destroy-event", self.browser_quit) self.window.resize(1024, 768) self.window.set_title(self.window_title) def setupBrowser(self): self.browser = WebView() self.browser.show() self.browser.open(self.url) self.scroller = ScrolledWindow() self.scroller.add(self.browser) self.window.add(self.scroller) self.browser.connect("title-changed", self.title_changed) self.scroller.show() def eTitleChanged(self, webview, frame, title): self.window.set_title(title) def eQuit(self): main_quit()
class Dan: def __init__(self): self.url = "http://www.bibud.com" self.setupWindow() self.setupBrowser() main() def setupWindow(self): self.window_title = "Bibud" self.window = Window() self.window.show() self.window.connect("destroy-event", self.browser_quit) self.window.resize(1024,768) self.window.set_title(self.window_title) def setupBrowser(self): self.browser = WebView() self.browser.show() self.browser.open(self.url) self.scroller = ScrolledWindow() self.scroller.add(self.browser) self.window.add(self.scroller) self.browser.connect("title-changed", self.title_changed) self.scroller.show() def eTitleChanged(self, webview, frame, title): self.window.set_title(title) def eQuit(self): main_quit()
def show(self): import gtk from gtk import Window, Label w = Window() w.set_size_request(*self.resolution) l = gtk.Label('Coordinates') w.add(l) l.show() w.add_events(gtk.gdk.EXPOSURE_MASK | gtk.gdk.LEAVE_NOTIFY_MASK | gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.POINTER_MOTION_HINT_MASK) def configure_event(widget, event): pass def button_release_event(widget, event): if event.button == 1: print "unclick" self.server.send('u', 1, event.x, event.y) return True def button_press_event(widget, event): if event.button == 1: print "click" self.server.send('d', 1, event.x, event.y) return True def motion_notify_event(widget, event): if event.is_hint: x, y, state = event.window.get_pointer() else: print "no hint" x, y, state = event.x, event.y, event.state l.set_text("(%d,%d)" % (x, y)) print "Event number %d, (%d,%d)" % (event.type, x, y) self.server.send('.', 1, event.x, event.y) return True w.connect("configure_event", configure_event) w.connect("motion_notify_event", motion_notify_event) w.connect("button_press_event", button_press_event) w.connect("button_release_event", button_release_event) w.connect("delete_event", gtk.main_quit) if self.fullscreen: w.fullscreen() w.show() self.server.resolution = w.get_size() gtk.main()
self.pack_start(self.form, False) self.pack_start(self.result) self.login = GeoCaching() self.search = None self.form.connect('search', self.do_search) def do_search(self, widget, lat, long): self.search = self.login.search_lat_long(lat, long) for row in self.search.results: self.result.add_cache(row) self.result.show_all() if __name__ == '__main__': W = Window() S = Search() W.connect('destroy', main_quit) W.set_title("Search for caches") W.set_size_request(300,200) W.add(S) W.show_all() main()
def shell_startup(config_path, config, bookset, startup_callback, cmdline_options, cmdline_args): window = Window() def window_startup_event_handler(*args): db_handle = bookset.get_dbhandle() plugin_name = cmdline_args[PLUGIN_ARGUMENT] if ( not startup_callback( config_path, config, null_function, null_function, window) or not db_handle.has_sub_database(GUI_STATE_SUB_DB) or len(cmdline_args) < 0 ): main_quit() window.disconnect(window_connection) guistate = db_handle.get_sub_database(GUI_STATE_SUB_DB) book = guistate.get_book() if (book == None or not book.has_enabled_frontend_plugin(plugin_name) ): main_quit() headless_state = db_handle.get_sub_database_do_cls_init( HEADLESS_STATE_SUB_DB, HeadlessShellState) plugin = book.get_frontend_plugin(plugin_name) transaction_type_codes = tuple(plugin.get_transaction_type_codes()) if len(transaction_type_codes) == 0: main_quit() if (headless_state.current_transaction_id == None or not plugin.has_transaction(headless_state.current_transaction_id)): # check above is important because we sub index # transaction_type_codes type_code = (transaction_type_codes[0] if len(cmdline_args) == 1 else int(cmdline_args[TRANSACTION_TYPE_CODE_POS_ARG]) ) # if the user specifies a type code, it better be an available one # should convert this to a warning some day if type_code not in transaction_type_codes: main_quit() transaction_id, bokeep_transaction = \ instantiate_transaction_class_add_to_book_backend_and_plugin( plugin.get_transaction_type_from_code(type_code), plugin, book) headless_state.current_transaction_id = transaction_id display_mode = TRANSACTION_ALL_EDIT_FIRST_TIME_HEADLESS transaction.get().commit() else: bokeep_transaction = book.get_transaction( headless_state.current_transaction_id) # go through all the transaction type codes for this plugin # and find one that provides class that matches the # class of the existing transaction # # if none of them match (how could that happen, bad error!) # we quit # # the implementation of the linear search is done as a generator # expression filtered on what we're searching for # by trying to iterate over that generator (.next()) we # find out if anything matches because StopIteration is # raised if nothing matches # but we also manage to stop the iteration early when something # does match # # yes, all this in the avoidance of doing some kind of # imperitive loop with a break statement and some kind of # check condition after... try: type_code = ( type_code_test for type_code_test in transaction_type_codes if (plugin.get_transaction_type_from_code(type_code_test) == bokeep_transaction.__class__) ).next() except StopIteration: # should give an error msg main_quit() display_mode = TRANSACTION_ALL_EDIT_HEADLESS def change_register_function(): book.get_backend_plugin().mark_transaction_dirty( headless_state.current_transaction_id, bokeep_transaction) def window_close(*args): book.get_backend_plugin().flush_backend() transaction.get().commit() bookset.close() # should change guistate (default shell persistent storage) # to be on this specific trans id now main_quit() def transaction_edit_finished_function(): headless_state.set_no_current_transaction() transaction.get().commit() window_close() window_vbox = VBox() window.add(window_vbox) display_hook = plugin.get_transaction_display_by_mode_hook(type_code) display_hook(bokeep_transaction, headless_state.current_transaction_id, plugin, window_vbox, change_register_function, book, display_mode, transaction_edit_finished_function) window.connect("delete_event", window_close) window.show_all() window_connection = window.connect( "window-state-event", window_startup_event_handler) window.show_all() gtk.main()
self.vbox = VBox() self.add_with_viewport(self.vbox) HasRecordBox.__init__(self, self.vbox, data, name=name) self.vbox.show() self.show() self.vbox.set_events(BUTTON_PRESS_MASK) class CommandBox(VBox, HasMenuBar): def __init__(self, name='CommandBox'): VBox.__init__(self) self.set_name(name) self.tbar = HandleToolbar() self.menubar = SimpleMenuBar() self.pack_start(self.menubar, FALSE, FALSE, 0) self.pack_end(self.tbar, FALSE, FALSE, 0) self.show() if __name__ == '__main__': import paella.gtk from gtk import mainloop, mainquit from paella.base.util import file2str from gtk import Window tt = TextTemplater(file2str('/etc/debconf.conf')) win = Window() win.add(tt) win.show() win.connect('destroy', mainquit) mainloop()
#!/usr/bin/env python from gtk import Window, ColorSelection, main window = Window() window.add(ColorSelection()) window.show_all() main()
if machine not in self.pages: self.append_page(text, machine) self.set_current_page(machine) def _print_items(self, machine, raw=True): slines = _itemlines(self.cfg, machine, SYSOPTS, raw=raw) dblines = _itemlines(self.cfg, machine, DBOPTS, raw=raw) mnlines = _itemlines(self.cfg, machine, MAINOPTS, raw=raw) mclines = _itemlines(self.cfg, machine, MACHOPTS, raw=raw) umlines = _itemlines(self.cfg, machine, UMLOPTS, raw=raw) xumlines = _itemlines(self.cfg, machine, XUMLOPTS, raw=raw) alllines = [slines, dblines, mnlines, mclines, umlines, xumlines] sep = '\n\n------------------\n\n' text = sep.join(['\n'.join(lines) for lines in alllines]) + '\n' return text if __name__ == '__main__': from gtk import Window cfg = get_machines_config() sections = cfg.sections() print sections #d.set_rows([dict(section=x) for x in sections]) m = MachineBrowser(cfg) win = Window() win.add(m) win.show() win.connect('destroy', mainquit) mainloop()
def __init__(self): Window.__init__(self) self.pool = DownloadPoolBox(3) self.add(self.pool) self.show()
import re import os import cv2 import sys import glob from time import localtime,strftime,time from random import randint import numpy as np import pandas as pd import matplotlib.pyplot as plt import imutils #thru the pip package. # from skimage.filters import threshold_adaptive from gtk import Window # Some globals - window = Window() screen = window.get_screen() # for positioning image windows windowX,windowY = 0,0 windowWidth = screen.get_width() windowHeight = screen.get_height() # In[3]: Directories = [multiMarkedpath,errorpath,verifypath,badRollspath] print('Checking Directories...') for dir in [saveMarkedDir]: if(not os.path.exists(dir)): print('Created : '+ dir)
class MDSplusNidOptionWidget(props, MDSplusWidget, ComboBox): __gtype_name__ = 'MDSplusNidOptionWidget' __gproperties__ = props.__gproperties__ def xdbox_cancel(self, button): self.xdbox.set_modal(False) self.xdbox.expr.set_text(self.node_value()) button.get_toplevel().hide() def xdbox_close(self, button): try: value = self.value self.xdbox.set_modal(False) button.get_toplevel().hide() except: pass def xdbox_redo(self, button): self.xdbox.expr.set_text(self.node_value()) def button_press(self, cb, event): if self.get_active_text() == "Computed": if self.get_property('popup-shown'): self.popup_xd = True else: if self.popup_xd: if not hasattr(self, 'xdbox'): self.initXdbox() self.get_toplevel().set_focus(None) self.xdbox.set_modal(False) self.xdbox.show_all() self.popup_xd = False def node_value(self): value = self.record if value is None: value = '' else: value = str(value.decompile()) return value def fixValues(self): idx = 0 for value in self.values: if value.find('<DEVTOP>') > -1: try: self.values[idx] = value.replace( '<DEVTOP>', str(self.devnode)) except Exception: pass idx = idx+1 def updateItems(self): if not hasattr(self, 'values'): return m = self.get_model() if isinstance(self.values, str): self.values = self.values.split('\n') self.fixValues() if len(self.values) > len(m): self.values = self.values[0:len(m)-1] self.append_text('Computed') def initXdbox(self): self.xdbox = Window() try: self.xdbox.set_title(str(self.node)) except: pass vbox = VBox() self.xdbox.expr = MDSplusExprWidget() vbox.pack_start(self.xdbox.expr, True, True, 20) close = Button(stock=STOCK_CLOSE) close.connect("clicked", self.xdbox_close) redo = Button(stock=STOCK_REDO) redo.connect("clicked", self.xdbox_redo) cancel = Button(stock=STOCK_CANCEL) cancel.connect("clicked", self.xdbox_cancel) hbox = HBox() hbox.pack_start(close, False, False, 20) hbox.pack_start(redo, False, False, 20) hbox.pack_start(cancel, False, False, 20) vbox.pack_start(hbox, False, False, 20) self.xdbox.add(vbox) self.xdbox.expr.set_text(self.node_value()) def reset(self): value = self.node_value() if not hasattr(self, "has_been_initialized"): self.updateItems() self.has_been_initialized = True if not guibuilder: self.popup_xd = True self.connect('event', self.button_press) if hasattr(self, 'values'): self.set_active(len(self.values)) if not guibuilder: for idx in range(len(self.values)): val = self.values[idx] if val != '': try: newval = self.getNode().compile(val).decompile() val = str(newval) except Exception: print("Invalid value specified for an option item. Value string was <%s>. \nError was %s." % ( val, sys.exc_info())) if value == val: self.set_active(idx) break if hasattr(self, 'xdbox'): self.xdbox.expr.set_text(value) def getValue(self): idx = self.get_active() if idx < len(self.values): value = self.values[idx] elif hasattr(self, 'xdbox'): value = self.xdbox.expr.get_text() else: value = self.node_value() if value == '': return None else: try: return self.node.compile(value) except Exception: MDSplusErrorMsg('Invalid value', 'Invalid value specified.\n\n%s\n\n%s' % ( value, sys.exc_info())) raise value = property(getValue)
class MDSplusNidOptionWidget(props,MDSplusWidget,ComboBox): __gtype_name__ = 'MDSplusNidOptionWidget' __gproperties__ = props.__gproperties__ def xdbox_cancel(self,button): self.xdbox.set_modal(False) self.xdbox.expr.set_text(self.node_value()) button.get_toplevel().hide() def xdbox_close(self,button): try: value=self.value self.xdbox.set_modal(False) button.get_toplevel().hide() except: pass def xdbox_redo(self,button): self.xdbox.expr.set_text(self.node_value()) def button_press(self,cb,event): if self.get_active_text() == "Computed": if self.get_property('popup-shown'): self.popup_xd=True else: if self.popup_xd: if not hasattr(self,'xdbox'): self.initXdbox() self.get_toplevel().set_focus(None) self.xdbox.set_modal(False) self.xdbox.show_all() self.popup_xd=False def node_value(self): value=self.record if value is None: value='' else: value=str(value.decompile()) return value def fixValues(self): idx=0 for value in self.values: if value.find('<DEVTOP>') > -1: try: self.values[idx]=value.replace('<DEVTOP>',str(self.devnode)) except Exception: pass idx=idx+1 def updateItems(self): if not hasattr(self,'values'): return m=self.get_model() if isinstance(self.values,str): self.values=self.values.split('\n') self.fixValues() if len(self.values) > len(m): self.values=self.values[0:len(m)-1] self.append_text('Computed') def initXdbox(self): self.xdbox=Window() try: self.xdbox.set_title(str(self.node)) except: pass vbox=VBox() self.xdbox.expr=MDSplusExprWidget() vbox.pack_start(self.xdbox.expr,True,True,20) close=Button(stock=STOCK_CLOSE) close.connect("clicked",self.xdbox_close) redo=Button(stock=STOCK_REDO) redo.connect("clicked",self.xdbox_redo) cancel=Button(stock=STOCK_CANCEL) cancel.connect("clicked",self.xdbox_cancel) hbox=HBox() hbox.pack_start(close,False,False,20) hbox.pack_start(redo,False,False,20) hbox.pack_start(cancel,False,False,20) vbox.pack_start(hbox,False,False,20) self.xdbox.add(vbox) self.xdbox.expr.set_text(self.node_value()) def reset(self): value=self.node_value() if not hasattr(self,"has_been_initialized"): self.updateItems() self.has_been_initialized=True if not guibuilder: self.popup_xd=True self.connect('event',self.button_press) if hasattr(self,'values'): self.set_active(len(self.values)) if not guibuilder: for idx in range(len(self.values)): val=self.values[idx] if val != '': try: newval=self.getNode().compile(val).decompile() val=str(newval) except Exception: print("Invalid value specified for an option item. Value string was <%s>. \nError was %s." % (val,sys.exc_info())) if value == val: self.set_active(idx) break if hasattr(self,'xdbox'): self.xdbox.expr.set_text(value) def getValue(self): idx=self.get_active() if idx < len(self.values): value=self.values[idx] elif hasattr(self,'xdbox'): value=self.xdbox.expr.get_text() else: value=self.node_value() if value == '': return None else: try: return self.node.compile(value) except Exception: MDSplusErrorMsg('Invalid value','Invalid value specified.\n\n%s\n\n%s' % (value,sys.exc_info())) raise value=property(getValue)