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()
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 create_gui(self): table = GtkTable() table.set_row_spacings(3) table.set_col_spacings(3) self.pack_start(table) # collect candidate field names from the schema. fnlist = ['disabled'] # Field Name self.field_label = GtkLabel('Label Field:') table.attach(self.field_label, 0, 1, 0, 1, xoptions=SHRINK, yoptions=SHRINK) self.label_field = pgucombo.pguCombo() self.label_field.set_popdown_strings(fnlist) self.label_field.entry.connect('changed', self.label_change_cb) table.attach(self.label_field, 1, 3, 0, 1, xoptions=SHRINK, yoptions=SHRINK) # Create Color control. table.attach(GtkLabel('Color:'), 0, 1, 1, 2, xoptions=SHRINK, yoptions=SHRINK) self.label_color = pgucolorsel.ColorControl('Label Color', self.label_change_cb) table.attach(self.label_color, 1, 3, 1, 2, yoptions=SHRINK) # Font table.attach(GtkLabel('Font:'), 0, 1, 2, 3, xoptions=SHRINK, yoptions=SHRINK) self.label_font = pgufont.pguFontControl() self.label_font.subscribe('font-changed', self.label_change_cb) table.attach(self.label_font, 1, 2, 2, 3, xoptions=SHRINK) ####################################################################### # Add Text entry/edit if self.text_entry: table.attach(GtkLabel('Text:'), 0, 1, 3, 4, xoptions=SHRINK, yoptions=SHRINK) self.text_entry = GtkEntry() self.text_entry.connect('activate', self.text_change_cb) if self.interactive: self.text_entry.connect('changed', self.text_change_cb) else: self.text_entry.connect('focus-out-event', self.text_change_cb) table.attach(self.text_entry, 1, 3, 3, 4) else: self.text_entry = None if self.enable_offsets: #Label offsets table.attach(GtkLabel('Label X Offset:'), 0, 1, 4, 5, xoptions=SHRINK, yoptions=SHRINK) spin_adjust = GtkAdjustment(value=0.0, lower=-20.0, upper=20.0, step_incr=1.0) self.x_offset = GtkSpinButton(spin_adjust) self.x_offset.set_editable(TRUE) self.x_offset.set_digits(1) self.x_offset.set_usize(75, 0) self.x_offset.connect('changed', self.label_change_cb) table.attach(self.x_offset, 1, 3, 4, 5, xoptions=SHRINK, yoptions=SHRINK) #Label offsets table.attach(GtkLabel('Label Y Offset:'), 0, 1, 5, 6, xoptions=SHRINK, yoptions=SHRINK) spin_adjust = GtkAdjustment(value=0.0, lower=-20.0, upper=20.0, step_incr=1.0) self.y_offset = GtkSpinButton(spin_adjust) self.y_offset.set_editable(TRUE) self.y_offset.set_digits(1) self.y_offset.set_usize(75, 0) self.y_offset.connect('changed', self.label_change_cb) table.attach(self.y_offset, 1, 3, 5, 6, xoptions=SHRINK, yoptions=SHRINK)
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()