Python gi.repository.Gtk 模块,FileChooserDialog() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用gi.repository.Gtk.FileChooserDialog()

项目:PyIDE    作者:raggesilver    | 项目源码 | 文件源码
def createProject(self, *args):
        self.getLang()
        dialog = Gtk.FileChooserDialog("Please choose a folder", self, Gtk.FileChooserAction.SELECT_FOLDER, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, "Select", Gtk.ResponseType.OK))
        response = dialog.run()


        if response == Gtk.ResponseType.OK:

            projectPath = dialog.get_filename()
            self.projectPath = projectPath
            with open(os.path.join(projectPath, '.pyide-project.json'), 'w+') as f:
                defaultSettings = {
                    'path': projectPath,
                    'name': projectPath.split('/')[len(projectPath.split('/')) - 1],
                    'language': self.language
                }
                json.dump(defaultSettings, f, indent=4, sort_keys=True, separators=(',', ':'))

            self.createMainFile()

            os.execl(sys.executable, *([sys.executable]+sys.argv+[projectPath]))

        dialog.destroy()
项目:sbrick-controller    作者:wintersandroid    | 项目源码 | 文件源码
def on_save_as_configuration(self, action, param):
        dialog = Gtk.FileChooserDialog("Save Configuration As...", self.window,
                                       Gtk.FileChooserAction.SAVE,
                                       (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
        dialog.set_filename(self.configFile)

        self.add_filters(dialog)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            self.configFile = dialog.get_filename()
            self.save_configuration(self.configFile)

        dialog.destroy()

    # noinspection PyUnusedLocal
项目:sbrick-controller    作者:wintersandroid    | 项目源码 | 文件源码
def on_open_configuration(self, action, param):
        dialog = Gtk.FileChooserDialog("Open Configuration...", self.window,
                                       Gtk.FileChooserAction.OPEN,
                                       (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        dialog.set_filename(self.configFile)

        self.add_filters(dialog)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            self.configFile = dialog.get_filename()
            self.read_config()
            if self.window:
                self.window.close()
            self.window = MainWindow(application=self, title="SBrick Controller", config=self.config)
            self.window.present()
            # self.save_configuration(self.configFile)
        dialog.destroy()
项目:pyspc    作者:carlosqsilva    | 项目源码 | 文件源码
def on_file(self, button):

        dialog = Gtk.FileChooserDialog("Please choose a file", self,
                                       Gtk.FileChooserAction.OPEN,
                                       (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
        filter_csv = Gtk.FileFilter()
        filter_csv.set_name("CSV Files")
        filter_csv.add_pattern("*.csv")
        dialog.add_filter(filter_csv)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            path = dialog.get_filename()
            self.data = pd.read_csv(path)
            self.verticalbox.remove(self.scrollable_treelist)
            self.add_treeview()

        dialog.destroy()
项目:pyspc    作者:carlosqsilva    | 项目源码 | 文件源码
def on_file_clicked(self, widget):
        # dialog = Gtk.FileChooserDialog("Please choose a file", self,
        #                                Gtk.FileChooserAction.OPEN,
        #                                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
        #                                 Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
        # response = dialog.run()
        # if response == Gtk.ResponseType.OK:
        #     path = dialog.get_filename()
        #     # self.open_file.set_label("File Selected: %s" % os.path.basename(path))
        #     self.data = pd.read_csv(path)

        # elif response == Gtk.ResponseType.CANCEL:
        #     print("Cancel clicked")

        # dialog.destroy()
        dialog = FileDialog(self)
        # dialog.show_all()
        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            self.data = dialog.data
        dialog.destroy()
项目:Ebook-Viewer    作者:michaldaniel    | 项目源码 | 文件源码
def show_dialog(self, importing=False):
        """
        Displays FileChooserDialog with ePub file filters and returns Gtk.ResponseType and filename string
        :return (response, filename):
        """
        dialog = Gtk.FileChooserDialog(_("Please choose a file"), self, Gtk.FileChooserAction.OPEN,
                                       (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        # Always start in user dir
        dialog.set_current_folder(path.expanduser("~"))

        # Add filters so only .epub files show
        # TODO: Filter list for all conversion supported ebooks
        self.__add_filters(dialog, importing)

        response = dialog.run()
        filename = dialog.get_filename()
        dialog.destroy()

        return response, filename
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def file_open_cb(self, *v):
        dialog = Gtk.FileChooserDialog(_("Open..."), self,
                                   Gtk.FileChooserAction.OPEN,
                                   (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                    Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
        dialog.set_default_response(Gtk.ResponseType.OK)
        if dialog.run() == Gtk.ResponseType.OK:
            filename = gu.decode_filename(dialog.get_filename())
            try:
                self.load_file(filename)
            except Exception, e:
                dialog.destroy()
                m = Gtk.MessageDialog(self, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR,
                        Gtk.ButtonsType.CLOSE,
                        _("Loading file '%(filename)s' failed: %(msg)s") %
                            {'filename': filename, 'msg': e})
                m.run()
                m.destroy()

            else:
                dialog.destroy()

        else:
            dialog.destroy()
项目:bcloud    作者:wangYanJava    | 项目源码 | 文件源码
def add_file_task(self, dir_name=None):
        '''??????, ?????????????'''
        file_dialog = Gtk.FileChooserDialog(_('Choose Files..'),
                self.app.window, Gtk.FileChooserAction.OPEN,
                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                 Gtk.STOCK_OK, Gtk.ResponseType.OK))
        file_dialog.set_modal(True)
        file_dialog.set_select_multiple(True)
        file_dialog.set_default_response(Gtk.ResponseType.OK)
        response = file_dialog.run()
        if response != Gtk.ResponseType.OK:
            file_dialog.destroy()
            return
        source_paths = file_dialog.get_filenames()
        file_dialog.destroy()
        if source_paths:
            self.upload_files(source_paths, dir_name)
项目:bcloud    作者:wangYanJava    | 项目源码 | 文件源码
def add_folder_task(self, dir_name=None):
        '''??????, ??????????????'''
        folder_dialog = Gtk.FileChooserDialog(_('Choose Folders..'),
                self.app.window, Gtk.FileChooserAction.SELECT_FOLDER,
                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                 Gtk.STOCK_OK, Gtk.ResponseType.OK))
        folder_dialog.set_modal(True)
        folder_dialog.set_select_multiple(True)
        folder_dialog.set_default_response(Gtk.ResponseType.OK)
        folder_dialog.set_current_folder(Config.HOME_DIR)
        response = folder_dialog.run()
        if response != Gtk.ResponseType.OK:
            folder_dialog.destroy()
            return
        source_paths = folder_dialog.get_filenames()
        folder_dialog.destroy()
        if source_paths:
            self.upload_files(source_paths, dir_name)
项目:bcloud    作者:wangYanJava    | 项目源码 | 文件源码
def on_download_to_activated(self, menu_item):
        '''????/??????????.'''
        tree_paths = self.iconview.get_selected_items()
        if not tree_paths:
            return

        dialog = Gtk.FileChooserDialog(_('Save to...'), self.app.window,
                Gtk.FileChooserAction.SELECT_FOLDER,
                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                 Gtk.STOCK_OK, Gtk.ResponseType.OK))
        response = dialog.run()
        if response != Gtk.ResponseType.OK:
            dialog.destroy()
            return
        dirname = dialog.get_filename()
        dialog.destroy()

        pcs_files = [self.get_pcs_file(p) for p in tree_paths]
        self.app.blink_page(self.app.download_page)
        self.app.download_page.add_tasks(pcs_files, dirname)
项目:ez_gpg    作者:sgnn7    | 项目源码 | 文件源码
def get_filename(window, title="Open..."):
        dialog = Gtk.FileChooserDialog(title,
                                       window,
                                       Gtk.FileChooserAction.OPEN,
                                       (Gtk.STOCK_CANCEL,
                                        Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_OPEN,
                                        Gtk.ResponseType.OK))

        dialog.set_default_response(Gtk.ResponseType.OK)
        UiUtils._set_keyfile_filter(dialog)

        response = dialog.run()

        filename = None
        if response == Gtk.ResponseType.OK:
            filename = dialog.get_filename()

        dialog.destroy()
        return filename
项目:bokken    作者:thestr4ng3r    | 项目源码 | 文件源码
def _save(self, widget, data):
        chooser = Gtk.FileChooserDialog(title=None,action=Gtk.FileChooserAction.SAVE, buttons=(Gtk.STOCK_CANCEL,Gtk.ResponseType.CANCEL,Gtk.STOCK_OPEN,Gtk.ResponseType.OK))
        response = chooser.run()

        if response == Gtk.ResponseType.OK:
            all = ['asm', 'hex', 'str']
            filename = chooser.get_filename()
            if data != 'all':
                output = open(filename + '.' + data, 'wb')
                content = self._get_content(data)
                output.write(content)
                output.close()
            else:
                for fmt in all:
                    output = open(filename + '.' + fmt, 'wb')
                    content = self._get_content(fmt)
                    output.write(content)
                    output.close()
        chooser.destroy()
项目:bokken    作者:thestr4ng3r    | 项目源码 | 文件源码
def on_open(self, action):
        chooser = Gtk.FileChooserDialog(title="Open dot File",
                                        action=Gtk.FileChooserAction.OPEN,
                                        buttons=(Gtk.STOCK_CANCEL,
                                                 Gtk.ResponseType.CANCEL,
                                                 Gtk.STOCK_OPEN,
                                                 Gtk.ResponseType.OK))
        chooser.set_default_response(Gtk.ResponseType.OK)
        chooser.set_current_folder(self.last_open_dir)
        filter = Gtk.FileFilter()
        filter.set_name("Graphviz dot files")
        filter.add_pattern("*.dot")
        chooser.add_filter(filter)
        filter = Gtk.FileFilter()
        filter.set_name("All files")
        filter.add_pattern("*")
        chooser.add_filter(filter)
        if chooser.run() == Gtk.ResponseType.OK:
            filename = chooser.get_filename()
            self.last_open_dir = chooser.get_current_folder()
            chooser.destroy()
            self.open_file(filename)
        else:
            chooser.destroy()
项目:chromecast-player    作者:wa4557    | 项目源码 | 文件源码
def main(self):
        dialog = Gtk.FileChooserDialog("Please choose a file", self.win,
            Gtk.FileChooserAction.OPEN,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
        self.button1 = dialog.add_button('Add to playlist', Gtk.ResponseType.OK)
        self.button2 = dialog.add_button('Play now', Gtk.ResponseType.OK)
        self.button1.connect("clicked", self._button_clicked)
        self.button2.connect("clicked", self._button_clicked)
        dialog.set_select_multiple(True)
        self.add_filters(dialog)
        ret = None
        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            ret = (dialog.get_uris(), self.but)
        dialog.destroy()
        return ret
项目:Remarkable    作者:jamiemcg    | 项目源码 | 文件源码
def save_as(self, widget):
        self.window.set_sensitive(False)
        chooser = Gtk.FileChooserDialog(title=None, action=Gtk.FileChooserAction.SAVE, buttons=(
            Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
        chooser.set_do_overwrite_confirmation(True)
        title = self.name.split("/")[-1]
        chooser.set_title("Save As: " + title)
        response = chooser.run()
        if response == Gtk.ResponseType.OK:
            file = open(chooser.get_filename(), 'w')
            self.name = chooser.get_filename()
            text = self.text_buffer.get_text(self.text_buffer.get_start_iter(), self.text_buffer.get_end_iter(), False)
            file.write(text)
            file.close()
            self.text_buffer.set_modified(False)
            title = self.name.split("/")[-1]
            self.window.set_title("Remarkable: " + title)
        elif response == Gtk.ResponseType.CANCEL:
            pass
        chooser.destroy()
        self.window.set_sensitive(True)
项目:Remarkable    作者:jamiemcg    | 项目源码 | 文件源码
def save_html(self, data):
        html = data
        chooser = Gtk.FileChooserDialog("Export HTML", None, Gtk.FileChooserAction.SAVE,
                                        (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                         Gtk.STOCK_OK, Gtk.ResponseType.OK))
        html_filter = Gtk.FileFilter()
        html_filter.set_name("HTML Files")
        html_filter.add_pattern("*.html")
        html_filter.add_pattern("*.htm")
        chooser.set_do_overwrite_confirmation(True)
        chooser.add_filter(html_filter)
        response = chooser.run()
        if response == Gtk.ResponseType.OK:
            file_name = chooser.get_filename()
            if not file_name.endswith(".html"):
                file_name += ".html"
            file = open(file_name, 'w')
            soup = BeautifulSoup(html, "lxml")

            file.write(soup.prettify())
            file.close()
        elif response == Gtk.ResponseType.CANCEL:
            pass
        chooser.destroy()
        self.window.set_sensitive(True)
项目:ghetto_omr    作者:pohzhiee    | 项目源码 | 文件源码
def on_file_clicked(self, widget):
        dialog = Gtk.FileChooserDialog("Please choose a file", self.get_toplevel(),
                                       Gtk.FileChooserAction.OPEN,
                                       (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        self.add_filters(dialog)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            print("Open clicked")
            print("File selected: " + dialog.get_filename())
            self.text_file.set_text(dialog.get_filename())
        elif response == Gtk.ResponseType.CANCEL:
            print("Cancel clicked")

        dialog.destroy()
项目:ghetto_omr    作者:pohzhiee    | 项目源码 | 文件源码
def on_folder_clicked(self, widget):
        dialog = Gtk.FileChooserDialog("Please choose a folder", self.get_toplevel(),
                                       Gtk.FileChooserAction.SELECT_FOLDER,
                                       (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                        "Select", Gtk.ResponseType.OK))
        dialog.set_default_size(800, 400)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            print("Select clicked")
            str1 = "Folder selected: " + dialog.get_filename()
            print(str1)
            self.fold_str = str1
            self.text_folder.set_text(dialog.get_filename())
        elif response == Gtk.ResponseType.CANCEL:
            print("Cancel clicked")

        dialog.destroy()
项目:ghetto_omr    作者:pohzhiee    | 项目源码 | 文件源码
def on_file_clicked(self, widget):
        dialog = Gtk.FileChooserDialog("Please choose a file", self,
            Gtk.FileChooserAction.OPEN,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        self.add_filters(dialog)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            print("Open clicked")
            print("File selected: " + dialog.get_filename())
            self.text_file.set_text(dialog.get_filename())
        elif response == Gtk.ResponseType.CANCEL:
            print("Cancel clicked")

        dialog.destroy()
项目:ghetto_omr    作者:pohzhiee    | 项目源码 | 文件源码
def on_folder_clicked(self, widget):
        dialog = Gtk.FileChooserDialog("Please choose a folder", self,
            Gtk.FileChooserAction.SELECT_FOLDER,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             "Select", Gtk.ResponseType.OK))
        dialog.set_default_size(800, 400)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            print("Select clicked")
            str1 = "Folder selected: " + dialog.get_filename()
            print(str1)
            self.fold_str = str1
            self.text_folder.set_text(dialog.get_filename())
        elif response == Gtk.ResponseType.CANCEL:
            print("Cancel clicked")

        dialog.destroy()
项目:poseidon    作者:sidus-dev    | 项目源码 | 文件源码
def force_save(self, content, name):

        d = Gtk.FileChooserDialog("{}: {}".format(_("Save as"), name), self,
            Gtk.FileChooserAction.SAVE,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             Gtk.STOCK_SAVE, Gtk.ResponseType.OK))

        d.set_current_name(name)
        d.set_default_size(int(width), int(height))
        response = d.run()

        if response == Gtk.ResponseType.OK:

            if os.path.exists(d.get_filename()):
                if self.do_decision(name): pass
                else:
                    d.destroy()
                    return True

            with open(d.get_filename(), 'w') as f:
                f.write(content)
                f.close()

        d.destroy()
项目:poseidon    作者:sidus-dev    | 项目源码 | 文件源码
def import_bookmarks(self):

        d = Gtk.FileChooserDialog(_("Import a HTML bookmark file"), self,
            Gtk.FileChooserAction.OPEN,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
            Gtk.STOCK_OPEN, Gtk.ResponseType.ACCEPT))

        d.set_default_size(int(width), int(height))

        filter_html = Gtk.FileFilter()
        filter_html.set_name("HTML files")
        filter_html.add_mime_type("text/html")
        d.add_filter(filter_html)

        response = d.run()

        if response == Gtk.ResponseType.ACCEPT:

            filename = d.get_filename()
            d.destroy()
            return filename

        d.destroy()
项目:cavalcade    作者:worron    | 项目源码 | 文件源码
def gtk_open_file(parent, filter_=None):
    """Gtk open file dialog"""
    dialog = Gtk.FileChooserDialog(
        "Select image file", parent, Gtk.FileChooserAction.OPEN,
        (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)
    )

    if filter_ is not None:
        dialog.add_filter(filter_)

    response = dialog.run()
    if response != Gtk.ResponseType.OK:
        is_ok, file_ = False, None
    else:
        is_ok = True
        file_ = dialog.get_filename()

    dialog.destroy()
    return is_ok, file_
项目:gpt    作者:encarsia    | 项目源码 | 文件源码
def on_folder_clicked(self):
        Gtk.Window.__init__(self, title=_("Change working directory"))
        dialog = Gtk.FileChooserDialog(_("Choose directory"), self,
            Gtk.FileChooserAction.SELECT_FOLDER,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             _("Apply"), Gtk.ResponseType.OK))
        dialog.set_default_size(800, 400)
        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            print(_("Select clicked"))
            print(_("Folder selected: ") + dialog.get_filename())
            self.selectedfolder = dialog.get_filename()
        elif response == Gtk.ResponseType.CANCEL:
            print(_("Cancel clicked"))
            self.selectedfolder = cli.stdir

        dialog.destroy()
项目:MTTT    作者:roxana-lafuente    | 项目源码 | 文件源码
def _on_file_clicked(self, widget, labelToUpdate, tab_name = "undefined"):
        """@brief     Get file path from dialog."""
        dialog = Gtk.FileChooserDialog("Please choose a file", None,
                                       Gtk.FileChooserAction.OPEN,
                                       (Gtk.STOCK_CANCEL,
                                        Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        self._add_file_filters(dialog)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            labelToUpdate.set_text(dialog.get_filename())
        elif response == Gtk.ResponseType.CANCEL:
            labelToUpdate.set_text("")

        if tab_name == "Machine translation":
            self.mt_out_text = os.path.dirname(dialog.get_filename())
        dialog.destroy()
项目:MTTT    作者:roxana-lafuente    | 项目源码 | 文件源码
def _on_dir_clicked(self, widget, labelToUpdate, command = ""):
        """@brief     Get folder path from dialog."""
        dialog = Gtk.FileChooserDialog("Please choose a directory", None,
                                       Gtk.FileChooserAction.OPEN,
                                       (Gtk.STOCK_CANCEL,
                                        Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        self._add_dir_filters(dialog)
        dialog.set_action(Gtk.FileChooserAction.SELECT_FOLDER)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            labelToUpdate.set_text(dialog.get_filename())
        elif response == Gtk.ResponseType.CANCEL:
            labelToUpdate.set_text("")

        if "change output directory" in command:
            self.output_directory = dialog.get_filename()
            self.post_editing_output.set_text(self.output_directory)
            self.evaluation_output.set_text(self.output_directory)

        dialog.destroy()
        if command == "change output directory and maybe create post edition table":
            self._check_if_both_files_are_choosen_post_edition(None, "")
项目:SafeEyes    作者:slgobinath    | 项目源码 | 文件源码
def select_image(self, button):
        """
        Show a file chooser dialog and let the user to select an image.
        """
        dialog = Gtk.FileChooserDialog(_('Please select an image'), self.window, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                       Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        png_filter = Gtk.FileFilter()
        png_filter.set_name("PNG files")
        png_filter.add_mime_type("image/png")
        png_filter.add_pattern("*.png")
        dialog.add_filter(png_filter)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            self.break_config['image'] = dialog.get_filename()
            pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(self.break_config['image'], 16, 16, True)
            self.img_break.set_from_pixbuf(pixbuf)
        elif response == Gtk.ResponseType.CANCEL:
            self.break_config.pop('image', None)
            self.img_break.set_from_stock('gtk-missing-image', Gtk.IconSize.BUTTON)

        dialog.destroy()
项目:sound-organiser-offline-app    作者:nils-van-zuijlen    | 项目源码 | 文件源码
def on_open_file_activate(self, image_menu_item):
        """Opening of a file"""
        dialog = Gtk.FileChooserDialog(action=Gtk.FileChooserAction.OPEN)
        dialog.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
            Gtk.STOCK_OPEN, Gtk.ResponseType.OK)
        dialog.set_transient_for(self.main_widget)
        file_filter = Gtk.FileFilter()
        file_filter.add_pattern("*.theatre")
        dialog.add_filter(file_filter)
        dialog.modal = True
        answer = dialog.run()
        try:
            if answer == Gtk.ResponseType.OK:
                self._open_file_callback(dialog.get_filename())
        finally:
            dialog.destroy()
项目:yt-browser    作者:juanfgs    | 项目源码 | 文件源码
def on_download_clicked(self,button,video_data):
        """ Show the file dialog """
        file_chooser_dialog = Gtk.FileChooserDialog("Elegir donde guardar el video", self.window, Gtk.FileChooserAction.SAVE,
                                                    (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                                     Gtk.STOCK_SAVE, Gtk.ResponseType.OK))

        file_chooser_dialog.set_current_name(video_data["title"])



        if file_chooser_dialog.run() == Gtk.ResponseType.OK:
            filename = file_chooser_dialog.get_filename()

            row  = button.get_parent().get_parent()

            # for widget in button.get_parent().get_children():
            #     if widget.__class__.__name__ == 'Button':
            #         widget.destroy()
            video_iter = self.add_video_to_queue(video_data)
            self.video_list.show_all()
            file_chooser_dialog.destroy()

            if video_data["action"] == "convert": #add postprocessing if convert was pressed
                self.backend.convert(True)

            self.download_video_thread(video_data["video_id"], filename,video_iter)
        else:
            file_chooser_dialog.destroy()
项目:aniwall    作者:worron    | 项目源码 | 文件源码
def run(self, path_suggest=None, name_suggest=None):
        """Activate dialog"""
        dialog = Gtk.FileChooserDialog(
            self.title, self.parent, self.action,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, self.action_button, Gtk.ResponseType.OK)
        )

        # set initial location and file name
        if path_suggest is not None:
            dialog.set_current_folder(path_suggest)
        else:
            dialog.set_current_folder(self.homedir)
        if name_suggest is not None:
            dialog.set_current_name(name_suggest)

        # listen response
        is_ok, path, filename = False, None, None
        response = dialog.run()

        if response == Gtk.ResponseType.OK:
            # get data
            is_ok = True
            path = dialog.get_current_folder()
            if self.action != Gtk.FileChooserAction.SELECT_FOLDER:
                filename = dialog.get_filename()

        # clean up
        dialog.destroy()
        return is_ok, path, filename
项目:mama    作者:maateen    | 项目源码 | 文件源码
def __init__(self):
        w=Gtk.Window()
        dialog = Gtk.FileChooserDialog(_("Choose a file"), w,Gtk.FileChooserAction.OPEN,(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
        dialog.set_default_size(800, 400)

        response = dialog.run()
        self.module = '-1'
        if response == Gtk.ResponseType.OK:
            self.module=dialog.get_filename()
        elif response == Gtk.ResponseType.CANCEL:
            print("Cancel clicked")

        dialog.destroy()
项目:Dict-O-nator    作者:theawless    | 项目源码 | 文件源码
def __init__(self, window: Gtk.Window):

        """Constructor.

        :param window: current window to set as parent.
        """
        self.owner = window
        self.file_chooser = Gtk.FileChooserDialog("Save file", window, Gtk.FileChooserAction.SAVE, (
            Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
        # Sets whether we get the overwrite confirmation
        self.file_chooser.set_do_overwrite_confirmation(True)
        self.save_possible = False
项目:ubi-virtual-assistant    作者:Alzemand    | 项目源码 | 文件源码
def on_button_clicked(self,widget):
        dialog =Gtk.FileChooserDialog("Select folder",None,Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
        dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        filter = Gtk.FileFilter()
        filter.set_name("Folder")
        filter.add_pattern("*")  # whats the pattern for a folder
        dialog.add_filter(filter)
        if dialog.run() == Gtk.ResponseType.ACCEPT:
            dialog.hide()
            print(dialog.get_filename())
            self.button.set_label(dialog.get_filename())
        dialog.destroy()
项目:ubi-virtual-assistant    作者:Alzemand    | 项目源码 | 文件源码
def on_button_clicked(self,widget):
        dialog =Gtk.FileChooserDialog("Select folder",None,Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
        dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        filter = Gtk.FileFilter()
        filter.set_name("Folder")
        filter.add_pattern("*")  # whats the pattern for a folder
        dialog.add_filter(filter)
        if dialog.run() == Gtk.ResponseType.ACCEPT:
            dialog.hide()
            print(dialog.get_filename())
            self.button.set_label(dialog.get_filename())
        dialog.destroy()
项目:PyIDE    作者:raggesilver    | 项目源码 | 文件源码
def openProject(self, *args):
        dialog = Gtk.FileChooserDialog('Select a project folder', self, Gtk.FileChooserAction.SELECT_FOLDER,(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
        response = dialog.run()


        if response == Gtk.ResponseType.OK:
            projectPath = dialog.get_filename()

            os.execl(sys.executable, *([sys.executable]+sys.argv+[projectPath]))

        dialog.destroy()
项目:pyspc    作者:carlosqsilva    | 项目源码 | 文件源码
def on_save_clicked(self, widget):
        dialog = Gtk.FileChooserDialog("Please choose a filename to save", self,
                                       Gtk.FileChooserAction.SAVE,
                                       (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
        dialog.set_current_name("Untitled.png")
        dialog.set_do_overwrite_confirmation(True)
        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            self.graph.save(dialog.get_filename(), dpi=600)

        dialog.destroy()
项目:simbuto    作者:nobodyinperson    | 项目源码 | 文件源码
def open_file_dialog(self, *args):
        # create a dialog
        dialog = Gtk.FileChooserDialog(
            _("Please choose a file"), # title
            self("main_applicationwindow"), # parent
            Gtk.FileChooserAction.OPEN, # Action
            # Buttons (obviously not possible with glade!?)
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
            Gtk.STOCK_OPEN, Gtk.ResponseType.OK)
            )

        # add the filter
        dialog.add_filter(self.simbuto_filefilter)

        response = dialog.run() # run the dialog
        if response == Gtk.ResponseType.OK: # file selected
            filename = dialog.get_filename()
            self.logger.debug(_("File '{}' selected").format(filename))
            # fill the editor
            self.fill_editor_from_file(filename)
        elif response == Gtk.ResponseType.CANCEL: # cancelled
            self.logger.debug(_("File selection cancelled"))
        else: # something else
            self.logger.debug(_("File selection dialog was closed"))

        dialog.destroy() # destroy the dialog, we don't need it anymore
项目:simbuto    作者:nobodyinperson    | 项目源码 | 文件源码
def saveas_dialog(self, *args):
        # create a dialog
        dialog = Gtk.FileChooserDialog(
            _("Please select a saving destination"), # title
            self("main_applicationwindow"), # parent
            Gtk.FileChooserAction.SAVE, # Action
            # Buttons (obviously not possible with glade!?)
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
            Gtk.STOCK_SAVE, Gtk.ResponseType.OK)
            )

        # add the filter
        dialog.add_filter(self.simbuto_filefilter)

        response = dialog.run() # run the dialog
        if response == Gtk.ResponseType.OK: # file selected
            filename = dialog.get_filename()
            self.logger.debug(_("File '{}' selected").format(filename))
            if not filename.endswith(".simbuto"):
                filename = "{}.simbuto".format(filename)
            # save
            self.save_current_budget_to_file(filename)
        elif response == Gtk.ResponseType.CANCEL: # cancelled
            self.logger.debug(_("File selection cancelled"))
        else: # something else
            self.logger.debug(_("File selection dialog was closed"))

        dialog.destroy() # destroy the dialog, we don't need it anymore
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def on_open(self, widget):
        """
        Open a FileChooserDialog and select a file.
        Load into this editor window if it is empty and unused,
        if not load into a new one.

        This method will catch exceptions raised while loading the file
        and display a dialog. Then it will destroy any newly created
        dialog.
        """
        dialog = Gtk.FileChooserDialog(None, self,
            Gtk.FileChooserAction.OPEN,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             Gtk.STOCK_OK, Gtk.ResponseType.OK))
        dialog.set_current_folder(self.savedir)
        ret = dialog.run()
        if ret == Gtk.ResponseType.OK:
            try:
                new_file = decode_filename(dialog.get_filename())
                assert new_file not in self.instance_dict
                win = self.__class__(new_file)
                win.show_all()
                win.set_title(new_file)

                if (not self.m_filename) and (not self.m_changed):
                    del self.instance_dict[self.get_idict_key()]
                    self.destroy()
            except Exception, e:
                # Since we catch all sorts of exceptions here, we don't have
                # to do handle string to int conversion in
                # PractiseSheet.parse_file. Just let int() raise ValueException
                # if the string in not an integer.

                if 'msg1' in dir(e):
                    solfege.win.display_error_message2(getattr(e, 'msg1', ''),
                        getattr(e, 'msg2', ''))

                else:
                    display_exception_message(e)
        dialog.destroy()
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def get_save_as_dialog(self):
        dialog = Gtk.FileChooserDialog(_("Save As..."), self,
            Gtk.FileChooserAction.SAVE,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             Gtk.STOCK_OK, Gtk.ResponseType.OK))
        dialog.set_default_response(Gtk.ResponseType.OK)
        return dialog
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def select_empty_directory(self, title):
        msg = _("Select an empty directory, since we want to fill it with files.")
        dialog = Gtk.FileChooserDialog(title,
            self, Gtk.FileChooserAction.SELECT_FOLDER,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             Gtk.STOCK_OK, Gtk.ResponseType.OK))
        label = Gtk.Label(label=msg)
        label.show()
        dialog.vbox.pack_start(label, False, False, padding=0)
        while 1:
            res = dialog.run()
            if res in (Gtk.ResponseType.CANCEL, Gtk.ResponseType.DELETE_EVENT):
                dialog.destroy()
                return

            elif res == Gtk.ResponseType.OK:

                if os.listdir(decode_filename(dialog.get_filename())):
                    msg_dlg = Gtk.MessageDialog(self, Gtk.DialogFlags.MODAL,
                        Gtk.MessageType.INFO, Gtk.ButtonsType.OK, msg)
                    msg_dlg.run()
                    msg_dlg.destroy()

                else:
                    break
        ret = decode_filename(dialog.get_filename())
        dialog.destroy()
        return ret
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def file_save_as_cb(self, *v):
        self.store_data_from_ui()
        dialog = Gtk.FileChooserDialog(_("Save as..."), self,
                                  Gtk.FileChooserAction.SAVE,
                                   (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                    Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
        dialog.set_default_response(Gtk.ResponseType.OK)

        if dialog.run() == Gtk.ResponseType.OK:
            self.m_P.m_filename = gu.decode_filename(dialog.get_filename())
            self.save_file()
        dialog.destroy()
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def __init__(self, parent):
        Gtk.FileChooserDialog.__init__(self, _("Select lesson file"),
            parent=parent,
            buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,))
        self.set_select_multiple(True)
        pv = LessonFilePreviewWidget(parent.m_model)
        pv.g_ok_button = self.add_button("gtk-ok", Gtk.ResponseType.OK)
        pv.g_ok_button.set_sensitive(False)
        pv.show()
        self.set_preview_widget(pv)
        self.connect('selection-changed', pv.update)
项目:ez_gpg    作者:sgnn7    | 项目源码 | 文件源码
def get_save_filename(window, filename, title="Save..."):
        dialog = Gtk.FileChooserDialog(title,
                                       window,
                                       Gtk.FileChooserAction.SAVE,
                                       (Gtk.STOCK_CANCEL,
                                        Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_SAVE,
                                        Gtk.ResponseType.ACCEPT))

        dialog.set_default_response(Gtk.ResponseType.OK)
        dialog.set_do_overwrite_confirmation(True)
        dialog.set_current_name(filename)
        UiUtils._set_save_keyfile_filter(dialog)

        response = dialog.run()

        filename = None
        armor = True
        if response == Gtk.ResponseType.ACCEPT:
            filename = dialog.get_filename()

            if dialog.get_filter().get_name() == 'Encoded key':
                armor = False

            # Suffix the filename
            if not (filename.endswith('.asc') or filename.endswith('.gpg')):
                suffix = '.asc'
                if not armor:
                    suffix = '.gpg'

                filename += suffix

            print("Filename chosen as:", filename)

        dialog.destroy()
        return filename, armor
项目:MokaPlayer    作者:vedard    | 项目源码 | 文件源码
def __ask_for_music_folder(self):
        dialog = Gtk.FileChooserDialog("Select where is your music", self,
                                       Gtk.FileChooserAction.SELECT_FOLDER,
                                       (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                        "Select", Gtk.ResponseType.OK))

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            self.player.library.musics_folder = dialog.get_filename()
            self.on_library_scan_activate(None)
        dialog.destroy()
项目:bokken    作者:thestr4ng3r    | 项目源码 | 文件源码
def select_file(self, widget):
        chooser = Gtk.FileChooserDialog(title="Select target",action=Gtk.FileChooserAction.OPEN,
                              buttons=(Gtk.STOCK_CANCEL,Gtk.ResponseType.CANCEL,Gtk.STOCK_OPEN,Gtk.ResponseType.OK))
        self.resp = chooser.run()
        if self.resp == Gtk.ResponseType.OK:
            self.file_name = chooser.get_filename()
            self.input_entry.get_child().set_text(self.file_name)
        chooser.destroy()
项目:bokken    作者:thestr4ng3r    | 项目源码 | 文件源码
def select_file(self, widget, icon_pos='', event=''):
        if self.input_entry2.get_text():
            self.get_file(self.input_entry2)
            self.response(0)
        else:
            chooser = Gtk.FileChooserDialog(title=None,action=Gtk.FileChooserAction.OPEN,
                      buttons=(Gtk.STOCK_CANCEL,Gtk.ResponseType.CANCEL,Gtk.STOCK_OPEN,Gtk.ResponseType.OK))
            self.resp = chooser.run()
            if self.resp == Gtk.ResponseType.DELETE_EVENT or self.resp == Gtk.ResponseType.REJECT or self.resp == Gtk.ResponseType.CANCEL:
                chooser.destroy()
            else:
                self.file_name = chooser.get_filename()
                self.input_entry2.set_text(self.file_name)
                chooser.destroy()
项目:MPV-VJ2    作者:paulguy    | 项目源码 | 文件源码
def saveSession(self, button):
        dialog = Gtk.FileChooserDialog("Save File",
                                       self,
                                       Gtk.FileChooserAction.SAVE)
        dialog.add_button("_Cancel", Gtk.ResponseType.CANCEL)
        dialog.add_button("_Save", Gtk.ResponseType.ACCEPT)
        dialog.set_do_overwrite_confirmation(True)
        dialog.connect('response', self.saveSessionResponse)
        dialog.show_all()
项目:MPV-VJ2    作者:paulguy    | 项目源码 | 文件源码
def loadSession(self, button):
        dialog = Gtk.FileChooserDialog("Load File",
                                       self,
                                       Gtk.FileChooserAction.OPEN)
        dialog.add_button("_Cancel", Gtk.ResponseType.CANCEL)
        dialog.add_button("_Load", Gtk.ResponseType.ACCEPT)
        dialog.connect('response', self.loadSessionResponse)
        dialog.show_all()
项目:ibus-typing-booster    作者:mike-fabian    | 项目源码 | 文件源码
def on_learn_from_file_clicked(self, dummy_widget):
        '''
        The button to learn from a user supplied text file
        has been clicked.
        '''
        SETUP_UI.learn_from_file_button.set_sensitive(False)
        filename = u''
        chooser = Gtk.FileChooserDialog(
            _('Open File ...'), SETUP_UI.builder.get_object('main_dialog'),
            Gtk.FileChooserAction.OPEN,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
        response = chooser.run()
        if response == Gtk.ResponseType.OK:
            filename = chooser.get_filename()
        chooser.destroy()
        while Gtk.events_pending():
            Gtk.main_iteration()
        if filename and os.path.isfile(filename):
            if SETUP_UI.tabsqlitedb.read_training_data_from_file(filename):
                dialog = Gtk.MessageDialog(
                    parent=SETUP_UI.builder.get_object('main_dialog'),
                    flags=Gtk.DialogFlags.MODAL,
                    message_type=Gtk.MessageType.INFO,
                    buttons=Gtk.ButtonsType.OK,
                    message_format=(
                        _("Learned successfully from file %(filename)s.")
                        %{'filename': filename}))
            else:
                dialog = Gtk.MessageDialog(
                    parent=SETUP_UI.builder.get_object('main_dialog'),
                    flags=Gtk.DialogFlags.MODAL,
                    message_type=Gtk.MessageType.ERROR,
                    buttons=Gtk.ButtonsType.OK,
                    message_format=(
                        _("Learning from file %(filename)s failed.")
                        %{'filename': filename}))
            dialog.run()
            dialog.destroy()
        SETUP_UI.learn_from_file_button.set_sensitive(True)