def load_from(self, button): dialog = gtk.FileSelection('Choose filename for marker info') dialog.set_filename(shared.get_last_dir()) dialog.show() response = dialog.run() if response == gtk.RESPONSE_OK: fname = dialog.get_filename() dialog.destroy() try: EventHandler().load_markers_from(fname) except IOError: error_msg('Could not load markers from %s' % fname, ) else: shared.set_file_selection(fname) self.fileName = fname else: dialog.destroy()
def Execute(self): """ This function gets the blocks chain and saves as a .png file by print screen. """ if gtk.gtk_version < (2, 4, 0): t_oFilesel = gtk.FileSelection( 'Exportar cadeia para imagem tipo .png') else: t_oFilesel = gtk.FileChooserDialog( title='Exportar cadeia para imagem tipo .png', action=gtk.FILE_CHOOSER_ACTION_SAVE, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK)) #Scotti if os.name == 'posix': t_oFilesel.set_current_folder(os.path.expanduser("~")) #Scotti t_oFilter = gtk.FileFilter() t_oFilter.set_name(_("PNG Image (*.png)")) t_oFilter.add_pattern("*.png") t_oFilesel.add_filter(t_oFilter) t_oFilter = gtk.FileFilter() t_oFilter.set_name(_("Todos os arquivos")) t_oFilter.add_pattern("*") t_oFilesel.add_filter(t_oFilter) t_oResponse = t_oFilesel.run() t_sFilename = t_oFilesel.get_filename() t_oFilesel.destroy() print t_sFilename
def open_tileset(self, widget): if self.modified: msg = "Save current file?" dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, msg) dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) result = dialog.run() dialog.destroy() if result == gtk.RESPONSE_YES: if self.filename: # do same as if there's no filename for now if not self.save_tileset(None): return False elif result == gtk.RESPONSE_CANCEL: return False self.file_win = gtk.FileSelection("Open") self.file_win.ok_button.connect("clicked", self.do_open) self.file_win.cancel_button.connect("clicked", lambda w: self.file_win.destroy()) self.file_win.show() return True
def display_file_selection(self, widget, data=None): self.selection_box = gtk.FileSelection(title="Choose Output File") self.selection_box.set_filename(self.task_manager.RESPONSE_FILE_NAME) self.selection_box.ok_button.connect("clicked", self.set_output_name) self.selection_box.cancel_button.connect("clicked", lambda w: self.selection_box.destroy()) self.selection_box.show()
def __init__(self): self.cur_filename='' self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("destroy", self.destroy) self.window.set_title("python Mozhi") self.window.set_border_width(2) self.window.set_size_request(600, 400) #-----------------------------------# # file Selection window # #-----------------------------------# self.filew = gtk.FileSelection("File selection") self.filew.ok_button.connect("clicked", self.save_dialog_ok_click) self.filew.cancel_button.connect("clicked",lambda w: self.filew.destroy()) self.filew.set_filename("mozhi.moz") #-----------------------------------# box=gtk.VBox(False,0) #--------------------------# # menu bar # #--------------------------# menubar = self.get_main_menu() box.pack_start(menubar, False, True, 0) menubar.show() #--------------------------# #--------------------------# # Toolbar # #--------------------------# handlebox = gtk.HandleBox() box.pack_start(handlebox, False, False, 5) toolbar = gtk.Toolbar() toolbar.set_orientation(gtk.ORIENTATION_HORIZONTAL) toolbar.set_style(gtk.TOOLBAR_BOTH) toolbar.set_border_width(5) handlebox.add(toolbar) iconw = gtk.Image() # icon widget iconw.set_from_file("img/exit.png") close_button = toolbar.append_item( "Close", # button label "Closes this app", # this button's tooltip "Private", # tooltip private info iconw, # icon widget self.destroy) # a signal toolbar.append_space() # space after item iconw = gtk.Image() # icon widget iconw.set_from_file("img/save.png") tooltips_button = toolbar.append_item( "Save","Save the Translation", "Private",iconw,self.save_trans) toolbar.show() handlebox.show() #-----------------------------------# #--------------------------# # TextView # # to show the translated # # malayalam text # #--------------------------# sw_mal = gtk.ScrolledWindow() sw_mal.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) self.textmal = gtk.TextView() self.textmalbuffer = self.textmal.get_buffer() self.textmal.set_editable(False) self.textmal.set_wrap_mode(gtk.WRAP_WORD) self.textmal.set_border_width(2) self.textmal.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(200,192,93)) sw_mal.add(self.textmal) self.textmal.show() box.pack_start(sw_mal) sw_mal.show() self.sw_mal=sw_mal #--------------------------# seperator=gtk.HSeparator() box.pack_start(seperator,False,True,5) seperator.show() #--------------------------# # TextView # # for the input of # # manglish text # #--------------------------# sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) self.texteng = gtk.TextView() self.textengbuffer = self.texteng.get_buffer() self.texteng.connect("key_release_event",self.txt_keypress) self.texteng.set_wrap_mode(gtk.WRAP_WORD) sw.add(self.texteng) self.texteng.show() box.pack_start(sw) sw.show() self.texteng.grab_focus() #--------------------------# # This packs the box into the window (a GTK container). self.window.add(box) box.show() # The final step is to display this newly created widget. self.window.show()
def newChannel(self): self.enableDisable() method = MethodSelector().show() if not method: return editor = ChannelEditor() path = None removable = [] if method == "manual": type = TypeSelector().show() if not type: return newchannel = {"type": type} if editor.show(None, newchannel, editalias=True): alias = newchannel["alias"] del newchannel["alias"] sysconf.set(("channels", alias), parseChannelData(newchannel)) self._changed = True if newchannel.get("removable"): removable.append(alias) elif method in ("descriptionpath", "descriptionurl"): if method == "descriptionpath": if gtk.pygtk_version > (2,4,0): dia = gtk.FileChooserDialog( action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_OK)) else: dia = gtk.FileSelection(_("Select Channel Description")) dia.hide_fileop_buttons() response = dia.run() filename = dia.get_filename() dia.destroy() if response != gtk.RESPONSE_OK: return if not os.path.isfile(filename): iface.error(_("File not found: %s") % filename) return file = open(filename) data = file.read() file.close() elif method == "descriptionurl": url = iface.askInput(_("Description URL")) if not url: return ctrl = iface.getControl() succ, fail = ctrl.downloadURLs([url], _("channel description")) if fail: iface.error(_("Unable to fetch channel description: %s") % fail[url]) return file = open(succ[url]) data = file.read() file.close() if succ[url].startswith(sysconf.get("data-dir")): os.unlink(succ[url]) newchannels = parseChannelsDescription(data) for alias in newchannels: newchannel = newchannels[alias] if editor.show(alias, newchannel, editalias=True): alias = newchannel["alias"] del newchannel["alias"] sysconf.set(("channels", alias), parseChannelData(newchannel)) self._changed = True if newchannel.get("removable"): removable.append(alias) elif method in ("detectmedia", "detectpath"): if method == "detectmedia": path = MountPointSelector().show() if not path: return elif method == "detectpath": if gtk.pygtk_version > (2,4,0): dia = gtk.FileChooserDialog( action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_OK)) else: dia = gtk.FileSelection(_("Select Path")) dia.hide_fileop_buttons() response = dia.run() path = dia.get_filename() dia.destroy() if response != gtk.RESPONSE_OK: return if not os.path.isdir(path): iface.error(_("Directory not found: %s") % path) return sysconf.set("default-localmedia", path, soft=True) foundchannel = False for newchannel in detectLocalChannels(path): foundchannel = True if editor.show(newchannel.get("alias"), newchannel, editalias=True): alias = newchannel["alias"] del newchannel["alias"] sysconf.set(("channels", alias), parseChannelData(newchannel)) self._changed = True if newchannel.get("removable"): removable.append(alias) if not foundchannel: iface.error(_("No channels detected!")) return if removable: ctrl = iface.getControl() ctrl.rebuildSysConfChannels() channels = [x for x in ctrl.getChannels() if x.getAlias() in removable] iface.updateChannels(channels=channels) if path: sysconf.remove("default-localmedia", soft=True) if self._changed: self.fill()
def menuitem_response(self, widget, string): fileSel = gtk.FileSelection() fileSel.ok_button.connect("clicked", self.file_ok_sel, fileSel) fileSel.show()
class MainWindow: index = 0 entry = gtk.Entry() filesel = gtk.FileSelection("Select a file") values = {} solver = '' def displayDialog(self, message): md = gtk.MessageDialog(self.window, 0, gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE, message) md.run() md.destroy() # This callback quits the program def delete_event(self, widget, event, data=None): gtk.main_quit() return False def square_callback(self, widget, data=None): self.index += 1 print str(self.index) + ": " + data for square in ui_squares: if (square == data): continue self.buttons[square].set_active(False) def insert_callback(self, widget, data=None): print data def solve_callback(self, widget, data=None): self.solve_rules() def reset_callback(self, widget, data=None): for square in ui_squares: self.buttons[square].set_label(" ") def set_square(self, square, value): self.buttons[square].set_label(" " + str(value) + " ") def open_callback(self, widget, data=None): self.filesel.show() def file_ok_sel(self, w): self.entry.set_text(self.filesel.get_filename()) self.filesel.hide() try: file = open(self.entry.get_text(), "r") tmp = file.read() if (len(tmp) == 0): print "Invalid File" return grid = tmp.strip() print grid #solve(grid) self.solver = Solver(grid) self.values = self.solver.grid_values() print self.values self.display_sudoku(self.values) except IOError, e: print "Error opening file ({0}): {1}".format(e.errno, e.strerror)
def load_mri(self, *args): print "loc3djr_maintoolbar.load_mri()" if self.niftiFilename is not None: fname = self.niftiFilename else: dialog = gtk.FileSelection('Choose nifti file') dialog.set_transient_for(widgets['dlgReader']) dialog.set_filename(shared.get_last_dir()) response = dialog.run() fname = dialog.get_filename() dialog.destroy() if response == gtk.RESPONSE_OK: print fname else: return #reader = vtkNiftiImageReader() #reader.SetFileName(fname) #reader.Update() pars = Params() if fname.endswith(".nii.gz"): pars.extension = ".".join(fname.split(".")[-2:]) pars.pattern = ".".join( fname.split(os.path.sep)[-1].split(".")[:-2]) #elif fname.endswith(".nii"): # pars.extension=".nii" else: pars.extension = ".".join(fname.split(".")[-1:]) pars.pattern = ".".join( fname.split(os.path.sep)[-1].split(".")[:-1]) print "pars.extension", pars.extension print "pars.pattern", pars.pattern pars.dir = os.path.dirname( fname) #sep.join(fname.split(os.path.sep)[:-1]) print "pars.dir", pars.dir pars.readerClass = 'vtkNiftiImageReader' reader = widgets.get_reader(pars) pars.first = 1 pars.last = reader.GetDepth() print "reader=", reader if not reader: print "hit cancel, see if we can survive" else: pars = widgets.get_params() pars = widgets.validate(pars) imageData = reader.GetOutput() #stupid workaround, somehow imageData.Extent is not written. dunno why #maybe its in vtkImageImportFromArray imageData.SetExtent(reader.GetDataExtent()) print "loc3djr_maintoolbar.load_mri(): reader.GetOutput() is ", imageData print "load_mri(): imageData.SetSpacing(", reader.GetDataSpacing( ), " )" imageData.SetSpacing(reader.GetDataSpacing()) print "calling EventHandler().notify('set image data', imageData)" EventHandler().notify('set image data', imageData) print "calling EventHandler().setNifti()" EventHandler().setNifti(reader.GetQForm(), reader.GetDataSpacing())
def selectFile(self, widget): self.filew = gtk.FileSelection("Select File") self.filew.connect("destroy", lambda cancel: self.filew.destroy()) self.filew.ok_button.connect("clicked", self.definePath) self.filew.cancel_button.connect("clicked", lambda cancel: self.filew.destroy()) self.filew.show_all()
def __init__(self, dm): self.file_name = None self.data_model = dm self.dump_depth = 0 # Create a new window self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.set_title("Data Model Tree Viewer") self.window.set_size_request(400, 600) self.window.connect("delete_event", self.delete_event) self.vbox = gtk.VBox(False, 0) self.window.add(self.vbox) self.vbox.show() self.menu_bar = gtk.MenuBar() self.vbox.pack_start(self.menu_bar, False, False, 2) self.file_menu = gtk.MenuItem("File") self.file_menu.show() self.menu = gtk.Menu() menu_name = "Open Data Model" menu_item = gtk.MenuItem(menu_name) menu_item.connect("activate", self.open_callback, menu_name) self.menu.append(menu_item) menu_name = "Save Data Model" menu_item = gtk.MenuItem(menu_name) menu_item.connect("activate", self.save_callback, menu_name) self.menu.append(menu_item) menu_name = "Dump Data Model" menu_item = gtk.MenuItem(menu_name) menu_item.connect("activate", self.dump_model_callback, menu_name) self.menu.append(menu_item) menu_name = "Dump Data Model Keys" menu_item = gtk.MenuItem(menu_name) menu_item.connect("activate", self.dump_keys_callback, menu_name) self.menu.append(menu_item) menu_name = "Dump GUI Tree" menu_item = gtk.MenuItem(menu_name) menu_item.connect("activate", self.dump_tree_callback, menu_name) self.menu.append(menu_item) menu_name = "Export JSON" menu_item = gtk.MenuItem(menu_name) menu_item.connect("activate", self.dump_json_callback, menu_name) self.menu.append(menu_item) menu_name = "Export JSON2" menu_item = gtk.MenuItem(menu_name) menu_item.connect("activate", self.dump_json_indented_callback, menu_name) self.menu.append(menu_item) menu_name = "Export MDL" menu_item = gtk.MenuItem(menu_name) menu_item.connect("activate", self.dump_as_mdl_callback, menu_name) self.menu.append(menu_item) self.file_menu.set_submenu(self.menu) self.menu_bar.append(self.file_menu) self.treestore = gtk.TreeStore(str, str) self.build_tree_from_data_model(None, "Data Model", self.data_model) self.treeview = gtk.TreeView(self.treestore) self.column = gtk.TreeViewColumn('Data Model') self.treeview.append_column(self.column) self.cell = gtk.CellRendererText() self.column.pack_start(self.cell, True) self.column.add_attribute(self.cell, 'text', 0) #self.treeview.set_search_column(0) #self.column.set_sort_column_id(0) #self.treeview.set_reorderable(True) self.scrolled_window = gtk.ScrolledWindow() self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.scrolled_window.add_with_viewport(self.treeview) self.vbox.pack_end(self.scrolled_window, True, True, 2) self.window.show_all() self.open_dialog = gtk.FileSelection("Open Data Model File") self.open_dialog.ok_button.connect("clicked", self.open_ok_callback) self.open_dialog.cancel_button.connect("clicked", self.open_cancel_callback) self.treeview.connect("row-activated", self.row_selected)
else: print("No '%s' key exist in shelve file!" % keyNr) f.close() return dictio locale.setlocale(locale.LC_ALL, '') backupFiles = {} active = False cntr = 0 last_clock = 0 # conf. variables in a global dictionary & start with prev. stop_config shelf = Save_recall() if not shelf.is_there('default_config'): actual_dir = gtk.FileSelection() default_config = { 'dir_BU': actual_dir.get_filename(), # backup dir 'source_ind': 2, # image(s) to save, index 'exten_ind': 0, # extension of file, index 'kept': 1, # number of backup to keep 'int_val': 600.0, # backup interval in second 'start': False # at start of interval, bool. } shelf.save('default_config') config = {} if shelf.is_there('laststop_config'): config_act = 'laststop_config' else: config_act = 'default_config' config = shelf.recall(config_act) # Preset mode messages msga = _("Adding numbered preset: a consecutive sequence of 5 .")