Python gtk 模块,STOCK_SAVE 实例源码

我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用gtk.STOCK_SAVE

项目:mgr.p2p.proxy    作者:tomusdrw    | 项目源码 | 文件源码
def connectionLost(self, reason):
        if len(self.buffer) == 0:
             dialog = gtk.MessageDialog(self, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                                        gtk.MESSAGE_ERROR, gtk.BUTTONS_OK,
                                        "An error occurred; file could not be retrieved.")
             dialog.run()
             dialog.destroy()
             return

        fd = gtk.FileChooserDialog(title=None, action=gtk.FILE_CHOOSER_ACTION_SAVE,
                                   buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_SAVE,gtk.RESPONSE_OK))
        fd.set_default_response(gtk.RESPONSE_OK)
        fd.set_current_name(self.filename)
        response = fd.run()
        if response == gtk.RESPONSE_OK:
            destfilename = fd.get_filename()
            f = open(destfilename, 'w')
            f.write(self.buffer)
            f.close()
        fd.destroy()
项目:gnome-connection-manager    作者:mjun    | 项目源码 | 文件源码
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
项目:gnome-connection-manager    作者:mjun    | 项目源码 | 文件源码
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()
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def gui_select_dir(self, start_dir=None):
        """Prompt the user to pick a directory"""
        import gtk

        if not start_dir:
            start_dir = self._last_dir

        dlg = gtk.FileChooserDialog("Choose folder",
                                    None,
                                    gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
                                    (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                     gtk.STOCK_SAVE, gtk.RESPONSE_OK))
        if start_dir and os.path.isdir(start_dir):
            dlg.set_current_folder(start_dir)

        res = dlg.run()
        fname = dlg.get_filename()
        dlg.destroy()

        if res == gtk.RESPONSE_OK and os.path.isdir(fname):
            self._last_dir = fname
            return fname
        else:
            return None
项目:ns3-rdma    作者:bobzhuyb    | 项目源码 | 文件源码
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
项目:Micro-Pi    作者:Bottersnike    | 项目源码 | 文件源码
def saveAs(self, *args):
        self.saveInternalOpenFiles()

        fn = gtk.FileChooserDialog(title="Save File As",
                                   action=gtk.FILE_CHOOSER_ACTION_SAVE,
                                   buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_SAVE,gtk.RESPONSE_OK))
        _filter = gtk.FileFilter()
        _filter.set_name("Micro:Pi Files")
        _filter.add_pattern("*.%s" % SETTINGS['fileExtention'])
        fn.add_filter(_filter)
        _filter = gtk.FileFilter()
        _filter.set_name("All Files")
        _filter.add_pattern("*")
        fn.add_filter(_filter)
        fn.show()

        resp = fn.run()

        #files = []
        #for f in self.notebook:
            #fin = self.notebook.get_tab_label(f).get_children()[0].get_label()
            #tb = f.get_child().get_buffer()
            #txt = tb.get_text(*tb.get_bounds())
            #files.append([fin, txt])
        #data = base64.b64encode(pickle.dumps(files))
        #data = "".join(data[i:i+64]+"\n" for i in xrange(0, len(data), 64))

        if resp == gtk.RESPONSE_OK:
            fp = fn.get_filename()
            if fp[-(len(SETTINGS["fileExtention"])+1):] != "." + SETTINGS["fileExtention"]:
                fp += "." + SETTINGS["fileExtention"]
            #open(fp, 'w').write(data)
            self.saveLocation = fp
            self.save()
            self.setSaved()
        fn.destroy()
