Python gtk.FILE_CHOOSER_ACTION_SAVE Examples

The following are 30 code examples of gtk.FILE_CHOOSER_ACTION_SAVE(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gtk , or try the search function .
Example #1
Source File: gnome_connection_manager.py    From gnome-connection-manager with GNU General Public License v3.0 6 votes vote down vote up
def show_save_buffer(self, terminal):        
        dlg = gtk.FileChooserDialog(title=_("Guardar como"), parent=self.wMain, action=gtk.FILE_CHOOSER_ACTION_SAVE)
        dlg.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
        dlg.add_button(gtk.STOCK_SAVE, gtk.RESPONSE_OK)        
        dlg.set_do_overwrite_confirmation(True)
        dlg.set_current_name( os.path.basename("gcm-buffer-%s.txt" % (time.strftime("%Y%m%d%H%M%S")) ))
        if not hasattr(self,'lastPath'):
            self.lastPath = os.path.expanduser("~")
        dlg.set_current_folder( self.lastPath )
        
        if dlg.run() == gtk.RESPONSE_OK:
            filename = dlg.get_filename()
            self.lastPath = os.path.dirname(filename)            
    
            try:              
                buff = terminal.get_text_range(0, 0, terminal.get_property('scrollback-lines')-1, terminal.get_column_count()-1, lambda *args: True, None, None ).strip()                
                f = open(filename, "w")
                f.write(buff)
                f.close()
            except:                
                dlg.destroy()
                msgbox("%s: %s" % (_("No se puede abrir archivo para escritura"), filename) )
                return
            
        dlg.destroy() 
Example #2
Source File: gnome_connection_manager.py    From gnome-connection-manager with GNU General Public License v3.0 6 votes vote down vote up
def show_open_dialog(parent, title, action):        
    dlg = gtk.FileChooserDialog(title=title, parent=parent, action=action)
    dlg.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
    
    dlg.add_button(gtk.STOCK_SAVE if action==gtk.FILE_CHOOSER_ACTION_SAVE else gtk.STOCK_OPEN, gtk.RESPONSE_OK)        
    dlg.set_do_overwrite_confirmation(True)        
    if not hasattr(parent,'lastPath'):
        parent.lastPath = os.path.expanduser("~")
    dlg.set_current_folder( parent.lastPath )
    
    if dlg.run() == gtk.RESPONSE_OK:
        filename = dlg.get_filename()
        parent.lastPath = os.path.dirname(filename)
    else:
        filename = None
    dlg.destroy()
    return filename 
Example #3
Source File: mcplatform.py    From GDMC with ISC License 5 votes vote down vote up
def askOpenFileGtk(title, suffixes, initialDir):
    fls = []
    def run_dlg():
        chooser = gtk.FileChooserDialog(title,
                                        None, gtk.FILE_CHOOSER_ACTION_SAVE,
                                        (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                        gtk.STOCK_OPEN, gtk.RESPONSE_OK))
    
        chooser.set_default_response(gtk.RESPONSE_OK)
        chooser.set_current_folder(initialDir)
        chooser.set_current_name("world")  # For some reason the Windows isn't closing if this line ins missing or the parameter is ""

        # Add custom Filter
        file_filter = gtk.FileFilter()
        file_filter.set_name(_("Levels and Schematics"))
        for suffix in suffixes:
            file_filter.add_pattern("*." + suffix)
        chooser.add_filter(file_filter)

        # Add "All files" Filter
        file_filter = gtk.FileFilter()
        file_filter.set_name("All files")
        file_filter.add_pattern("*")
        chooser.add_filter(file_filter)

        response = chooser.run()
        if response == gtk.RESPONSE_OK:
            fls.append(chooser.get_filename())
        else:
            fls.append(None)
        chooser.destroy()
        gtk.main_quit()

    gtk.idle_add(run_dlg)
    gtk.main()

    return fls[0] 
Example #4
Source File: mcplatform.py    From MCEdit-Unified with ISC License 5 votes vote down vote up
def askOpenFolderGtk(title, initialDir):
    if hasGtk:
        fls = []

        def run_dlg():
            chooser = gtk.FileChooserDialog(title,
                                        None, gtk.FILE_CHOOSER_ACTION_SAVE,
                                        (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                        gtk.STOCK_OPEN, gtk.RESPONSE_OK))

            chooser.set_default_response(gtk.RESPONSE_OK)
            chooser.set_current_folder(initialDir)
            chooser.set_current_name("world")
            chooser.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)

            response = chooser.run()
            if response == gtk.RESPONSE_OK:
                fls.append(chooser.get_filename())  # Returns the folder path if gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER is the action
            else:
                fls.append(None)
            chooser.destroy()
            gtk.main_quit()

        gtk.idle_add(run_dlg)
        gtk.main()
        return fls[0]
    else:
        print "You currently need gtk to use an Open Folder Dialog!" 
