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()
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()
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()
#!/usr/bin/env python from gtk import Window, ColorSelection, main window = Window() window.add(ColorSelection()) window.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()
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()
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()