def do_bolt_circle(self, fWizard, tmpDir): self.tmpDir = tmpDir self.fWizard = fWizard self.sRadius = 0.0 self.hSpeed = 100 self.W = gtk.Dialog('Bolt 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) offsetLabel = gtk.Label('Offset') offsetLabel.set_alignment(0.95, 0.5) offsetLabel.set_width_chars(10) t.attach(offsetLabel, 0, 1, 0, 1) self.offset = gtk.CheckButton('Kerf Width') t.attach(self.offset, 1, 2, 0, 1) ocBox = gtk.HBox() self.ocBlank = gtk.Label(' ') ocBox.pack_start(self.ocBlank, expand = True, fill = True) self.overcut = gtk.CheckButton('Over Cut') self.overcut.set_sensitive(False) ocBox.pack_start(self.overcut) ocLabel = gtk.Label('OC Length') ocLabel.set_alignment(0.95, 0.5) ocLabel.set_width_chars(9) ocBox.pack_start(ocLabel) self.ocEntry = gtk.Entry() self.ocEntry.set_width_chars(5) self.ocEntry.set_sensitive(False) ocBox.pack_start(self.ocEntry) t.attach(ocBox, 2, 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) self.bLeft = gtk.RadioButton(self.centre, 'Bottom Left') t.attach(self.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) hdLabel = gtk.Label('Hole Diameter') hdLabel.set_alignment(0.95, 0.5) hdLabel.set_width_chars(10) t.attach(hdLabel, 0, 1, 7, 8) self.hdEntry = gtk.Entry() self.hdEntry.set_width_chars(10) self.hdEntry.connect('changed', self.diameter_changed) t.attach(self.hdEntry, 1, 2, 7, 8) hLabel = gtk.Label('# of holes') hLabel.set_alignment(0.95, 0.5) hLabel.set_width_chars(10) t.attach(hLabel, 0, 1, 8, 9) self.hEntry = gtk.Entry() self.hEntry.set_width_chars(10) t.attach(self.hEntry, 1, 2, 8, 9) aLabel = gtk.Label('Start Angle') aLabel.set_alignment(0.95, 0.5) aLabel.set_width_chars(10) t.attach(aLabel, 0, 1, 9, 10) self.aEntry = gtk.Entry() self.aEntry.set_width_chars(10) self.aEntry.set_text('0') t.attach(self.aEntry, 1, 2, 9, 10) cALabel = gtk.Label('Circle Angle') cALabel.set_alignment(0.95, 0.5) cALabel.set_width_chars(10) t.attach(cALabel, 2, 3, 9, 10) self.cAEntry = gtk.Entry() self.cAEntry.set_width_chars(10) self.cAEntry.set_text('360') t.attach(self.cAEntry, 3, 4, 9, 10) preview = gtk.Button('Preview') preview.connect('pressed', self.send_preview) t.attach(preview, 0, 1, 11, 12) 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, 11, 12) end = gtk.Button('Return') end.connect('pressed', self.end_this_shape) t.attach(end, 4, 5, 11, 12) pixbuf = gtk.gdk.pixbuf_new_from_file_at_size( filename='./plasmac/wizards/images/bolt-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('origin'): if line.strip().split('=')[1] == 'True': self.centre.set_active(1) else: self.bLeft.set_active(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 __init__(self): gtk.Frame.__init__(self, "Lattice") self.set_label_align(0.5, 0.5) TypeBox = gtk.VBox() HBox = gtk.HBox() TypeFrame = gtk.Frame("Type") ParamFrame = gtk.Frame("Parameters") self.CubicRadio = gtk.RadioButton(None, "Simple Cubic") self.TetraRadio = gtk.RadioButton(self.CubicRadio, "Tetragonal") self.FCCRadio = gtk.RadioButton(self.CubicRadio, "FCC") self.BCCRadio = gtk.RadioButton(self.CubicRadio, "BCC") self.OrthoRadio = gtk.RadioButton(self.CubicRadio, "Orthorhombic") self.ArbRadio = gtk.RadioButton(self.CubicRadio, "Arbitrary") self.CubicRadio.connect("toggled", self.RadioCallback, "Cubic") self.FCCRadio.connect("toggled", self.RadioCallback, "FCC") self.BCCRadio.connect("toggled", self.RadioCallback, "BCC") self.OrthoRadio.connect("toggled", self.RadioCallback, "Ortho") self.ArbRadio.connect("toggled", self.RadioCallback, "Arb") TypeBox.pack_start(self.CubicRadio) TypeBox.pack_start(self.FCCRadio) TypeBox.pack_start(self.BCCRadio) TypeBox.pack_start(self.OrthoRadio) TypeBox.pack_start(self.ArbRadio) TypeFrame.add(TypeBox) # Setup the lattice vector table VectorTable = gtk.Table(3, 4, False) a0label = gtk.Label() a0label.set_markup("a<small><sub>0</sub></small>") a1label = gtk.Label() a1label.set_markup("a<small><sub>1</sub></small>") a2label = gtk.Label() a2label.set_markup("a<small><sub>2</sub></small>") VectorTable.attach(a0label, 0, 1, 0, 1, gtk.SHRINK, gtk.SHRINK, 5) VectorTable.attach(a1label, 0, 1, 1, 2, gtk.SHRINK, gtk.SHRINK, 5) VectorTable.attach(a2label, 0, 1, 2, 3, gtk.SHRINK, gtk.SHRINK, 5) self.SpinButtons = [] for row in range(0, 3): spinlist = [] for col in range(1, 4): spin = gtk.SpinButton(\ gtk.Adjustment(0.0, -1.0e5, 1.00e5, 0.01, 0.1)) spinlist.append(spin) spin.set_digits(5) spin.set_width_chars(8) VectorTable.attach(spin, col, col + 1, row, row + 1) self.SpinButtons.append(spinlist) VectorFrame = gtk.Frame("Lattice Vectors") VectorFrame.add(VectorTable) # Setup the parameters ParamBox = gtk.VBox() # Cubic parameters ParamTable = gtk.Table(6, 4) self.aButton = gtk.SpinButton\ (gtk.Adjustment(1.0, 0.0, 1e5, 0.01, 0.1)) self.aButton.set_digits(5) self.aButton.set_width_chars(8) self.bButton = gtk.SpinButton(gtk.Adjustment(1.0, 0.0, 1e5, 0.01, 0.1)) self.bButton.set_digits(5) self.bButton.set_width_chars(8) self.cButton = gtk.SpinButton(gtk.Adjustment(1.0, 0.0, 1e5, 0.01, 0.1)) self.cButton.set_digits(5) self.cButton.set_width_chars(8) self.alphaButton = gtk.SpinButton( gtk.Adjustment(90.0, 0.0, 180.0, 0.01, 0.1)) self.alphaButton.set_digits(3) self.betaButton = gtk.SpinButton( gtk.Adjustment(90.0, 0.0, 180.0, 0.01, 0.1)) self.betaButton.set_digits(3) self.gammaButton = gtk.SpinButton( gtk.Adjustment(90.0, 0.0, 180.0, 0.01, 0.1)) self.gammaButton.set_digits(3) # Set parameters changing callback self.aButton.connect("value_changed", self.parameters_callback) self.bButton.connect("value_changed", self.parameters_callback) self.cButton.connect("value_changed", self.parameters_callback) self.alphaButton.connect("value_changed", self.parameters_callback) self.betaButton.connect("value_changed", self.parameters_callback) self.gammaButton.connect("value_changed", self.parameters_callback) ParamTable.attach(gtk.Label("a"), 0, 1, 0, 1) ParamTable.attach(gtk.Label("b"), 0, 1, 1, 2) ParamTable.attach(gtk.Label("c"), 0, 1, 2, 3) alphaLabel = gtk.Label() alphaLabel.set_markup( "<span foreground=\"blue\" font_family=\"Standard Symbols L\">α</span>" ) betaLabel = gtk.Label() betaLabel.set_markup( "<span foreground=\"blue\" font_family=\"Standard Symbols L\">β</span>" ) gammaLabel = gtk.Label() gammaLabel.set_markup( "<span foreground=\"blue\" font_family=\"Standard Symbols L\">γ</span>" ) ParamTable.attach(alphaLabel, 2, 3, 0, 1, gtk.SHRINK, gtk.SHRINK, 5, 2) ParamTable.attach(betaLabel, 2, 3, 1, 2, gtk.SHRINK, gtk.SHRINK, 5, 2) ParamTable.attach(gammaLabel, 2, 3, 2, 3, gtk.SHRINK, gtk.SHRINK, 5, 2) ParamTable.attach(self.aButton, 1, 2, 0, 1, gtk.SHRINK, gtk.SHRINK, 5, 2) ParamTable.attach(self.bButton, 1, 2, 1, 2, gtk.SHRINK, gtk.SHRINK, 5, 2) ParamTable.attach(self.cButton, 1, 2, 2, 3, gtk.SHRINK, gtk.SHRINK, 5, 2) ParamTable.attach(self.alphaButton, 3, 4, 0, 1, gtk.SHRINK, gtk.SHRINK, 5, 2) ParamTable.attach(self.betaButton, 3, 4, 1, 2, gtk.SHRINK, gtk.SHRINK, 5, 2) ParamTable.attach(self.gammaButton, 3, 4, 2, 3, gtk.SHRINK, gtk.SHRINK, 5, 2) ParamBox.pack_start(ParamTable) ParamFrame.add(ParamBox) # Pack the main Lattice box HBox.pack_start(TypeFrame, False, False, 3) HBox.pack_start(ParamFrame, False, False, 3) HBox.pack_start(VectorFrame, False, False, 3) self.set_cubic() self.lattice_sensitive(False) self.params_sensitive([True, False, False, False, False, False]) self.add(HBox)
def __init__(self): gtk.Frame.__init__(self, "Atom positions") self.set_label_align(0.5, 0.5) self.VBox = gtk.VBox() # Number of atoms control numAtomsBox = gtk.HBox() numAtomsLabel = gtk.Label() numAtomsLabel.set_markup( "<span foreground=\"blue\"># of atoms:</span>") self.NumAtomsButton = gtk.SpinButton( gtk.Adjustment(1.0, 0.0, 1.0e4, 1.0, 10.0)) numAtomsBox.pack_start(numAtomsLabel) numAtomsBox.pack_start(self.NumAtomsButton) self.NumAtomsButton.connect("value_changed", self.atom_num_callback) # Relative or absolute coordinates selection coordTypeBox = gtk.HBox() coordTypeLabel = gtk.Label() coordTypeLabel.set_markup( "<span foreground=\"blue\">Coordinate type:</span>") coordTypeBox.pack_start(coordTypeLabel) self.RelButton = gtk.RadioButton(None, "Relative") self.AbsButton = gtk.RadioButton(self.RelButton, "Absolute") coordTypeBox.pack_start(self.RelButton) coordTypeBox.pack_start(self.AbsButton) firstLineBox = gtk.HBox() firstLineBox.pack_start(numAtomsBox) firstLineBox.pack_start(coordTypeBox) self.AtomTable = gtk.Table(1, 4) typeLabel = gtk.Label() typeLabel.set_markup("<span foreground=\"blue\"> Type </span>") xLabel = gtk.Label() xLabel.set_markup("<span foreground=\"blue\">x-coord</span>") yLabel = gtk.Label() yLabel.set_markup("<span foreground=\"blue\">y-coord</span>") zLabel = gtk.Label() zLabel.set_markup("<span foreground=\"blue\">z-coord</span>") self.AtomTable.attach(typeLabel, 0, 1, 0, 1) self.AtomTable.attach(xLabel, 1, 2, 0, 1) self.AtomTable.attach(yLabel, 2, 3, 0, 1) self.AtomTable.attach(zLabel, 3, 4, 0, 1) atomTableBox = gtk.VBox() atomTableBox.pack_start(self.AtomTable, False, False) atomTableScroll = gtk.ScrolledWindow() atomTableScroll.add_with_viewport(atomTableBox) atomTableScroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) atomTableScroll.set_size_request(-1, 200) self.TypeList = [] self.VBox.pack_start(firstLineBox) self.VBox.pack_start(atomTableScroll) self.add(self.VBox) self.AtomRowList = [] self.TypeList = [] self.NumAtoms = 0 self.NumTypes = 0 self.set_num_atoms(1) self.show_all()
def __init__(self, parent, config): gtk.Window.__init__(self) self.set_title("Options") self.connect('delete_event', self.do_delete) self.config = config self.t = gtk.Table() self.n = 0 def addc(a, b, af=gtk.FILL | gtk.EXPAND, bf=gtk.FILL): self.t.attach(a, 0, 1, self.n, self.n + 1, af) self.t.attach(b, 1, 2, self.n, self.n + 1, bf) self.n += 1 self.format_label = gtk.Label('Format: ') self.format_list = gtk.ListStore(str) for f in YoutubeConnector.YTConnector.STR_FORMATS: self.format_list.append((f, )) self.format_switcher = gtk.ComboBox() self.format_switcher.set_model(self.format_list) cell = gtk.CellRendererText() self.format_switcher.pack_start(cell, True) self.format_switcher.add_attribute(cell, 'text', 0) try: i = YoutubeConnector.YTConnector.STR_FORMATS.index( config['format']) self.format_switcher.set_active(i) except Exception as e: print e self.format_switcher.show() self.format_label.show() addc(self.format_label, self.format_switcher) self.quality_label = gtk.Label('Quality: ') self.quality_list = gtk.ListStore(str) for quality in YoutubeConnector.YTConnector.STR_QUALITIES: self.quality_list.append((quality, )) self.quality_switcher = gtk.ComboBox() self.quality_switcher.set_model(self.quality_list) cell = gtk.CellRendererText() self.quality_switcher.pack_start(cell, True) self.quality_switcher.add_attribute(cell, 'text', 0) try: i = YoutubeConnector.YTConnector.STR_QUALITIES.index( config['quality']) self.quality_switcher.set_active(i) except Exception as e: print e self.quality_switcher.show() self.quality_label.show() addc(self.quality_label, self.quality_switcher) self.playerEntry = gtk.Entry() if 'player' in self.config: self.playerEntry.set_text(self.config['player']) self.playerLabel = gtk.Label("Player (blank for auto): ") self.playerChooseButton = gtk.Button("File") self.playerChooseButton.connect('clicked', self.player_choose_file_callback) h = gtk.HBox() h.pack_start(self.playerEntry, gtk.FILL | gtk.EXPAND) h.pack_start(self.playerChooseButton, 0) addc(self.playerLabel, h) self.userAgentEntry = gtk.Entry() if 'User-Agent' in self.config: self.userAgentEntry.set_text(self.config['User-Agent']) self.userAgentLabel = gtk.Label("User-Agent (blank for auto): ") addc(self.userAgentLabel, self.userAgentEntry) self.allow_several = gtk.CheckButton() self.allow_several.set_active(self.config['allow_several']) self.allow_several_label = gtk.Label("Allow more than one at a time: ") addc(self.allow_several_label, self.allow_several) self.show_desc = gtk.CheckButton() self.show_desc.set_active(self.config['show_desc']) self.show_desc_label = gtk.Label("Show description: ") addc(self.show_desc_label, self.show_desc) h = gtk.HBox() self.ok_button = gtk.Button('OK') self.ok_button.connect('clicked', self.do_ok) self.ok_button.show() self.cancel_button = gtk.Button('Cancel') self.cancel_button.connect('clicked', self.do_cancel) self.cancel_button.show() h.pack_start(self.ok_button) h.pack_start(self.cancel_button) self.t.attach(h, 0, 2, self.n, self.n + 1) self.t.show_all() self.add(self.t) self.set_transient_for(parent) self.set_position(gtk.WIN_POS_CENTER_ON_PARENT) self.set_resizable(False)
def createWin(self): self.log.info(HEADER, "In createWin") # # Main window # gtk.Window.__init__(self) try: self.set_icon_from_file(progIcon) except gobject.GError as err: self.log.warn( HEADER, "In createWin progIcon=" + str(progIcon) + "\n error=" + str(err)) self.connect("destroy", self.on_destroy) self.set_title("Screensaver Images Tags") self.set_border_width(5) width = 1000 height = 600 self.set_size_request(width, height) # # Vertical box = tag lists + buttons # vTagBut = gtk.VBox(False, 5) # vTagBut.set_border_width(5) self.add(vTagBut) # Tag lists # # Horizontal box = tag list simple + buttons + multiple # hSimpleButMultiple = gtk.HBox(False, 5) hSimpleButMultiple.set_border_width(5) # Simple list # # Create the scrolled windows simpleTagSW = gtk.ScrolledWindow() simpleTagSW.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) simpleTagSW.set_shadow_type(gtk.SHADOW_IN) simpleTagSW.set_size_request(300, height - 100) # Create tags treeview simpleTagSW.add(self.simpleGuiC.createTagTv()) hSimpleButMultiple.pack_start(simpleTagSW, False, False) # Create buttons # tagButTab = gtk.Table(2, 1, False) # tagButTab.set_row_spacings(5) # tagButTab.set_col_spacings(5) # copy multiple selection gtk.stock_add([(gtk.STOCK_GO_FORWARD, "", 0, 0, "")]) self.copyBut = gtk.Button(stock=gtk.STOCK_GO_FORWARD) self.copyBut.connect("clicked", self.onCopy) self.copyBut.set_sensitive(False) tagButTab.attach(self.copyBut, 0, 1, 0, 1, gtk.EXPAND, gtk.EXPAND, 10, 10) # remove multiple selection gtk.stock_add([(gtk.STOCK_GO_BACK, "", 0, 0, "")]) self.delBut = gtk.Button(stock=gtk.STOCK_GO_BACK) self.delBut.connect("clicked", self.onDelete) self.delBut.set_sensitive(False) tagButTab.attach(self.delBut, 0, 1, 1, 2, gtk.EXPAND, gtk.EXPAND, 10, 10) hSimpleButMultiple.pack_start(tagButTab, False, False) # Multiple list # # Create the scrolled windows multiTagSW = gtk.ScrolledWindow() multiTagSW.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) multiTagSW.set_shadow_type(gtk.SHADOW_IN) # multiTagSW.set_size_request(width*3/5, height) # Create tags treeview # trick to copy self.multiGuiC.tagC.tagMultiList = self.simpleGuiC.tagC.tagMultiList multiTagSW.add(self.multiGuiC.createTagTv()) hSimpleButMultiple.pack_start(multiTagSW, True, True) vTagBut.add(hSimpleButMultiple) # Buttons # # Create buttons butTab = gtk.Table(1, 5, True) # scan tags gtk.stock_add([(gtk.STOCK_REFRESH, "Lire les tags", 0, 0, "")]) scanBut = gtk.Button(stock=gtk.STOCK_REFRESH) scanBut.connect("clicked", self.onScan) butTab.attach(scanBut, 0, 1, 0, 1, gtk.EXPAND, gtk.EXPAND, 0, 0) # create links gtk.stock_add([(gtk.STOCK_EXECUTE, "Créé les images", 0, 0, "")]) exeBut = gtk.Button(stock=gtk.STOCK_EXECUTE) exeBut.connect("clicked", self.onExecute) butTab.attach(exeBut, 1, 2, 0, 1, gtk.EXPAND, gtk.EXPAND, 0, 0) # quit quitBut = gtk.Button(stock=gtk.STOCK_QUIT) quitBut.connect("clicked", self.on_destroy) butTab.attach(quitBut, 4, 5, 0, 1, gtk.EXPAND, gtk.EXPAND, 0, 0) vTagBut.pack_start(butTab, False, False, 10) # Display the window self.show_all() self.log.info(HEADER, "Out createWin")
def show_builded_images_dialog(self, widget, primary_action=""): title = primary_action if primary_action else "Your builded images" dialog = CrumbsDialog( title, self.builder, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) dialog.set_border_width(12) label = gtk.Label() label.set_use_markup(True) label.set_alignment(0.0, 0.5) label.set_padding(12, 0) if primary_action == "Run image": label.set_markup( "<span font_desc='12'>Select the image file you want to run:</span>" ) elif primary_action == "Deploy image": label.set_markup( "<span font_desc='12'>Select the image file you want to deploy:</span>" ) else: label.set_markup( "<span font_desc='12'>Select the image file you want to %s</span>" % primary_action) dialog.vbox.pack_start(label, expand=False, fill=False) # filter created images as action attribution (deploy or run) action_attr = "" action_images = [] for fileitem in self.image_store: action_attr = fileitem['action_attr'] if (action_attr == 'run' and primary_action == "Run image") \ or (action_attr == 'deploy' and primary_action == "Deploy image"): action_images.append(fileitem) # pack the corresponding 'runnable' or 'deploy' radio_buttons, if there has no more than one file. # assume that there does not both have 'deploy' and 'runnable' files in the same building result # in possible as design. curr_row = 0 rows = (len(action_images)) if len(action_images) < 10 else 10 table = gtk.Table(rows, 10, True) table.set_row_spacings(6) table.set_col_spacing(0, 12) table.set_col_spacing(5, 12) sel_parent_btn = None for fileitem in action_images: sel_btn = gtk.RadioButton(sel_parent_btn, fileitem['type']) sel_parent_btn = sel_btn if not sel_parent_btn else sel_parent_btn sel_btn.set_active(fileitem['is_toggled']) sel_btn.connect('toggled', self.table_selected_cb, fileitem) if curr_row < 10: table.attach(sel_btn, 0, 4, curr_row, curr_row + 1, xpadding=24) else: table.attach(sel_btn, 5, 9, curr_row - 10, curr_row - 9, xpadding=24) curr_row += 1 dialog.vbox.pack_start(table, expand=False, fill=False, padding=6) button = dialog.add_button("Cancel", gtk.RESPONSE_CANCEL) HobAltButton.style_button(button) if primary_action: button = dialog.add_button(primary_action, gtk.RESPONSE_YES) HobButton.style_button(button) dialog.show_all() response = dialog.run() dialog.destroy() if response != gtk.RESPONSE_YES: return for fileitem in self.image_store: if fileitem['is_toggled']: if fileitem['action_attr'] == 'run': self.builder.runqemu_image(fileitem['name'], self.sel_kernel) elif fileitem['action_attr'] == 'deploy': self.builder.deploy_image(fileitem['name'])
def __init__(self): from multidragview import MultiDragTreeView self.store1 = gtk.ListStore(str, bool) #package name, currently installed? self.store2 = gtk.ListStore(str, bool) #package name, action r_name1 = gtk.CellRendererText() c_name1 = gtk.TreeViewColumn(_('Software name')) c_name1.pack_start(r_name1) c_name1.add_attribute(r_name1, 'text', 0) c_name1.set_sort_column_id(0) r_status1 = gtk.CellRendererText() c_status1 = gtk.TreeViewColumn(_('Status')) c_status1.pack_start(r_status1) c_status1.set_cell_data_func(r_status1, self.r_status1_cell_func) c_status1.set_sort_column_id(1) self.view1 = view1 = MultiDragTreeView(self.store1) view1.append_column(c_name1) view1.append_column(c_status1) view1.get_selection().set_mode(gtk.SELECTION_MULTIPLE) scroll1 = gtk.ScrolledWindow() scroll1.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) scroll1.set_shadow_type(gtk.SHADOW_IN) scroll1.add(view1) r_name2 = gtk.CellRendererText() c_name2 = gtk.TreeViewColumn(_('Software name')) c_name2.pack_start(r_name2) c_name2.add_attribute(r_name2, 'text', 0) c_name2.set_sort_column_id(0) r_action2 = gtk.CellRendererText() c_action2 = gtk.TreeViewColumn(_('Action')) c_action2.pack_start(r_action2) c_action2.set_cell_data_func(r_action2, self.r_action_cell_func) c_action2.set_sort_column_id(1) self.view2 = view2 = MultiDragTreeView(self.store2) view2.append_column(c_name2) view2.append_column(c_action2) view2.get_selection().set_mode(gtk.SELECTION_MULTIPLE) scroll2 = gtk.ScrolledWindow() scroll2.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) scroll2.set_shadow_type(gtk.SHADOW_IN) scroll2.add(view2) TARGETS = [('treeview_row', gtk.TARGET_SAME_APP, 0)] view1.enable_model_drag_source(gtk.gdk.BUTTON1_MASK, TARGETS, gtk.gdk.ACTION_COPY) view1.enable_model_drag_dest(TARGETS, gtk.gdk.ACTION_DEFAULT) view1.connect('drag_data_get', self.drag_data_get_data) view1.connect('drag_data_received', self.drag_data_received_data_dummy) view2.enable_model_drag_source(gtk.gdk.BUTTON1_MASK, TARGETS, gtk.gdk.ACTION_MOVE) view2.enable_model_drag_dest(TARGETS, gtk.gdk.ACTION_DEFAULT) view2.connect('drag_data_get', self.drag_data_get_data) view2.connect('drag_data_received', self.drag_data_received_data) table = gtk.Table() table.set_col_spacings(30) table.set_row_spacings(5) table.attach(gtk.Label(_('Diff between now and the snapshot')), 0, 1, 0, 1, gtk.FILL, gtk.FILL) table.attach(gtk.Label(_('Your plan')), 1, 2, 0, 1, gtk.FILL, gtk.FILL) table.attach(scroll1, 0, 1, 1, 2, gtk.FILL) table.attach(scroll2, 1, 2, 1, 2, gtk.FILL) gtk.VBox.__init__(self, False, 5) self.pack_start(table) self.set_tooltip_text(_('Drag from left to right'))
def _setup_page_summary(self): summary = gtk.Label() summary.set_markup( _('<span weight="bold">Summary!!!</span>\nPlease check if everything is correct.' )) summary.set_alignment(0, 0.5) self.name = gtk.Label() self.name.set_alignment(0, 0.5) self.base_version = gtk.Label() self.base_version.set_alignment(0, 0.5) self.compression = gtk.Label() self.compression.set_alignment(0, 0.5) table = gtk.Table(3, 2) label = gtk.Label(_('Name:')) label.set_alignment(1, 0.5) table.attach(label, 0, 1, 0, 1, xoptions=gtk.FILL, xpadding=5, ypadding=2) table.attach(self.name, 1, 2, 0, 1, ypadding=2) label = gtk.Label(_('Base Version:')) label.set_alignment(1, 0.5) table.attach(label, 0, 1, 1, 2, xoptions=gtk.FILL, xpadding=5, ypadding=2) table.attach(self.base_version, 1, 2, 1, 2, ypadding=2) label = gtk.Label(_('Compression:')) label.set_alignment(1, 0.5) table.attach(label, 0, 1, 2, 3, xoptions=gtk.FILL, xpadding=5, ypadding=2) table.attach(self.compression, 1, 2, 2, 3, ypadding=2) box = gtk.VBox() box.pack_start(summary, False, False, 5) box.pack_start(table, False, False, 5) self.summary = gtk.Alignment(1, 1, 1, 1) self.summary.add(box) self.summary.set_padding(5, 5, 5, 5) self.assistant.append_page(self.summary) self.assistant.set_page_title(self.summary, _('Summary')) self.assistant.set_page_complete(self.summary, True) self.assistant.set_page_type(self.summary, gtk.ASSISTANT_PAGE_CONFIRM)
def __init__(self): super(BrushEditorWindow, self).__init__() # UI topbox = gtk.VBox() self.add(topbox) # Brush preview self.bprev = BrushPreview() box = gtk.HBox() box.pack_start(gtk.VBox()) box.pack_start(self.bprev, False, False) box.pack_start(gtk.VBox()) topbox.pack_start(box, False, False) # Brush parameters table = gtk.Table(2) topbox.pack_start(table, False, False) self.prop = {} self.prop['radius_min'] = self._add_slider(table, 'radius_min', -1, 5, 3, .1, .5, islog=True) self.prop['radius_max'] = self._add_slider(table, 'radius_max', -1, 5, 3, .1, .5, islog=True) self.prop['yratio'] = self._add_slider(table, 'yratio', 1.0, 32., 1., 0.1, 2) self.prop['spacing'] = self._add_slider(table, 'spacing', 0.01, 4, 0.25, .01, 0.1) self.prop['opacity_min'] = self._add_slider(table, 'opacity_min', 0, 1, 1, 1 / 255., 10 / 255.) self.prop['opacity_max'] = self._add_slider(table, 'opacity_max', 0, 1, 1, 1 / 255., 10 / 255.) self.prop['hardness'] = self._add_slider(table, 'hardness', 0, 1, 1, .01, 0.1) self.prop['erase'] = self._add_slider(table, 'erase', 0, 1, 1, .01, 0.1) self.prop['opa_comp'] = self._add_slider(table, 'opa_comp', 0, 2, .9, 0.01, 0.1) self.prop['motion_track'] = self._add_slider(table, 'motion_track', 0.0, 2.0, 1.0, .1, 1) self.prop['hi_speed_track'] = self._add_slider(table, 'hi_speed_track', 0.0, 2.0, 0.0, .01, 0.1) self.prop['smudge'] = self._add_slider(table, 'smudge', 0.0, 1.0, 0.0, .01, 0.1) self.prop['smudge_var'] = self._add_slider(table, 'smudge_var', 0.0, 1.0, 0.0, .01, 0.1) self.prop['grain'] = self._add_slider(table, 'grain', 0.0, 1.0, 0.0, .01, 0.1) self.prop['dab_radius_jitter'] = self._add_slider( table, 'dab_radius_jitter', 0.0, 1.0, 0.0, .01, 0.1) self.prop['dab_pos_jitter'] = self._add_slider(table, 'dab_pos_jitter', 0.0, 5.0, 0.0, .01, 0.1) self.prop['direction_jitter'] = self._add_slider( table, 'direction_jitter', 0.0, 1.0, 0.0, .01, 0.1) self.set_title('Brush Editor') self.set_default_size(320, 100) self.connect('delete-event', self.hide) topbox.show_all()
def do_gusset(self, fWizard, tmpDir): self.tmpDir = tmpDir self.fWizard = fWizard self.W = gtk.Dialog('Gusset', 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) wLabel = gtk.Label('Width') wLabel.set_alignment(0.95, 0.5) wLabel.set_width_chars(10) t.attach(wLabel, 0, 1, 5, 6) self.wEntry = gtk.Entry() self.wEntry.set_width_chars(10) t.attach(self.wEntry, 1, 2, 5, 6) hLabel = gtk.Label('Height') hLabel.set_alignment(0.95, 0.5) hLabel.set_width_chars(10) t.attach(hLabel, 0, 1, 6, 7) self.hEntry = gtk.Entry() self.hEntry.set_width_chars(10) t.attach(self.hEntry, 1, 2, 6, 7) rLabel = gtk.Label('Radius') rLabel.set_alignment(0.95, 0.5) rLabel.set_width_chars(10) t.attach(rLabel, 0, 1, 7, 8) self.rEntry = gtk.Entry() self.rEntry.set_width_chars(10) self.rEntry.set_text('0') t.attach(self.rEntry, 1, 2, 7, 8) aLabel = gtk.Label('Angle') aLabel.set_alignment(0.95, 0.5) aLabel.set_width_chars(10) t.attach(aLabel, 0, 1, 8, 9) self.aEntry = gtk.Entry() self.aEntry.set_width_chars(10) self.aEntry.set_text('90') t.attach(self.aEntry, 1, 2, 8, 9) preview = gtk.Button('Preview') preview.connect('pressed', self.send_preview) t.attach(preview, 0, 1, 10, 11) 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, 10, 11) end = gtk.Button('Return') end.connect('pressed', self.end_this_shape) t.attach(end, 4, 5, 10, 11) pixbuf = gtk.gdk.pixbuf_new_from_file_at_size( filename='./wizards/images/gusset.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]) response = self.W.run()
def __init__(self, df): keydict=df.list_keys() keylist=keydict.keys() self.graphlist=[] ncols=6 cols=range(ncols) nrows=(len(keydict)/ncols+1)*2+3 oddrows=[] evenrows=[] buttonlist={} graphwindow=gtk.Window(gtk.WINDOW_TOPLEVEL) graphwindow.set_title('Laboratory Gasication') graphwindow.set_border_width(10) table=gtk.Table(rows=nrows, columns=ncols) graphwindow.add(table) for i in range(nrows): if round(i/2)==i/2.: evenrows.append(i) else: oddrows.append(i) for i in range(len(keylist)+len(evenrows)): try: label=gtk.Label('\n'+keylist[0]+'\n') try: colstart=cols[0] colend=cols[0]+1 except IndexError: pass rowstart=evenrows[0] rowend=evenrows[0]+1 try: del(cols[0]) table.attach(label, colstart, colend, rowstart, rowend) label.show() vbox=gtk.VBox(True, 0) for b in keydict[keylist[0]]: buttonlist[b]=gtk.CheckButton(b.replace('_',' ')) buttonlist[b].connect("toggled", self.check, b) vbox.pack_start(buttonlist[b], True, True, 0) buttonlist[b].show() table.attach(vbox, colstart, colend, rowstart+1, rowend+1) vbox.show() del(keylist[0]) except IndexError: del(evenrows[0]) cols=range(ncols) except IndexError: pass label=gtk.Label('\n Graph Title \n') table.attach(label, 0, 1, nrows-3, nrows-2) label.show() self.graphtitle=gtk.Entry() table.attach(self.graphtitle, 1, 2, nrows-3, nrows-2) self.graphtitle.show() label=gtk.Label('\n Y-axis Label \n') table.attach(label, 0, 1, nrows-2, nrows-1) label.show() self.graphylabel=gtk.Entry() table.attach(self.graphylabel, 1, 2, nrows-2, nrows-1) self.graphylabel.show() graphbutton=gtk.Button('Create Graph') graphbutton.connect('clicked', self.graph, df) table.attach(graphbutton, 0, 2, nrows-1, nrows) graphbutton.show() table.show() graphwindow.show()
class Burner: def destroy(self, widget, data=None): gtk.main_quit() def usage(): print "Usage is not ready yet. See help button inside gcode-burner." # TODO def help(self, widget): self.help_dialog = gtk.MessageDialog( self.window, flags=gtk.DIALOG_DESTROY_WITH_PARENT, type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_OK, message_format=None) f = open("gcode-burner.info", "r") self.help_dialog.set_markup(f.read()) f.close() self.help_dialog.run() self.help_dialog.destroy() # g_signal_connect_swapped (dialog, "response", # G_CALLBACK (gtk_widget_destroy), # dialog); def set_image(self, widget=None): input_file = self.input_file.get_filename() if input_file == None: input_file = self.args_input_file if not os.path.isfile(input_file): message = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_OK, message_format=None) message.set_markup('Wrong file!') message.run() message.destroy() return try: self.pixbuf = gtk.gdk.pixbuf_new_from_file(input_file) except: message = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_NONE, message_format=None) message.set_markup('Wrong image!') message.run() message.destroy() return self.img_w, self.img_h = self.pixbuf.get_width( ), self.pixbuf.get_height() if self.img_w == 0 or self.img_h == 0: print '(Wrong img)' return scale = float(self.config.get('Global', 'image-scale')) if self.img_w > self.img_h: scaled_buf = self.pixbuf.scale_simple( int(scale), int(scale * self.img_h / self.img_w), gtk.gdk.INTERP_BILINEAR) else: scaled_buf = self.pixbuf.scale_simple( int(scale * self.img_w / self.img_h), int(scale), gtk.gdk.INTERP_BILINEAR) self.image.set_from_pixbuf(scaled_buf) self.set_hw() def set_hw(self): try: self.w = self.spin_buttons["dots_x"].get_value() self.h = self.spin_buttons["dots_y"].get_value() if self.checkbuttons["aspect"].get_active(): self.h = self.w / self.img_w * self.img_h self.spin_buttons["dots_y"].set_value(self.h) except: pass def generate_gcode(self, arg): output_file = self.output_file.get_text() if self.checkbuttons['save_to_file'].get_active(): if self.checkbuttons['add_file_suffix'].get_active(): d = os.path.dirname(output_file) l = os.listdir(d) name = os.path.split(output_file)[-1] name, ext = os.path.splitext(name) max_n = 0 for s in l: r = re.match( r"^%s_0*(\d+)%s$" % (re.escape(name), re.escape(ext)), s) if r: max_n = max(max_n, int(r.group(1))) output_file = d + "/" + name + "_%04d" % (max_n + 1) + ext try: f = open(output_file, 'w') except: message = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_NONE, message_format=None) message.set_markup('Can not write to specified file! (%s)' % output_file) message.run() message.destroy() return self.scaled_pixbuf = self.pixbuf.scale_simple(int(self.w), int(self.h), gtk.gdk.INTERP_BILINEAR) pixels = self.scaled_pixbuf.get_pixels_array() zmin, zmax, ztr, x, y, x0, y0, feed = [ self.spin_buttons[key].get_value() for key in 'z_min z_max z_traverse dot_width dot_height x_offset y_offset feed' .split() ] header = self.header.get_text(self.header.get_start_iter(), self.header.get_end_iter()) clean = self.clean_gcode.get_text(self.clean_gcode.get_start_iter(), self.clean_gcode.get_end_iter()) clean_each = self.clean_each.get_text().lower() try: clean_v = float(clean_each) except: clean_v = None if clean_v <= 0: clean_v = None v_sum = 0. gcode = header parameterize = self.checkbuttons['paramtererization'].get_active() if parameterize: gcode += """ #<x-offset> = %s #<y-offset> = %s #<z-offset> = 0 #<x-scale> = 1 #<y-scale> = 1 #<z-scale> = 1 #<z-traverse> = %s #<feed> = %s """ % (x0, y0, ztr, feed) gcode += '\n(Header end)\n' gcode += 'G0 Z#<z-traverse>\n' gcode += 'G0 X#<x-offset> Y#<y-offset>\n' gcode += 'G1 X#<x-offset> Y#<x-offset> F#<feed>\n' else: gcode += '\n(Header end)\n' gcode += 'G0 Z%f\n' % (ztr) gcode += 'G0 X%f Y%f\n' % (x0, y0) gcode += 'G1 X%f Y%f F%f\n' % (x0, y0, feed) gcodel = [] for j in range(len(pixels[0])): if "row" in clean_each: gcodel.append(clean + "\n") if self.checkbuttons['echo_filter_progress'].get_active(): print "FILTER_PROGRESS=%d" % int(100 * j / len(pixels[0])) for k in range(len(pixels)): # make zig-zag i = k if j % 2 == 0 else len(pixels) - k - 1 #xy = j*rowstride+i*ch r = pixels[i][j][0] g = pixels[i][j][1] b = pixels[i][j][2] v = float(int(r) + int(g) + int(b)) / 255 / 3 v_sum += 1. - v if clean_v != None and v_sum > clean_v: gcodel.append(clean + "\n") v_sum = 0 if v != 0: depth = eval(self.z_func.get_text()) if depth != None: if parameterize: gcodel.append( 'G0 X[%s*#<x-scale>+#<x-offset>] Y[%s*#<y-scale>+#<y-offset>]\n' % (x * i, y * j)) gcodel.append('G1 Z[%s*#<z-scale>+#<z-offset>]\n' % depth) gcodel.append('G0 Z#<z-traverse>\n') else: gcodel.append('G0 X%f Y%f\n' % (x0 + x * i, y0 + y * j)) gcodel.append('G1 Z%f\n' % depth) gcodel.append('G0 Z%f\n' % (ztr)) gcode += "".join(gcodel) footer = self.footer.get_text(self.footer.get_start_iter(), self.footer.get_end_iter()) gcode += '(Footer start)\n' + footer if self.checkbuttons['save_to_file'].get_active(): f.write(gcode) f.close() else: print gcode if self.checkbuttons['save_options'].get_active(): for key in self.spin_buttons: self.config.set('Spinners', key, self.spin_buttons[key].get_value()) for key in self.checkbuttons: self.config.set( 'CheckButtons', key, 1 if self.checkbuttons[key].get_active() else 0) self.config.set('Global', 'header', header) self.config.set('Global', 'footer', footer) self.config.set('Global', 'clean-gcode', clean) input_file = self.input_file.get_filename() if input_file == None: input_file = self.args_input_file self.config.set('Global', 'input_file', input_file) self.config.set('Global', 'output_file', self.output_file.get_text()) self.config.set('Global', 'clean-each', self.clean_each.get_text()) self.config.set('Global', 'z_func', self.z_func.get_text()) f = open(self.ini_file, "w") self.config.write(f) f.close() self.destroy(None, None) def set_spinners(self): self.spin_buttons["dots_x"].set_value(self.w) self.spin_buttons["dots_y"].set_value(self.h) self.spin_buttons['dot_width'].set_value( self.spin_buttons["width"].get_value() / self.w) self.spin_buttons['dot_height'].set_value( self.spin_buttons["height"].get_value() / self.h) def change_spinners(self, widget, key): if self.change_spinners_lock: return self.change_spinners_lock = True if key == 'dot_width': self.spin_buttons['width'].set_value( self.w * self.spin_buttons[key].get_value()) if key == 'width': self.set_spinners() if key == 'dot_height': self.spin_buttons['height'].set_value( self.h * self.spin_buttons[key].get_value()) if key == 'height': self.set_spinners() if key == 'dots_x': self.w = self.spin_buttons[key].get_value() if self.checkbuttons["aspect"].get_active(): self.h = self.w / self.img_w * self.img_h self.set_spinners() if key == 'dots_y': self.h = self.spin_buttons[key].get_value() if self.checkbuttons["aspect"].get_active(): self.w = self.h / self.img_h * self.img_w self.set_spinners() if self.checkbuttons["aspect"].get_active(): if key in ['dot_width', 'width']: self.spin_buttons['height'].set_value( self.spin_buttons['width'].get_value() * self.h / self.w) self.spin_buttons['dot_height'].set_value( float(self.spin_buttons['height'].get_value()) / self.h) else: self.spin_buttons['width'].set_value( self.spin_buttons['height'].get_value() * self.w / self.h) self.spin_buttons['dot_width'].set_value( float(self.spin_buttons['width'].get_value()) / self.w) self.change_spinners_lock = False def show_filename(self, widget): if widget.get_active(): self.output_file.show() else: self.output_file.hide() def save_to_click(self, widget): self.output_file_dialog.set_filename(self.output_file.get_text()) result = self.output_file_dialog.run() if result == gtk.RESPONSE_OK: self.output_file.set_text(self.output_file_dialog.get_filename()) self.output_file_dialog.hide() def __init__(self): self.change_spinners_lock = False self.ini_file = os.path.join( os.path.dirname(os.path.realpath(__file__)), "gcode-burner.ini") import ConfigParser self.config = ConfigParser.RawConfigParser() self.config.read(self.ini_file) spinners = dict(self.config.items('Spinners')) field_names = dict(self.config.items('Field_names')) spinners_order = self.config.get('Global', 'spinners_order').split() checkbuttons_order = self.config.get('Global', 'checkbuttons_order').split() layout = self.config.get('Global', 'layout') try: opts, args = getopt.getopt(sys.argv[1:], "hi:", ["help", "input="]) except getopt.GetoptError, err: # print help information and exit: print str( err) # will print something like "option -a not recognized" usage() sys.exit(2) input_file = None for o, a in opts: if o in ("-h", "--help"): usage() sys.exit() else: assert False, "unhandled option" if args == []: self.args_input_file = self.config.get('Global', 'input_file') else: self.args_input_file = args[0] self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("destroy", self.destroy) table = gtk.Table( 2 + len(spinners_order) + len(checkbuttons_order) + 1, 4) i = 0 self.image = gtk.Image() if layout == "vertical": table.attach(self.image, 0, 3, 0, 1) else: table.attach(self.image, 3, 4, 1, 2 + len(spinners_order) + len(checkbuttons_order) + 1) i += 1 self.input_file = gtk.FileChooserButton('Open image', backend=None) table.attach(self.input_file, 0, 2, i, i + 1, xoptions=gtk.FILL) self.args_input_file = os.path.realpath(self.args_input_file) self.input_file.select_filename(self.args_input_file) self.input_file.connect("file-set", self.set_image) self.set_image() i += 1 self.spin_buttons = {} self.z_func = gtk.Entry() self.z_func.set_text(self.config.get('Global', 'z_func')) table.attach(gtk.Label('Z function'), 0, 1, i, i + 1) table.attach(self.z_func, 1, 2, i, i + 1) i += 1 for key in spinners_order: if key == '|': table.attach(gtk.HSeparator(), 0, 2, i, i + 1, xoptions=gtk.FILL) i += 1 continue adj = gtk.Adjustment(float(spinners[key]), -100000.0, 100000.0, 0.1, 100.0, 0.0) self.spin_buttons[key] = gtk.SpinButton(adjustment=adj, climb_rate=0.1, digits=5) table.attach(self.spin_buttons[key], 1, 2, i, i + 1, xoptions=gtk.FILL) table.attach(gtk.Label(field_names[key]), 0, 1, i, i + 1, xoptions=gtk.FILL) adj.connect("value_changed", self.change_spinners, key) i += 1 self.set_hw() self.clean_each = gtk.Entry() self.clean_each.set_text(self.config.get('Global', 'clean-each')) table.attach(gtk.Label(self.config.get('Field_names', 'clean-each')), 0, 1, i, i + 1) table.attach(self.clean_each, 1, 2, i, i + 1) i += 1 self.checkbuttons = {} j = 0 for key in checkbuttons_order: self.checkbuttons[key] = gtk.CheckButton(field_names[key]) self.checkbuttons[key].set_active( bool(int(self.config.get('CheckButtons', key)))) table.attach(self.checkbuttons[key], j, j + 1, i, i + 1, xoptions=gtk.FILL) j = (j + 1) % 2 if j == 0: i += 1 if j != 0: i += 1 self.output_file = gtk.Entry() self.output_file.set_text(self.config.get('Global', 'output_file')) hbox = gtk.HBox() hbox.pack_start(self.output_file) self.output_file_dialog = gtk.FileChooserDialog( title='Save Gcode to', action=gtk.FILE_CHOOSER_ACTION_SAVE, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK)) self.output_file_dialog.set_default_response(gtk.RESPONSE_OK) image = gtk.Image() image.set_from_stock(gtk.STOCK_SAVE_AS, gtk.ICON_SIZE_BUTTON) self.save_to = gtk.Button(label=None) self.save_to.set_image(image) hbox.pack_start(self.save_to, expand=False) self.save_to.connect("clicked", self.save_to_click) table.attach(hbox, 1, 3, i, i + 1) self.checkbuttons['save_to_file'].connect("toggled", self.show_filename) table.attach(gtk.Label('File name'), 0, 1, i, i + 1) i += 1 button = gtk.Button("Generate Gcode") table.attach(button, 2, 3, i, i + 1) button.connect("clicked", self.generate_gcode) button = gtk.Button("Help") table.attach(button, 0, 1, i, i + 1) button.connect("clicked", self.help) i += 1 frame = gtk.Frame('Header') textview = gtk.TextView() self.header = textview.get_buffer() self.header.set_text(self.config.get('Global', 'header')) textview.set_wrap_mode(gtk.WRAP_NONE) sw = gtk.ScrolledWindow() sw.set_size_request(250, 150) frame.add(sw) sw.add(textview) table.attach(frame, 2, 3, 1, 7, xoptions=gtk.EXPAND | gtk.FILL, yoptions=gtk.EXPAND | gtk.FILL, xpadding=5, ypadding=5) frame = gtk.Frame('Footer') textview = gtk.TextView() self.footer = textview.get_buffer() self.footer.set_text(self.config.get('Global', 'footer')) textview.set_wrap_mode(gtk.WRAP_NONE) sw = gtk.ScrolledWindow() frame.add(sw) sw.add(textview) table.attach(frame, 2, 3, 7, 15, xoptions=gtk.EXPAND | gtk.FILL, yoptions=gtk.EXPAND | gtk.FILL, xpadding=5, ypadding=5) frame = gtk.Frame('Clean Gcode') textview = gtk.TextView() self.clean_gcode = textview.get_buffer() self.clean_gcode.set_text(self.config.get('Global', 'clean-gcode')) textview.set_wrap_mode(gtk.WRAP_NONE) sw = gtk.ScrolledWindow() frame.add(sw) sw.add(textview) table.attach(frame, 2, 3, 15, 21, xoptions=gtk.EXPAND | gtk.FILL, yoptions=gtk.EXPAND | gtk.FILL, xpadding=5, ypadding=5) self.window.add(table) self.window.show_all()
def app_table(self): # Labels #info_label = Label("您可以根据自己需要对深度系统在默认情况下使用的程序进行设置") web_label = Label(_("Web")) mail_label = Label(_("Mail")) editor_label = Label(_("Editor")) music_label = Label(_("Music")) movie_label = Label(_("Video")) pic_label = Label(_("Photo")) terminal_label = Label(_("Terminal")) self.web = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH) self.mail = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH) self.editor = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH) self.music = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH) self.movie = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH) self.pic = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH) self.terminal = self.get_terminal_combo() table = gtk.Table(8, 2, False) #table.attach(style.wrap_with_align(info_label), 0, 2, 0, 1) table.attach(style.wrap_with_align(web_label, width=self.LEFT_WIDTH), 0, 1, 1, 2) table.attach(style.wrap_with_align(mail_label, width=self.LEFT_WIDTH), 0, 1, 2, 3) table.attach( style.wrap_with_align(editor_label, width=self.LEFT_WIDTH), 0, 1, 3, 4) table.attach(style.wrap_with_align(music_label, width=self.LEFT_WIDTH), 0, 1, 4, 5) table.attach(style.wrap_with_align(movie_label, width=self.LEFT_WIDTH), 0, 1, 5, 6) table.attach(style.wrap_with_align(pic_label, width=self.LEFT_WIDTH), 0, 1, 6, 7) table.attach( style.wrap_with_align(terminal_label, width=self.LEFT_WIDTH), 0, 1, 7, 8) table.attach(style.wrap_with_align(self.web), 1, 2, 1, 2, 0) table.attach(style.wrap_with_align(self.mail), 1, 2, 2, 3, 0) table.attach(style.wrap_with_align(self.editor), 1, 2, 3, 4) table.attach(style.wrap_with_align(self.music), 1, 2, 4, 5) table.attach(style.wrap_with_align(self.movie), 1, 2, 5, 6) table.attach(style.wrap_with_align(self.pic), 1, 2, 6, 7) table.attach(style.wrap_with_align(self.terminal), 1, 2, 7, 8) align = style.set_box_with_align(table, "text") style.set_table(table) self.pack_start(align, False, False) all_app_dict = self.get_all_app() #print all_app_dict apps = [ self.web, self.mail, self.editor, self.music, self.movie, self.pic ] for app in apps: app.set_size_request(self.ENTRY_WIDTH, 22) for key in all_app_dict.iterkeys(): if self.get_default_app: apps[key].add_items(all_app_dict[key]) else: apps[key].add_items(all_app_dict[key], clear_first=False)
#!/usr/bin/env python # -*- coding: utf-8 -*- import gtk, pygtk import datetime as dt if __name__ == "__main__": w = gtk.Window() #w.set_size_request(600, 300) w.connect("destroy", lambda *a, **k: gtk.main_quit()) filas = 31 columnas = 3 * 24 / 2 # Celda cada 2 horas. tabla = gtk.Table(filas, columnas) for x in range(columnas): for y in range(filas): entry = gtk.Entry() entry.set_text("(%d, %d)" % (x, y)) tabla.attach(entry, x, x+1, y, y+1, xoptions = 0) w.add(tabla) w.show_all() gtk.main()
def _build_ui_tab(self, group): # The scrolled window sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) sw.show() # Notebook tab tab = self._notebook.append_page(sw, gtk.Label(_(group.get_name()))) # Settings table table = gtk.Table(len(group), 2, False) table.set_resize_mode(gtk.RESIZE_IMMEDIATE) table.show() sw.add_with_viewport(table) row = 0 for element in group: if not isinstance(element, settings.RadioSetting): continue # Label label = gtk.Label(element.get_shortname() + ":") label.set_alignment(0.0, 0.5) label.show() table.attach(label, 0, 1, row, row + 1, xoptions=gtk.FILL, yoptions=0, xpadding=6, ypadding=3) if isinstance(element.value, list) and \ isinstance(element.value[0], settings.RadioSettingValueInteger): box = gtk.HBox(True) else: box = gtk.VBox(True) # Widget container box.show() table.attach(box, 1, 2, row, row + 1, xoptions=gtk.FILL, yoptions=0, xpadding=12, ypadding=3) for i in list(element.keys()): value = element[i] if isinstance(value, settings.RadioSettingValueInteger): widget = gtk.SpinButton() adj = widget.get_adjustment() adj.configure(value.get_value(), value.get_min(), value.get_max(), value.get_step(), 1, 0) widget.connect("value-changed", self._save_setting, value) elif isinstance(value, settings.RadioSettingValueFloat): widget = gtk.Entry() widget.set_width_chars(16) widget.set_text(value.format()) widget.connect("focus-out-event", lambda w, e, v: self._save_setting(w, v), value) elif isinstance(value, settings.RadioSettingValueBoolean): widget = gtk.CheckButton(_("Enabled")) widget.set_active(value.get_value()) widget.connect("toggled", self._save_setting, value) elif isinstance(value, settings.RadioSettingValueList): choice = miscwidgets.make_choice([], editable=False) model = choice.get_model() model.clear() for option in value.get_options(): choice.append_text(option) choice.value = value.get_value() widget = choice.widget choice.connect("changed", self._save_setting, value) elif isinstance(value, settings.RadioSettingValueString): widget = gtk.Entry() widget.set_width_chars(32) widget.set_text(str(value).rstrip()) widget.connect("focus-out-event", lambda w, e, v: self._save_setting(w, v), value) else: LOG.error("Unsupported widget type: %s" % value.__class__) widget.set_sensitive(value.get_mutable()) label.set_mnemonic_widget(widget) widget.get_accessible().set_name(element.get_shortname()) widget.show() box.pack_start(widget, 1, 1, 1) row += 1 return tab
def setup(self, progressbar): # Get Datadirs from unitsync datadir = self.ini.get(self.profile, 'SPRING_DATADIR', None) if datadir != None: os.chdir(datadir) unitsync.Init(True, 1) self.datadirs = [] datadirs = unitsync.GetDataDirectories(False) for i in range(0, len(datadirs)): if os.path.isdir(datadirs[i]) == True: self.datadirs.append(datadirs[i]) # Map Index self.map_index = index_map(self.map_index_file, progressbar) if os.path.isfile(self.map_index_file) == False: self.map_index.create_index() self.map_index.check_if_update_needed() # Mod Index self.mod_index = index_mod(self.mod_index_file, progressbar) if os.path.isfile(self.mod_index_file) == False: self.mod_index.create_index() self.mod_index.check_if_update_needed() self.lobby_table = gtk.Table(rows=2, columns=2, homogeneous=False) self.gui_lobby = gui_lobby(self) self.config = config(self) self.battle = battle(self) # Main Window self.window.set_title("Unity Lobby") self.window.set_resizable(True) self.window.connect("delete-event", gtk.main_quit) self.window.add_events(gtk.gdk.BUTTON_PRESS_MASK) # Vertical Box Part 1/2 vbox = gtk.VBox(False, 0) vbox.show() self.window.add(vbox) # Menu Part 1/2 menu_bar = gtk.MenuBar() menu_bar.show() # Battle Notebook self.battle_notebook = gtk.Notebook() self.battle_notebook.set_tab_pos(gtk.POS_LEFT) self.battle.create(self.battle_notebook) # Options Notebook self.options_notebook = gtk.Notebook() self.options_notebook.set_tab_pos(gtk.POS_LEFT) self.config.create(self.options_notebook) #Vertical Box Part 2/2 vbox.pack_start(menu_bar, False, False, 2) vbox.pack_start(self.battle_notebook, True, True, 2) vbox.pack_start(self.options_notebook, True, True, 2) vbox.pack_start(self.lobby_table, True, True, 2) self.window.show() # Menu Part 2/2 #Menu Items battle_item = gtk.MenuItem("Battle") lobby_item = gtk.MenuItem("Lobby") config_item = gtk.MenuItem("Options") self.start_item = gtk.MenuItem("Start") menu_bar.append(battle_item) menu_bar.append(lobby_item) menu_bar.append(config_item) menu_bar.append(self.start_item) battle_item.show() lobby_item.show() self.start_item.set_right_justified(1) config_item.show() #Menu-Connect battle_item.connect("button_press_event", self.battle_section) config_item.connect("button_press_event", self.config_section) self.start_item.connect("button_press_event", self.battle.script_create) lobby_item.connect("button_press_event", self.lobby_section) # Main Window destory event self.window.connect("delete-event", self.destroy) self.battle_section(None, None)
def __init__(self, widget=None, varlist=None, vallist=None, icon=None, button=None, button2=None, color=HobColors.LIGHT_GRAY): gtk.EventBox.__init__(self) # set color style = self.get_style().copy() style.bg[gtk.STATE_NORMAL] = self.get_colormap().alloc_color( color, False, False) self.set_style(style) self.row = gtk.Table(1, 2, False) self.row.set_border_width(10) self.add(self.row) total_rows = 0 if widget: total_rows = 10 if varlist and vallist: # pack the icon and the text on the left total_rows += len(varlist) self.table = gtk.Table(total_rows, 20, True) self.table.set_row_spacings(6) self.table.set_size_request(100, -1) self.row.attach(self.table, 0, 1, 0, 1, xoptions=gtk.FILL | gtk.EXPAND, yoptions=gtk.FILL) colid = 0 rowid = 0 self.line_widgets = {} if icon: self.table.attach(icon, colid, colid + 2, 0, 1) colid = colid + 2 if widget: self.table.attach(widget, colid, 20, 0, 10) rowid = 10 if varlist and vallist: for row in range(rowid, total_rows): index = row - rowid self.line_widgets[varlist[index]] = self.text2label( varlist[index], vallist[index]) self.table.attach(self.line_widgets[varlist[index]], colid, 20, row, row + 1) # pack the button on the right if button: self.bbox = gtk.VBox() self.bbox.pack_start(button, expand=True, fill=False) if button2: self.bbox.pack_start(button2, expand=True, fill=False) self.bbox.set_size_request(150, -1) self.row.attach(self.bbox, 1, 2, 0, 1, xoptions=gtk.FILL, yoptions=gtk.EXPAND)
def show_login_dialog(self, title, message, username=None, password=None, username_prompt=None, register_callback=None, register_text=None): if username_prompt is None: username_prompt = _('Username') if register_text is None: register_text = _('New user') dialog = gtk.MessageDialog( self.main_window, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_CANCEL) dialog.add_button(_('Login'), gtk.RESPONSE_OK) dialog.set_image( gtk.image_new_from_stock(gtk.STOCK_DIALOG_AUTHENTICATION, gtk.ICON_SIZE_DIALOG)) dialog.set_title(_('Authentication required')) dialog.set_markup('<span weight="bold" size="larger">' + title + '</span>') dialog.format_secondary_markup(message) dialog.set_default_response(gtk.RESPONSE_OK) if register_callback is not None: dialog.add_button(register_text, gtk.RESPONSE_HELP) username_entry = gtk.Entry() password_entry = gtk.Entry() username_entry.connect('activate', lambda w: password_entry.grab_focus()) password_entry.set_visibility(False) password_entry.set_activates_default(True) if username is not None: username_entry.set_text(username) if password is not None: password_entry.set_text(password) table = gtk.Table(2, 2) table.set_row_spacings(6) table.set_col_spacings(6) username_label = gtk.Label() username_label.set_markup('<b>' + username_prompt + ':</b>') username_label.set_alignment(0.0, 0.5) table.attach(username_label, 0, 1, 0, 1, gtk.FILL, 0) table.attach(username_entry, 1, 2, 0, 1) password_label = gtk.Label() password_label.set_markup('<b>' + _('Password') + ':</b>') password_label.set_alignment(0.0, 0.5) table.attach(password_label, 0, 1, 1, 2, gtk.FILL, 0) table.attach(password_entry, 1, 2, 1, 2) dialog.vbox.pack_end(table, True, True, 0) dialog.show_all() response = dialog.run() while response == gtk.RESPONSE_HELP: register_callback() response = dialog.run() password_entry.set_visibility(True) username = username_entry.get_text() password = password_entry.get_text() success = (response == gtk.RESPONSE_OK) dialog.destroy() return (success, (username, password))
def creds_dialog_main(creds): """ Libvirt openAuth callback for username/password credentials """ import gtk dialog = gtk.Dialog( "Authentication required", None, 0, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) label = [] entry = [] box = gtk.Table(2, len(creds)) box.set_border_width(6) box.set_row_spacings(6) box.set_col_spacings(12) def _on_ent_activate(ent): idx = entry.index(ent) if idx < len(entry) - 1: entry[idx + 1].grab_focus() else: dialog.response(gtk.RESPONSE_OK) row = 0 for cred in creds: if (cred[0] == libvirt.VIR_CRED_AUTHNAME or cred[0] == libvirt.VIR_CRED_PASSPHRASE): prompt = cred[1] if not prompt.endswith(":"): prompt += ":" text_label = gtk.Label(prompt) text_label.set_alignment(0.0, 0.5) label.append(text_label) else: return -1 ent = gtk.Entry() if cred[0] == libvirt.VIR_CRED_PASSPHRASE: ent.set_visibility(False) ent.connect("activate", _on_ent_activate) entry.append(ent) box.attach(label[row], 0, 1, row, row + 1, gtk.FILL, 0, 0, 0) box.attach(entry[row], 1, 2, row, row + 1, gtk.FILL, 0, 0, 0) row = row + 1 vbox = dialog.get_child() vbox.add(box) dialog.show_all() res = dialog.run() dialog.hide() if res == gtk.RESPONSE_OK: row = 0 for cred in creds: cred[4] = entry[row].get_text() row = row + 1 ret = 0 else: ret = -1 dialog.destroy() return ret
def __init__(self, title, parent, flag, settings): gtk.Dialog.__init__(self, title, parent, flag) s = settings self.s = s t = gtk.Table(rows=3, columns=3) t.set_col_spacings(10) t.set_row_spacings(10) l = gtk.Label("PDF Viewer:") l.set_alignment(xalign=1.0, yalign=0.5) t.attach(l, 0, 1, 0, 1) l.show() l = gtk.Entry() l.set_width_chars(40) l.set_text(s.vars["pdfviewer"]) l.set_alignment(xalign=0.0) t.attach(l, 1, 2, 0, 1) l.show() self.pdf_viewer = l l = gtk.Label("PDF Location:") l.set_alignment(xalign=1.0, yalign=0.5) t.attach(l, 0, 1, 1, 2) l.show() l = gtk.Entry() l.set_width_chars(40) l.set_text(s.vars["pdflocation"]) l.set_alignment(xalign=0.0) t.attach(l, 1, 2, 1, 2) l.show() self.pdf_location = l b = gtk.Button("Choose") b.show() b.connect("clicked", self.choose_pdf_location, None) t.attach(b, 2, 3, 1, 2) # ---- l = gtk.Label("Preview converter:") l.set_alignment(xalign=1.0, yalign=0.5) t.attach(l, 0, 1, 2, 3) l.show() l = gtk.Entry() l.set_width_chars(40) l.set_text(s.vars["pdfconvert"]) l.set_alignment(xalign=0.0) t.attach(l, 1, 2, 2, 3) l.show() self.pdf_convert = l b = gtk.Button("Choose") b.show() b.connect("clicked", self.choose_pdf_convert, None) t.attach(b, 2, 3, 2, 3) # ---- self.vbox.pack_start(t) t.show() self.add_button("Ok", 1) self.add_button("Cancel", 2)
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 # pdb.gimp_edit_paste_as_new() is deprecated, # but pdb.gimp_edit_paste_as_new_image() isn't available until 2.9. # isn't available in GIMP 2.8. version = map(int, pdb.gimp_version().split('.')) if version[0] > 2 or version[0] == 2 and version[1] > 8: newimg = pdb.gimp_edit_paste_as_new_image() else: 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) # Copy EXIF information from the old image to the new one. # This uses an API that's new in GIMP 2.9, so it won't happen # in GIMP 2.8 and earlier. if "gimp_image_get_metadata" in dir(pdb): metadata = pdb.gimp_image_get_metadata(img) pdb.gimp_image_set_metadata(newimg, metadata) else: print "Not copying EXIF metadata -- don't have the API." # 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)
class ApplicationDemo(hildon.App): def __init__(self, parent=None): hildon.App.__init__(self) self.set_title(self.__class__.__name__) self.connect('destroy', lambda *w: gtk.main_quit()) self.view = hildon.AppView("") self.set_appview(self.view) register_stock_icons() merge = gtk.UIManager() self.set_data("ui-manager", merge) merge.insert_action_group(self.__create_action_group(), 0) self.add_accel_group(merge.get_accel_group()) try: mergeid = merge.add_ui_from_string(ui_info) except gobject.GError, msg: print "building menus failed: %s" % msg bar = self.view.get_menu() for menu in merge.get_widget("/MenuBar").get_children(): print menu bar.add(menu) bar.show() table = gtk.Table(1, 4, False) self.view.add(table) #table.attach(bar, # # X direction # # Y direction # 0, 1, 0, 1, # gtk.EXPAND | gtk.FILL, 0, # 0, 0); bar = merge.get_widget("/ToolBar") bar.set_tooltips(True) bar.show() self.view.set_toolbar(bar) #table.attach(bar, # # X direction # # Y direction # 0, 1, 1, 2, # gtk.EXPAND | gtk.FILL, 0, # 0, 0) # Create document sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) sw.set_shadow_type(gtk.SHADOW_IN) table.attach( sw, # X direction Y direction 0, 1, 2, 3, gtk.EXPAND | gtk.FILL, gtk.EXPAND | gtk.FILL, 0, 0) contents = gtk.TextView() contents.grab_focus() sw.add(contents) # Create statusbar self.statusbar = gtk.Statusbar() table.attach( self.statusbar, # X direction Y direction 0, 1, 3, 4, gtk.EXPAND | gtk.FILL, 0, 0, 0) # Show text widget info in the statusbar buffer = contents.get_buffer() buffer.connect("changed", self.update_statusbar) mark_set_callback = ( lambda buffer, new_location, mark: self.update_statusbar(buffer)) # cursor moved buffer.connect("mark_set", mark_set_callback) self.connect("window_state_event", self.update_resize_grip) self.update_statusbar(buffer) self.show_all()
def __init__(self, app): gtk.VBox.__init__(self) self.app = app self.caption_label = gtk.Label(self.caption) spacer = gtk.VBox() self.add(spacer) self.set_border_width(15) self.set_size_request(550, 300) tab = gtk.Table(6, 2, False) tab.set_row_spacings(10) tab.set_col_spacings(10) spacer.add(tab) #--------------------------- label = gtk.Label('External image viewer:') label.set_alignment(0, 0.5) tab.attach(label, 0, 1, 0, 1, gtk.FILL, gtk.SHRINK) self.entry1 = gtk.Entry() self.entry1.set_text(config.ext_image_view) tab.attach(self.entry1, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.SHRINK) #--------------------------- label = gtk.Label('External text editor:') label.set_alignment(0, 0.5) tab.attach(label, 0, 1, 1, 2, gtk.FILL, gtk.SHRINK) self.entry2 = gtk.Entry() self.entry2.set_text(config.ext_text_view) tab.attach(self.entry2, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.SHRINK) #--------------------------- label = gtk.Label('External document viewer:') label.set_alignment(0, 0.5) tab.attach(label, 0, 1, 2, 3, gtk.FILL, gtk.SHRINK) self.entry3 = gtk.Entry() self.entry3.set_text(config.ext_doc_view) tab.attach(self.entry3, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.SHRINK) #--------------------------- label = gtk.Label('External HTML viewer:') label.set_alignment(0, 0.5) tab.attach(label, 0, 1, 3, 4, gtk.FILL, gtk.SHRINK) self.entry4 = gtk.Entry() self.entry4.set_text(config.ext_html_view) tab.attach(self.entry4, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.SHRINK) #--------------------------- label = gtk.Label('External binary editor:') label.set_alignment(0, 0.5) tab.attach(label, 0, 1, 4, 5, gtk.FILL, gtk.SHRINK) self.entry5 = gtk.Entry() self.entry5.set_text(config.ext_binary_view) tab.attach(self.entry5, 1, 2, 4, 5, gtk.EXPAND | gtk.FILL, gtk.SHRINK) #--------------------------- label = gtk.Label('External compare tool:') label.set_alignment(0, 0.5) tab.attach(label, 0, 1, 5, 6, gtk.FILL, gtk.SHRINK) self.entry6 = gtk.Entry() self.entry6.set_text(config.ext_compare_view) tab.attach(self.entry6, 1, 2, 5, 6, gtk.EXPAND | gtk.FILL, gtk.SHRINK) self.show_all()
def __init__(self, fullscreen=False, is_slideshow=slideshow, show_library=False, manga_mode=False, double_page=False, zoom_mode=None, open_path=None, open_page=1): super(MainWindow, self).__init__(gtk.WINDOW_TOPLEVEL) # ---------------------------------------------------------------- # Attributes # ---------------------------------------------------------------- # Used to detect window fullscreen state transitions. self.was_fullscreen = False self.is_manga_mode = False self.previous_size = (None, None) self.was_out_of_focus = False #: Used to remember if changing to fullscreen enabled 'Hide all' self.hide_all_forced = False # Remember last scroll destination. self._last_scroll_destination = constants.SCROLL_TO_START self.layout = _dummy_layout() self._spacing = 2 self._waiting_for_redraw = False self._image_box = gtk.HBox(False, 2) # XXX transitional(kept for osd.py) self._main_layout = gtk.Layout() self._event_handler = event.EventHandler(self) self._vadjust = self._main_layout.get_vadjustment() self._hadjust = self._main_layout.get_hadjustment() self._scroll = (gtk.HScrollbar(self._hadjust), gtk.VScrollbar(self._vadjust)) self.filehandler = file_handler.FileHandler(self) self.filehandler.file_closed += self._on_file_closed self.filehandler.file_opened += self._on_file_opened self.imagehandler = image_handler.ImageHandler(self) self.imagehandler.page_available += self._page_available self.thumbnailsidebar = thumbbar.ThumbnailSidebar(self) self.statusbar = status.Statusbar() self.clipboard = clipboard.Clipboard(self) self.slideshow = slideshow.Slideshow(self) self.cursor_handler = cursor_handler.CursorHandler(self) self.enhancer = enhance_backend.ImageEnhancer(self) self.lens = lens.MagnifyingLens(self) self.osd = osd.OnScreenDisplay(self) self.zoom = zoom.ZoomModel() self.uimanager = ui.MainUI(self) self.menubar = self.uimanager.get_widget('/Menu') self.toolbar = self.uimanager.get_widget('/Tool') self.popup = self.uimanager.get_widget('/Popup') self.actiongroup = self.uimanager.get_action_groups()[0] self.images = [gtk.Image(), gtk.Image()] # XXX limited to at most 2 pages # ---------------------------------------------------------------- # Setup # ---------------------------------------------------------------- self.set_title(constants.APPNAME) self.set_size_request(300, 300) # Avoid making the window *too* small self.restore_window_geometry() # Hook up keyboard shortcuts self._event_handler.register_key_events() # This is a hack to get the focus away from the toolbar so that # we don't activate it with space or some other key (alternative?) self.toolbar.set_focus_child( self.uimanager.get_widget('/Tool/expander')) self.toolbar.set_style(gtk.TOOLBAR_ICONS) self.toolbar.set_icon_size(gtk.ICON_SIZE_LARGE_TOOLBAR) for img in self.images: self._main_layout.put(img, 0, 0) self.set_bg_colour(prefs['bg colour']) self._vadjust.step_increment = 15 self._vadjust.page_increment = 1 self._hadjust.step_increment = 15 self._hadjust.page_increment = 1 table = gtk.Table(2, 2, False) table.attach(self.thumbnailsidebar, 0, 1, 2, 5, gtk.FILL, gtk.FILL | gtk.EXPAND, 0, 0) table.attach(self._main_layout, 1, 2, 2, 3, gtk.FILL | gtk.EXPAND, gtk.FILL | gtk.EXPAND, 0, 0) table.attach(self._scroll[constants.HEIGHT_AXIS], 2, 3, 2, 3, gtk.FILL | gtk.SHRINK, gtk.FILL | gtk.SHRINK, 0, 0) table.attach(self._scroll[constants.WIDTH_AXIS], 1, 2, 4, 5, gtk.FILL | gtk.SHRINK, gtk.FILL, 0, 0) table.attach(self.menubar, 0, 3, 0, 1, gtk.FILL | gtk.SHRINK, gtk.FILL, 0, 0) table.attach(self.toolbar, 0, 3, 1, 2, gtk.FILL | gtk.SHRINK, gtk.FILL, 0, 0) table.attach(self.statusbar, 0, 3, 5, 6, gtk.FILL | gtk.SHRINK, gtk.FILL, 0, 0) if prefs['default double page'] or double_page: self.actiongroup.get_action('double_page').activate() if prefs['default manga mode'] or manga_mode: self.actiongroup.get_action('manga_mode').activate() # Determine zoom mode. If zoom_mode is passed, it overrides # the zoom mode preference. zoom_actions = { constants.ZOOM_MODE_BEST: 'best_fit_mode', constants.ZOOM_MODE_WIDTH: 'fit_width_mode', constants.ZOOM_MODE_HEIGHT: 'fit_height_mode', constants.ZOOM_MODE_SIZE: 'fit_size_mode', constants.ZOOM_MODE_MANUAL: 'fit_manual_mode' } if zoom_mode is not None: zoom_action = zoom_actions[zoom_mode] else: zoom_action = zoom_actions[prefs['zoom mode']] if zoom_action == 'fit_manual_mode': # This little ugly hack is to get the activate call on # 'fit_manual_mode' to actually create an event (and callback). # Since manual mode is the default selected radio button action # it won't send an event if we activate it when it is already # the selected one. self.actiongroup.get_action('best_fit_mode').activate() self.actiongroup.get_action(zoom_action).activate() if prefs['stretch']: self.actiongroup.get_action('stretch').activate() if prefs['invert smart scroll']: self.actiongroup.get_action('invert_scroll').activate() if prefs['keep transformation']: prefs['keep transformation'] = False self.actiongroup.get_action('keep_transformation').activate() else: prefs['rotation'] = 0 prefs['vertical flip'] = False prefs['horizontal flip'] = False # List of "toggles" than can be shown/hidden by the user. self._toggle_list = ( # Preference Action Widget(s) ('show menubar', 'menubar', (self.menubar, )), ('show scrollbar', 'scrollbar', self._scroll), ('show statusbar', 'statusbar', (self.statusbar, )), ('show thumbnails', 'thumbnails', (self.thumbnailsidebar, )), ('show toolbar', 'toolbar', (self.toolbar, )), ) # Each "toggle" widget "eats" part of the main layout visible area. self._toggle_axis = { self.thumbnailsidebar: constants.WIDTH_AXIS, self._scroll[constants.HEIGHT_AXIS]: constants.WIDTH_AXIS, self._scroll[constants.WIDTH_AXIS]: constants.HEIGHT_AXIS, self.statusbar: constants.HEIGHT_AXIS, self.toolbar: constants.HEIGHT_AXIS, self.menubar: constants.HEIGHT_AXIS, } # Start with all "toggle" widgets hidden to avoid ugly transitions. for preference, action, widget_list in self._toggle_list: for widget in widget_list: widget.hide() toggleaction = self.actiongroup.get_action('hide_all') toggleaction.set_active(prefs['hide all']) # Sync each "toggle" widget active state with its preference. for preference, action, widget_list in self._toggle_list: self.actiongroup.get_action(action).set_active(prefs[preference]) self.actiongroup.get_action('menu_autorotate_width').set_sensitive( False) self.actiongroup.get_action('menu_autorotate_height').set_sensitive( False) self.add(table) table.show() self._main_layout.show() self._main_layout.set_events(gtk.gdk.BUTTON1_MOTION_MASK | gtk.gdk.BUTTON2_MOTION_MASK | gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.POINTER_MOTION_MASK) self._main_layout.drag_dest_set( gtk.DEST_DEFAULT_ALL, [('text/uri-list', 0, 0)], gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE) self.connect('focus-in-event', self.gained_focus) self.connect('focus-out-event', self.lost_focus) self.connect('delete_event', self.close_program) self.connect('key_press_event', self._event_handler.key_press_event) self.connect('key_release_event', self._event_handler.key_release_event) self.connect('configure_event', self._event_handler.resize_event) self.connect('window-state-event', self._event_handler.window_state_event) self._main_layout.connect('button_release_event', self._event_handler.mouse_release_event) self._main_layout.connect('scroll_event', self._event_handler.scroll_wheel_event) self._main_layout.connect('button_press_event', self._event_handler.mouse_press_event) self._main_layout.connect('motion_notify_event', self._event_handler.mouse_move_event) self._main_layout.connect('drag_data_received', self._event_handler.drag_n_drop_event) self.uimanager.set_sensitivities() self.show() if prefs['default fullscreen'] or fullscreen: toggleaction = self.actiongroup.get_action('fullscreen') toggleaction.set_active(True) if prefs['previous quit was quit and save']: fileinfo = self.filehandler.read_fileinfo_file() if fileinfo != None: open_path = fileinfo[0] open_page = fileinfo[1] + 1 prefs['previous quit was quit and save'] = False if open_path is not None: self.filehandler.open_file(open_path) if is_slideshow: self.actiongroup.get_action('slideshow').activate() if show_library: self.actiongroup.get_action('library').activate() self.cursor_handler.auto_hide_on() # Make sure we receive *all* mouse motion events, # even if a modal dialog is being shown. def _on_event(event): if gtk.gdk.MOTION_NOTIFY == event.type: self.cursor_handler.refresh() gtk.main_do_event(event) gtk.gdk.event_handler_set(_on_event)
def on_tags_edit(self, files, temp_mpdpaths, music_dir): """Display the editing dialog""" # Try loading module global tagpy if tagpy is None: try: import tagpy except ImportError: ui.show_msg(self.window, _("Taglib and/or tagpy not found, tag editing support disabled."), _("Edit Tags"), 'editTagsError', gtk.BUTTONS_CLOSE, response_cb=ui.dialog_destroy) ui.change_cursor(None) return # Set default tag encoding to utf8.. fixes some reported bugs. import tagpy.id3v2 as id3v2 id3v2.FrameFactory.instance().setDefaultTextEncoding(tagpy.StringType.UTF8) # Make sure tagpy is at least 0.91 if hasattr(tagpy.Tag.title, '__call__'): ui.show_msg(self.window, _("Tagpy version < 0.91. Please upgrade to a newer version, tag editing support disabled."), _("Edit Tags"), 'editTagsError', gtk.BUTTONS_CLOSE, response_cb=ui.dialog_destroy) ui.change_cursor(None) return if not os.path.isdir(misc.file_from_utf8(music_dir)): ui.show_msg(self.window, _("The path %s does not exist. Please specify a valid music directory in preferences.") % music_dir, _("Edit Tags"), 'editTagsError', gtk.BUTTONS_CLOSE, response_cb=ui.dialog_destroy) ui.change_cursor(None) return # XXX file list was created here if len(files) == 0: ui.change_cursor(None) return # Initialize: self.tagnum = -1 tags = [{'title':'', 'artist':'', 'album':'', 'year':'', 'track':'', 'genre':'', 'comment':'', 'title-changed':False, 'artist-changed':False, 'album-changed':False, 'year-changed':False, 'track-changed':False, 'genre-changed':False, 'comment-changed':False, 'fullpath':misc.file_from_utf8(filename), 'mpdpath':path} for filename, path in zip(files, temp_mpdpaths)] if not os.path.exists(tags[0]['fullpath']): ui.change_cursor(None) ui.show_msg(self.window, _("File '%s' not found. Please specify a valid music directory in preferences.") % tags[0]['fullpath'], _("Edit Tags"), 'editTagsError', gtk.BUTTONS_CLOSE, response_cb=ui.dialog_destroy) return if not self.tags_next_tag(tags): ui.change_cursor(None) ui.show_msg(self.window, _("No music files with editable tags found."), _("Edit Tags"), 'editTagsError', gtk.BUTTONS_CLOSE, response_cb=ui.dialog_destroy) return editwindow = ui.dialog(parent=self.window, flags=gtk.DIALOG_MODAL, role='editTags', resizable=False, separator=False) editwindow.set_size_request(375, -1) table = gtk.Table(9, 2, False) table.set_row_spacings(2) self.filelabel = ui.label(select=True, wrap=True) filehbox = gtk.HBox() sonataicon = ui.image(stock='sonata', stocksize=gtk.ICON_SIZE_DND, x=1) expandbutton = ui.button(" ") self.set_expandbutton_state(expandbutton) expandvbox = gtk.VBox() expandvbox.pack_start(ui.label(), True, True) expandvbox.pack_start(expandbutton, False, False) expandvbox.pack_start(ui.label(), True, True) expandbutton.connect('clicked', self.toggle_path) blanklabel = ui.label(w=5, h=12) filehbox.pack_start(sonataicon, False, False, 2) filehbox.pack_start(self.filelabel, True, True, 2) filehbox.pack_start(expandvbox, False, False, 2) filehbox.pack_start(blanklabel, False, False, 2) titlelabel, titleentry, titlebutton, titlehbox = self._create_label_entry_button_hbox(_("Title:")) artistlabel, artistentry, artistbutton, artisthbox = self._create_label_entry_button_hbox(_("Artist:")) albumlabel, albumentry, albumbutton, albumhbox = self._create_label_entry_button_hbox(_("Album:")) yearlabel, yearentry, yearbutton, yearhbox = self._create_label_entry_button_hbox(_("Year:")) yearentry.set_size_request(50,-1) tracklabel, trackentry, trackbutton, trackhbox = self._create_label_entry_button_hbox(" " + _("Track:"), True) trackentry.set_size_request(50,-1) yearandtrackhbox = gtk.HBox() yearandtrackhbox.pack_start(yearhbox, True, True, 0) yearandtrackhbox.pack_start(trackhbox, True, True, 0) yearentry.connect("insert_text", self.tags_win_entry_constraint, True) trackentry.connect("insert_text", self.tags_win_entry_constraint, False) genrelabel = ui.label(text=_("Genre:"), x=1) genrecombo = ui.comboentry(items=self.tags_win_genres(), wrap=2) genreentry = genrecombo.get_child() genrehbox = gtk.HBox() genrebutton = ui.button() genrebuttonvbox = self.tags_win_create_apply_all_button(genrebutton, genreentry) genrehbox.pack_start(genrelabel, False, False, 2) genrehbox.pack_start(genrecombo, True, True, 2) genrehbox.pack_start(genrebuttonvbox, False, False, 2) commentlabel, commententry, commentbutton, commenthbox = self._create_label_entry_button_hbox(_("Comment:")) ui.set_widths_equal([titlelabel, artistlabel, albumlabel, yearlabel, genrelabel, commentlabel, sonataicon]) genrecombo.set_size_request(-1, titleentry.size_request()[1]) tablewidgets = [ui.label(), filehbox, ui.label(), titlehbox, artisthbox, albumhbox, yearandtrackhbox, genrehbox, commenthbox, ui.label()] for i, widget in enumerate(tablewidgets): table.attach(widget, 1, 2, i+1, i+2, gtk.FILL|gtk.EXPAND, gtk.FILL|gtk.EXPAND, 2, 0) editwindow.vbox.pack_start(table) saveall_button = None if len(files) > 1: # Only show save all button if more than one song being edited. saveall_button = ui.button(text=_("Save _All")) editwindow.action_area.pack_start(saveall_button) editwindow.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT) editwindow.add_button(gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT) editwindow.connect('delete_event', self.tags_win_hide, tags) entries = [titleentry, artistentry, albumentry, yearentry, trackentry, genreentry, commententry] buttons = [titlebutton, artistbutton, albumbutton, yearbutton, trackbutton, genrebutton, commentbutton] entries_names = ["title", "artist", "album", "year", "track", "genre", "comment"] editwindow.connect('response', self.tags_win_response, tags, entries, entries_names) if saveall_button: saveall_button.connect('clicked', self.tags_win_save_all, editwindow, tags, entries, entries_names) for button, name, entry in zip(buttons, entries_names, entries): entry.connect('changed', self.tags_win_entry_changed) button.connect('clicked', self.tags_win_apply_all, name, tags, entry) self.tags_win_update(editwindow, tags, entries, entries_names) ui.change_cursor(None) self.filelabel.set_size_request(editwindow.size_request()[0] - titlelabel.size_request()[0] - 70, -1) editwindow.show_all()
def __init__(self): if len(sys.argv) != 2: #TODO: move to ... or remove raise SystemExit("Usage: python main.py <image file>") # Create a new window self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("delete-event", self.delete_event) self.window.connect("destroy", self.destroy) # Sets the border width of the window. self.window.set_title('BNF Viewer') self.window.set_border_width(10) #self.window.set_size_request(200,100) self.window.set_default_size(640, 400) self.vbox = gtk.VBox() #False, 0 #self.box1.pack_start(self.button1, True, True, 0) self.toolbar = gtk.Toolbar() self.toolbar.set_style(gtk.TOOLBAR_TEXT) self.toolbar.append_item('Rules', 'Show Rules', 'private text', None, self.on_button_clicked) self.toolbar.append_space() self.vbox.add(self.toolbar) self.table = gtk.Table(2, 2, False) self.clutter_widget = cluttergtk.Embed() self.clutter_widget.set_size_request(200, 200) self.table.attach(self.clutter_widget, 0, 1, 0, 1, gtk.EXPAND | gtk.FILL, gtk.EXPAND | gtk.FILL, 0, 0) self.vbox.add( self.table) # pack_end(self.clutter_widget, True, True, 0) self.stage_color = clutter.Color(0, 0, 0, 255) # Black self.actor_color = clutter.Color(255, 255, 255, 153) self.stage = self.clutter_widget.get_stage() self.stage.set_color(self.stage_color) self.stage.set_size(640, 480) # Create a viewport actor to be able to scroll actor. By passing NULL it # will create new GtkAdjustments self.viewport = cluttergtk.Viewport() self.stage.add(self.viewport) self.viewport.set_size(640, 480) # Load image from first command line argument and add it to viewport self.texture = clutter.Texture(sys.argv[1]) self.viewport_group = clutter.Group() self.viewport_group.add(self.texture) self.viewport.add(self.viewport_group) self.texture.set_position(0, 0) # Create scrollbars and connect them to viewport self.h_adjustment, self.v_adjustment = self.viewport.get_adjustments() self.scrollbar = gtk.VScrollbar(self.v_adjustment) self.table.attach(self.scrollbar, 1, 2, 0, 1, 0, gtk.EXPAND | gtk.FILL, 0, 0) self.scrollbar = gtk.HScrollbar(self.h_adjustment) self.table.attach(self.scrollbar, 0, 1, 1, 2, gtk.EXPAND | gtk.FILL, 0, 0, 0) # Connect a signal handler to handle mouse clicks and key presses on the stage self.stage.connect("button-press-event", self.on_stage_button_pressed) # Add a group to the stage self.group = clutter.Group() self.group.set_position(40, 40) self.viewport_group.add(self.group) # Add a rectangle to the stage self.rect = clutter.Rectangle(self.actor_color) self.rect.set_size(100, 400) self.rect.set_position(20, 20) self.group.add(self.rect) #self.rect.show() # Add a label to the stage self.label = clutter.Text("Sans 12", "Some Text", self.actor_color) self.label.set_size(500, 500) self.label.set_position(20, 15) self.group.add(self.label) #label.show() # This packs the button into the window (which is a container). self.window.add(self.vbox) # Show the window and the button self.window.show_all()
def __init__(self, parent): gtk.Dialog.__init__(self, "Please select an element", parent, \ gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,\ (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) self.ElementList = [] ElementTable = gtk.Table(10, 18, True) # List row consists of Z, name, row, column self.ElementList.append([1, "H", 1, 1]) self.ElementList.append([2, "He", 1, 18]) self.ElementList.append([3, "Li", 2, 1]) self.ElementList.append([4, "Be", 2, 2]) self.ElementList.append([5, "B", 2, 13]) self.ElementList.append([6, "C", 2, 14]) self.ElementList.append([7, "N", 2, 15]) self.ElementList.append([8, "O", 2, 16]) self.ElementList.append([9, "F", 2, 17]) self.ElementList.append([10, "Ne", 2, 18]) self.ElementList.append([11, "Na", 3, 1]) self.ElementList.append([12, "Mg", 3, 2]) self.ElementList.append([13, "Al", 3, 13]) self.ElementList.append([14, "Si", 3, 14]) self.ElementList.append([15, "P", 3, 15]) self.ElementList.append([16, "S", 3, 16]) self.ElementList.append([17, "Cl", 3, 17]) self.ElementList.append([18, "Ar", 3, 18]) self.ElementList.append([19, "K", 4, 1]) self.ElementList.append([20, "Ca", 4, 2]) self.ElementList.append([21, "Sc", 4, 3]) self.ElementList.append([22, "Ti", 4, 4]) self.ElementList.append([23, "V", 4, 5]) self.ElementList.append([24, "Cr", 4, 6]) self.ElementList.append([25, "Mn", 4, 7]) self.ElementList.append([26, "Fe", 4, 8]) self.ElementList.append([27, "Co", 4, 9]) self.ElementList.append([28, "Ni", 4, 10]) self.ElementList.append([29, "Cu", 4, 11]) self.ElementList.append([30, "Zn", 4, 12]) self.ElementList.append([31, "Ga", 4, 13]) self.ElementList.append([32, "Ge", 4, 14]) self.ElementList.append([33, "As", 4, 15]) self.ElementList.append([34, "Se", 4, 16]) self.ElementList.append([35, "Br", 4, 17]) self.ElementList.append([36, "Kr", 4, 18]) self.ElementList.append([37, "Rb", 5, 1]) self.ElementList.append([38, "Sr", 5, 2]) self.ElementList.append([39, "Y", 5, 3]) self.ElementList.append([40, "Zr", 5, 4]) self.ElementList.append([41, "Nb", 5, 5]) self.ElementList.append([42, "Mo", 5, 6]) self.ElementList.append([43, "Tc", 5, 7]) self.ElementList.append([44, "Ru", 5, 8]) self.ElementList.append([45, "Rh", 5, 9]) self.ElementList.append([46, "Pd", 5, 10]) self.ElementList.append([47, "Ag", 5, 11]) self.ElementList.append([48, "Cd", 5, 12]) self.ElementList.append([49, "In", 5, 13]) self.ElementList.append([50, "Sn", 5, 14]) self.ElementList.append([51, "Sb", 5, 15]) self.ElementList.append([52, "Te", 5, 16]) self.ElementList.append([53, "I", 5, 17]) self.ElementList.append([54, "Xe", 5, 18]) self.ElementList.append([55, "Cs", 6, 1]) self.ElementList.append([56, "Ba", 6, 2]) self.ElementList.append([71, "Lu", 6, 3]) self.ElementList.append([72, "Hf", 6, 4]) self.ElementList.append([73, "Ta", 6, 5]) self.ElementList.append([74, "Re", 6, 6]) self.ElementList.append([75, "Ta", 6, 7]) self.ElementList.append([76, "Os", 6, 8]) self.ElementList.append([77, "Ir", 6, 9]) self.ElementList.append([78, "Pt", 6, 10]) self.ElementList.append([79, "Au", 6, 11]) self.ElementList.append([80, "Hg", 6, 12]) self.ElementList.append([81, "Tl", 6, 13]) self.ElementList.append([82, "Pb", 6, 14]) self.ElementList.append([83, "Bi", 6, 15]) self.ElementList.append([84, "Po", 6, 16]) self.ElementList.append([85, "At", 6, 17]) self.ElementList.append([86, "Rn", 6, 18]) self.ElementList.append([87, "Fr", 7, 1]) self.ElementList.append([88, "Ra", 7, 2]) self.ElementList.append([103, "Lr", 7, 3]) self.ElementList.append([104, "Rf", 7, 4]) self.ElementList.append([105, "Db", 7, 5]) self.ElementList.append([106, "Sg", 7, 6]) self.ElementList.append([107, "Bh", 7, 7]) self.ElementList.append([108, "Hs", 7, 8]) self.ElementList.append([109, "Mt", 7, 9]) self.ElementList.append([110, "Ds", 7, 10]) self.ElementList.append([111, "Rg", 7, 11]) self.ElementList.append([112, "Uub", 7, 12]) self.ElementList.append([113, "Uut", 7, 13]) self.ElementList.append([114, "Uuq", 7, 14]) self.ElementList.append([115, "UUp", 7, 15]) self.ElementList.append([116, "UUh", 7, 16]) self.ElementList.append([117, "UUs", 7, 17]) self.ElementList.append([118, "UUo", 7, 18]) self.ElementList.append([57, "La", 9, 3]) self.ElementList.append([58, "Ce", 9, 4]) self.ElementList.append([59, "Pr", 9, 5]) self.ElementList.append([60, "Nd", 9, 6]) self.ElementList.append([61, "Pm", 9, 7]) self.ElementList.append([62, "Sm", 9, 8]) self.ElementList.append([63, "Eu", 9, 9]) self.ElementList.append([64, "Gd", 9, 10]) self.ElementList.append([65, "Tb", 9, 11]) self.ElementList.append([66, "Dy", 9, 12]) self.ElementList.append([67, "Ho", 9, 13]) self.ElementList.append([68, "Er", 9, 14]) self.ElementList.append([69, "Tm", 9, 15]) self.ElementList.append([70, "Tb", 9, 16]) self.ElementList.append([89, "Ac", 10, 3]) self.ElementList.append([90, "Th", 10, 4]) self.ElementList.append([91, "Pa", 10, 5]) self.ElementList.append([92, "U", 10, 6]) self.ElementList.append([93, "Np", 10, 7]) self.ElementList.append([94, "Pu", 10, 8]) self.ElementList.append([95, "Am", 10, 9]) self.ElementList.append([96, "Cm", 10, 10]) self.ElementList.append([97, "Bk", 10, 11]) self.ElementList.append([98, "Cf", 10, 12]) self.ElementList.append([99, "Es", 10, 13]) self.ElementList.append([100, "Fm", 10, 14]) self.ElementList.append([101, "Md", 10, 15]) self.ElementList.append([102, "No", 10, 16]) # Create table self.blue = gtk.gdk.Color(45000, 45000, 65535) self.pink = gtk.gdk.Color(65535, 45000, 45000) for elem in self.ElementList: button = gtk.Button(elem[1]) if (elem[0] == 1): button.modify_bg(gtk.STATE_NORMAL, self.pink) self.LastButton = button else: button.modify_bg(gtk.STATE_NORMAL, self.blue) button.modify_bg(gtk.STATE_ACTIVE, self.pink) ElementTable.attach(button, elem[3] - 1, elem[3], elem[2] - 1, elem[2]) button.connect("clicked", self.clicked_callback, elem) self.Z = 1 self.vbox.pack_start(ElementTable, False, False, 10) self.show_all() self.hide()
table.attach(label, x1, x2, y, y + 1, gtk.SHRINK | gtk.FILL) table.attach(text, x3, x4, y, y + 1, gtk.EXPAND | gtk.FILL) return text a = Assistant(complete) a.add_text_page( 'Getting started', 'Welcome to Gramps, the Genealogical Research ' 'and Analysis Management Programming System.\n' 'Several options and information need to be gathered ' 'before Gramps is ready to be used. Any of this ' 'information can be changed in the future in the ' 'Preferences dialog under the Settings menu.') box = gtk.VBox() box.set_spacing(12) table = gtk.Table(8, 4) table.set_row_spacings(6) table.set_col_spacings(6) make_label(table, _('Name:'), 0, 0, 1, 1, 4) make_label(table, _('Address:'), 1, 0, 1, 1, 4) make_label(table, _('City:'), 2, 0, 1, 1, 2) make_label(table, _('State/Province:'), 2, 2, 3, 3, 4) make_label(table, _('Country:'), 3, 0, 1, 1, 2) make_label(table, _('ZIP/Postal code:'), 3, 2, 3, 3, 4) make_label(table, _('Phone:'), 4, 0, 1, 1, 4) make_label(table, _('Email:'), 5, 0, 1, 1, 4) box.add(table) a.add_page('Researcher information', box) a.add_text_page('Conclusion title', 'Very long conclusion text here')
class EdMainWindow(): def __init__(self, fname, parent, names): self.full = False self.fcount = 0 self.statuscount = 0 self.alt = False register_stock_icons() global mained mained = self # Create the toplevel window window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window = window www = gtk.gdk.screen_width() hhh = gtk.gdk.screen_height() if pedconfig.conf.full_screen: window.set_default_size(www, hhh) else: xx = pedconfig.conf.sql.get_int("xx") yy = pedconfig.conf.sql.get_int("yy") ww = pedconfig.conf.sql.get_int("ww") hh = pedconfig.conf.sql.get_int("hh") if ww == 0 or hh == 0: window.set_position(gtk.WIN_POS_CENTER) window.set_default_size(7 * www / 8, 5 * hhh / 8) window.move(www / 32, hhh / 10) else: window.set_default_size(ww, hh) window.move(xx, yy) try: window.set_icon_from_file(get_img_path("pyedit.png")) except: print "Canot load icon." merge = gtk.UIManager() window.set_data("ui-manager", merge) aa = create_action_group(self) merge.insert_action_group(aa, 0) window.add_accel_group(merge.get_accel_group()) try: mergeid = merge.add_ui_from_string(ui_info) except gobject.GError, msg: print "Building menus failed: %s" % msg # Add MRU for cnt in range(6): ss = "/sess_%d" % cnt fname = pedconfig.conf.sql.get(ss) if fname != "": self.add_mru(merge, aa, fname, ss) merge_id = merge.new_merge_id() merge.add_ui(merge_id, "ui/MenuBar/FileMenu/SaveAs", "", None, gtk.UI_MANAGER_SEPARATOR, False) mbar = merge.get_widget("/MenuBar") mbar.show() window.set_events(gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.POINTER_MOTION_HINT_MASK | gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.KEY_PRESS_MASK | gtk.gdk.KEY_RELEASE_MASK | gtk.gdk.FOCUS_CHANGE_MASK) #window.set_events( gtk.gdk.ALL_EVENTS_MASK) global notebook # Create note for the main window, give access to it for all notebook = gtk.Notebook() self.notebook = notebook notebook.popup_enable() notebook.set_scrollable(True) #notebook.add_events(gtk.gdk.FOCUS_CHANGE_MASK) notebook.add_events(gtk.gdk.ALL_EVENTS_MASK) notebook.connect("switch-page", self.note_swpage_cb) notebook.connect("focus-in-event", self.note_focus_in) # Futile attempts #notebook.connect("change-current-page", self.note_page_cb) #notebook.connect("grab-focus", self.note_grab_focus_cb) #notebook.connect("focus", self.note_focus_cb) #notebook.connect("create-window", self.note_create_cb) #notebook.connect("enter-notify-event", self.note_enter_notify) window.connect("window_state_event", self.update_resize_grip) #window.connect("destroy", OnExit) window.connect("unmap", OnExit) window.connect("key-press-event", self.area_key) window.connect("key-release-event", self.area_key) #window.connect("set-focus", self.area_focus) window.connect("focus-in-event", self.area_focus_in) window.connect("focus-out-event", self.area_focus_out) window.connect("window-state-event", self.area_winstate) window.connect("size_allocate", self.area_size) #window.connect("area-focus-event", self.area_focus_in) #window.connect("event", self.area_event) #window.connect("enter-notify-event", self.area_enter) #window.connect("leave-notify-event", self.area_leave) #window.connect("event", self.unmap) table = gtk.Table(2, 4, False) window.add(table) table.attach( mbar, # X direction # # Y direction 0, 1, 0, 1, gtk.EXPAND | gtk.FILL, 0, 0, 0) tbar = merge.get_widget("/ToolBar") tbar.set_tooltips(True) tbar.show() table.attach( tbar, # X direction # # Y direction 0, 1, 1, 2, gtk.EXPAND | gtk.FILL, 0, 0, 0) hpaned = gtk.HPaned() hpaned.set_border_width(5) scroll = gtk.ScrolledWindow() treeview = self.create_tree() treeview.connect("row-activated", self.tree_sel) treeview.connect("cursor-changed", self.tree_sel_row) self.treeview = treeview scroll.add(treeview) frame2 = gtk.Frame() frame2.add(scroll) hpaned.add(frame2) self.hpanepos = pedconfig.conf.sql.get_int("hpaned") if self.hpanepos == 0: self.hpanepos = 200 hpaned.set_position(self.hpanepos) hpaned.pack2(notebook) self.hpaned = hpaned # Create statusbars self.statusbar = gtk.Statusbar() self.statusbar2 = gtk.Statusbar() slab = gtk.Label(" ") hpane2 = gtk.HPaned() hpane2.set_position(self.get_width() - 280) hpane2.pack2(self.statusbar2) self.hpane2 = hpane2 shbox = gtk.HBox() shbox.pack_start(slab, False) shbox.pack_start(self.statusbar) hpane2.pack1(shbox) # Main Pane table.attach( hpaned, # X direction Y direction 0, 1, 2, 3, gtk.EXPAND | gtk.FILL, gtk.EXPAND | gtk.FILL, 0, 0) table.attach( hpane2, # X direction Y direction 0, 1, 3, 4, gtk.EXPAND | gtk.FILL, 0, 0, 0) window.show_all() # ---------------------------------------------------------------- cnt = 0 # Read in buffers for aa in names: aaa = os.path.realpath(aa) #print "loading file: ", aaa vpaned = edPane() ret = vpaned.area.loadfile(aaa) if not ret: self.update_statusbar("Cannot read file '{0:s}'".format(aaa)) continue ret = vpaned.area2.loadfile(aaa) cnt += 1 notebook.append_page(vpaned) vpaned.area.set_tablabel() if cnt == 0: if (pedconfig.conf.verbose): print "Loading session in", os.getcwd() fcnt = pedconfig.conf.sql.get_int("cnt") # Load old session for nnn in range(fcnt): ss = "/sess_%d" % nnn fff = pedconfig.conf.sql.get_str(ss) if (pedconfig.conf.verbose): print "Loading file:", fff vpaned = edPane() ret = vpaned.area.loadfile(fff) if not ret: self.update_statusbar( "Cannot read file '{0:s}'".format(fff)) continue vpaned.area2.loadfile(fff) notebook.append_page(vpaned) vpaned.area.set_tablabel() # Show newly created buffers: window.show_all() # Set last file fff = pedconfig.conf.sql.get_str("curr") #print "curr file", fff cc = notebook.get_n_pages() for mm in range(cc): vcurr = notebook.get_nth_page(mm) if vcurr.area.fname == fff: #print "found buff", fff notebook.set_current_page(mm) self.window.set_focus(vcurr.vbox.area) break # Set the signal handler for 1s tick #signal.signal(signal.SIGALRM, handler_tick) #signal.alarm(1) # We use gobj instead of SIGALRM, so it is more multi platform gobject.timeout_add(1000, handler_tick) self.update_statusbar("Initial")
(FractionWidget, "30M", (gst.FractionRange(gst.Fraction(1, 1), gst.Fraction(30000, 1001)), )), (FractionWidget, gst.Fraction(25000, 1001), ( gst.FractionRange(gst.Fraction(1, 1), gst.Fraction(30000, 1001)), ( "25:1", gst.Fraction(30, 1), "30M", ), )), ) W = gtk.Window() v = gtk.VBox() t = gtk.Table() for y, (klass, default, args) in enumerate(widgets): w = klass(*args) w.setWidgetValue(default) l = gtk.Label(str(w.getWidgetValue())) w.connectValueChanged(valueChanged, w, l) w.show() l.show() t.attach(w, 0, 1, y, y + 1) t.attach(l, 1, 2, y, y + 1) t.show() W.add(t) W.show() gtk.main()