Example #5
Source File: mcplatform.py    From MCEdit-Unified with ISC License 5 votes vote down vote up
def askOpenFileGtk(title, suffixes, initialDir):
    fls = []

    def run_dlg():
        chooser = gtk.FileChooserDialog(title,
                                        None, gtk.FILE_CHOOSER_ACTION_SAVE,
                                        (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                        gtk.STOCK_OPEN, gtk.RESPONSE_OK))
    
        chooser.set_default_response(gtk.RESPONSE_OK)
        chooser.set_current_folder(initialDir)
        chooser.set_current_name("world")  # For some reason the Windows isn't closing if this line ins missing or the parameter is ""

        # Add custom Filter
        file_filter = gtk.FileFilter()
        file_filter.set_name(_("Levels and Schematics"))
        for suffix in suffixes:
            file_filter.add_pattern("*." + suffix)
        chooser.add_filter(file_filter)

        # Add "All files" Filter
        file_filter = gtk.FileFilter()
        file_filter.set_name("All files")
        file_filter.add_pattern("*")
        chooser.add_filter(file_filter)

        response = chooser.run()
        if response == gtk.RESPONSE_OK:
            fls.append(chooser.get_filename())
        else:
            fls.append(None)
        chooser.destroy()
        gtk.main_quit()

    gtk.idle_add(run_dlg)
    gtk.main()

    return fls[0] 
Example #6
Source File: gnome_connection_manager.py    From gnome-connection-manager with GNU General Public License v3.0 5 votes vote down vote up
def on_exportar_servidores1_activate(self, widget, *args):
        filename = show_open_dialog(parent=self.wMain, title=_("Guardar como"), action=gtk.FILE_CHOOSER_ACTION_SAVE)
        if filename != None:
            password = inputbox(_('Exportar Servidores'), _('Ingrese clave: '), password=True)
            if password == None:
                return
                
            try:
                cp= ConfigParser.RawConfigParser( )
                cp.read( filename + ".tmp" )
                i=1
                cp.add_section("gcm")
                cp.set("gcm", "gcm", encrypt(password, password[::-1]))
                global groups
                for grupo in groups:
                    for host in groups[grupo]:
                        section = "host " + str(i)
                        cp.add_section(section)
                        HostUtils.save_host_to_ini(cp, section, host, password)                        
                        i+=1
                f = open(filename + ".tmp", "w")
                cp.write(f)
                f.close()
                os.rename(filename + ".tmp", filename)
            except:
                msgbox(_("Archivo invalido"))
    #-- Wmain.on_exportar_servidores1_activate }

    #-- Wmain.on_salir1_activate { 
Example #7
Source File: core.py    From Tocino with GNU General Public License v2.0 5 votes vote down vote up
def _get_export_file_name(self):
        sel = gtk.FileChooserDialog("Save...", self.canvas.get_toplevel(),
                                    gtk.FILE_CHOOSER_ACTION_SAVE,
                                    (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                     gtk.STOCK_SAVE, gtk.RESPONSE_OK))
        sel.set_default_response(gtk.RESPONSE_OK)
        sel.set_local_only(True)
        sel.set_do_overwrite_confirmation(True)
        sel.set_current_name("Unnamed.pdf")

        filter = gtk.FileFilter()
        filter.set_name("Embedded PostScript")
        filter.add_mime_type("image/x-eps")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Portable Document Graphics")
        filter.add_mime_type("application/pdf")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Scalable Vector Graphics")
        filter.add_mime_type("image/svg+xml")
        sel.add_filter(filter)

        resp = sel.run()
        if resp != gtk.RESPONSE_OK:
            sel.destroy()
            return None
        
        file_name = sel.get_filename()
        sel.destroy()
        return file_name 