项目:tintwizard    作者:vanadey    | 项目源码 | 文件源码
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
项目:griffith    作者:Strit    | 项目源码 | 文件源码
def run(self):
        basedir = None
        if self.config is not None:
            basedir = self.config.get('export_dir', None, section='export-csv')
        if not basedir:
            filename = gutils.file_chooser(_("Export a %s document")%"CSV", action=gtk.FILE_CHOOSER_ACTION_SAVE, \
                buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK), name='griffith_list.csv')
        else:
            filename = gutils.file_chooser(_("Export a %s document")%"CSV", action=gtk.FILE_CHOOSER_ACTION_SAVE, \
                buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE,gtk.RESPONSE_OK), name='griffith_list.csv', folder=basedir)
        if filename and filename[0]:
            if self.config is not None and filename[1]:
                self.config.set('export_dir', filename[1], section='export-csv')
                self.config.save()
            overwrite = None
            if os.path.isfile(filename[0]):
                if gutils.question(_("File exists. Do you want to overwrite it?"), self.parent_window):
                    overwrite = True
                else:
                    overwrite = False

            if overwrite or overwrite is None:
                movies = self.get_query().execute()

                writer = csv.writer(file(filename[0], 'w'), dialect=csv.excel)
                # write column header row
                writer.writerow(self.fields_to_export)
                # write data rows
                for movie in movies:
                    t = []
                    for s in self.exported_columns:
                        t.append(movie[s])
                    writer.writerow(t)
                gutils.info(_("%s file has been created.") % "CSV", self.parent_window)
项目:griffith    作者:Strit    | 项目源码 | 文件源码
def show_dialog(self):
        # shows a file dialog and sets self.filepath
        # derived classes which overwrite this method have also to set self.filepath
        basedir = None
        if not self.config is None and not self.config_section is None:
            basedir = self.config.get('export_dir', None, section=self.config_section)
        if basedir is None:
            filenames = gutils.file_chooser(_('Export a %s document') % self.export_name, action=gtk.FILE_CHOOSER_ACTION_SAVE, \
                buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK), name=self.filename)
        else:
            filenames = gutils.file_chooser(_('Export a %s document') % self.export_name, action=gtk.FILE_CHOOSER_ACTION_SAVE, \
                buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK), name=self.filename, folder=basedir)
        if filenames[0]:
            self.filepath = filenames[0]
            if len(filenames) > 1:
                self.dirpath = filenames[1]
            else:
                self.dirpath = os.path.dirname(self.filepath)
            self.filename = os.path.basename(self.filepath)
            if not self.config is None and self.dirpath and not self.config_section is None:
                self.config.set('export_dir', self.dirpath, section=self.config_section)
                self.config.save()
            overwrite = None
            if os.path.isfile(self.filepath):
                if gutils.question(_('File exists. Do you want to overwrite it?'), self.parent_window):
                    overwrite = True
                else:
                    overwrite = False

            if overwrite == True or overwrite is None:
                return True
        return False
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def gui_save_file(self, start_dir=None, default_name=None, types=[]):
        """Prompt the user to pick a filename to save"""
        import gtk

        if not start_dir:
            start_dir = self._last_dir

        dlg = gtk.FileChooserDialog("Save file as",
                                    None,
                                    gtk.FILE_CHOOSER_ACTION_SAVE,
                                    (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                     gtk.STOCK_SAVE, gtk.RESPONSE_OK))
        if start_dir and os.path.isdir(start_dir):
            dlg.set_current_folder(start_dir)

        if default_name:
            dlg.set_current_name(default_name)

        extensions = {}
        for desc, ext in types:
            ff = gtk.FileFilter()
            ff.set_name(desc)
            ff.add_pattern("*.%s" % ext)
            extensions[desc] = ext
            dlg.add_filter(ff)

        res = dlg.run()

        fname = dlg.get_filename()
        ext = extensions[dlg.get_filter().get_name()]
        if fname and not fname.endswith(".%s" % ext):
            fname = "%s.%s" % (fname, ext)

        dlg.destroy()

        if res == gtk.RESPONSE_OK:
            self._last_dir = os.path.dirname(fname)
            return fname
        else:
            return None
