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()
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)
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()
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()
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()
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()
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)