Example #8
Source File: grid.py    From Tocino with GNU General Public License v2.0 5 votes vote down vote up
def __output_png_cb(self, widget):
        dialog = gtk.FileChooserDialog("Output Png", self.__window, 
                                       gtk.FILE_CHOOSER_ACTION_SAVE, ("Save", 1))
        self.__dialog = dialog
        dialog.set_default_response(1)
        dialog.connect("response", self.__dialog_response_cb)
        dialog.show()
        return 
Example #9
Source File: core.py    From ns3-802.11ad with GNU General Public License v2.0 5 votes vote down vote up
def _get_export_file_name(self):
        sel = gtk.FileChooserDialog("Save...", self.canvas.get_toplevel(),
                                    gtk.FILE_CHOOSER_ACTION_SAVE,
                                    (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                     gtk.STOCK_SAVE, gtk.RESPONSE_OK))
        sel.set_default_response(gtk.RESPONSE_OK)
        sel.set_local_only(True)
        sel.set_do_overwrite_confirmation(True)
        sel.set_current_name("Unnamed.pdf")

        filter = gtk.FileFilter()
        filter.set_name("Embedded PostScript")
        filter.add_mime_type("image/x-eps")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Portable Document Graphics")
        filter.add_mime_type("application/pdf")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Scalable Vector Graphics")
        filter.add_mime_type("image/svg+xml")
        sel.add_filter(filter)

        resp = sel.run()
        if resp != gtk.RESPONSE_OK:
            sel.destroy()
            return None
        
        file_name = sel.get_filename()
        sel.destroy()
        return file_name 
Example #10
Source File: grid.py    From ns3-802.11ad with GNU General Public License v2.0 5 votes vote down vote up
def __output_png_cb(self, widget):
        """! Output PNG Callback
        @param self this object
        @param widget widget
        @return none
        """
        dialog = gtk.FileChooserDialog("Output Png", self.__window, 
                                       gtk.FILE_CHOOSER_ACTION_SAVE, ("Save", 1))
        self.__dialog = dialog
        dialog.set_default_response(1)
        dialog.connect("response", self.__dialog_response_cb)
        dialog.show()
        return 
Example #11
Source File: core.py    From ns3-ecn-sharp with GNU General Public License v2.0 5 votes vote down vote up
def _get_export_file_name(self):
        sel = gtk.FileChooserDialog("Save...", self.canvas.get_toplevel(),
                                    gtk.FILE_CHOOSER_ACTION_SAVE,
                                    (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                     gtk.STOCK_SAVE, gtk.RESPONSE_OK))
        sel.set_default_response(gtk.RESPONSE_OK)
        sel.set_local_only(True)
        sel.set_do_overwrite_confirmation(True)
        sel.set_current_name("Unnamed.pdf")

        filter = gtk.FileFilter()
        filter.set_name("Embedded PostScript")
        filter.add_mime_type("image/x-eps")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Portable Document Graphics")
        filter.add_mime_type("application/pdf")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Scalable Vector Graphics")
        filter.add_mime_type("image/svg+xml")
        sel.add_filter(filter)

        resp = sel.run()
        if resp != gtk.RESPONSE_OK:
            sel.destroy()
            return None
        
        file_name = sel.get_filename()
        sel.destroy()
        return file_name 
Example #12
Source File: grid.py    From ns3-ecn-sharp with GNU General Public License v2.0 5 votes vote down vote up
def __output_png_cb(self, widget):
        dialog = gtk.FileChooserDialog("Output Png", self.__window, 
                                       gtk.FILE_CHOOSER_ACTION_SAVE, ("Save", 1))
        self.__dialog = dialog
        dialog.set_default_response(1)
        dialog.connect("response", self.__dialog_response_cb)
        dialog.show()
        return 