项目:tintwizard    作者:vanadey    | 项目源码 | 文件源码
def __init__(self, tw):
        """Create and shows the window."""
        self.tw = tw

        # Create top-level window
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)

        self.set_title("Preferences")
        self.connect("delete_event", self.quit)

        self.layout = gtk.Table(2, 2, False)

        self.table = gtk.Table(5, 2, False)
        self.table.set_row_spacings(5)
        self.table.set_col_spacings(5)

        createLabel(self.table, text="Default Font", gridX=0, gridY=0)
        self.font = gtk.FontButton(self.tw.defaults["font"])
        self.font.set_alignment(0, 0.5)
        self.table.attach(self.font, 1, 2, 0, 1, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)

        createLabel(self.table, text="Default Background Color", gridX=0, gridY=1)
        self.bgColor = gtk.ColorButton(gtk.gdk.color_parse(self.tw.defaults["bgColor"]))
        self.bgColor.set_alignment(0, 0.5)
        self.table.attach(self.bgColor, 1, 2, 1, 2, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)

        createLabel(self.table, text="Default Foreground Color", gridX=0, gridY=2)
        self.fgColor = gtk.ColorButton(gtk.gdk.color_parse(self.tw.defaults["fgColor"]))
        self.fgColor.set_alignment(0, 0.5)
        self.table.attach(self.fgColor, 1, 2, 2, 3, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)

        createLabel(self.table, text="Default Border Color", gridX=0, gridY=3)
        self.borderColor = gtk.ColorButton(gtk.gdk.color_parse(self.tw.defaults["borderColor"]))
        self.borderColor.set_alignment(0, 0.5)
        self.table.attach(self.borderColor, 1, 2, 3, 4, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)

        createLabel(self.table, text="Number of background styles", gridX=0, gridY=4)
        self.bgCount = createEntry(self.table, maxSize=6, width=8, text=str(self.tw.defaults["bgCount"]), gridX=1, gridY=4, xExpand=True, yExpand=True)

        self.layout.attach(self.table, 0, 2, 0, 1, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND, xpadding=20, ypadding=5)

        createButton(self.layout, text="Save", stock=gtk.STOCK_SAVE, name="save", gridX=0, gridY=1, xExpand=True, yExpand=True, handler=self.save)
        createButton(self.layout, text="Cancel", stock=gtk.STOCK_CANCEL, name="cancel", gridX=1, gridY=1, xExpand=True, yExpand=True, handler=self.quit)

        self.add(self.layout)

        self.show_all()
项目:griffith    作者:Strit    | 项目源码 | 文件源码
def run(self):
        tmp_dir = mkdtemp()
        griffith_list = open(os.path.join(tmp_dir,"movies"),"w")
        t = []

        def checkForNoneAndEncode(val):
            if val is None:
                return ''
            return val.encode('utf-8')

        movies = self.get_query().execute().fetchall()
        for movie in movies:
            t.append("%s | %s | %s | %s" % (movie['number'], \
                checkForNoneAndEncode(movie['o_title']), 
                checkForNoneAndEncode(movie['title']), 
                checkForNoneAndEncode(movie['director'])))

        griffith_list.write("<title>%s</title><br><br>" % _("My Movies List"))

        for movie in t:
            griffith_list.write(movie)
            griffith_list.write("<br>")

        griffith_list.close()

        # this is a mac, lets export to iPod's notes folder
        # TODO: windows and linux iPod autodetection
        if platform.system() == 'Darwin':
            thisPod=Path2iPod()
            thisPath=thisPod.returnPath()

            if thisPath:
                commands.getoutput('mv '+os.path.join(tmp_dir,"movies")+' "'+thisPath+'/Notes/"') # FIXME: WTF?
                gutils.info(_("List successfully exported to iPod."), self.parent_window)
            else:
                gutils.info(_("iPod is not connected."), self.parent_window)
        # this is not a mac, lets save the file
        else:
            filename = gutils.file_chooser(_("Export a %s document")%"iPod", action=gtk.FILE_CHOOSER_ACTION_SAVE, \
                buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_SAVE,gtk.RESPONSE_OK),name='ipod_griffith_list')
            if filename and filename[0]:
                overwrite = None
                if os.path.isfile(filename[0]):
                    if gutils.question(_("File exists. Do you want to overwrite it?"), self.parent_window):
                        overwrite = True
                    else:
                        overwrite = False
                if overwrite == True or overwrite is None:
                    shutil.copyfile(os.path.join(tmp_dir,"movies"), filename[0])
                    gutils.info(_("The list was successfully exported. Now you should move it to the 'Notes' folder on your iPod."), self.parent_window)