def __init__(self, ok_cb=None, cancel_cb=None, cb_data=None): gtk.GtkWindow.__init__(self) self.set_title('Select a Color') vbox = gtk.GtkVBox(spacing=3) self.add(vbox) self.user_ok_cb = ok_cb self.user_cancel_cb = cancel_cb self.user_cb_data = cb_data self.connect('delete-event', self.user_cancel_cb) #add the color selection widget self.colorsel = gtk.GtkColorSelection() self.colorsel.set_opacity(gtk.TRUE) vbox.pack_start(self.colorsel) #add the ok and cancel buttons button_box = gtk.GtkHButtonBox() ok_button = gtk.GtkButton("OK") ok_button.connect('clicked', self.ok_cb, cb_data) cancel_button = gtk.GtkButton("Cancel") cancel_button.connect('clicked', self.cancel_cb, cb_data) button_box.pack_start(ok_button) button_box.pack_start(cancel_button) vbox.pack_start(button_box, expand=gtk.FALSE) vbox.show_all() ok_button.set_flags(gtk.CAN_DEFAULT) ok_button.grab_default()
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, question, default, callback): gtk.GtkWindow.__init__(self) self.callback = callback self.text = gtk.GtkText() self.set_title(question) self.text.set_editable(gtk.TRUE) self.text.insert_defaults(default) self.text.set_word_wrap(gtk.TRUE) scrl = gtkutil.scrollify(self.text) vb = gtk.GtkVBox() bb = gtk.GtkHButtonBox() vb.pack_start(scrl) bb.set_spacing(0) bb.set_layout(gtk.BUTTONBOX_END) cancelb = gtkutil.cbutton("Cancel", self.callcancel) bb.add(cancelb) okb = gtkutil.cbutton("OK", self.callok) cancelb.set_flags(gtk.CAN_DEFAULT) okb.set_flags(gtk.CAN_DEFAULT) okb.set_flags(gtk.HAS_DEFAULT) bb.add(okb) vb.add(bb, expand=gtk.FALSE) self.add(vb) self.set_usize(300, 200) self.connect('delete_event', dontgo) self.show_all()
def __init__(self, ok_cb=None, cancel_cb=None, cb_data=None, classify_type=CLASSIFY_EQUAL_INTERVAL): gtk.GtkWindow.__init__(self) self.set_title('Classification') self.user_ok_cb = ok_cb self.user_cancel_cb = cancel_cb self.user_cb_data = cb_data self.classify_type = classify_type self.set_border_width(6) #main vertical box vbox = gtk.GtkVBox(spacing=6) type_box = gtk.GtkHBox(spacing=6) type_box.pack_start(gtk.GtkLabel('Type:'), expand=gtk.FALSE) opt_menu = gtk.GtkOptionMenu() type_menu = gtk.GtkMenu() #using classification_types dictionary from gvclassification for i in range(len(classification_types)): for type in classification_types.iteritems(): if type[1] == i: item = gtk.GtkMenuItem(type[0]) item.connect('activate', self.type_menu_cb, classification_types[type[0]]) type_menu.append(item) opt_menu.set_menu(type_menu) opt_menu.set_history(classify_type) opt_menu.resize_children() type_box.pack_start(opt_menu) vbox.pack_start(type_box, expand=gtk.FALSE) #Number of classes classes_box = gtk.GtkHBox(spacing=6) classes_box.pack_start(gtk.GtkLabel('Number of classes:')) adj = gtk.GtkAdjustment(5, 2, 80, 1, 5, 5, 0) self.spinner = gtk.GtkSpinButton(adj) self.spinner.set_snap_to_ticks(gtk.TRUE) self.spinner.set_digits(0) classes_box.pack_start(self.spinner) vbox.pack_start(classes_box, expand=gtk.FALSE) #add the ok and cancel buttons button_box = gtk.GtkHButtonBox() ok_button = gtk.GtkButton("OK") ok_button.connect('clicked', self.ok_cb, cb_data) cancel_button = gtk.GtkButton("Cancel") cancel_button.connect('clicked', self.cancel_cb, cb_data) button_box.pack_start(ok_button) button_box.pack_start(cancel_button) vbox.pack_start(button_box, expand=gtk.FALSE) vbox.show_all() self.add(vbox) ok_button.set_flags(gtk.CAN_DEFAULT) ok_button.grab_default()
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 __init__(self, callback, referenceable=None, initialUser="******", initialPassword="******", initialHostname="localhost", initialPortno=str(pb.portno), initialService="", initialPerspective=""): gtk.GtkWindow.__init__(self, gtk.WINDOW_TOPLEVEL) version_label = gtk.GtkLabel("Twisted v%s" % copyright.version) self.pbReferenceable = referenceable self.pbCallback = callback # version_label.show() self.username = gtk.GtkEntry() self.password = gtk.GtkEntry() self.service = gtk.GtkEntry() self.perspective = gtk.GtkEntry() self.hostname = gtk.GtkEntry() self.port = gtk.GtkEntry() self.password.set_visibility(gtk.FALSE) self.username.set_text(initialUser) self.password.set_text(initialPassword) self.service.set_text(initialService) self.perspective.set_text(initialPerspective) self.hostname.set_text(initialHostname) self.port.set_text(str(initialPortno)) userlbl = gtk.GtkLabel("Username:"******"Password:"******"Service:") perspeclbl = gtk.GtkLabel("Perspective:") hostlbl = gtk.GtkLabel("Hostname:") portlbl = gtk.GtkLabel("Port #:") self.allLabels = [ userlbl, passlbl, servicelbl, perspeclbl, hostlbl, portlbl ] self.logstat = gtk.GtkLabel("Protocol PB-%s" % pb.Broker.version) self.okbutton = cbutton("Log In", self.login) self.okbutton["can_default"] = 1 self.okbutton["receives_default"] = 1 okbtnbx = gtk.GtkHButtonBox() okbtnbx.add(self.okbutton) vbox = gtk.GtkVBox() vbox.add(version_label) table = gtk.GtkTable(2, 6) row = 0 for label, entry in [(userlbl, self.username), (passlbl, self.password), (hostlbl, self.hostname), (servicelbl, self.service), (perspeclbl, self.perspective), (portlbl, self.port)]: table.attach(label, 0, 1, row, row + 1) table.attach(entry, 1, 2, row, row + 1) row = row + 1 vbox.add(table) vbox.add(self.logstat) vbox.add(okbtnbx) self.add(vbox) self.username.grab_focus() self.okbutton.grab_default() for fld in self.username, self.password, self.hostname, self.service, self.perspective: fld.signal_connect('activate', self.login) fld.signal_connect('focus_in_event', selectAll) self.signal_connect('destroy', gtk.mainquit, None)
def __init__(self, title=None, cwd=None, dialog_type=FILE_OPEN, filter=None, app=None, multiselect=0): gtk.GtkWindow.__init__(self) if dialog_type >= FILE_OPEN and dialog_type <= DIRECTORY_SELECT: self.dialog_type = dialog_type else: self.dialog_type = FILE_OPEN self.filter = None #current filter self.filters = {} #active filter objects self.filter_keys = [] #ordered list of the names of the filters self.file_selection = [] self.multiselect = multiselect self.set_border_width(5) self.set_policy(as=gtk.FALSE, ag=gtk.FALSE, autos=gtk.TRUE) self.drives = None if title == None: if dialog_type == FILE_OPEN: title = nls.get('filedlg-title-open-file', 'Open File ...') elif dialog_type == FILE_SAVE: title = nls.get('filedlg-title-save-file', 'Save File ...') elif dialog_type == DIRECTORY_SELECT: title = nls.get('filedlg-title-select-directory', 'Select Directory ...') self.set_title(title) #setup the current working directory if cwd is None or not os.path.exists(cwd): cwd = gview.get_preference('working-directory') if cwd is None: cwd = os.getcwd() self.cwd = cwd #widgets vbox = gtk.GtkVBox(spacing=5) if dialog_type == FILE_OPEN or dialog_type == DIRECTORY_SELECT: lbl = gtk.GtkLabel(nls.get('filedlg-label-open-from', 'Open From:')) elif dialog_type == FILE_SAVE: lbl = gtk.GtkLabel(nls.get('filedlg-label-save-in', 'Save In:')) self.opt_menu = gtk.GtkOptionMenu() self.opt_menu.set_menu(gtk.GtkMenu()) hbox = gtk.GtkHBox() hbox.pack_start(lbl, expand=gtk.FALSE) hbox.pack_start(self.opt_menu) vbox.pack_start(hbox, expand = gtk.FALSE) self.list_directory = gtk.GtkCList() scr_directories = gtk.GtkScrolledWindow() scr_directories.add(self.list_directory) self.list_directory.connect('button-press-event', self.directory_selected_cb) if dialog_type == DIRECTORY_SELECT: self.list_files = None vbox.pack_start(scr_directories) else: self.list_files = gtk.GtkCList() if self.multiselect: self.list_files.set_selection_mode( gtk.SELECTION_EXTENDED ) scr_files = gtk.GtkScrolledWindow() scr_files.add(self.list_files) self.list_files.connect('button-press-event', self.file_clicked_cb) self.list_files.connect('select-row', self.file_selected_cb ) self.list_files.connect('unselect-row', self.file_unselected_cb ) pane = gtk.GtkHPaned() scr_directories.set_usize(100, -1) scr_files.set_usize(100, -1) pane.add1(scr_directories) pane.add2(scr_files) pane.set_position(200) vbox.pack_start(pane) widget = None if dialog_type == FILE_SAVE: self.txt_filename = gtk.GtkEntry() widget = self.txt_filename elif dialog_type == FILE_OPEN: combo = gtk.GtkCombo() combo.set_value_in_list(gtk.FALSE, gtk.FALSE) combo.disable_activate() if app is not None: rfl = app.get_rfl() rfl.insert(0, '') combo.set_popdown_strings( rfl ) self.txt_filename = combo.entry widget = combo if widget is not None: table = gtk.GtkTable(rows=2, cols=2) lbl = gtk.GtkLabel(nls.get('filedlg-label-file-name', 'File Name:')) self.txt_filename.connect('focus-out-event', self.map_path_cb) self.txt_filename.connect('key-press-event', self.map_path_cb) table.attach(lbl, 0, 1, 0, 1) table.attach(widget, 1, 2, 0, 1) lbl = gtk.GtkLabel(nls.get('filedlg-label-filter-extension', 'Filter extension:')) self.cmb_filter = pguCombo() self.set_filter(filter) self.cmb_filter.entry.connect('changed', self.filter_cb) table.attach(lbl, 0, 1, 1, 2) table.attach(self.cmb_filter, 1, 2, 1, 2) vbox.pack_start(table, expand=gtk.FALSE) if dialog_type == FILE_SAVE: self.ok_button = gtk.GtkButton(nls.get('filedlg-button-ok', 'OK')) elif dialog_type == FILE_OPEN: self.ok_button = gtk.GtkButton(nls.get('filedlg-button-open', 'Open')) elif dialog_type == DIRECTORY_SELECT: self.ok_button = gtk.GtkButton(nls.get('filedlg-button-ok', 'OK')) self.cancel_button = gtk.GtkButton(nls.get('filedlg-button-cancel', 'Cancel')) self.ok_button.connect('clicked', self.remove_grab) self.ok_button.connect('clicked', self.update_cwd) self.cancel_button.connect('clicked', self.remove_grab) btn_box = gtk.GtkHButtonBox() btn_box.pack_start(self.ok_button) btn_box.pack_start(self.cancel_button) vbox.pack_start(btn_box, expand=gtk.FALSE) self.add(vbox) self.show_all() #make modal gtk.grab_add(self) self.ok_button.set_flags(gtk.CAN_DEFAULT) self.ok_button.grab_default() self.set_usize(400, 400) self.menu_update = gtk.FALSE while gtk.events_pending(): gtk.mainiteration(FALSE) self.refresh_directory() self.connect('delete-event', self.quit) self.ok_button.connect('clicked', self.quit) self.cancel_button.connect('clicked', self.quit) self.publish('quit') self.add_events(gtk.GDK.KEY_PRESS_MASK) self.connect('key-press-event', self.key_press_cb) self.result = 'cancel'
def __init__(self, classification): """Initialize a GvClassificationDlg on a particular GvLayer""" gtk.GtkWindow.__init__(self) self.set_title('Layer Classification') self.set_usize(-1, 400) self.connect('delete-event', self.close) self.set_border_width(5) self.color_buttons = [] self.sym_menus = [] self.scale_spinners = [] self.view_mgr = None self.ranges = [] self.labels = [] self.reclassdlg = None self.updating = FALSE items = load_ramp_config_file() self.ramp = None if classification is None: self.classification = GvClassification() elif issubclass(classification.__class__, GvClassification): self.classification = classification else: raise TypeError, 'GvClassificationDlg now requires a \ GvClassification instance' if self.classification.count <= 0: self.ramp = items[0] self.classification.prepare_default() #d = self.classification.serialize() #main vertical box vbox = gtk.GtkVBox(spacing=3) save_box = gtk.GtkHButtonBox() btn_save = gtk.GtkButton('Save ...') btn_save.connect('clicked', self.save_cb) btn_load = gtk.GtkButton('Load ...') btn_load.connect('clicked', self.load_cb) save_box.pack_start(btn_load) save_box.pack_start(btn_save) try: import pgucombo self.property_list = pgucombo.pguCombo() except: self.property_list = gtk.GtkCombo() self.property_list.entry.connect('changed', self.property_select_cb) self.update_property_list() save_box.pack_start(self.property_list) vbox.pack_start(save_box, expand=gtk.FALSE) #classification frame class_frame = gtk.GtkFrame() frame_box = gtk.GtkVBox(spacing=3) title_box = gtk.GtkHBox() title_lbl = gtk.GtkLabel('Legend Title: ') self.title_txt = gtk.GtkEntry() self.title_txt.set_text(self.classification.get_title()) self.title_txt.connect('changed', self.title_changed_cb) title_box.pack_start(title_lbl, expand=gtk.FALSE) title_box.pack_start(self.title_txt) frame_box.pack_start(title_box, expand=gtk.FALSE) frame_box.set_border_width(5) #classification list class_box = gtk.GtkScrolledWindow() self.class_list = gtk.GtkList() self.class_list.connect('select-child', self.list_selected) class_box.add_with_viewport(self.class_list) frame_box.pack_start(class_box) self.reset_classification_list() class_frame.add(frame_box) vbox.pack_start(class_frame) ar_box = gtk.GtkHButtonBox() add_btn = gtk.GtkButton('Add class') add_btn.connect('clicked', self.add_class_cb) classify_btn = gtk.GtkButton('reclassify ...') classify_btn.connect('clicked', self.reclassify_cb) reset_btn = gtk.GtkButton('Revert') reset_btn.connect('clicked', self.reset_cb) ar_box.pack_start(add_btn) ar_box.pack_start(classify_btn) ar_box.pack_start(reset_btn) vbox.pack_start(ar_box, expand=gtk.FALSE) #Color Ramp choices ramp_table = gtk.GtkTable(rows=2, cols=2) ramp_table.show() ramp_lbl = gtk.GtkLabel('Color Ramps: ') ramp_lbl.show() ramp_table.attach(ramp_lbl, 0, 1, 0, 1) ramp_opt = gtk.GtkOptionMenu() ramp_opt.show() self.ramp_menu = gtk.GtkMenu() self.ramp_menu.show() ramp_item = gtk.GtkMenuItem() ramp_item.add(gtk.GtkHSeparator()) ramp_item.set_sensitive(gtk.FALSE) ramp_item.show_all self.ramp_menu.append(ramp_item) for n in items: ramp_item = gtk.GtkMenuItem() ramp_item.add(n) ramp_item.show_all() if issubclass(n.__class__, ColorRamp): ramp_item.connect('activate', self.ramp_cb, n) else: ramp_item.set_sensitive(gtk.FALSE) self.ramp_menu.append(ramp_item) ramp_opt.set_menu(self.ramp_menu) ramp_opt.show() ramp_opt.set_history(0) ramp_table.attach(ramp_opt, 1, 2, 0, 1) ramp_table.show_all() vbox.pack_start(ramp_table, expand=gtk.FALSE) #buttons button_box = gtk.GtkHButtonBox() #button_box.set_layout_default(gtk.BUTTONBOX_START) self.ok_button = gtk.GtkButton('OK') self.ok_button.connect('clicked', self.ok_cb) self.apply_button = gtk.GtkButton('Apply') self.apply_button.connect('clicked', self.apply_cb) self.cancel_button = gtk.GtkButton('Cancel') self.cancel_button.connect('clicked', self.cancel_cb) button_box.pack_start(self.ok_button, expand=gtk.FALSE) button_box.pack_start(self.apply_button, expand=gtk.FALSE) button_box.pack_start(self.cancel_button, expand=gtk.FALSE) vbox.pack_start(button_box, expand=gtk.FALSE) vbox.show_all() self.add(vbox) #make ok_button a default button ? why isn't it working ? self.ok_button.set_flags(gtk.CAN_DEFAULT) self.ok_button.grab_default() self.publish('classification-changed') self.update_property_list()