Example #13
Source File: core.py    From CRE-NS3 with GNU General Public License v2.0 5 votes vote down vote up
def _get_export_file_name(self):
        sel = gtk.FileChooserDialog("Save...", self.canvas.get_toplevel(),
                                    gtk.FILE_CHOOSER_ACTION_SAVE,
                                    (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                     gtk.STOCK_SAVE, gtk.RESPONSE_OK))
        sel.set_default_response(gtk.RESPONSE_OK)
        sel.set_local_only(True)
        sel.set_do_overwrite_confirmation(True)
        sel.set_current_name("Unnamed.pdf")

        filter = gtk.FileFilter()
        filter.set_name("Embedded PostScript")
        filter.add_mime_type("image/x-eps")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Portable Document Graphics")
        filter.add_mime_type("application/pdf")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Scalable Vector Graphics")
        filter.add_mime_type("image/svg+xml")
        sel.add_filter(filter)

        resp = sel.run()
        if resp != gtk.RESPONSE_OK:
            sel.destroy()
            return None
        
        file_name = sel.get_filename()
        sel.destroy()
        return file_name 
Example #14
Source File: grid.py    From CRE-NS3 with GNU General Public License v2.0 5 votes vote down vote up
def __output_png_cb(self, widget):
        dialog = gtk.FileChooserDialog("Output Png", self.__window, 
                                       gtk.FILE_CHOOSER_ACTION_SAVE, ("Save", 1))
        self.__dialog = dialog
        dialog.set_default_response(1)
        dialog.connect("response", self.__dialog_response_cb)
        dialog.show()
        return 
Example #15
Source File: tintwizard.py    From malfs-milis with MIT License 5 votes vote down vote up
def saveAs(self, widget=None, event=None):
		"""Prompts the user to select a file and then saves the generated config file."""
		self.generateConfig()

		chooser = gtk.FileChooserDialog("Save Config File As...", self, gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK))
		chooser.set_default_response(gtk.RESPONSE_OK)

		if self.curDir != None:
			chooser.set_current_folder(self.curDir)

		chooserFilter = gtk.FileFilter()
		chooserFilter.set_name("All files")
		chooserFilter.add_pattern("*")
		chooser.add_filter(chooserFilter)
		chooser.show()

		response = chooser.run()

		if response == gtk.RESPONSE_OK:
			self.filename = chooser.get_filename()

			if os.path.exists(self.filename):
				overwrite = confirmDialog(self, "This file already exists. Overwrite this file?")

				if overwrite == gtk.RESPONSE_YES:
					self.writeFile()
					chooser.destroy()
					return True
				else:
					self.filename = None
					chooser.destroy()
					return False
			else:
				self.writeFile()
				chooser.destroy()
				return True
		else:
			self.filename = None
			chooser.destroy()
			return False 
Example #16
Source File: core.py    From ns-3-dev-git with GNU General Public License v2.0 5 votes vote down vote up
def _get_export_file_name(self):
        sel = gtk.FileChooserDialog("Save...", self.canvas.get_toplevel(),
                                    gtk.FILE_CHOOSER_ACTION_SAVE,
                                    (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                     gtk.STOCK_SAVE, gtk.RESPONSE_OK))
        sel.set_default_response(gtk.RESPONSE_OK)
        sel.set_local_only(True)
        sel.set_do_overwrite_confirmation(True)
        sel.set_current_name("Unnamed.pdf")

        filter = gtk.FileFilter()
        filter.set_name("Embedded PostScript")
        filter.add_mime_type("image/x-eps")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Portable Document Graphics")
        filter.add_mime_type("application/pdf")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Scalable Vector Graphics")
        filter.add_mime_type("image/svg+xml")
        sel.add_filter(filter)

        resp = sel.run()
        if resp != gtk.RESPONSE_OK:
            sel.destroy()
            return None
        
        file_name = sel.get_filename()
        sel.destroy()
        return file_name 
