def setupDialog(self, parent): self.dialog = gtk.Dialog("Preferences", parent, gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT, gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT)) self.widgets = [] self.tooltips = gtk.Tooltips() notebook = gtk.Notebook() notebook.set_border_width(4) self.dialog.vbox.set_border_width(4) self.dialog.vbox.pack_start(notebook) #self.dialog.add(vbox) for group in self.opts: if not group.getGUI(): continue tab = gtk.VBox(False, 8) tab.set_border_width(8) #print("tab", tab) desc = gtk.Label(group.description) tab.pack_start(desc, False, False) for optnumber, option in enumerate(group): optBox = gtk.HBox(spacing=8) l = gtk.Label(getPrettyName(option)) self.tooltips.set_tip(l, option.description) optBox.pack_start(l, False, True) if option.type in ('String', 'Integer', 'Password'): entry = gtk.Entry() if option.type == 'Password': entry.set_visibility(False) val = option.value if val and val is not NoDefaultOption: entry.set_text(str(val)) self.tooltips.set_tip(entry, option.description) optBox.pack_end(entry, False, True) self.widgets.append( (option.type, option.name, entry.get_text)) elif option.type == 'Choice': choices = option.getChoices() combo = gtk.combo_box_new_text() combo.append_text(_('Select one')) active_num = 0 for n, c in enumerate(choices): combo.append_text(c) if c == option.value: active_num = n + 1 combo.set_active(active_num) optBox.pack_end(combo, False, True) self.tooltips.set_tip(combo, option.description, None) def getter(combo=combo): model = combo.get_model() active = combo.get_active() if active == 0: return None return model[active][0] self.widgets.append((option.type, option.name, getter)) elif option.type == 'Boolean': entry = gtk.CheckButton("") self.tooltips.set_tip(entry, option.description) if option.value: entry.set_active(True) else: entry.set_active(False) optBox.pack_end(entry, False, True) self.widgets.append( (option.type, option.name, entry.get_active)) else: print("unknown option", option.type) tab.pack_start(optBox, False, False) notebook.append_page(tab, gtk.Label(group.name)) self.tooltips.enable()
def __init__(self): # Here is our main window (a dialog) and a handle for the handlebox # Ok, we need a toolbar, an icon with a mask (one for all of # the buttons) and an icon widget to put this icon in (but # we'll create a separate widget for each button) # create a new window with a given title, and nice size dialog = gtk.Dialog() dialog.set_title("GTKToolbar Tutorial") dialog.set_size_request(450, 250) dialog.set_resizable(True) # typically we quit if someone tries to close us dialog.connect("delete_event", self.delete_event) # to make it nice we'll put the toolbar into the handle box, # so that it can be detached from the main window handlebox = gtk.HandleBox() dialog.vbox.pack_start(handlebox, False, False, 5) # toolbar will be horizontal, with both icons and text, and # with 5pxl spaces between items and finally, # we'll also put it into our handlebox toolbar = gtk.Toolbar() toolbar.set_orientation(gtk.ORIENTATION_HORIZONTAL) toolbar.set_style(gtk.TOOLBAR_BOTH) toolbar.set_border_width(5) handlebox.add(toolbar) # our first item is <close> button iconw = gtk.Image() # icon widget iconw.set_from_file("gtk.xpm") close_button = toolbar.append_item( "Close", # button label "Closes this app", # this button's tooltip "Private", # tooltip private info iconw, # icon widget self.delete_event) # a signal toolbar.append_space() # space after item # now, let's make our radio buttons group... iconw = gtk.Image() # icon widget iconw.set_from_file("gtk.xpm") icon_button = toolbar.append_element( gtk.TOOLBAR_CHILD_RADIOBUTTON, # type of element None, # widget "Icon", # label "Only icons in toolbar", # tooltip "Private", # tooltip private string iconw, # icon self.radio_event, # signal toolbar) # data for signal toolbar.append_space() self.icon_button = icon_button # following radio buttons refer to previous ones iconw = gtk.Image() # icon widget iconw.set_from_file("gtk.xpm") text_button = toolbar.append_element( gtk.TOOLBAR_CHILD_RADIOBUTTON, icon_button, "Text", "Only texts in toolbar", "Private", iconw, self.radio_event, toolbar) toolbar.append_space() self.text_button = text_button iconw = gtk.Image() # icon widget iconw.set_from_file("gtk.xpm") both_button = toolbar.append_element( gtk.TOOLBAR_CHILD_RADIOBUTTON, text_button, "Both", "Icons and text in toolbar", "Private", iconw, self.radio_event, toolbar) toolbar.append_space() self.both_button = both_button both_button.set_active(True) # here we have just a simple toggle button iconw = gtk.Image() # icon widget iconw.set_from_file("gtk.xpm") tooltips_button = toolbar.append_element( gtk.TOOLBAR_CHILD_TOGGLEBUTTON, None, "Tooltips", "Toolbar with or without tips", "Private", iconw, self.toggle_event, toolbar) toolbar.append_space() tooltips_button.set_active(True) # to pack a widget into toolbar, we only have to # create it and append it with an appropriate tooltip entry = gtk.Entry() toolbar.append_widget(entry, "This is just an entry", "Private") # well, it isn't created within the toolbar, so we must still show it entry.show() # that's it ! let's show everything. toolbar.show() handlebox.show() dialog.show()
def engines(self, b): #self.usi1.stop_engine() #self.usi2.stop_engine() engine_list = self.get_engine_list() dialog = gtk.Dialog("Engines", None, 0, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) hb = gtk.HBox(False, 20) hb.show() fr = gtk.Frame() fr.show() liststore = gtk.ListStore(str, str) for e in engine_list: engine_name , path = e liststore.append(e) self.liststore = liststore treeview = gtk.TreeView(liststore) self.treeview = treeview tvcolumn = gtk.TreeViewColumn('Select an Engine:') treeview.append_column(tvcolumn) cell = gtk.CellRendererText() cell.set_property('cell-background', gtk.gdk.color_parse("#F8F8FF")) tvcolumn.pack_start(cell, True) tvcolumn.set_min_width(200) tvcolumn.set_attributes(cell, text=0) treeview.show() fr.add(treeview) hb.pack_start(fr, True, True, 20) treeview.connect('button-press-event', self.engine_changed) bb = gtk.VButtonBox() bb.set_layout(gtk.BUTTONBOX_START) bb.show() al = gtk.Alignment(xalign=0.0, yalign=0.5, xscale=0.0, yscale=0.0) al.add(bb) al.show() add_button = gtk.Button("Add") add_button.show() bb.add(add_button) add_button.connect("clicked", self.add_engine, "add engine") self.delete_button = gtk.Button("Delete") self.delete_button.set_sensitive(False) self.delete_button.show() bb.add(self.delete_button) self.delete_button.connect("clicked", self.delete_engine, "delete engine") self.rename_button = gtk.Button("Rename") self.rename_button.set_sensitive(False) self.rename_button.show() bb.add(self.rename_button) self.rename_button.connect("clicked", self.rename_engine, "rename engine") hb.pack_start(al, False, True, 0) dialog.vbox.pack_start(hb, True, True, 15) dialog.set_default_response(gtk.RESPONSE_OK) response = dialog.run() if response == gtk.RESPONSE_OK: elist = [] tm = self.treeview.get_model() l_iter = tm.get_iter_first() while (l_iter is not None): name = tm.get_value(l_iter, 0) path = tm.get_value(l_iter, 1) elist.append((name, path)) l_iter = tm.iter_next(l_iter) self.set_engine_list(elist) dialog.destroy()
def dialog_codeboxhandle(self, title): """Opens the CodeBox Handle Dialog""" dialog = gtk.Dialog( title=title, parent=self.dad.window, flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) dialog.set_default_size(300, -1) dialog.set_position(gtk.WIN_POS_CENTER_ON_PARENT) button_prog_lang = gtk.Button() button_label = self.dad.codebox_syn_highl if self.dad.codebox_syn_highl != cons.PLAIN_TEXT_ID else self.dad.auto_syn_highl button_stock_id = config.get_stock_id_for_code_type(button_label) button_prog_lang.set_label(button_label) button_prog_lang.set_image( gtk.image_new_from_stock(button_stock_id, gtk.ICON_SIZE_MENU)) radiobutton_plain_text = gtk.RadioButton(label=_("Plain Text")) radiobutton_auto_syntax_highl = gtk.RadioButton( label=_("Automatic Syntax Highlighting")) radiobutton_auto_syntax_highl.set_group(radiobutton_plain_text) if self.dad.codebox_syn_highl == cons.PLAIN_TEXT_ID: radiobutton_plain_text.set_active(True) button_prog_lang.set_sensitive(False) else: radiobutton_auto_syntax_highl.set_active(True) type_vbox = gtk.VBox() type_vbox.pack_start(radiobutton_plain_text) type_vbox.pack_start(radiobutton_auto_syntax_highl) type_vbox.pack_start(button_prog_lang) type_frame = gtk.Frame(label="<b>" + _("Type") + "</b>") type_frame.get_label_widget().set_use_markup(True) type_frame.set_shadow_type(gtk.SHADOW_NONE) type_frame.add(type_vbox) label_width = gtk.Label(_("Width")) adj_width = gtk.Adjustment(value=self.dad.codebox_width, lower=1, upper=10000, step_incr=1) spinbutton_width = gtk.SpinButton(adj_width) spinbutton_width.set_value(self.dad.codebox_width) label_height = gtk.Label(_("Height")) adj_height = gtk.Adjustment(value=self.dad.codebox_height, lower=1, upper=10000, step_incr=1) spinbutton_height = gtk.SpinButton(adj_height) spinbutton_height.set_value(self.dad.codebox_height) radiobutton_codebox_pixels = gtk.RadioButton(label=_("pixels")) radiobutton_codebox_percent = gtk.RadioButton(label="%") radiobutton_codebox_percent.set_group(radiobutton_codebox_pixels) radiobutton_codebox_pixels.set_active(self.dad.codebox_width_pixels) radiobutton_codebox_percent.set_active( not self.dad.codebox_width_pixels) vbox_pix_perc = gtk.VBox() vbox_pix_perc.pack_start(radiobutton_codebox_pixels) vbox_pix_perc.pack_start(radiobutton_codebox_percent) hbox_width = gtk.HBox() hbox_width.pack_start(label_width, expand=False) hbox_width.pack_start(spinbutton_width, expand=False) hbox_width.pack_start(vbox_pix_perc) hbox_width.set_spacing(5) hbox_height = gtk.HBox() hbox_height.pack_start(label_height, expand=False) hbox_height.pack_start(spinbutton_height, expand=False) hbox_height.set_spacing(5) vbox_size = gtk.VBox() vbox_size.pack_start(hbox_width) vbox_size.pack_start(hbox_height) size_align = gtk.Alignment() size_align.set_padding(0, 6, 6, 6) size_align.add(vbox_size) size_frame = gtk.Frame(label="<b>" + _("Size") + "</b>") size_frame.get_label_widget().set_use_markup(True) size_frame.set_shadow_type(gtk.SHADOW_NONE) size_frame.add(size_align) checkbutton_codebox_linenumbers = gtk.CheckButton( label=_("Show Line Numbers")) checkbutton_codebox_linenumbers.set_active(self.dad.codebox_line_num) checkbutton_codebox_matchbrackets = gtk.CheckButton( label=_("Highlight Matching Brackets")) checkbutton_codebox_matchbrackets.set_active( self.dad.codebox_match_bra) vbox_options = gtk.VBox() vbox_options.pack_start(checkbutton_codebox_linenumbers) vbox_options.pack_start(checkbutton_codebox_matchbrackets) opt_align = gtk.Alignment() opt_align.set_padding(6, 6, 6, 6) opt_align.add(vbox_options) options_frame = gtk.Frame(label="<b>" + _("Options") + "</b>") options_frame.get_label_widget().set_use_markup(True) options_frame.set_shadow_type(gtk.SHADOW_NONE) options_frame.add(opt_align) content_area = dialog.get_content_area() content_area.set_spacing(5) content_area.pack_start(type_frame) content_area.pack_start(size_frame) content_area.pack_start(options_frame) content_area.show_all() def on_button_prog_lang_clicked(button): icon_n_key_list = [] for key in self.dad.available_languages: stock_id = config.get_stock_id_for_code_type(key) icon_n_key_list.append([key, stock_id, key]) sel_key = support.dialog_choose_element_in_list( self.dad.window, _("Automatic Syntax Highlighting"), [], "", icon_n_key_list) if sel_key: button.set_label(sel_key) button.set_image( gtk.image_new_from_stock(sel_key, gtk.ICON_SIZE_MENU)) button_prog_lang.connect('clicked', on_button_prog_lang_clicked) def on_radiobutton_auto_syntax_highl_toggled(radiobutton): button_prog_lang.set_sensitive(radiobutton.get_active()) def on_key_press_codeboxhandle(widget, event): keyname = gtk.gdk.keyval_name(event.keyval) if keyname == cons.STR_KEY_RETURN: spinbutton_width.update() spinbutton_height.update() try: dialog.get_widget_for_response( gtk.RESPONSE_ACCEPT).clicked() except: print cons.STR_PYGTK_222_REQUIRED return True return False def on_radiobutton_codebox_pixels_toggled(radiobutton): if radiobutton.get_active(): spinbutton_width.set_value(700) else: if spinbutton_width.get_value() > 100: spinbutton_width.set_value(90) radiobutton_auto_syntax_highl.connect( "toggled", on_radiobutton_auto_syntax_highl_toggled) dialog.connect('key_press_event', on_key_press_codeboxhandle) radiobutton_codebox_pixels.connect( 'toggled', on_radiobutton_codebox_pixels_toggled) response = dialog.run() dialog.hide() if response == gtk.RESPONSE_ACCEPT: self.dad.codebox_width = spinbutton_width.get_value() self.dad.codebox_width_pixels = radiobutton_codebox_pixels.get_active( ) self.dad.codebox_height = spinbutton_height.get_value() self.dad.codebox_line_num = checkbutton_codebox_linenumbers.get_active( ) self.dad.codebox_match_bra = checkbutton_codebox_matchbrackets.get_active( ) if radiobutton_plain_text.get_active(): self.dad.codebox_syn_highl = cons.PLAIN_TEXT_ID else: self.dad.codebox_syn_highl = button_prog_lang.get_label() return True return False
def find(self, self2, replace=False): self.reptxt = "" if replace: head = "pyedit: Find / Replace" else: head = "pyedit: Find in text" dialog = gtk.Dialog(head, None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) dialog.set_default_response(gtk.RESPONSE_ACCEPT) dialog.replace = replace try: dialog.set_icon_from_file(get_img_path("pyedit_sub.png")) except: print "Cannot load find dialog icon", sys.exc_info() self.dialog = dialog # Spacers label1 = gtk.Label(" ") label2 = gtk.Label(" ") label3 = gtk.Label(" ") label4 = gtk.Label(" ") label5 = gtk.Label(" ") label6 = gtk.Label(" ") label7 = gtk.Label(" ") label8 = gtk.Label(" ") entry = gtk.Entry() entry.set_activates_default(True) if self2.oldsearch == "": self2.oldsearch = pedconfig.conf.sql.get_str("src") if self2.oldsearch == None: self2.oldsearch = "" if self2.oldrep == "": self2.oldrep = pedconfig.conf.sql.get_str("rep") if self2.oldrep == None: self2.oldrep = "" # See if we have a selection for search if self2.xsel != -1: xssel = min(self2.xsel, self2.xsel2) xesel = max(self2.xsel, self2.xsel2) yssel = min(self2.ysel, self2.ysel2) yesel = max(self2.ysel, self2.ysel2) if yssel == yesel: self2.oldsearch = self2.text[yssel][xssel:xesel] entry.set_text(self2.oldsearch) dialog.vbox.pack_start(label4) hbox2 = gtk.HBox() hbox2.pack_start(label6, False) hbox2.pack_start(entry) hbox2.pack_start(label7, False) dialog.vbox.pack_start(hbox2) dialog.checkbox = gtk.CheckButton("Use _regular expression") dialog.checkbox2 = gtk.CheckButton("Case In_sensitive") dialog.checkbox.set_active(pedconfig.conf.sql.get_int("regex")) dialog.checkbox2.set_active(pedconfig.conf.sql.get_int("nocase")) dialog.vbox.pack_start(label5) hbox = gtk.HBox() hbox.pack_start(label1) hbox.pack_start(dialog.checkbox) hbox.pack_start(label2) hbox.pack_start(dialog.checkbox2) hbox.pack_start(label3) dialog.vbox.pack_start(hbox) dialog.vbox.pack_start(label8) label30 = gtk.Label(" ") label31 = gtk.Label(" ") label32 = gtk.Label(" ") label33 = gtk.Label(" ") label34 = gtk.Label(" ") label35 = gtk.Label(" ") dialog.checkbox3 = gtk.CheckButton("Search _All Buffers") #dialog.checkbox4 = gtk.CheckButton("Hello") hbox4 = gtk.HBox() hbox4.pack_start(label30) hbox4.pack_start(dialog.checkbox3) #hbox4.pack_start(label31); hbox4.pack_start(dialog.checkbox4) hbox4.pack_start(label32) dialog.vbox.pack_start(hbox4) dialog.vbox.pack_start(label33) if replace: dialog.repl = gtk.Entry() dialog.repl.set_text(self2.oldrep) dialog.repl.set_activates_default(True) label10 = gtk.Label(" ") label11 = gtk.Label(" ") label12 = gtk.Label(" ") label13 = gtk.Label(" ") hbox3 = gtk.HBox() hbox3.pack_start(label10, False) hbox3.pack_start(dialog.repl) hbox3.pack_start(label11, False) dialog.vbox.pack_start(hbox3) dialog.vbox.pack_start(label12) dialog.show_all() response = dialog.run() self2.oldsearch = entry.get_text() self.srctxt = entry.get_text() if replace: self.reptxt = dialog.repl.get_text() dialog.destroy() if response != gtk.RESPONSE_ACCEPT: return if dialog.checkbox3.get_active(): nn = self2.mained.notebook.get_n_pages() cnt = 0 cnt2 = 0 while True: if cnt >= nn: break ppp = self2.mained.notebook.get_nth_page(cnt) self.xnum = cnt * 4 find_show(self, ppp.area) cnt += 1 else: self.xnum = 0 find_show(self, self2)
def __init__(self, parent, db, db_owner, tmpdir, pyro_timeout): self.db = db self.db_owner = db_owner if pyro_timeout: self.pyro_timeout = float(pyro_timeout) else: self.pyro_timeout = None self.regname = None self.updater = None self.tmpdir = tmpdir self.gcapture_windows = [] gobject.threads_init() # self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window = gtk.Dialog( "Choose a suite", parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) # self.window.set_modal(True) self.window.set_title("Suite Chooser") self.window.set_size_request(750, 400) # TODO: not needed for a dialog window? self.window.set_icon(get_icon()) # self.window.set_border_width(5) self.window.connect("delete_event", self.delete_all_event) sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.regd_treeview = gtk.TreeView() self.regd_treestore = gtk.TreeStore(str, str, str, str, str, str, str) self.regd_treeview.set_model(self.regd_treestore) self.regd_treeview.set_rules_hint(True) # search column zero (Ctrl-F) self.regd_treeview.connect('key_press_event', self.on_suite_select) self.regd_treeview.connect('button_press_event', self.on_suite_select) self.regd_treeview.set_search_column(0) # Start updating the liststore now, as we need values in it # immediately below (it may be possible to delay this till the # end of __init___() but it doesn't really matter. if self.db: self.dbopt = '--db=' + self.db else: self.dbopt = '' regd_ts = self.regd_treeview.get_selection() regd_ts.set_mode(gtk.SELECTION_SINGLE) cr = gtk.CellRendererText() # cr.set_property('cell-background', '#def') tvc = gtk.TreeViewColumn('Suite', cr, text=0, foreground=4, background=5) tvc.set_resizable(True) tvc.set_sort_column_id(0) self.regd_treeview.append_column(tvc) cr = gtk.CellRendererText() tvc = gtk.TreeViewColumn('Port', cr, text=1, foreground=4, background=5) tvc.set_resizable(True) # not sure how this sorting works # tvc.set_sort_column_id(1) self.regd_treeview.append_column(tvc) cr = gtk.CellRendererText() # cr.set_property('cell-background', '#def') tvc = gtk.TreeViewColumn('Title', cr, markup=2, foreground=4, background=6) tvc.set_resizable(True) # vc.set_sort_column_id(2) self.regd_treeview.append_column(tvc) cr = gtk.CellRendererText() tvc = gtk.TreeViewColumn('Location', cr, text=3, foreground=4, background=5) tvc.set_resizable(True) # vc.set_sort_column_id(3) self.regd_treeview.append_column(tvc) vbox = self.window.vbox sw.add(self.regd_treeview) vbox.pack_start(sw, True) self.selected_label_text = ( '(double-click or OK to select; right-click for db options)') self.selected_label = gtk.Label(self.selected_label_text) filter_entry = EntryTempText() filter_entry.set_width_chars(7) # Reduce width in toolbar filter_entry.connect("activate", self.filter) filter_entry.set_temp_text("filter") filter_toolitem = gtk.ToolItem() filter_toolitem.add(filter_entry) tooltip = gtk.Tooltips() tooltip.enable() tooltip.set_tip(filter_toolitem, "Filter suites \n(enter a sub-string or regex)") expand_button = gtk.ToolButton() image = gtk.image_new_from_stock(gtk.STOCK_ADD, gtk.ICON_SIZE_SMALL_TOOLBAR) expand_button.set_icon_widget(image) expand_button.connect('clicked', lambda x: self.regd_treeview.expand_all()) collapse_button = gtk.ToolButton() image = gtk.image_new_from_stock(gtk.STOCK_REMOVE, gtk.ICON_SIZE_SMALL_TOOLBAR) collapse_button.set_icon_widget(image) collapse_button.connect('clicked', lambda x: self.regd_treeview.collapse_all()) hbox = gtk.HBox() eb = gtk.EventBox() eb.add(self.selected_label) eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#bbc')) hbox.pack_start(eb, True) hbox.pack_start(expand_button, False) hbox.pack_start(collapse_button, False) hbox.pack_start(filter_toolitem, False) vbox.pack_start(hbox, False) self.window.show_all() self.start_updater()
def dialog_tablecolhandle(self, title, rename_text): """Opens the Table Column Handle Dialog""" dialog = gtk.Dialog( title=title, parent=self.dad.window, flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) dialog.set_default_size(300, -1) dialog.set_position(gtk.WIN_POS_CENTER_ON_PARENT) hbox_column_rename = gtk.HBox() image_column_rename = gtk.Image() image_column_rename.set_from_stock(gtk.STOCK_EDIT, gtk.ICON_SIZE_BUTTON) table_column_rename_radiobutton = gtk.RadioButton( label=_("Rename Column")) table_column_rename_entry = gtk.Entry() table_column_rename_entry.set_text(rename_text) table_column_rename_entry.set_sensitive( self.dad.table_column_mode == 'rename') hbox_column_rename.pack_start(image_column_rename, expand=False) hbox_column_rename.pack_start(table_column_rename_radiobutton) hbox_column_rename.pack_start(table_column_rename_entry) hbox_column_delete = gtk.HBox() image_column_delete = gtk.Image() image_column_delete.set_from_stock(gtk.STOCK_CLEAR, gtk.ICON_SIZE_BUTTON) table_column_delete_radiobutton = gtk.RadioButton( label=_("Delete Column")) table_column_delete_radiobutton.set_group( table_column_rename_radiobutton) hbox_column_delete.pack_start(image_column_delete, expand=False) hbox_column_delete.pack_start(table_column_delete_radiobutton) hbox_column_add = gtk.HBox() image_column_add = gtk.Image() image_column_add.set_from_stock(gtk.STOCK_ADD, gtk.ICON_SIZE_BUTTON) table_column_add_radiobutton = gtk.RadioButton(label=_("Add Column")) table_column_add_radiobutton.set_group(table_column_rename_radiobutton) table_column_new_entry = gtk.Entry() hbox_column_add.pack_start(image_column_add, expand=False) hbox_column_add.pack_start(table_column_add_radiobutton) hbox_column_add.pack_start(table_column_new_entry) table_column_new_entry.set_sensitive( self.dad.table_column_mode == 'add') hbox_column_left = gtk.HBox() image_column_left = gtk.Image() image_column_left.set_from_stock(gtk.STOCK_GO_BACK, gtk.ICON_SIZE_BUTTON) table_column_left_radiobutton = gtk.RadioButton( label=_("Move Column Left")) table_column_left_radiobutton.set_group( table_column_rename_radiobutton) hbox_column_left.pack_start(image_column_left, expand=False) hbox_column_left.pack_start(table_column_left_radiobutton) hbox_column_right = gtk.HBox() image_column_right = gtk.Image() image_column_right.set_from_stock(gtk.STOCK_GO_FORWARD, gtk.ICON_SIZE_BUTTON) table_column_right_radiobutton = gtk.RadioButton( label=_("Move Column Right")) table_column_right_radiobutton.set_group( table_column_rename_radiobutton) hbox_column_right.pack_start(image_column_right, expand=False) hbox_column_right.pack_start(table_column_right_radiobutton) table_column_rename_radiobutton.set_active( self.dad.table_column_mode == "rename") table_column_delete_radiobutton.set_active( self.dad.table_column_mode == "delete") table_column_add_radiobutton.set_active( self.dad.table_column_mode == "add") table_column_left_radiobutton.set_active( self.dad.table_column_mode == cons.TAG_PROP_LEFT) table_column_right_radiobutton.set_active( self.dad.table_column_mode == cons.TAG_PROP_RIGHT) if self.dad.table_column_mode == "rename": table_column_rename_entry.grab_focus() elif self.dad.table_column_mode == "add": table_column_new_entry.grab_focus() tablehandle_vbox_col = gtk.VBox() tablehandle_vbox_col.pack_start(hbox_column_rename) tablehandle_vbox_col.pack_start(hbox_column_delete) tablehandle_vbox_col.pack_start(hbox_column_add) tablehandle_vbox_col.pack_start(hbox_column_left) tablehandle_vbox_col.pack_start(hbox_column_right) content_area = dialog.get_content_area() content_area.set_spacing(5) content_area.pack_start(tablehandle_vbox_col) content_area.show_all() def on_key_press_tablecolhandle(widget, event): keyname = gtk.gdk.keyval_name(event.keyval) if keyname == cons.STR_KEY_RETURN: try: dialog.get_widget_for_response( gtk.RESPONSE_ACCEPT).clicked() except: print cons.STR_PYGTK_222_REQUIRED return True elif keyname == cons.STR_KEY_TAB: if self.dad.table_column_mode == "rename": table_column_delete_radiobutton.set_active(True) elif self.dad.table_column_mode == "delete": table_column_add_radiobutton.set_active(True) elif self.dad.table_column_mode == "add": table_column_left_radiobutton.set_active(True) elif self.dad.table_column_mode == cons.TAG_PROP_LEFT: table_column_right_radiobutton.set_active(True) else: table_column_rename_radiobutton.set_active(True) return True return False def on_table_column_rename_radiobutton_toggled(radiobutton): if radiobutton.get_active(): table_column_rename_entry.set_sensitive(True) self.dad.table_column_mode = "rename" table_column_rename_entry.grab_focus() else: table_column_rename_entry.set_sensitive(False) def on_table_column_delete_radiobutton_toggled(radiobutton): if radiobutton.get_active(): self.dad.table_column_mode = "delete" def on_table_column_add_radiobutton_toggled(radiobutton): if radiobutton.get_active(): table_column_new_entry.set_sensitive(True) self.dad.table_column_mode = "add" table_column_new_entry.grab_focus() else: table_column_new_entry.set_sensitive(False) def on_table_column_left_radiobutton_toggled(radiobutton): if radiobutton.get_active(): self.dad.table_column_mode = cons.TAG_PROP_LEFT def on_table_column_right_radiobutton_toggled(radiobutton): if radiobutton.get_active(): self.dad.table_column_mode = cons.TAG_PROP_RIGHT dialog.connect('key_press_event', on_key_press_tablecolhandle) table_column_rename_radiobutton.connect( 'toggled', on_table_column_rename_radiobutton_toggled) table_column_delete_radiobutton.connect( 'toggled', on_table_column_delete_radiobutton_toggled) table_column_add_radiobutton.connect( 'toggled', on_table_column_add_radiobutton_toggled) table_column_left_radiobutton.connect( 'toggled', on_table_column_left_radiobutton_toggled) table_column_right_radiobutton.connect( 'toggled', on_table_column_right_radiobutton_toggled) response = dialog.run() dialog.hide() if response == gtk.RESPONSE_ACCEPT: ret_rename = unicode(table_column_rename_entry.get_text(), cons.STR_UTF8, cons.STR_IGNORE) ret_add = unicode(table_column_new_entry.get_text(), cons.STR_UTF8, cons.STR_IGNORE) return [True, ret_rename, ret_add] return [False, None, None]
import gtk import gobject import pango import tagcloud import json w = gtk.Dialog() w.set_title('Discover new podcasts') w.set_default_size(650, 450) tv = gtk.TreeView() tv.set_headers_visible(False) tv.set_size_request(160, -1) class OpmlEdit(object): pass class Search(object): pass class OpmlFixed(object): pass class TagCloud(object): pass search_providers = ( ('gpodder.net', 'search_gpodder.png', Search), ('YouTube', 'search_youtube.png', Search), ('SoundCloud', 'search_soundcloud.png', Search), ('Miro Guide', 'search_miro.png', Search), ) directory_providers = ( ('Toplist', 'directory_toplist.png', OpmlFixed), ('Examples', 'directory_example.png', OpmlFixed), ('Tag cloud', 'directory_tags.png', TagCloud),
def display_data(self, widget): #print self.combobox_state.get_active_text(), self.combobox_year.get_active_text(), self.combobox_district.get_active_text(), self.combobox_crime.get_active_text() #filtered_data = self.data[((self.data['STATE.UT']==self.combobox_state.get_active_text()) & (self.data['DISTRICT']==self.combobox_district.get_active_text()) & (self.data['YEAR']==self.combobox_year.get_active_text()))].filter(items=['STATE/UT','DISTRICT','YEAR', self.combobox_crime.get_active_text()]) dialog = gtk.Dialog("My dialog", self, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) dialog.set_size_request(400, 700) liststore = gtk.ListStore(str, str, str, str) treeview = gtk.TreeView(liststore) tvcolumn = gtk.TreeViewColumn("STATE/UT") tvcolumn1 = gtk.TreeViewColumn("DISTRICT") tvcolumn2 = gtk.TreeViewColumn("YEAR") tvcolumn3 = gtk.TreeViewColumn(self.combobox_crime.get_active_text()) for i in self.filtered_data.values.tolist(): liststore.append(i) #liststore.append(['Open', gtk.STOCK_OPEN, 'Open a File', True]) treeview.append_column(tvcolumn) treeview.append_column(tvcolumn1) treeview.append_column(tvcolumn2) treeview.append_column(tvcolumn3) cell = gtk.CellRendererText() cell1 = gtk.CellRendererText() cell2 = gtk.CellRendererText() cell3 = gtk.CellRendererText() cell.set_property('cell-background', 'yellow') cell1.set_property('cell-background', 'cyan') cell2.set_property('cell-background', 'pink') cell3.set_property('cell-background', 'red') tvcolumn.pack_start(cell, False) tvcolumn1.pack_start(cell1, True) tvcolumn2.pack_start(cell2, True) tvcolumn3.pack_start(cell3, True) tvcolumn.set_attributes(cell, text=0) tvcolumn1.set_attributes(cell1, text=1) tvcolumn2.set_attributes(cell2, text=2) tvcolumn3.set_attributes(cell3, text=3) scrolled_window = gtk.ScrolledWindow() scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) scrolled_window.add(treeview) scrolled_window.set_border_width(10) #scrolled_window.set_min_content_height(200) scrolled_window.add(treeview) treeview.set_search_column(0) dialog.vbox.add(scrolled_window) treeview.show() scrolled_window.show() res = dialog.run() dialog.destroy() return
def _info(exctyp, value, tb): if exctyp.__name__ == 'KeyboardInterrupt': sys.stderr.write('%s: %s\n' % (exctyp.__name__, value)) sys.exit(1) trace = None dialog = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, buttons=gtk.BUTTONS_NONE) dialog.set_title(_("Bug Detected")) if gtk.check_version(2, 4, 0) is not None: dialog.set_has_separator(False) primary = _( "<big><b>A programming error has been detected during the execution of this program.</b></big>" ) secondary = _( "It probably isn't fatal, but should be reported to the developers nonetheless." ) try: setsec = dialog.format_secondary_text except AttributeError: raise dialog.vbox.get_children()[0].get_children()[1].set_markup( '%s\n\n%s' % (primary, secondary)) #lbl.set_property ("use-markup", True) else: del setsec dialog.set_markup(primary) dialog.format_secondary_text(secondary) try: email = feedback dialog.add_button(_("Report..."), 3) except NameError: # could ask for an email address instead... pass dialog.add_button(_("Details..."), 2) dialog.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE) dialog.add_button(gtk.STOCK_QUIT, 1) dialog.add_button(_("Report Bug"), 3) while True: resp = dialog.run() if resp == 3: #if trace == None: # trace = analyse (exctyp, value, tb) # TODO: prettyprint, deal with problems in sending feedback, &tc handle = webbrowser.get() print dir(handle) handle.open("http://bugs.ascend4.org/bug_report_page.php") if trace == None: trace = analyse(exctyp, value, tb) print trace.getvalue() # try: # server = smtphost # except NameError: # server = 'localhost' # # message = 'From: buggy_application"\nTo: bad_programmer\nSubject: Exception feedback\n\n%s' % trace.getvalue() # # s = SMTP() # s.connect (server) # s.sendmail (email, (email,), message) # s.quit() break elif resp == 2: if trace == None: trace = analyse(exctyp, value, tb) # Show details... details = gtk.Dialog( _("Bug Details"), dialog, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, ( gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE, )) details.set_property("has-separator", False) textview = gtk.TextView() textview.show() textview.set_editable(False) textview.modify_font(pango.FontDescription("Monospace")) sw = gtk.ScrolledWindow() sw.show() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) sw.add(textview) details.vbox.add(sw) textbuffer = textview.get_buffer() # envtext = "\n".join(["%s = %s" % (k,os.environ[k]) for k in sorted(os.environ.keys())]) # textbuffer.set_text (trace.getvalue() + "\n\n\nENVIRONMENT\n\n" + envtext) textbuffer.set_text(trace.getvalue()) monitor = gtk.gdk.screen_get_default().get_monitor_at_window( dialog.window) area = gtk.gdk.screen_get_default().get_monitor_geometry(monitor) try: w = area.width // 1.6 h = area.height // 1.6 except SyntaxError: # python < 2.2 w = area.width / 1.6 h = area.height / 1.6 details.set_default_size(int(w), int(h)) details.run() details.destroy() elif resp == 1 and gtk.main_level() > 0: gtk.main_quit() break else: break dialog.destroy()
def __init__(self, screen, callback, view_type='form', new=False, many=0, domain=None, context=None, save_current=False): NoModal.__init__(self) self.screen = screen self.callback = callback self.many = many self.domain = domain self.context = context self.save_current = save_current self.prev_view = self.screen.current_view self.screen.screen_container.alternate_view = True if view_type not in (x.view_type for x in self.screen.views) and \ view_type not in self.screen.view_to_load: self.screen.add_view_id(None, view_type) self.screen.switch_view(view_type=view_type) if new: self.screen.new() self.win = gtk.Dialog(_('Link'), self.parent, gtk.DIALOG_DESTROY_WITH_PARENT) self.win.set_position(gtk.WIN_POS_CENTER_ON_PARENT) self.win.set_icon(TRYTON_ICON) self.win.set_has_separator(False) self.win.set_deletable(False) self.win.connect('delete-event', lambda *a: True) self.win.connect('close', self.close) self.win.connect('response', self.response) self.accel_group = gtk.AccelGroup() self.win.add_accel_group(self.accel_group) readonly = self.screen.readonly or self.screen.group.readonly self.but_ok = None self.but_new = None if view_type == 'form': if not new and self.screen.current_record.id < 0: stock_id = gtk.STOCK_DELETE else: stock_id = gtk.STOCK_CANCEL self.but_cancel = self.win.add_button(stock_id, gtk.RESPONSE_CANCEL) if new and self.many: self.but_new = self.win.add_button(gtk.STOCK_NEW, gtk.RESPONSE_ACCEPT) self.but_new.set_accel_path('<tryton>/Form/New', self.accel_group) if self.save_current: self.but_ok = gtk.Button(_('_Save')) img_save = gtk.Image() img_save.set_from_stock('tryton-save', gtk.ICON_SIZE_BUTTON) self.but_ok.set_image(img_save) self.but_ok.set_accel_path('<tryton>/Form/Save', self.accel_group) self.but_ok.set_can_default(True) self.but_ok.show() self.win.add_action_widget(self.but_ok, gtk.RESPONSE_OK) if not new: self.but_ok.props.sensitive = False else: self.but_ok = self.win.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK) self.but_ok.add_accelerator('clicked', self.accel_group, gtk.keysyms.Return, gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) self.win.set_default_response(gtk.RESPONSE_OK) self.win.set_title(self.screen.current_view.title) title = gtk.Label() title.modify_font(pango.FontDescription("bold 12")) title.set_label(self.screen.current_view.title) title.set_padding(20, 3) title.set_alignment(0.0, 0.5) title.set_size_request(0, -1) # Allow overflow title.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#000000")) title.show() hbox = gtk.HBox() hbox.pack_start(title, expand=True, fill=True) hbox.show() frame = gtk.Frame() frame.set_shadow_type(gtk.SHADOW_ETCHED_IN) frame.add(hbox) frame.show() eb = gtk.EventBox() eb.add(frame) eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) eb.show() self.win.vbox.pack_start(eb, expand=False, fill=True, padding=3) self.create_info_bar() self.win.vbox.pack_start(self.info_bar, False, True) if view_type == 'tree': hbox = gtk.HBox(homogeneous=False, spacing=0) tooltips = common.Tooltips() access = common.MODELACCESS[screen.model_name] if domain is not None: self.wid_text = gtk.Entry() self.wid_text.set_property('width_chars', 13) self.wid_text.connect('activate', self._sig_activate) self.wid_text.connect('focus-out-event', self._focus_out) hbox.pack_start(self.wid_text, expand=True, fill=True) self.but_add = gtk.Button() tooltips.set_tip(self.but_add, _('Add')) self.but_add.connect('clicked', self._sig_add) img_add = gtk.Image() img_add.set_from_stock('tryton-list-add', gtk.ICON_SIZE_SMALL_TOOLBAR) img_add.set_alignment(0.5, 0.5) self.but_add.add(img_add) self.but_add.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_add, expand=False, fill=False) if not access['read'] or readonly: self.but_add.set_sensitive(False) self.but_remove = gtk.Button() tooltips.set_tip(self.but_remove, _('Remove <Del>')) self.but_remove.connect('clicked', self._sig_remove, True) img_remove = gtk.Image() img_remove.set_from_stock('tryton-list-remove', gtk.ICON_SIZE_SMALL_TOOLBAR) img_remove.set_alignment(0.5, 0.5) self.but_remove.add(img_remove) self.but_remove.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_remove, expand=False, fill=False) if not access['read'] or readonly: self.but_remove.set_sensitive(False) hbox.pack_start(gtk.VSeparator(), expand=False, fill=True) self.but_new = gtk.Button() tooltips.set_tip(self.but_new, _('Create a new record <F3>')) self.but_new.connect('clicked', self._sig_new) img_new = gtk.Image() img_new.set_from_stock('tryton-new', gtk.ICON_SIZE_SMALL_TOOLBAR) img_new.set_alignment(0.5, 0.5) self.but_new.add(img_new) self.but_new.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_new, expand=False, fill=False) if not access['create'] or readonly: self.but_new.set_sensitive(False) self.but_del = gtk.Button() tooltips.set_tip(self.but_del, _('Delete selected record <Del>')) self.but_del.connect('clicked', self._sig_remove, False) img_del = gtk.Image() img_del.set_from_stock('tryton-delete', gtk.ICON_SIZE_SMALL_TOOLBAR) img_del.set_alignment(0.5, 0.5) self.but_del.add(img_del) self.but_del.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_del, expand=False, fill=False) if not access['delete'] or readonly: self.but_del.set_sensitive(False) self.but_undel = gtk.Button() tooltips.set_tip(self.but_undel, _('Undelete selected record <Ins>')) self.but_undel.connect('clicked', self._sig_undelete) img_undel = gtk.Image() img_undel.set_from_stock('tryton-undo', gtk.ICON_SIZE_SMALL_TOOLBAR) img_undel.set_alignment(0.5, 0.5) self.but_undel.add(img_undel) self.but_undel.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_undel, expand=False, fill=False) if not access['delete'] or readonly: self.but_undel.set_sensitive(False) hbox.pack_start(gtk.VSeparator(), expand=False, fill=True) self.but_pre = gtk.Button() tooltips.set_tip(self.but_pre, _('Previous')) self.but_pre.connect('clicked', self._sig_previous) img_pre = gtk.Image() img_pre.set_from_stock('tryton-go-previous', gtk.ICON_SIZE_SMALL_TOOLBAR) img_pre.set_alignment(0.5, 0.5) self.but_pre.add(img_pre) self.but_pre.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_pre, expand=False, fill=False) self.label = gtk.Label('(0,0)') hbox.pack_start(self.label, expand=False, fill=False) self.but_next = gtk.Button() tooltips.set_tip(self.but_next, _('Next')) self.but_next.connect('clicked', self._sig_next) img_next = gtk.Image() img_next.set_from_stock('tryton-go-next', gtk.ICON_SIZE_SMALL_TOOLBAR) img_next.set_alignment(0.5, 0.5) self.but_next.add(img_next) self.but_next.set_relief(gtk.RELIEF_NONE) hbox.pack_start(self.but_next, expand=False, fill=False) hbox.pack_start(gtk.VSeparator(), expand=False, fill=True) but_switch = gtk.Button() tooltips.set_tip(but_switch, _('Switch')) but_switch.connect('clicked', self.switch_view) img_switch = gtk.Image() img_switch.set_from_stock('tryton-fullscreen', gtk.ICON_SIZE_SMALL_TOOLBAR) img_switch.set_alignment(0.5, 0.5) but_switch.add(img_switch) but_switch.set_relief(gtk.RELIEF_NONE) hbox.pack_start(but_switch, expand=False, fill=False) but_switch.props.sensitive = screen.number_of_views > 1 tooltips.enable() alignment = gtk.Alignment(1.0) alignment.add(hbox) alignment.show_all() self.win.vbox.pack_start(alignment, expand=False, fill=True) scroll = gtk.ScrolledWindow() scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scroll.set_placement(gtk.CORNER_TOP_LEFT) scroll.set_shadow_type(gtk.SHADOW_NONE) scroll.show() self.win.vbox.pack_start(scroll, expand=True, fill=True) scroll.add(self.screen.screen_container.alternate_viewport) sensible_allocation = self.sensible_widget.get_allocation() self.win.set_default_size(int(sensible_allocation.width * 0.9), int(sensible_allocation.height * 0.9)) if view_type == 'tree': self.screen.signal_connect(self, 'record-message', self._sig_label) self.screen.screen_container.alternate_viewport.connect( 'key-press-event', self.on_keypress) if self.save_current and not new: self.screen.signal_connect(self, 'record-message', self.activate_save) self.screen.signal_connect(self, 'record-modified', self.activate_save) self.register() self.win.show() common.center_window(self.win, self.parent, self.sensible_widget) self.screen.display() self.screen.current_view.set_cursor()
def __init__(self, core, gom, threadtv, config): TITLE = "Preferences" # Core instance for manage the KB self.uicore = core self.gom = gom self.threadtv = threadtv self.config = config # Dialog self.dialog = gtk.Dialog(title=TITLE, parent=None, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) self.dialog.resize(250, 75) # Notebook self.prefs_nb = gtk.Notebook() ######################################################### # Main Table self.main_table = gtk.Table(rows=3, columns=2, homogeneous=True) self.main_table.set_row_spacings(2) self.main_table.set_col_spacings(2) # Label to add table to Notebook self.main_lbl = gtk.Label('Main') # Choose network iface self.iface_lbl = gtk.Label('Interface') self.iface_combo = gtk.combo_box_new_text() for iface in self.uicore.get_interfaces(): self.iface_combo.append_text(iface) #self.iface_combo.set_active(0) # Add lements to Table self.main_table.attach(self.iface_lbl, 0, 1, 0, 1) self.main_table.attach(self.iface_combo, 1, 2, 0, 1) # Add NoteBook to VBox self.dialog.vbox.pack_start(self.prefs_nb, False, False, 2) # Add Table to Notebook self.prefs_nb.append_page(self.main_table, self.main_lbl) ######################################################### # Update Table self.update_table = gtk.Table(rows=3, columns=2, homogeneous=True) self.update_table.set_row_spacings(2) self.update_table.set_col_spacings(2) # Label to add table to Notebook self.update_lbl = gtk.Label('Update') # Add exploits and nikto update buttons self.exploit_lbl = gtk.Label('Exploit DB') self.nikto_lbl = gtk.Label('Nikto Rules') self.exploit_bt = gtk.Button('Update', gtk.STOCK_REFRESH) self.exploit_bt.connect('clicked', self.update_exploits) self.nikto_bt = gtk.Button('Update', gtk.STOCK_REFRESH) self.nikto_bt.connect('clicked', self.update_nikto) # Add lements to Table self.update_table.attach(self.exploit_lbl, 0, 1, 0, 1) self.update_table.attach(self.exploit_bt, 1, 2, 0, 1) self.update_table.attach(self.nikto_lbl, 0, 1, 1, 2) self.update_table.attach(self.nikto_bt, 1, 2, 1, 2) # Add Table to Notebook self.prefs_nb.append_page(self.update_table, self.update_lbl) ######################################################### # the cancel button self.butt_cancel = self.dialog.action_area.get_children()[1] self.butt_cancel.connect("clicked", lambda x: self.dialog.destroy()) # the ok button self.butt_ok = self.dialog.action_area.get_children()[0] # self.butt_ok.connect("clicked", lambda x: self.dialog.destroy()) self.butt_ok.connect("clicked", self.set_interface) # Finish self.dialog.show_all() self.dialog.show()
def open_dialog(self, widget, data=None): self.dialog = gtk.Dialog() self.dialog.show() self.dialog.set_title("Extra Message") self.dialog.set_border_width(50)
def edit_appli(self, widget, event, section, app): d = gtk.Dialog(title=self.utils._("Edit the launcher")) # Edition du nom de l'appli entry = gtk.Entry() entry.connect("activate", self.mod_app_name, entry, d, section, app) # entrée valide entry.show() namebtn = gtk.Button(label=self.utils._("Change")) namebtn.connect_object("clicked", self.mod_app_name, entry, None, d, section, app) namebtn.show() # on met ça dans une boîte box = gtk.HBox(False, 2) box.pack_start(entry, True, True, 3) box.pack_start(namebtn, False, False, 0) box.show() # et le tout dans un étiquette nameframe = gtk.Frame(self.utils._("Change the label")) nameframe.add(box) nameframe.show() icon = app["icon"] iconpreview = gtk.Image() if icon.endswith('.png') or icon.endswith('.jpg'): iconpreview.set_from_file(icon) else: iconpreview.set_from_icon_name(icon, iconsize) iconpreview.set_pixel_size(iconsize) iconpreview.show() # Changement de l'icône iconbtn = gtk.Button(label=self.utils._("Change icon")) iconbtn.connect_object("clicked", self.mod_app_icon_dialog, entry, None, d, section, app) iconbtn.show() # on met ça dans une boîte # et le tout dans un étiquette iconframe = gtk.Frame(self.utils._("Change the application icon")) iconframe.add(iconbtn) iconframe.show() # déplacement de l'application upbtn = gtk.Button(label=self.utils._("Move up")) downbtn = gtk.Button(label=self.utils._("Move down")) upi = gtk.Image() upi.set_from_stock(gtk.STOCK_GO_UP, gtk.ICON_SIZE_MENU) upbtn.set_image(upi) downi = gtk.Image() downi.set_from_stock(gtk.STOCK_GO_DOWN, gtk.ICON_SIZE_MENU) downbtn.set_image(downi) upbtn.connect_object("clicked", self.move_app_up, None, d, section, app) downbtn.connect_object("clicked", self.move_app_down, None, d, section, app) upbtn.show() downbtn.show() # on met ça dans une boîte box = gtk.HBox(False, 2) box.pack_start(upbtn, True, True, 3) box.pack_start(downbtn, False, False, 0) box.show() # et le tout dans un étiquette moveframe = gtk.Frame(self.utils._("Move this app")) moveframe.add(box) moveframe.show() # Nécessaire pour la suppression delbtn = gtk.Button(label=self.utils._("Delete"), stock=gtk.STOCK_DELETE) delbtn.connect("clicked", self.del_appli, d, section, app) delbtn.show() delframe = gtk.Frame(self.utils._("Delete this launcher")) delframe.add(delbtn) delframe.show() # ajout des objets au dialogue d.vbox.pack_start(nameframe) hbox = gtk.HBox(False, 2) hbox.pack_start(iconpreview) hbox.pack_start(iconframe) hbox.show() d.vbox.pack_start(hbox, True, True, 0) d.vbox.pack_start(moveframe) d.vbox.pack_start(delframe) d.run()
def python_wallpaper(img, layer): gimp.context_push() (x1, y1, x2, y2) = layer.mask_bounds sel_aspect = float(x2 - x1) / (y2 - y1) # Figure out which size we're targeting diff = 100 width = 1600 height = 1200 for res in common_resolutions: res_aspect = float(res[0]) / res[1] if (abs(res_aspect - sel_aspect) < diff): width = res[0] height = res[1] diff = abs(res_aspect - sel_aspect) if diff > .25: # That different, there's probably something wrong errdialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, "No preset size matches aspect ratio " + \ str(sel_aspect)) errdialog.show_all() errdialog.run() return #print "Making wallpaper of size", width, "x", height # If it's an XCF, save it as a JPG # However, in gimp 2.8, img.name is "Untitled" if the image # hasn't been saved as an XCF, which this image likely hasn't. # So test for that: if img.name.find('.') < 0: if img.filename: name = os.path.basename(img.filename) else: # If there's neither an image name or a filename -- # e.g. it was created as new, or dragged/pasted from a browser -- # make up a placeholder and hope the user notices and changes it. name = "wallpaper.jpg" else: name = img.name if name[-4:] == ".xcf": name = name[0:-4] + ".jpg" elif name[-7:] == ".xcf.gz": name = name[0:-7] + ".jpg" elif name[-8:] == ".xcf.bz2": name = name[0:-8] + ".jpg" #print wallpaperdir, width, name #print img #print dir(img) #print " " dirpathname = os.path.join(wallpaperdir, "%dx%d" % (width, height)) if not os.path.exists(dirpathname): fulldirpathname = dirpathname dirpathname = os.path.join(wallpaperdir, str(width)) if not os.path.exists(dirpathname): errdialog = gtk.MessageDialog( None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, "Neither %s nor %s exists" % (fulldirpathname, dirpathname)) errdialog.show_all() errdialog.run() return pathname = os.path.join(dirpathname, name) #newimg.name = name #newimg.filename = pathname #print "Trying to set name, pathname to", name, pathname if not pdb.gimp_edit_copy_visible(img): return newimg = pdb.gimp_edit_paste_as_new() # Paste-as-new creates an image with transparency, # which will warn if you try to save as jpeg, so: newimg.flatten() newimg.scale(width, height) # Check to make sure we won't be overwriting def check_overwrite_cb(widget): newpath = os.path.join(pathentry.get_text(), fileentry.get_text()) if os.access(newpath, os.R_OK): msglabel.set_text(newpath + " already exists!") dialog.set_response_sensitive(gtk.RESPONSE_OK, False) else: msglabel.set_text(" ") dialog.set_response_sensitive(gtk.RESPONSE_OK, True) # want to bring up the save dialog interactively here -- # but unfortunately there's no way to call save-as interactively # from python! So give the user a chance to change the directory: # or filename: # dialog = gtk.Dialog("Save as Wallpaper", None, 0, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, "Edit", gtk.RESPONSE_NONE, gtk.STOCK_OK, gtk.RESPONSE_OK)) #dialog.connect('destroy', lambda win: gtk.main_quit()) label = gtk.Label("Wallpaper: " + str(width) + "x" + str(height)) dialog.vbox.pack_start(label, True, True, 0) table = gtk.Table(3, 2) table.set_row_spacings(10) table.set_col_spacings(10) label = gtk.Label("Directory:") table.attach(label, 0, 1, 0, 1) pathentry = gtk.Entry() pathentry.set_width_chars(55) pathentry.set_text(dirpathname) table.attach(pathentry, 1, 2, 0, 1) label = gtk.Label("File name:") table.attach(label, 0, 1, 1, 2) fileentry = gtk.Entry() fileentry.set_width_chars(10) fileentry.set_text(name) table.attach(fileentry, 1, 2, 1, 2) msglabel = gtk.Label(" ") table.attach(msglabel, 0, 2, 2, 3) dialog.vbox.pack_start(table, True, True, 0) # set_default_response only marks the button visually -- # it doesn't actually change behavior. dialog.set_default_response(gtk.RESPONSE_OK) # To make Enter really do something, use activate on the entry: def dialogRespond(entry, dialog, response): dialog.response(response) fileentry.connect("activate", dialogRespond, dialog, gtk.RESPONSE_OK) pathentry.connect("changed", check_overwrite_cb) fileentry.connect("changed", check_overwrite_cb) check_overwrite_cb(None) dialog.show_all() fileentry.grab_focus() response = dialog.run() pathname = pathentry.get_text() newname = fileentry.get_text() pathname = os.path.join(pathname, newname) if newname != name: # Change the image name on the original -- so that if we make # backgrounds of any other sizes, the name will stay the same. pdb.gimp_image_set_filename(img, newname) name = newname # Set name and dirpath for the new image, in case user choses "Edit" pdb.gimp_image_set_filename(newimg, pathname) if response == gtk.RESPONSE_OK: dialog.hide() dialog.destroy() # Neither hide nor destroy will work unless we collect # gtk events before proceeding: while gtk.events_pending(): gtk.main_iteration() try: pdb.gimp_file_save(newimg, newimg.active_layer, pathname, pathname, run_mode=0) # If the save was successful, we don't need to show the new image, # so delete it: gimp.delete(newimg) gimp.context_pop() return except RuntimeError, e: print "Couldn't save!", str(e)
def display_graph(self, widget): dialog = gtk.Dialog("My dialog", self, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) dialog.set_size_request(1300, 500) # Crime name filter if " " not in self.combobox_crime.get_active_text(): crime = self.combobox_crime.get_active_text() else: crime = ".".join(self.combobox_crime.get_active_text().split(" ")) fig = Figure(figsize=(12, 10), dpi=100) sales = [{ 'Groups': '0-9', 'Counts': 38 }, { 'Groups': '10-19', 'Counts': 41 }, { 'Groups': '20-29', 'Counts': 77 }, { 'Groups': '30-39', 'Counts': 73 }, { 'Groups': '40-49', 'Counts': 77 }] df = pd.DataFrame(sales) ax = fig.add_subplot(111) if (self.combobox_year.get_active_text() == "All" and self.combobox_district.get_active_text() != "All"): self.filtered_data = self.filtered_data.reset_index(drop=True) ypos = np.arange(len(self.filtered_data['YEAR'].tolist())) p1 = ax.bar(ypos, self.filtered_data[crime], width=0.6, color='r') ax.set_title(crime.lower() + 's in ' + self.combobox_district.get_active_text() + ' - Yearwise') ax.set_xticks(ypos + 0.3) ax.set_xticklabels(self.filtered_data.YEAR) elif (self.combobox_district.get_active_text() == "All" and self.combobox_year.get_active_text() != "All"): fd_total_removed = self.filtered_data[ self.filtered_data.DISTRICT != 'TOTAL'] ypos = np.arange(len(fd_total_removed['DISTRICT'].tolist())) p1 = ax.bar(ypos, fd_total_removed[crime], width=0.3, color='r') fontx = { 'fontsize': 7, 'fontweight': 2, 'verticalalignment': 'center', 'horizontalalignment': 'center' } ax.set_title(crime + 's in ' + self.combobox_state.get_active_text() + '(' + self.combobox_state.get_active_text() + ' )' + ' - Districtwise') ax.set_xticks(ypos + 0.15) ax.set_xticklabels(fd_total_removed.DISTRICT, fontdict=fontx) else: print(df.index) p1 = ax.bar(df.index, df.Counts, width=0.8, color='r') ax.set_title('Scores by group and gender') ax.set_xticks(df.index + 0.4) ax.set_xticklabels(df.Groups) canvas = FigureCanvas(fig) # a gtk.DrawingArea canvas.set_size_request(800, 600) dialog.vbox.pack_start(canvas) toolbar = NavigationToolbar(canvas, dialog) dialog.vbox.pack_start(toolbar, False, False) canvas.show() dialog.run() dialog.destroy() return
def save(self, widget): parent = get_toplevel_window() dia = gtk.Dialog(_('Save As'), parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) dia.set_icon(TRYTON_ICON) dia.set_has_separator(True) dia.set_default_response(gtk.RESPONSE_OK) dia.vbox.set_spacing(5) dia.vbox.set_homogeneous(False) title = gtk.Label('<b>' + _('Image Size') + '</b>') title.set_alignment(0.0, 0.5) title.set_use_markup(True) dia.vbox.pack_start(title) table = gtk.Table(2, 2) table.set_col_spacings(3) table.set_row_spacings(3) table.set_border_width(1) table.attach(gtk.Label(_('Width:')), 0, 1, 0, 1, yoptions=False, xoptions=gtk.FILL) spinwidth = gtk.SpinButton(gtk.Adjustment(400.0, 0.0, sys.maxint, 1.0, 10.0)) spinwidth.set_numeric(True) spinwidth.set_activates_default(True) table.attach(spinwidth, 1, 2, 0, 1, yoptions=False, xoptions=gtk.FILL) table.attach(gtk.Label(_('Height:')), 0, 1, 1, 2, yoptions=False, xoptions=gtk.FILL) spinheight = gtk.SpinButton(gtk.Adjustment(200.0, 0.0, sys.maxint, 1.0, 10.0)) spinheight.set_numeric(True) spinheight.set_activates_default(True) table.attach(spinheight, 1, 2, 1, 2, yoptions=False, xoptions=gtk.FILL) dia.vbox.pack_start(table) filechooser = gtk.FileChooserWidget(gtk.FILE_CHOOSER_ACTION_SAVE, None) filechooser.set_current_folder(CONFIG['client.default_path']) filter = gtk.FileFilter() filter.set_name(_('PNG image (*.png)')) filter.add_mime_type('image/png') filter.add_pattern('*.png') filechooser.add_filter(filter) dia.vbox.pack_start(filechooser) dia.show_all() while True: response = dia.run() width = spinwidth.get_value_as_int() height = spinheight.get_value_as_int() filename = filechooser.get_filename() if filename: filename = filename.decode('utf-8') try: CONFIG['client.default_path'] = \ os.path.dirname(filename) CONFIG.save() except IOError: pass if response == gtk.RESPONSE_OK: if width and height and filename: if not filename.endswith('.png'): filename = filename + '.png' try: self.widgets['root'].export_png( filename, width, height) break except MemoryError: message(_('Image size too large!'), dia, gtk.MESSAGE_ERROR) else: break parent.present() dia.destroy()
def compare_states(self, widget): crimes = [ "MURDER", "RAPE", "KIDNAPPING.ABDUCTION", "RIOTS", "ROBBERY", "BURGLARY", "DOWRY.DEATHS" ] intyear = int(self.combobox_yearc.get_active_text()) state1_data = self.data.query( 'STATEorUT == @self.combobox_state1.get_active_text() and YEAR == @intyear' ).filter(items=[ 'STATEorUT', 'DISTRICT', 'YEAR', crimes[0], crimes[1], crimes[2], crimes[3], crimes[4], crimes[5], crimes[6] ])[self.data.DISTRICT == 'TOTAL'] state2_data = self.data.query( 'STATEorUT == @self.combobox_state2.get_active_text() and YEAR == @intyear' ).filter(items=[ 'STATEorUT', 'DISTRICT', 'YEAR', crimes[0], crimes[1], crimes[2], crimes[3], crimes[4], crimes[5], crimes[6] ])[self.data.DISTRICT == 'TOTAL'] print(state1_data.iloc[0]['MURDER']) state1_total = [ state1_data.iloc[0][crimes[0]], state1_data.iloc[0][crimes[1]], state1_data.iloc[0][crimes[2]], state1_data.iloc[0][crimes[3]], state1_data.iloc[0][crimes[4]], state1_data.iloc[0][crimes[5]], state1_data.iloc[0][crimes[6]] ] state2_total = [ state2_data.iloc[0][crimes[0]], state2_data.iloc[0][crimes[1]], state2_data.iloc[0][crimes[2]], state2_data.iloc[0][crimes[3]], state2_data.iloc[0][crimes[4]], state2_data.iloc[0][crimes[5]], state2_data.iloc[0][crimes[6]] ] print(state1_total) dialog = gtk.Dialog("My dialog", self, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) fig = Figure(figsize=(5, 4), dpi=100) dialog.set_size_request(1300, 500) ax = fig.add_subplot(111) ypos = np.arange(len(crimes)) print(ypos) p1 = ax.bar(ypos - 0.4, state1_total, width=0.4, color='r', align='center') p2 = ax.bar(ypos, state2_total, width=0.4, color='b', align='center') ax.set_title("Comparison of " + self.combobox_state1.get_active_text() + " and " + self.combobox_state2.get_active_text()) ax.set_xticks(ypos - 0.2) ax.set_xticklabels(crimes) ax.set_ylabel('Total Crimes') ax.legend((p1[0], p2[0]), (self.combobox_state1.get_active_text(), self.combobox_state2.get_active_text())) canvas = FigureCanvas(fig) # a gtk.DrawingArea canvas.set_size_request(800, 600) dialog.vbox.pack_start(canvas) toolbar = NavigationToolbar(canvas, dialog) dialog.vbox.pack_start(toolbar, False, False) canvas.show() dialog.run() dialog.destroy() return
def dialog_tablehandle(self, title, is_insert): """Opens the Table Handle Dialog""" dialog = gtk.Dialog( title=title, parent=self.dad.window, flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) dialog.set_default_size(300, -1) dialog.set_position(gtk.WIN_POS_CENTER_ON_PARENT) label_rows = gtk.Label(_("Rows")) adj_rows = gtk.Adjustment(value=self.dad.table_rows, lower=1, upper=10000, step_incr=1) spinbutton_rows = gtk.SpinButton(adj_rows) spinbutton_rows.set_value(self.dad.table_rows) label_columns = gtk.Label(_("Columns")) adj_columns = gtk.Adjustment(value=self.dad.table_columns, lower=1, upper=10000, step_incr=1) spinbutton_columns = gtk.SpinButton(adj_columns) spinbutton_columns.set_value(self.dad.table_columns) hbox_rows_cols = gtk.HBox() hbox_rows_cols.pack_start(label_rows, expand=False) hbox_rows_cols.pack_start(spinbutton_rows, expand=False) hbox_rows_cols.pack_start(label_columns, expand=False) hbox_rows_cols.pack_start(spinbutton_columns, expand=False) hbox_rows_cols.set_spacing(5) size_align = gtk.Alignment() size_align.set_padding(6, 6, 6, 6) size_align.add(hbox_rows_cols) size_frame = gtk.Frame(label="<b>" + _("Table Size") + "</b>") size_frame.get_label_widget().set_use_markup(True) size_frame.set_shadow_type(gtk.SHADOW_NONE) size_frame.add(size_align) label_col_min = gtk.Label(_("Min Width")) adj_col_min = gtk.Adjustment(value=self.dad.table_col_min, lower=1, upper=10000, step_incr=1) spinbutton_col_min = gtk.SpinButton(adj_col_min) spinbutton_col_min.set_value(self.dad.table_col_min) label_col_max = gtk.Label(_("Max Width")) adj_col_max = gtk.Adjustment(value=self.dad.table_col_max, lower=1, upper=10000, step_incr=1) spinbutton_col_max = gtk.SpinButton(adj_col_max) spinbutton_col_max.set_value(self.dad.table_col_max) hbox_col_min_max = gtk.HBox() hbox_col_min_max.pack_start(label_col_min, expand=False) hbox_col_min_max.pack_start(spinbutton_col_min, expand=False) hbox_col_min_max.pack_start(label_col_max, expand=False) hbox_col_min_max.pack_start(spinbutton_col_max, expand=False) hbox_col_min_max.set_spacing(5) col_min_max_align = gtk.Alignment() col_min_max_align.set_padding(6, 6, 6, 6) col_min_max_align.add(hbox_col_min_max) col_min_max_frame = gtk.Frame(label="<b>" + _("Column Properties") + "</b>") col_min_max_frame.get_label_widget().set_use_markup(True) col_min_max_frame.set_shadow_type(gtk.SHADOW_NONE) col_min_max_frame.add(col_min_max_align) checkbutton_table_ins_from_file = gtk.CheckButton( label=_("Import from CSV File")) content_area = dialog.get_content_area() content_area.set_spacing(5) if is_insert: content_area.pack_start(size_frame) content_area.pack_start(col_min_max_frame) if is_insert: content_area.pack_start(checkbutton_table_ins_from_file) content_area.show_all() def on_key_press_tablehandle(widget, event): keyname = gtk.gdk.keyval_name(event.keyval) if keyname == cons.STR_KEY_RETURN: spinbutton_rows.update() spinbutton_columns.update() spinbutton_col_min.update() spinbutton_col_max.update() try: dialog.get_widget_for_response( gtk.RESPONSE_ACCEPT).clicked() except: print cons.STR_PYGTK_222_REQUIRED return True return False def on_checkbutton_table_ins_from_file_toggled(checkbutton): size_frame.set_sensitive(not checkbutton.get_active()) col_min_max_frame.set_sensitive(not checkbutton.get_active()) dialog.connect('key_press_event', on_key_press_tablehandle) checkbutton_table_ins_from_file.connect( 'toggled', on_checkbutton_table_ins_from_file_toggled) response = dialog.run() dialog.hide() if response == gtk.RESPONSE_ACCEPT: self.dad.table_rows = int(spinbutton_rows.get_value()) self.dad.table_columns = int(spinbutton_columns.get_value()) self.dad.table_col_min = int(spinbutton_col_min.get_value()) self.dad.table_col_max = int(spinbutton_col_max.get_value()) ret_csv = checkbutton_table_ins_from_file.get_active() return [True, ret_csv] return [False, None]
def get_channel_sweep_parameters(voltage=100, frequency=10e3, channels=None, parent=None): ''' Show dialog to select parameters for a sweep across a selected set of channels. Parameters ---------- voltage : int Default actuation voltage. frequency : int Default actuation frequency. channels : pandas.Series Default channels selection, encoded as boolean array indexed by channel number, where `True` values indicate selected channel(s). parent : gtk.Window If not ``None``, parent window for dialog. For example, display dialog at position relative to the parent window. Returns ------- dict Values collected from widgets with the following keys: `'frequency'`, `voltage'`, and (optionally) `'channels'`. ''' # Create a form view containing widgets to set the waveform attributes # (i.e., voltage and frequency). form = Form.of( Float.named('voltage').using(default=voltage, validators=[ValueAtLeast(minimum=0)]), Float.named('frequency').using(default=frequency, validators=[ValueAtLeast(minimum=1)])) form_view = create_form_view(form) # If default channel selection was provided, create a treeview with one row # per channel, and a checkbox in each row to mark the selection status of # the corresponding channel. if channels is not None: df_channel_select = pd.DataFrame(channels.index, columns=['channel']) df_channel_select.insert(1, 'select', channels.values) view_channels = ListSelect(df_channel_select) # Create dialog window. dialog = gtk.Dialog(title='Channel sweep parameters', buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) # Add waveform widgets to dialog window. frame_waveform = gtk.Frame('Waveform properties') frame_waveform.add(form_view.widget) dialog.vbox.pack_start(child=frame_waveform, expand=False, fill=False, padding=5) # Add channel selection widgets to dialog window. if channels is not None: frame_channels = gtk.Frame('Select channels to sweep') frame_channels.add(view_channels.widget) dialog.vbox.pack_start(child=frame_channels, expand=True, fill=True, padding=5) # Mark all widgets as visible. dialog.vbox.show_all() if parent is not None: dialog.window.set_transient_for(parent) response = dialog.run() dialog.destroy() if response != gtk.RESPONSE_OK: raise RuntimeError('Dialog cancelled.') # Collection waveform and channel selection values from dialog. form_values = { name: f.element.value for name, f in form_view.form.fields.items() } if channels is not None: form_values['channels'] = ( df_channel_select.loc[df_channel_select['select'], 'channel'].values) return form_values
def insert_page_dialog(parent, doc, caption=_("Insert page")): result = [] dialog = gtk.Dialog(caption, parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) dialog.set_icon(parent.get_icon()) dialog.set_resizable(False) #------------------------ pages = doc.get_pages() index = pages.index(doc.active_page) hbox = gtk.HBox(False, 10) hbox.set_border_width(10) label = gtk.Label(_('Insert:')) hbox.pack_start(label, False, False, 0) adj = gtk.Adjustment(1, 1, 1000, 1, 1, 0) spinner = gtk.SpinButton(adj, 0, 0) spinner.set_numeric(True) hbox.pack_start(spinner, False, False, 0) label = gtk.Label(_('page(s)')) hbox.pack_start(label, False, False, 0) hbox2 = gtk.HBox(False, 10) hbox2.set_border_width(10) adj2 = gtk.Adjustment(index + 1, 1, len(pages), 1, 1, 0) spinner2 = gtk.SpinButton(adj2, 0, 0) spinner2.set_numeric(True) hbox2.pack_end(spinner2, False, False, 0) label = gtk.Label(_('page No.:')) hbox2.pack_end(label, False, False, 0) vbox = gtk.VBox(False, 0) radiobut1 = gtk.RadioButton(None, _("Before")) radiobut2 = gtk.RadioButton(radiobut1, _("After")) vbox.pack_start(radiobut1) vbox.pack_start(radiobut2) radiobut2.set_active(True) hbox2.pack_start(vbox, False, False, 0) #------------------------ dialog.vbox.pack_start(hbox) dialog.vbox.pack_start(hbox2) dialog.show_all() ret = dialog.run() if ret == gtk.RESPONSE_OK: number = int(adj.get_value()) target = int(adj2.get_value()) - 1 if radiobut2.get_active(): position = uc2const.AFTER else: position = uc2const.BEFORE result = [number, target, position] dialog.destroy() return result
def __init__(self, model_name, parent, model=None, attrs=None, model_ctx=None, window=None, default_get_ctx=None, readonly=False): if attrs is None: attrs = {} if model_ctx is None: model_ctx = {} if default_get_ctx is None: default_get_ctx = {} if not window: window = service.LocalService('gui.main').window self.dia = gtk.Dialog(_('OpenERP - Link'), window, gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT) self.window = window if ('string' in attrs) and attrs['string']: self.dia.set_title(self.dia.get_title() + ' - ' + attrs['string']) self.dia.set_property('default-width', 760) self.dia.set_property('default-height', 500) self.dia.set_position(gtk.WIN_POS_CENTER_ON_PARENT) self.dia.set_icon(common.OPENERP_ICON) self.accel_group = gtk.AccelGroup() self.dia.add_accel_group(self.accel_group) self.but_cancel = self.dia.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CANCEL) self.but_cancel.add_accelerator('clicked', self.accel_group, gtk.keysyms.Escape, gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) self.but_ok = self.dia.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK) self.but_ok.add_accelerator('clicked', self.accel_group, gtk.keysyms.Return, gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) self.default_get_ctx = default_get_ctx scroll = gtk.ScrolledWindow() scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scroll.set_placement(gtk.CORNER_TOP_LEFT) scroll.set_shadow_type(gtk.SHADOW_NONE) self.dia.vbox.pack_start(scroll, expand=True, fill=True) vp = gtk.Viewport() vp.set_shadow_type(gtk.SHADOW_NONE) scroll.add(vp) self.screen = Screen(model_name, view_type=[], parent=parent, window=self.dia, readonly=readonly) self.screen.models._context.update(model_ctx) if not model: model = self.screen.new(context=default_get_ctx) else: self.screen.models.model_add(model) self.screen.current_model = model if ('views' in attrs) and ('form' in attrs['views']): arch = attrs['views']['form']['arch'] fields = attrs['views']['form']['fields'] self.screen.add_view(arch, fields, display=True, context=default_get_ctx) else: self.screen.add_view_id(False, 'form', display=True, context=default_get_ctx) vp.add(self.screen.widget) x,y = self.screen.screen_container.size_get() vp.set_size_request(x,y+30) self.dia.show_all() self.screen.readonly = readonly self.screen.display()
def __init__(self, model, callback, sel_multi=True, context=None, domain=None, view_ids=None, views_preload=None, new=True, title=''): NoModal.__init__(self) if view_ids is None: view_ids = [] if views_preload is None: views_preload = {} self.domain = domain or [] self.context = context or {} self.view_ids = view_ids self.views_preload = views_preload self.sel_multi = sel_multi self.callback = callback self.title = title self.win = gtk.Dialog(_('Search'), self.parent, gtk.DIALOG_DESTROY_WITH_PARENT) self.win.set_icon(TRYTON_ICON) self.win.set_default_response(gtk.RESPONSE_APPLY) self.win.connect('response', self.response) self.accel_group = gtk.AccelGroup() self.win.add_accel_group(self.accel_group) self.but_cancel = self.win.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) self.but_find = self.win.add_button(gtk.STOCK_FIND, gtk.RESPONSE_APPLY) if new and common.MODELACCESS[model]['create']: self.but_new = self.win.add_button(gtk.STOCK_NEW, gtk.RESPONSE_ACCEPT) self.but_new.set_accel_path('<tryton>/Form/New', self.accel_group) self.but_ok = self.win.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK) self.but_ok.add_accelerator('clicked', self.accel_group, gtk.keysyms.Return, gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) hbox = gtk.HBox() hbox.show() self.win.vbox.pack_start(hbox, expand=False, fill=True) self.win.vbox.pack_start(gtk.HSeparator(), expand=False, fill=True) scrollwindow = gtk.ScrolledWindow() scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.win.vbox.pack_start(scrollwindow, expand=True, fill=True) self.screen = Screen(model, domain=domain, mode=['tree'], context=context, view_ids=view_ids, views_preload=views_preload, row_activate=self.sig_activate, readonly=True) self.view = self.screen.current_view # Prevent to set tree_state self.screen.tree_states_done.add(id(self.view)) sel = self.view.treeview.get_selection() self.win.set_title(_('Search %s') % self.title) if not sel_multi: sel.set_mode(gtk.SELECTION_SINGLE) else: sel.set_mode(gtk.SELECTION_MULTIPLE) viewport = gtk.Viewport() viewport.set_shadow_type(gtk.SHADOW_NONE) viewport.add(self.screen.widget) self.screen.widget.show() viewport.show() scrollwindow.add(viewport) scrollwindow.show() self.model_name = model self.win.set_default_size(700, 500) self.register() sensible_allocation = self.sensible_widget.get_allocation() self.win.set_default_size(int(sensible_allocation.width * 0.9), int(sensible_allocation.height * 0.9))
def do_line(self, fWizard, tmpDir): self.tmpDir = tmpDir self.fWizard = fWizard self.W = gtk.Dialog('Line', None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, buttons=None) self.W.set_keep_above(True) self.W.set_position(gtk.WIN_POS_CENTER_ALWAYS) self.W.set_default_size(250, 200) t = gtk.Table(1, 1, True) t.set_row_spacings(6) self.W.vbox.add(t) xSLabel = gtk.Label('X start') xSLabel.set_alignment(0.95, 0.5) xSLabel.set_width_chars(10) t.attach(xSLabel, 0, 1, 0, 1) self.xSEntry = gtk.Entry() self.xSEntry.set_width_chars(10) t.attach(self.xSEntry, 1, 2, 0, 1) ySLabel = gtk.Label('Y start') ySLabel.set_alignment(0.95, 0.5) ySLabel.set_width_chars(10) t.attach(ySLabel, 0, 1, 1, 2) self.ySEntry = gtk.Entry() self.ySEntry.set_width_chars(10) t.attach(self.ySEntry, 1, 2, 1, 2) i1Label = gtk.Label('do the next two') i1Label.set_alignment(1.0, 1.0) t.attach(i1Label, 0, 2, 2, 3) xELabel = gtk.Label('X end') xELabel.set_alignment(0.95, 0.5) xELabel.set_width_chars(10) t.attach(xELabel, 0, 1, 3, 4) self.xEEntry = gtk.Entry() self.xEEntry.set_width_chars(10) t.attach(self.xEEntry, 1, 2, 3, 4) yELabel = gtk.Label('Y end') yELabel.set_alignment(0.95, 0.5) yELabel.set_width_chars(10) t.attach(yELabel, 0, 1, 4, 5) self.yEEntry = gtk.Entry() self.yEEntry.set_width_chars(10) t.attach(self.yEEntry, 1, 2, 4, 5) i2Label = gtk.Label('or the next two') i2Label.set_alignment(1.0, 1.0) t.attach(i2Label, 0, 2, 5, 6) aLabel = gtk.Label('Angle') aLabel.set_alignment(0.95, 0.5) aLabel.set_width_chars(10) t.attach(aLabel, 0, 1, 6, 7) self.aEntry = gtk.Entry() self.aEntry.set_width_chars(10) self.aEntry.set_text('0') t.attach(self.aEntry, 1, 2, 6, 7) lLabel = gtk.Label('Length') lLabel.set_alignment(0.95, 0.5) lLabel.set_width_chars(10) t.attach(lLabel, 0, 1, 7, 8) self.lEntry = gtk.Entry() self.lEntry.set_width_chars(10) t.attach(self.lEntry, 1, 2, 7, 8) preview = gtk.Button('Preview') preview.connect('pressed', self.send_preview) t.attach(preview, 0, 1, 9, 10) self.add = gtk.Button('Add') self.add.set_sensitive(False) self.add.connect('pressed', self.add_shape_to_file) t.attach(self.add, 2, 3, 9, 10) end = gtk.Button('Return') end.connect('pressed', self.end_this_shape) t.attach(end, 4, 5, 9, 10) pixbuf = gtk.gdk.pixbuf_new_from_file_at_size( filename='./wizards/images/line.png', width=240, height=240) image = gtk.Image() image.set_from_pixbuf(pixbuf) t.attach(image, 2, 5, 0, 8) self.xSEntry.grab_focus() self.W.show_all() if os.path.exists(self.configFile): f_in = open(self.configFile, 'r') for line in f_in: if line.startswith('preamble'): self.preamble = line.strip().split('=')[1] elif line.startswith('postamble'): self.postamble = line.strip().split('=')[1] response = self.W.run()
def _bp_cell_editing_started_cb(self, cell, editable, path): iter = self.liststore.get_iter(path) action_name = self.liststore.get_value(iter, self.action_column) bp_name = self.liststore.get_value(iter, self.bp_column) editable.set_sensitive(False) dialog = gtk.Dialog() if not gtk2compat.USE_GTK3: dialog.set_extension_events(gdk.EXTENSION_EVENTS_ALL) dialog.set_modal(True) dialog.set_title(_("Edit binding for '%s'") % action_name) dialog.set_transient_for(self.get_toplevel()) dialog.set_position(gtk.WIN_POS_CENTER_ON_PARENT) dialog.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK) dialog.set_default_response(gtk.RESPONSE_OK) dialog.connect("response", self._bp_edit_dialog_response_cb, editable) dialog.ok_btn = dialog.get_widget_for_response(gtk.RESPONSE_OK) dialog.ok_btn.set_sensitive(bp_name is not None) evbox = gtk.EventBox() evbox.set_border_width(12) evbox.connect("button-press-event", self._bp_edit_box_button_press_cb, dialog, editable) evbox.connect("enter-notify-event", self._bp_edit_box_enter_cb) table = gtk.Table(3, 2) table.set_row_spacings(12) table.set_col_spacings(12) row = 0 label = gtk.Label() label.set_alignment(0, 0.5) label.set_text(_("Action:")) table.attach(label, 0, 1, row, row + 1, gtk.FILL) label = gtk.Label() label.set_alignment(0, 0.5) label.set_text(str(action_name)) table.attach(label, 1, 2, row, row + 1, gtk.FILL | gtk.EXPAND) row += 1 label = gtk.Label() label.set_alignment(0, 0.5) label.set_text(_("Button press:")) table.attach(label, 0, 1, row, row + 1, gtk.FILL) label = gtk.Label() label.set_alignment(0, 0.5) label.set_text(str(bp_name)) dialog.bp_name = bp_name dialog.bp_name_orig = bp_name dialog.bp_label = label table.attach(label, 1, 2, row, row + 1, gtk.FILL | gtk.EXPAND) row += 1 label = gtk.Label() label.set_size_request(300, 75) label.set_alignment(0, 0) label.set_line_wrap(True) dialog.hint_label = label self._bp_edit_dialog_set_standard_hint(dialog) table.attach(label, 0, 2, row, row + 1, gtk.FILL | gtk.EXPAND, gtk.FILL | gtk.EXPAND, 0, 12) evbox.add(table) dialog.get_content_area().pack_start(evbox, True, True) evbox.show_all() dialog.show()
def main_show(self, parent): self.parent = parent self.W = gtk.Dialog('PlasmaC Conversational', None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, buttons = None) self.W.set_keep_above(True) self.W.set_position(gtk.WIN_POS_CENTER) self.W.set_default_size(890, 663) self.W.connect('delete_event', self.on_delete_event) top = gtk.HBox(True, 2) bottom = gtk.HBox() self.W.vbox.pack_start(top, expand = False, fill = True) self.W.vbox.pack_start(bottom, expand = True, fill = True) self.left = gtk.VBox() right = gtk.Frame() bottom.pack_start(self.left, expand = False, fill = True) bottom.pack_start(right, expand = True, fill = True) self.line = gtk.ToggleButton() self.line.connect('toggled', self.on_line_toggled) self.circle = gtk.ToggleButton() self.circle.connect('toggled', self.on_circle_toggled) self.triangle = gtk.ToggleButton() self.triangle.connect('toggled', self.on_triangle_toggled) self.rectangle = gtk.ToggleButton() self.rectangle.connect('toggled', self.on_rectangle_toggled) self.polygon = gtk.ToggleButton() self.polygon.connect('toggled', self.on_polygon_toggled) self.bolt_circle = gtk.ToggleButton() self.bolt_circle.connect('toggled', self.on_bolt_circle_toggled) self.slot = gtk.ToggleButton() self.slot.connect('toggled', self.on_slot_toggled) self.star = gtk.ToggleButton() self.star.connect('toggled', self.on_star_toggled) self.gusset = gtk.ToggleButton() self.gusset.connect('toggled', self.on_gusset_toggled) self.sector = gtk.ToggleButton() self.sector.connect('toggled', self.on_sector_toggled) self.rotate = gtk.ToggleButton() self.rotate.connect('toggled', self.on_rotate_toggled) self.array = gtk.ToggleButton() self.array.connect('toggled', self.on_array_toggled) self.buttons = [self.line, self.circle, self.triangle, self.rectangle, \ self.polygon, self.bolt_circle, self.slot, self.star, \ self.gusset, self.sector, self.rotate, self.array] bunames = ['line', 'circle', 'triangle', 'rectangle', 'polygon', \ 'bolt_circle', 'slot', 'star', 'gusset', 'sector', \ 'rotate', 'array'] tooltips = ['create a line or arc', \ 'create a circle', \ 'create a triangle', \ 'create a rectangle', \ 'create a regular polygon', \ 'create a bolt circle', \ 'create a slot', \ 'create a star', \ 'create a gusset', \ 'create a sector', \ 'rotate a shape', \ 'create an array of shapes'] for wizard in bunames: if bunames.index(wizard) <= 11: pixbuf = gtk.gdk.pixbuf_new_from_file_at_size( filename='./wizards/images/{}-thumb.png'.format(wizard), width=60, height=60) image = gtk.Image() image.set_from_pixbuf(pixbuf) self.buttons[bunames.index(wizard)].set_image(image) print(self.buttons[bunames.index(wizard)], bunames.index(wizard)) self.buttons[bunames.index(wizard)].set_tooltip_text(tooltips[bunames.index(wizard)]) top.add(self.buttons[bunames.index(wizard)]) right.add(self.preview) self.entries = gtk.Table(1, 1, True) self.entries.set_row_spacings(self.rowSpace) self.left.pack_start(self.entries, expand = False, fill = True) spaceFrame = gtk.Frame() spaceFrame.set_shadow_type(gtk.SHADOW_NONE) self.left.pack_start(spaceFrame, expand = True, fill = True) self.button_frame = gtk.Frame() self.button_frame.set_shadow_type(gtk.SHADOW_ETCHED_IN) self.left.pack_start(self.button_frame, expand = False, fill = True) self.button_box = gtk.Table(1, 5, True) self.button_frame.add(self.button_box) bLabel1 = gtk.Label() bLabel1.set_width_chars(9) self.button_box.attach(bLabel1, 0, 1, 0, 1) self.new = gtk.Button('New') self.new.connect('clicked', self.on_new_clicked) self.button_box.attach(self.new, 0, 1, 0, 1) self.save = gtk.Button('Save') self.save.connect('clicked', self.on_save_clicked) self.button_box.attach(self.save, 1, 2, 0, 1) self.settings = gtk.Button('Settings') self.settings.connect('clicked', self.on_settings_clicked) self.button_box.attach(self.settings, 2, 3, 0, 1) self.quit = gtk.Button('Quit') self.quit.connect('clicked', self.on_quit_clicked) self.button_box.attach(self.quit, 3, 4, 0, 1) self.send = gtk.Button('Send') self.send.connect('clicked', self.on_send_clicked) self.button_box.attach(self.send, 4, 5, 0, 1) if self.scale == 1: unitCode = ['21', '0.25', 32] else: unitCode = ['20', '0.004', 1.26] self.preamble = 'G{} G64P{} G40 G49 G80 G90 G92.1 G94 G97'.format(unitCode[0], unitCode[1]) self.postamble = 'G{} G64P{} G40 G49 G80 G90 G92.1 G94 G97'.format(unitCode[0], unitCode[1]) self.origin = False self.leadin = 0 self.leadout = 0 self.holeRadius = unitCode[2] / 2.0 self.holeSpeed = 60.0 wWidth = 890 wHeight = 582 gSize = 0 fSize = '9' if os.path.exists(self.configFile): f_in = open(self.configFile, 'r') try: for line in f_in: if line.startswith('preamble'): self.preamble = line.strip().split('=')[1] elif line.startswith('postamble'): self.postamble = line.strip().split('=')[1] elif line.startswith('origin') and line.strip().split('=')[1] == 'True': self.origin = True elif line.startswith('lead-in'): self.leadIn = line.strip().split('=')[1] elif line.startswith('lead-out'): self.leadOut = line.strip().split('=')[1] elif line.startswith('hole-diameter'): self.holeRadius = float(line.strip().split('=')[1]) / 2 elif line.startswith('hole-speed'): self.holeSpeed = float(line.strip().split('=')[1]) elif line.startswith('window-width'): wWidth = int(line.strip().split('=')[1]) elif line.startswith('window-height'): wHeight = int(line.strip().split('=')[1]) elif line.startswith('grid-size'): # glcanon has a reversed scale to just about everything else... :( gSize = float(line.strip().split('=')[1]) * (0.03937000787402 / self.scale) elif line.startswith('font-size'): fSize = line.strip().split('=')[1] except: print('Using default wizard settings') if wWidth and wHeight: self.resize_window(wWidth, wHeight) if gSize: self.preview.grid_size = gSize gtk.settings_get_default().set_property('gtk-font-name', 'sans {}'.format(fSize)) self.W.show_all() self.s.poll() if self.s.file: try: shutil.copyfile(self.s.file, self.fNgc) shutil.copyfile(self.s.file, self.fNgcBkp) self.preview.load(self.fNgc) except: self.on_new_clicked(None) else: self.on_new_clicked(None) #hal.set_p('plasmac_run.preview-tab', '1') self.s.poll() self.xOrigin = float(self.s.actual_position[0] - self.s.g5x_offset[0] - self.s.g92_offset[0]) self.yOrigin = float(self.s.actual_position[1] - self.s.g5x_offset[1] - self.s.g92_offset[1]) self.xSaved = '0.000' self.ySaved = '0.000' self.oSaved = self.origin # self.on_line_clicked(None) self.line.set_active(True) response = self.W.run()
def __init__(self, context, plotter): self.context = context self.plotter = plotter dialog = gtk.Dialog("My Dialog", context, 0, (gtk.STOCK_OK, gtk.RESPONSE_OK)) box = dialog.get_content_area() table = gtk.Table(2, 18) table.set_row_spacings(5) table.set_col_spacings(5) l = [] l.append(gtk.Label("Canvas Style")) l.append(gtk.Label("Marker Style")) l.append(gtk.Label("Marker Size")) l.append(gtk.Label("Marker Color")) l.append(gtk.Label("Marker Alpha")) l.append(gtk.Label("Line Color")) l.append(gtk.Label("Line Width")) l.append(gtk.Label("CI Band Color")) l.append(gtk.Label("CI Band Alpha")) l.append(gtk.Label("Title")) l.append(gtk.Label("Title size")) l.append(gtk.Label("X-axis title")) l.append(gtk.Label("X-axis unit")) l.append(gtk.Label("X-axis title size")) l.append(gtk.Label("X-axis labels size")) l.append(gtk.Label("Y-axis title")) l.append(gtk.Label("Y-axis unit")) l.append(gtk.Label("Y-axis title size")) l.append(gtk.Label("Y-axis labels size")) hbox = [] hlines = [] for i in range(0, len(l)): l[i].set_alignment(xalign=0, yalign=0.5) hbox.append(gtk.HBox(False, 5)) hlines.append(gtk.HSeparator()) table.attach(l[i], 0, 1, 2 * i, 2 * i + 1) table.attach(hbox[i], 1, 2, 2 * i, 2 * i + 1) table.attach(hlines[i], 0, 2, 2 * i + 1, 2 * i + 2) combo_cs = self.create_combobox(plt.style.available, hbox, 0) combo_mst = self.create_combobox(self.plotter.markers, hbox, 1) spin_msz = self.create_spinbutton(hbox, float(self.plotter.pstyle[2]), 1.0, 20.0, 1.0, 2, 2) combo_mc = self.create_combobox(self.plotter.colors, hbox, 3) spin_ma = self.create_spinbutton(hbox, float(self.plotter.pstyle[4]), 0.0, 1.0, 0.05, 2, 4) combo_lc = self.create_combobox(self.plotter.colors, hbox, 5) spin_lw = self.create_spinbutton(hbox, float(self.plotter.pstyle[6]), 0.0, 10.0, 0.5, 2, 6) combo_bc = self.create_combobox(self.plotter.colors, hbox, 7) spin_ba = self.create_spinbutton(hbox, float(self.plotter.pstyle[8]), 0.0, 1.0, 0.05, 2, 8) entry_title = self.create_entry(hbox, 0, 9) entry_xaxis = self.create_entry(hbox, 1, 11) entry_xunit = self.create_entry(hbox, 3, 12) entry_yaxis = self.create_entry(hbox, 2, 15) entry_yunit = self.create_entry(hbox, 4, 16) spin_title_size = self.create_spinbutton( hbox, float(self.plotter.pstyle[10]), 10.0, 40.0, 1.0, 1, 10) spin_xtile_size = self.create_spinbutton( hbox, float(self.plotter.pstyle[13]), 10.0, 40.0, 1.0, 1, 13) spin_xlabels_size = self.create_spinbutton( hbox, float(self.plotter.pstyle[14]), 10.0, 40.0, 1.0, 1, 14) spin_ytile_size = self.create_spinbutton( hbox, float(self.plotter.pstyle[17]), 10.0, 40.0, 1.0, 1, 17) spin_ylabels_size = self.create_spinbutton( hbox, float(self.plotter.pstyle[18]), 10.0, 40.0, 1.0, 1, 18) box.add(table) dialog.show_all() response = dialog.run() if response == gtk.RESPONSE_OK: dialog.destroy() else: dialog.destroy()
def __on_edit(self, widget): if not HexView: try: text = unicode(self.value) except UnicodeDecodeError: dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, _("Cannot edit this field because I can't convert it to utf8.\n" "Try to edit the field with python shell or simply install " "pygtkhex that provides a nice HexView to edit raw fields")) dialog.run() dialog.hide() dialog.destroy() return dialog = gtk.Dialog(_('Editing string field'), None, gtk.DIALOG_MODAL, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) if not HexView: buffer = gtk.TextBuffer() buffer.set_text(text) view = gtk.TextView(buffer) view.modify_font(pango.FontDescription( Prefs()['gui.maintab.hexview.font'].value)) sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) sw.set_shadow_type(gtk.SHADOW_ETCHED_IN) sw.add(view) sw.show_all() dialog.vbox.pack_start(sw) else: hex = HexView() hex.set_insert_mode(True) hex.set_read_only_mode(False) hex.font = Prefs()['gui.maintab.hexview.font'].value hex.payload = self.value hex.show() dialog.vbox.pack_start(hex) dialog.set_size_request(400, 300) if dialog.run() == gtk.RESPONSE_ACCEPT: if not HexView: self.entry.set_text(buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter(), True)) else: self.value = hex.payload self._ignore_changed = True try: self.entry.set_text(unicode(self.value)) except UnicodeDecodeError: self.entry.set_text('') dialog.hide() dialog.destroy()
def do_circle(self, fWizard, tmpDir): self.tmpDir = tmpDir self.fWizard = fWizard self.sRadius = 0.0 self.hSpeed = 100 self.W = gtk.Dialog('Circle', None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, buttons=None) self.W.set_keep_above(True) self.W.set_position(gtk.WIN_POS_CENTER_ALWAYS) self.W.set_default_size(250, 200) t = gtk.Table(1, 1, True) t.set_row_spacings(6) self.W.vbox.add(t) cutLabel = gtk.Label('Cut Type') cutLabel.set_alignment(0.95, 0.5) cutLabel.set_width_chars(10) t.attach(cutLabel, 0, 1, 0, 1) self.outside = gtk.RadioButton(None, 'Outside') t.attach(self.outside, 1, 2, 0, 1) inside = gtk.RadioButton(self.outside, 'Inside') t.attach(inside, 2, 3, 0, 1) offsetLabel = gtk.Label('Offset') offsetLabel.set_alignment(0.95, 0.5) offsetLabel.set_width_chars(10) t.attach(offsetLabel, 3, 4, 0, 1) self.offset = gtk.CheckButton('Kerf Width') t.attach(self.offset, 4, 5, 0, 1) lLabel = gtk.Label('Lead In') lLabel.set_alignment(0.95, 0.5) lLabel.set_width_chars(10) t.attach(lLabel, 0, 1, 1, 2) self.liEntry = gtk.Entry() self.liEntry.set_width_chars(10) t.attach(self.liEntry, 1, 2, 1, 2) loLabel = gtk.Label('Lead Out') loLabel.set_alignment(0.95, 0.5) loLabel.set_width_chars(10) t.attach(loLabel, 0, 1, 2, 3) self.loEntry = gtk.Entry() self.loEntry.set_width_chars(10) t.attach(self.loEntry, 1, 2, 2, 3) xSLabel = gtk.Label('X start') xSLabel.set_alignment(0.95, 0.5) xSLabel.set_width_chars(10) t.attach(xSLabel, 0, 1, 3, 4) self.xSEntry = gtk.Entry() self.xSEntry.set_width_chars(10) t.attach(self.xSEntry, 1, 2, 3, 4) ySLabel = gtk.Label('Y start') ySLabel.set_alignment(0.95, 0.5) ySLabel.set_width_chars(10) t.attach(ySLabel, 0, 1, 4, 5) self.ySEntry = gtk.Entry() self.ySEntry.set_width_chars(10) t.attach(self.ySEntry, 1, 2, 4, 5) self.centre = gtk.RadioButton(None, 'Centre') t.attach(self.centre, 1, 2, 5, 6) bLeft = gtk.RadioButton(self.centre, 'Bottom Left') t.attach(bLeft, 0, 1, 5, 6) dLabel = gtk.Label('Diameter') dLabel.set_alignment(0.95, 0.5) dLabel.set_width_chars(10) t.attach(dLabel, 0, 1, 6, 7) self.dEntry = gtk.Entry() self.dEntry.set_width_chars(10) t.attach(self.dEntry, 1, 2, 6, 7) preview = gtk.Button('Preview') preview.connect('pressed', self.send_preview) t.attach(preview, 0, 1, 9, 10) self.add = gtk.Button('Add') self.add.set_sensitive(False) self.add.connect('pressed', self.add_shape_to_file) t.attach(self.add, 2, 3, 9, 10) end = gtk.Button('Return') end.connect('pressed', self.end_this_shape) t.attach(end, 4, 5, 9, 10) pixbuf = gtk.gdk.pixbuf_new_from_file_at_size( filename='./wizards/images/circle.png', width=240, height=240) image = gtk.Image() image.set_from_pixbuf(pixbuf) t.attach(image, 2, 5, 1, 9) self.xSEntry.grab_focus() self.W.show_all() if os.path.exists(self.configFile): f_in = open(self.configFile, 'r') for line in f_in: if line.startswith('preamble'): self.preamble = line.strip().split('=')[1] elif line.startswith('postamble'): self.postamble = line.strip().split('=')[1] elif line.startswith('lead-in'): self.liEntry.set_text(line.strip().split('=')[1]) elif line.startswith('lead-out'): self.loEntry.set_text(line.strip().split('=')[1]) elif line.startswith('hole-diameter'): self.sRadius = float(line.strip().split('=')[1]) / 2 elif line.startswith('hole-speed'): self.hSpeed = float(line.strip().split('=')[1]) response = self.W.run()
def newGameDialog(self, widget, data=None): dialog = gtk.Dialog(title="Start New Game", parent=self.window) dialog.set_default_size(500, 300) dialog.vbox.set_spacing(2) dialog.vbox.set_homogeneous(True) dialog.show() #some labels have (seemingly) superfluous spaces to make everything pretty! #red redhbox = gtk.HBox(False, 5) redhbox.show() dialog.vbox.pack_start(redhbox) redlabel = gtk.Label("Red: ") redhbox.pack_start(redlabel, expand=False, fill=False) redlabel.show() redfilelabel = gtk.Label("null") redfilelabelscrolledwindow = gtk.ScrolledWindow() redhbox.pack_start(redfilelabelscrolledwindow) redfilelabelscrolledwindow.add_with_viewport(redfilelabel) redfilelabelscrolledwindow.show() redfilelabel.show() redfilebutton = gtk.Button("Assign") redfilebutton.connect("clicked", self.selectAIFile, redfilelabel) redhbox.pack_start(redfilebutton, expand=False, fill=False) redfilebutton.show() redremovebutton = gtk.Button("Remove") redremovebutton.connect("clicked", self.removeAIFile, redfilelabel) redhbox.pack_start(redremovebutton, expand=False, fill=False) redremovebutton.show() #orange orangehbox = gtk.HBox(False, 5) orangehbox.show() dialog.vbox.pack_start(orangehbox) orangelabel = gtk.Label("Orange: ") orangehbox.pack_start(orangelabel, expand=False, fill=False) orangelabel.show() orangefilelabel = gtk.Label("null") orangefilelabelscrolledwindow = gtk.ScrolledWindow() orangehbox.pack_start(orangefilelabelscrolledwindow) orangefilelabelscrolledwindow.add_with_viewport(orangefilelabel) orangefilelabelscrolledwindow.show() orangefilelabel.show() orangefilebutton = gtk.Button("Assign") orangefilebutton.connect("clicked", self.selectAIFile, orangefilelabel) orangehbox.pack_start(orangefilebutton, expand=False, fill=False) orangefilebutton.show() orangeremovebutton = gtk.Button("Remove") orangeremovebutton.connect("clicked", self.removeAIFile, orangefilelabel) orangehbox.pack_start(orangeremovebutton, expand=False, fill=False) orangeremovebutton.show() #yellow yellowhbox = gtk.HBox(False, 5) yellowhbox.show() dialog.vbox.pack_start(yellowhbox) yellowlabel = gtk.Label("Yellow: ") yellowhbox.pack_start(yellowlabel, expand=False, fill=False) yellowlabel.show() yellowfilelabel = gtk.Label("null") yellowfilelabelscrolledwindow = gtk.ScrolledWindow() yellowhbox.pack_start(yellowfilelabelscrolledwindow) yellowfilelabelscrolledwindow.add_with_viewport(yellowfilelabel) yellowfilelabelscrolledwindow.show() yellowfilelabel.show() yellowfilebutton = gtk.Button("Assign") yellowfilebutton.connect("clicked", self.selectAIFile, yellowfilelabel) yellowhbox.pack_start(yellowfilebutton, expand=False, fill=False) yellowfilebutton.show() yellowremovebutton = gtk.Button("Remove") yellowremovebutton.connect("clicked", self.removeAIFile, yellowfilelabel) yellowhbox.pack_start(yellowremovebutton, expand=False, fill=False) yellowremovebutton.show() #green greenhbox = gtk.HBox(False, 5) greenhbox.show() dialog.vbox.pack_start(greenhbox) greenlabel = gtk.Label("Green: ") greenhbox.pack_start(greenlabel, expand=False, fill=False) greenlabel.show() greenfilelabel = gtk.Label("null") greenfilelabelscrolledwindow = gtk.ScrolledWindow() greenhbox.pack_start(greenfilelabelscrolledwindow) greenfilelabelscrolledwindow.add_with_viewport(greenfilelabel) greenfilelabelscrolledwindow.show() greenfilelabel.show() greenfilebutton = gtk.Button("Assign") greenfilebutton.connect("clicked", self.selectAIFile, greenfilelabel) greenhbox.pack_start(greenfilebutton, expand=False, fill=False) greenfilebutton.show() greenremovebutton = gtk.Button("Remove") greenremovebutton.connect("clicked", self.removeAIFile, greenfilelabel) greenhbox.pack_start(greenremovebutton, expand=False, fill=False) greenremovebutton.show() #blue bluehbox = gtk.HBox(False, 5) bluehbox.show() dialog.vbox.pack_start(bluehbox) bluelabel = gtk.Label("Blue: ") bluehbox.pack_start(bluelabel, expand=False, fill=False) bluelabel.show() bluefilelabel = gtk.Label("null") bluefilelabelscrolledwindow = gtk.ScrolledWindow() bluehbox.pack_start(bluefilelabelscrolledwindow) bluefilelabelscrolledwindow.add_with_viewport(bluefilelabel) bluefilelabelscrolledwindow.show() bluefilelabel.show() bluefilebutton = gtk.Button("Assign") bluefilebutton.connect("clicked", self.selectAIFile, bluefilelabel) bluehbox.pack_start(bluefilebutton, expand=False, fill=False) bluefilebutton.show() blueremovebutton = gtk.Button("Remove") blueremovebutton.connect("clicked", self.removeAIFile, bluefilelabel) bluehbox.pack_start(blueremovebutton, expand=False, fill=False) blueremovebutton.show() #indigo indigohbox = gtk.HBox(False, 5) indigohbox.show() dialog.vbox.pack_start(indigohbox) indigolabel = gtk.Label("Indigo: ") indigohbox.pack_start(indigolabel, expand=False, fill=False) indigolabel.show() indigofilelabel = gtk.Label("null") indigofilelabelscrolledwindow = gtk.ScrolledWindow() indigohbox.pack_start(indigofilelabelscrolledwindow) indigofilelabelscrolledwindow.add_with_viewport(indigofilelabel) indigofilelabelscrolledwindow.show() indigofilelabel.show() indigofilebutton = gtk.Button("Assign") indigofilebutton.connect("clicked", self.selectAIFile, indigofilelabel) indigohbox.pack_start(indigofilebutton, expand=False, fill=False) indigofilebutton.show() indigoremovebutton = gtk.Button("Remove") indigoremovebutton.connect("clicked", self.removeAIFile, indigofilelabel) indigohbox.pack_start(indigoremovebutton, expand=False, fill=False) indigoremovebutton.show() #violet violethbox = gtk.HBox(False, 5) violethbox.show() dialog.vbox.pack_start(violethbox) violetlabel = gtk.Label("Violet: ") violethbox.pack_start(violetlabel, expand=False, fill=False) violetlabel.show() violetfilelabel = gtk.Label("null") violetfilelabelscrolledwindow = gtk.ScrolledWindow() violethbox.pack_start(violetfilelabelscrolledwindow) violetfilelabelscrolledwindow.add_with_viewport(violetfilelabel) violetfilelabelscrolledwindow.show() violetfilelabel.show() violetfilebutton = gtk.Button("Assign") violetfilebutton.connect("clicked", self.selectAIFile, violetfilelabel) violethbox.pack_start(violetfilebutton, expand=False, fill=False) violetfilebutton.show() violetremovebutton = gtk.Button("Remove") violetremovebutton.connect("clicked", self.removeAIFile, violetfilelabel) violethbox.pack_start(violetremovebutton, expand=False, fill=False) violetremovebutton.show() #begin simulation button ai_paths = [ redfilelabel, orangefilelabel, yellowfilelabel, greenfilelabel, bluefilelabel, indigofilelabel, violetfilelabel ] beginbutton = gtk.Button("Begin Simulation") beginbutton.connect("clicked", self.startGame, ai_paths) beginbuttonhbox = gtk.HBox(False, 0) dialog.vbox.pack_start(beginbuttonhbox, padding=10) beginbuttonhbox.pack_end(beginbutton, padding=20) beginbutton.show() beginbuttonhbox.show() #cancel button cancelbutton = gtk.Button("Cancel") cancelbutton.connect("clicked", lambda x: dialog.destroy()) cancelbuttonhbox = gtk.HBox(False, 0) dialog.vbox.pack_start(cancelbuttonhbox, padding=10) cancelbuttonhbox.pack_end(cancelbutton, padding=20) cancelbutton.show() cancelbuttonhbox.show()