def __init__(self, size=(300,300), name="Piddle-GTK"): import gtk # width, height = (int(round(size[0])), int(round(size[1]))) top = self.__top = gtk.GtkDialog() vbox = top.vbox frame = self.__frame = gtk.GtkFrame() frame.set_shadow_type(gtk.SHADOW_IN) da = gtk.GtkDrawingArea() button = gtk.GtkButton("Dismiss") button.connect("clicked", lambda button, top=top: top.destroy()) frame.set_border_width(10) bbox = self.__bbox = gtk.GtkHButtonBox() bbox.set_layout(gtk.BUTTONBOX_END) bbox.pack_end(button) top.action_area.pack_end(bbox) frame.add(da) vbox.pack_start(frame) InteractiveCanvas.__init__(self, da, top) top.set_wmclass("canvas", "Canvas") da.realize() da.set_usize(width, height) top.show_all() top.set_icon_name(name) top.set_title(name) self.ensure_size(width, height)
def __init__(self): gtk.GtkHBox.__init__(self, gtk.FALSE, 5) self.entry = gtk.GtkEntry() self.pack_start(self.entry) self.entry.show() self.button = gtk.GtkButton("...") self.button.connect("clicked", self.show_dialog) self.pack_start(self.button, expand=gtk.FALSE) self.button.show() self.dialog = gtk.GtkDialog() self.dialog.set_title(self.get_title()) def delete_event(win, event): win.hide() return gtk.TRUE self.dialog.connect("delete_event", delete_event) box = gtk.GtkVBox() box.set_border_width(5) self.dialog.vbox.pack_start(box) box.show() swin = gtk.GtkScrolledWindow() swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) box.pack_start(swin) swin.show() items = map(None, self.get_list()) list = gtk.GtkList() list.set_selection_mode(gtk.SELECTION_BROWSE) self.selected = self.get_default() self.entry.set_text(self.selected) items.sort() for s in items: item = gtk.GtkListItem(s) list.add(item) if s == self.selected: list.select_child(item) item.show() swin.add_with_viewport(list) list.show() b = gtk.GtkButton("OK") self.dialog.action_area.pack_start(b) b.set_flags(gtk.CAN_DEFAULT) b.grab_default() b.show() b.connect("clicked", self.selection_ok, list) b = gtk.GtkButton("Cancel") self.dialog.action_area.pack_start(b) b.set_flags(gtk.CAN_DEFAULT) b.show() b.connect("clicked", self.dialog.hide) self.dialog.set_usize(300, 225)
def __init__(self, title): top = gtk.GtkDialog() top.set_title(title) # set up the text widget at the top: scrwin = gtk.GtkScrolledWindow() scrwin.set_border_width(10) scrwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS) text = self.__text = gtk.GtkText(vadj=scrwin.get_vadjustment()) text.freeze() scrwin.add(text) top.vbox.pack_start(scrwin) # set up the dismiss button: button = gtk.GtkButton("Dismiss") button.connect("clicked", lambda button, top=top: top.destroy()) bbox = gtk.GtkHButtonBox() bbox.set_layout(gtk.BUTTONBOX_END) bbox.pack_end(button) top.action_area.pack_end(bbox) # all done! top.set_default_size(500, 300) top.show_all()
def report_error(err): "Write 'error' to stderr and, if possible, display a dialog box too." try: sys.stderr.write('*** ' + err + '\n') except: pass try: import pygtk; pygtk.require('2.0') import gtk; g = gtk except: import gtk win = gtk.GtkDialog() message = gtk.GtkLabel(err + '\n\nAlso, pygtk2 needs to be present') win.set_title('Missing ROX-Lib2') win.set_position(gtk.WIN_POS_CENTER) message.set_padding(20, 20) win.vbox.pack_start(message) ok = gtk.GtkButton("OK") ok.set_flags(gtk.CAN_DEFAULT) win.action_area.pack_start(ok) ok.connect('clicked', gtk.mainquit) ok.grab_default() win.connect('destroy', gtk.mainquit) win.show_all() gtk.mainloop() else: box = g.MessageDialog(None, g.MESSAGE_ERROR, 0, g.BUTTONS_OK, err) box.set_title('Missing ROX-Lib2') box.set_position(g.WIN_POS_CENTER) box.set_default_response(g.RESPONSE_OK) box.run() sys.exit(1)
if __name__ == '__main__': a = ColorRamp() a.add_color((0.0, 1.0, 0.0, 1.0), 0.0) a.add_color((1.0, 1.0, 0.0, 1.0), 0.50) a.add_color((1.0, 0.0, 0.0, 1.0), 1.0) print a.colors a.apply_ramp(test_cb, 5) print a.colors a.serialize('c:\\test_ramp') b = ColorRamp() b.deserialize('c:\\test_ramp') print b.colors c = ColorButton((1.0, 0.0, 0.0, 1.0)) c.connect('color-set', color_set) dlg = gtk.GtkDialog() btn = gtk.GtkButton('OK') btn.connect('clicked', gtk.mainquit) dlg.vbox.pack_start(a) dlg.vbox.pack_start(b) dlg.vbox.pack_start(c) dlg.action_area.pack_start(btn) dlg.show_all() dlg.show() gtk.mainloop()
def _interact(func_name): (blurb, help, author, copyright, date, menupath, imagetypes, plugin_type, params, results, function) = _registered_plugins_[func_name] # short circuit for no parameters ... if len(params) == 0: return [] import gtk import gimpui gtk.rc_parse(gimp.gtkrc()) defaults = _get_defaults(func_name) # define a mapping of param types to edit objects ... class StringEntry(gtk.GtkEntry): def __init__(self, default=''): import gtk gtk.GtkEntry.__init__(self) self.set_text(str(default)) def get_value(self): return self.get_text() class IntEntry(StringEntry): def get_value(self): import string return string.atoi(self.get_text()) class FloatEntry(StringEntry): def get_value(self): import string return string.atof(self.get_text()) class ArrayEntry(StringEntry): def get_value(self): return eval(self.get_text()) class SliderEntry(gtk.GtkHScale): # bounds is (upper, lower, step) def __init__(self, default=0, bounds=(0, 100, 5)): import gtk self.adj = gtk.GtkAdjustment(default, bounds[0], bounds[1], bounds[2], bounds[2], bounds[2]) gtk.GtkHScale.__init__(self, self.adj) def get_value(self): return self.adj.value class SpinnerEntry(gtk.GtkSpinButton): # bounds is (upper, lower, step) def __init__(self, default=0, bounds=(0, 100, 5)): import gtk self.adj = gtk.GtkAdjustment(default, bounds[0], bounds[1], bounds[2], bounds[2], bounds[2]) gtk.GtkSpinButton.__init__(self, self.adj, 1, 0) def get_value(self): return int(self.adj.value) class ToggleEntry(gtk.GtkToggleButton): def __init__(self, default=0): import gtk gtk.GtkToggleButton.__init__(self) self.label = gtk.GtkLabel("No") self.add(self.label) self.label.show() self.connect("toggled", self.changed) self.set_active(default) def changed(self, tog): if tog.active: self.label.set_text("Yes") else: self.label.set_text("No") def get_value(self): return self.get_active() _edit_mapping = { PF_INT8 : IntEntry, PF_INT16 : IntEntry, PF_INT32 : IntEntry, PF_FLOAT : FloatEntry, PF_STRING : StringEntry, PF_INT8ARRAY : ArrayEntry, PF_INT16ARRAY : ArrayEntry, PF_INT32ARRAY : ArrayEntry, PF_FLOATARRAY : ArrayEntry, PF_STRINGARRAY : ArrayEntry, PF_COLOUR : gimpui.ColourSelector, PF_REGION : IntEntry, # should handle differently ... PF_IMAGE : gimpui.ImageSelector, PF_LAYER : gimpui.LayerSelector, PF_CHANNEL : gimpui.ChannelSelector, PF_DRAWABLE : gimpui.DrawableSelector, PF_TOGGLE : ToggleEntry, PF_SLIDER : SliderEntry, PF_SPINNER : SpinnerEntry, PF_FONT : gimpui.FontSelector, PF_FILE : gimpui.FileSelector, PF_BRUSH : gimpui.BrushSelector, PF_PATTERN : gimpui.PatternSelector, PF_GRADIENT : gimpui.GradientSelector, } tooltips = gtk.GtkTooltips() dialog = gtk.GtkDialog() dialog.set_title(func_name) table = gtk.GtkTable(len(params), 3, gtk.FALSE) table.set_border_width(5) table.set_row_spacings(2) table.set_col_spacings(10) dialog.vbox.pack_start(table) table.show() vbox = gtk.GtkVBox(gtk.FALSE, 15) table.attach(vbox, 0,1, 0,len(params), xoptions=gtk.FILL) vbox.show() pix = _get_logo(vbox.get_colormap()) vbox.pack_start(pix, expand=gtk.FALSE) pix.show() label = gtk.GtkLabel(blurb) label.set_line_wrap(TRUE) label.set_justify(gtk.JUSTIFY_LEFT) label.set_usize(100, -1) vbox.pack_start(label, expand=gtk.FALSE) label.show() edit_wids = [] for i in range(len(params)): type = params[i][0] name = params[i][1] desc = params[i][2] def_val = defaults[i] label = gtk.GtkLabel(name) label.set_alignment(1.0, 0.5) table.attach(label, 1,2, i,i+1, xoptions=gtk.FILL) label.show() if type in (PF_SPINNER, PF_SLIDER): wid = _edit_mapping[type](def_val, params[i][4]) else: wid = _edit_mapping[type](def_val) table.attach(wid, 2,3, i,i+1) tooltips.set_tip(wid, desc, None) wid.show() edit_wids.append(wid) def delete_event(win, event=None): import gtk win.hide() gtk.mainquit() return TRUE # this is a hack ... finished = [ 0 ] def ok_clicked(button, win=dialog, finished=finished): import gtk win.hide() finished[0] = 1 gtk.mainquit() b = gtk.GtkButton("OK") b.set_flags(gtk.CAN_DEFAULT) dialog.action_area.pack_start(b) b.grab_default() b.connect("clicked", ok_clicked) b.show() b = gtk.GtkButton("Cancel") b.set_flags(gtk.CAN_DEFAULT) dialog.action_area.pack_start(b) b.connect("clicked", delete_event) b.show() dialog.show() tooltips.enable() # run the main loop gtk.mainloop() ret = None if finished[0]: # OK was clicked ret = map(lambda wid: wid.get_value(), edit_wids) _set_defaults(func_name, ret) dialog.destroy() return ret