Example #17
Source File: grid.py    From ns-3-dev-git with GNU General Public License v2.0 5 votes vote down vote up
def __output_png_cb(self, widget):
        """! Output PNG Callback
        @param self this object
        @param widget widget
        @return none
        """
        dialog = gtk.FileChooserDialog("Output Png", self.__window, 
                                       gtk.FILE_CHOOSER_ACTION_SAVE, ("Save", 1))
        self.__dialog = dialog
        dialog.set_default_response(1)
        dialog.connect("response", self.__dialog_response_cb)
        dialog.show()
        return 
Example #18
Source File: core.py    From royal-chaos with MIT License 5 votes vote down vote up
def _get_export_file_name(self):
        sel = gtk.FileChooserDialog("Save...", self.canvas.get_toplevel(),
                                    gtk.FILE_CHOOSER_ACTION_SAVE,
                                    (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                     gtk.STOCK_SAVE, gtk.RESPONSE_OK))
        sel.set_default_response(gtk.RESPONSE_OK)
        sel.set_local_only(True)
        sel.set_do_overwrite_confirmation(True)
        sel.set_current_name("Unnamed.pdf")

        filter = gtk.FileFilter()
        filter.set_name("Embedded PostScript")
        filter.add_mime_type("image/x-eps")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Portable Document Graphics")
        filter.add_mime_type("application/pdf")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Scalable Vector Graphics")
        filter.add_mime_type("image/svg+xml")
        sel.add_filter(filter)

        resp = sel.run()
        if resp != gtk.RESPONSE_OK:
            sel.destroy()
            return None
        
        file_name = sel.get_filename()
        sel.destroy()
        return file_name 
Example #19
Source File: grid.py    From royal-chaos with MIT License 5 votes vote down vote up
def __output_png_cb(self, widget):
        """! Output PNG Callback
        @param self this object
        @param widget widget
        @return none
        """
        dialog = gtk.FileChooserDialog("Output Png", self.__window, 
                                       gtk.FILE_CHOOSER_ACTION_SAVE, ("Save", 1))
        self.__dialog = dialog
        dialog.set_default_response(1)
        dialog.connect("response", self.__dialog_response_cb)
        dialog.show()
        return 
Example #20
Source File: core.py    From ns3-rdma with GNU General Public License v2.0 5 votes vote down vote up
def _get_export_file_name(self):
        sel = gtk.FileChooserDialog("Save...", self.canvas.get_toplevel(),
                                    gtk.FILE_CHOOSER_ACTION_SAVE,
                                    (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                     gtk.STOCK_SAVE, gtk.RESPONSE_OK))
        sel.set_default_response(gtk.RESPONSE_OK)
        sel.set_local_only(True)
        sel.set_do_overwrite_confirmation(True)
        sel.set_current_name("Unnamed.pdf")

        filter = gtk.FileFilter()
        filter.set_name("Embedded PostScript")
        filter.add_mime_type("image/x-eps")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Portable Document Graphics")
        filter.add_mime_type("application/pdf")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Scalable Vector Graphics")
        filter.add_mime_type("image/svg+xml")
        sel.add_filter(filter)

        resp = sel.run()
        if resp != gtk.RESPONSE_OK:
            sel.destroy()
            return None
        
        file_name = sel.get_filename()
        sel.destroy()
        return file_name 
Example #21
Source File: grid.py    From ns3-rdma with GNU General Public License v2.0 5 votes vote down vote up
def __output_png_cb(self, widget):
        dialog = gtk.FileChooserDialog("Output Png", self.__window, 
                                       gtk.FILE_CHOOSER_ACTION_SAVE, ("Save", 1))
        self.__dialog = dialog
        dialog.set_default_response(1)
        dialog.connect("response", self.__dialog_response_cb)
        dialog.show()
        return 
Example #22
Source File: core.py    From 802.11ah-ns3 with GNU General Public License v2.0 5 votes vote down vote up
def _get_export_file_name(self):
        sel = gtk.FileChooserDialog("Save...", self.canvas.get_toplevel(),
                                    gtk.FILE_CHOOSER_ACTION_SAVE,
                                    (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                     gtk.STOCK_SAVE, gtk.RESPONSE_OK))
        sel.set_default_response(gtk.RESPONSE_OK)
        sel.set_local_only(True)
        sel.set_do_overwrite_confirmation(True)
        sel.set_current_name("Unnamed.pdf")

        filter = gtk.FileFilter()
        filter.set_name("Embedded PostScript")
        filter.add_mime_type("image/x-eps")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Portable Document Graphics")
        filter.add_mime_type("application/pdf")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Scalable Vector Graphics")
        filter.add_mime_type("image/svg+xml")
        sel.add_filter(filter)

        resp = sel.run()
        if resp != gtk.RESPONSE_OK:
            sel.destroy()
            return None
        
        file_name = sel.get_filename()
        sel.destroy()
        return file_name 
Example #23
Source File: grid.py    From 802.11ah-ns3 with GNU General Public License v2.0 5 votes vote down vote up
def __output_png_cb(self, widget):
        dialog = gtk.FileChooserDialog("Output Png", self.__window, 
                                       gtk.FILE_CHOOSER_ACTION_SAVE, ("Save", 1))
        self.__dialog = dialog
        dialog.set_default_response(1)
        dialog.connect("response", self.__dialog_response_cb)
        dialog.show()
        return 
Example #24
Source File: core.py    From ns3-load-balance with GNU General Public License v2.0 5 votes vote down vote up
def _get_export_file_name(self):
        sel = gtk.FileChooserDialog("Save...", self.canvas.get_toplevel(),
                                    gtk.FILE_CHOOSER_ACTION_SAVE,
                                    (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                     gtk.STOCK_SAVE, gtk.RESPONSE_OK))
        sel.set_default_response(gtk.RESPONSE_OK)
        sel.set_local_only(True)
        sel.set_do_overwrite_confirmation(True)
        sel.set_current_name("Unnamed.pdf")

        filter = gtk.FileFilter()
        filter.set_name("Embedded PostScript")
        filter.add_mime_type("image/x-eps")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Portable Document Graphics")
        filter.add_mime_type("application/pdf")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Scalable Vector Graphics")
        filter.add_mime_type("image/svg+xml")
        sel.add_filter(filter)

        resp = sel.run()
        if resp != gtk.RESPONSE_OK:
            sel.destroy()
            return None
        
        file_name = sel.get_filename()
        sel.destroy()
        return file_name 
Example #25
Source File: grid.py    From ns3-load-balance with GNU General Public License v2.0 5 votes vote down vote up
def __output_png_cb(self, widget):
        dialog = gtk.FileChooserDialog("Output Png", self.__window, 
                                       gtk.FILE_CHOOSER_ACTION_SAVE, ("Save", 1))
        self.__dialog = dialog
        dialog.set_default_response(1)
        dialog.connect("response", self.__dialog_response_cb)
        dialog.show()
        return 
Example #26
Source File: core.py    From IEEE-802.11ah-ns-3 with GNU General Public License v2.0 5 votes vote down vote up
def _get_export_file_name(self):
        sel = gtk.FileChooserDialog("Save...", self.canvas.get_toplevel(),
                                    gtk.FILE_CHOOSER_ACTION_SAVE,
                                    (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                     gtk.STOCK_SAVE, gtk.RESPONSE_OK))
        sel.set_default_response(gtk.RESPONSE_OK)
        sel.set_local_only(True)
        sel.set_do_overwrite_confirmation(True)
        sel.set_current_name("Unnamed.pdf")

        filter = gtk.FileFilter()
        filter.set_name("Embedded PostScript")
        filter.add_mime_type("image/x-eps")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Portable Document Graphics")
        filter.add_mime_type("application/pdf")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Scalable Vector Graphics")
        filter.add_mime_type("image/svg+xml")
        sel.add_filter(filter)

        resp = sel.run()
        if resp != gtk.RESPONSE_OK:
            sel.destroy()
            return None
        
        file_name = sel.get_filename()
        sel.destroy()
        return file_name 
Example #27
Source File: grid.py    From IEEE-802.11ah-ns-3 with GNU General Public License v2.0 5 votes vote down vote up
def __output_png_cb(self, widget):
        dialog = gtk.FileChooserDialog("Output Png", self.__window, 
                                       gtk.FILE_CHOOSER_ACTION_SAVE, ("Save", 1))
        self.__dialog = dialog
        dialog.set_default_response(1)
        dialog.connect("response", self.__dialog_response_cb)
        dialog.show()
        return 
Example #28
Source File: core.py    From ntu-dsi-dcn with GNU General Public License v2.0 5 votes vote down vote up
def _get_export_file_name(self):
        sel = gtk.FileChooserDialog("Save...", self.canvas.get_toplevel(),
                                    gtk.FILE_CHOOSER_ACTION_SAVE,
                                    (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                     gtk.STOCK_SAVE, gtk.RESPONSE_OK))
        sel.set_default_response(gtk.RESPONSE_OK)
        sel.set_local_only(True)
        sel.set_do_overwrite_confirmation(True)
        sel.set_current_name("Unnamed.pdf")

        filter = gtk.FileFilter()
        filter.set_name("Embedded PostScript")
        filter.add_mime_type("image/x-eps")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Portable Document Graphics")
        filter.add_mime_type("application/pdf")
        sel.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("Scalable Vector Graphics")
        filter.add_mime_type("image/svg+xml")
        sel.add_filter(filter)

        resp = sel.run()
        if resp != gtk.RESPONSE_OK:
            sel.destroy()
            return None
        
        file_name = sel.get_filename()
        sel.destroy()
        return file_name 
Example #29
Source File: grid.py    From ntu-dsi-dcn with GNU General Public License v2.0 5 votes vote down vote up
def __output_png_cb(self, widget):
        dialog = gtk.FileChooserDialog("Output Png", self.__window, 
                                       gtk.FILE_CHOOSER_ACTION_SAVE, ("Save", 1))
        self.__dialog = dialog
        dialog.set_default_response(1)
        dialog.connect("response", self.__dialog_response_cb)
        dialog.show()
        return 
Example #30
Source File: mcplatform.py    From GDMC with ISC License 4 votes vote down vote up
def run_dlg():
                chooser = gtk.FileChooserDialog(title,
                                                None, gtk.FILE_CHOOSER_ACTION_SAVE,
                                                (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                                gtk.STOCK_SAVE, gtk.RESPONSE_OK))

                chooser.set_default_response(gtk.RESPONSE_OK)
                chooser.set_current_folder(initialDir)
                chooser.set_current_name(defaultName)

                # Add custom Filter
                if type(_filetype) in (list, tuple):
                    for i, filet in enumerate(_filetype):
                        if i % 2 == 0:
                            file_filter = gtk.FileFilter()
                            file_filter.set_name(filet)
                            if ";" in _suffix[i + 1]:
                                for _suff in _suffix.split(";"):
                                    if _suff:
                                        file_filter.add_pattern(_suff)
                            else:
                                file_filter.add_pattern(_suffix[i + 1])
                            chooser.add_filter(file_filter)
                else:
                    file_filter = gtk.FileFilter()
                    file_filter.set_name(filetype[:filetype.index("\0")])
                    if "\0" in suffix and suffix.count("*.") > 1:
                        __suffix = suffix.split("\0")[:-2]
                    else:
                        __suffix = suffix
                    if type(__suffix) in (list, tuple):
                        for suff in __suffix:
                            file_filter.add_pattern("*." + suff)
                    else:
                        file_filter.add_pattern("*." + __suffix)
                    chooser.add_filter(file_filter)

                # Add "All files" Filter
                file_filter = gtk.FileFilter()
                file_filter.set_name("All files")
                file_filter.add_pattern("*")
                chooser.add_filter(file_filter)

                response = chooser.run()
                if response == gtk.RESPONSE_OK:
                    fls.append(chooser.get_filename())
                else:
                    fls.append(None)
                chooser.destroy()
                gtk.main_quit()