Python gi.repository.Gtk 模块,STOCK_OPEN 实例源码

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

项目: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 __init__(self, filename=None):
        self.m_instance_number = EditorDialogBase.instance_counter
        EditorDialogBase.instance_counter += 1
        self.m_filename = filename
        self.m_savetime = time.time()
        self.connect('delete_event', self.on_delete_event)
        self.g_ui_manager = Gtk.UIManager()
        accelgroup = self.g_ui_manager.get_accel_group()
        self.add_accel_group(accelgroup)

        self.g_actiongroup = Gtk.ActionGroup('')
        self.g_actiongroup.add_actions([
         ('Close', Gtk.STOCK_CLOSE, None, None, None, self.close_window),
         ('Save', Gtk.STOCK_SAVE, None, None, None, self.on_save),
         ('SaveAs', Gtk.STOCK_SAVE_AS, None, None, None, self.on_save_as),
         ('New', Gtk.STOCK_NEW, None, None, None, self.new_file),
         ('Open', Gtk.STOCK_OPEN, None, None, None, self.on_open),
         ('Help', Gtk.STOCK_HELP, None, None, None, self.on_show_help),
        ])
项目: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()
项目: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()
项目: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_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()
项目: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_
项目:plotcommander    作者:FilipDominec    | 项目源码 | 文件源码
def __init__(self):
        super(CellRendererFadeWindow, self).__init__(title="CellRendererFade Example")

        self.set_default_size(200, 200)
        self.liststore = Gtk.ListStore(str, str)
        self.liststore.append(["New", Gtk.STOCK_NEW])
        self.liststore.append(["Open", Gtk.STOCK_OPEN])
        self.liststore.append(["Save", Gtk.STOCK_SAVE])

        treeview = Gtk.TreeView(model=self.liststore)
        renderer_text = Gtk.CellRendererText()
        column_text = Gtk.TreeViewColumn("Text", renderer_text, text=0)
        treeview.append_column(column_text)

        renderer_pixbuf = CellRenderFade(param=0.001)
        column_pixbuf = Gtk.TreeViewColumn("Image", renderer_pixbuf, stock_id=1)
        treeview.append_column(column_pixbuf)
        self.add(treeview)
项目: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()
项目: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()
项目: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()
项目: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
项目: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()
项目: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)
项目:Remarkable    作者:jamiemcg    | 项目源码 | 文件源码
def open(self, widget):
        start, end = self.text_buffer.get_bounds()
        text = self.text_buffer.get_text(start, end, False)

        self.window.set_sensitive(False)
        chooser = Gtk.FileChooserDialog(title="Open File", action=Gtk.FileChooserAction.OPEN, buttons=(
            Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
        response = chooser.run()

        if response == Gtk.ResponseType.OK:
            # The user has selected a file
            selected_file = chooser.get_filename()

            if len(text) == 0 and not self.text_buffer.get_modified():
                # Current file is empty. Load contents of selected file into this view

                self.text_buffer.begin_not_undoable_action()
                file = open(selected_file, 'r')
                text = file.read()
                file.close()
                self.name = chooser.get_filename()
                self.text_buffer.set_text(text)
                title = chooser.get_filename().split("/")[-1]
                self.window.set_title("Remarkable: " + title)
                self.text_buffer.set_modified(False)
                self.text_buffer.end_not_undoable_action()
            else:
                # A file is already open. Load the selected file in a new Remarkable process
                subprocess.Popen(["remarkable", selected_file])

        elif response == Gtk.ResponseType.CANCEL:
            # The user has clicked cancel
            pass

        chooser.destroy()
        self.window.set_sensitive(True)
项目:XFWM_theme_creator    作者:Sjc1000    | 项目源码 | 文件源码
def load(self, *_):
        chooser = Gtk.FileChooserDialog('Please select a xfwm4 folder.', self,
            Gtk.FileChooserAction.SELECT_FOLDER, (Gtk.STOCK_CANCEL,
            Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
        response = chooser.run()
        if response == Gtk.ResponseType.OK:
            self.file_selecter.clean()
            folder = chooser.get_filename()
            self.load_files(folder)
            self.file_selecter.populate()
        chooser.destroy()
        return None
项目:poseidon    作者:sidus-dev    | 项目源码 | 文件源码
def open(self, view):

        d = Gtk.FileChooserDialog(_("Open 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))
        response = d.run()

        if response == Gtk.ResponseType.ACCEPT:

            view.load_uri("file://{}".format(d.get_filename()))

        d.destroy()
项目:indprog    作者:schlagenhauf    | 项目源码 | 文件源码
def __loadGraph(self, widget=None, data=None):
        dialog = Gtk.FileChooserDialog('Load Graph From File', self.w,
                Gtk.FileChooserAction.OPEN,
                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                 Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            print("Open clicked")
            print("File selected: " + dialog.get_filename())
        elif response == Gtk.ResponseType.CANCEL \
            or response == Gtk.ResponseType.CLOSE \
            or response == Gtk.ResponseType.DELETE_EVENT:
            print("Cancel clicked")

        dialog.destroy()
项目:hachoir3    作者:vstinner    | 项目源码 | 文件源码
def _select_clicked(self, widget):
        file_chooser = Gtk.FileChooserDialog("Ouvrir..", None,
                                             Gtk.FILE_CHOOSER_ACTION_OPEN,
                                             (Gtk.STOCK_CANCEL, Gtk.RESPONSE_CANCEL,
                                              Gtk.STOCK_OPEN, Gtk.RESPONSE_OK))
        file_chooser.set_default_response(Gtk.RESPONSE_OK)
        file_chooser.show()

        reponse = file_chooser.run()
        if reponse == Gtk.RESPONSE_OK:
            selected_file = file_chooser.get_filename()
            self.add_file(selected_file)
        file_chooser.destroy()
项目:cozy    作者:geigi    | 项目源码 | 文件源码
def locate(self, button):
        """
        Locate the file and update the database if the user selected one.
        """
        directory, filename = os.path.split(self.missing_file)
        dialog = Gtk.FileChooserDialog("Please locate the file " + filename, self.parent.window,
                                       Gtk.FileChooserAction.OPEN,
                                       (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        filter = Gtk.FileFilter()
        filter.add_pattern(filename)
        filter.set_name(filename)
        dialog.add_filter(filter)
        path, file_extension = os.path.splitext(self.missing_file)
        filter = Gtk.FileFilter()
        filter.add_pattern("*" + file_extension)
        filter.set_name(file_extension + " files")
        dialog.add_filter(filter)
        filter = Gtk.FileFilter()
        filter.add_pattern("*")
        filter.set_name(_("All files"))
        dialog.add_filter(filter)
        dialog.set_local_only(False)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            new_location = dialog.get_filename()
            Track.update(file=new_location).where(
                Track.file == self.missing_file).execute()

            directory, filename = os.path.split(new_location)
            importer.import_file(filename, directory, new_location, update=True)
            self.parent.refresh_content()
            self.dialog.destroy()
            self.parent.dialog_open = False
            load_file(Track.select().where(Track.file == new_location).get())
            play_pause(None, True)

        dialog.destroy()
项目:python-sense-emu    作者:RPi-Distro    | 项目源码 | 文件源码
def on_play(self, action, param):
        open_dialog = Gtk.FileChooserDialog(
            transient_for=self.window,
            title=_('Select the recording to play'),
            action=Gtk.FileChooserAction.OPEN)
        open_dialog.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
        open_dialog.add_button(Gtk.STOCK_OPEN, Gtk.ResponseType.ACCEPT)
        try:
            response = open_dialog.run()
            open_dialog.hide()
            if response == Gtk.ResponseType.ACCEPT:
                self.window.play(open_dialog.get_filename())
        finally:
            open_dialog.destroy()
项目:hubangl    作者:soonum    | 项目源码 | 文件源码
def on_load_clicked(self, widget):
        file_load_dialog = Gtk.FileChooserDialog(
                title="Load Session",
                action=Gtk.FileChooserAction.OPEN,
                buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                         Gtk.STOCK_OPEN, Gtk.ResponseType.ACCEPT)
        )
        file_load_dialog.set_icon_from_file(self.images.logo_favicon_path)
        file_load_dialog.set_modal(True)
        file_load_dialog.connect("response", self.on_load_response)
        file_load_dialog.run()
项目:gstation-edit    作者:fengalin    | 项目源码 | 文件源码
def run_file_chooser(self, action, proposed_name=None):
        folder = None
        if self.config.has_section('Import-Export'):
            folder = self.config.get('Import-Export', 'folder')

        title = 'Import'
        stock_ok = Gtk.STOCK_OPEN
        if action == Gtk.FileChooserAction.SAVE:
            stock_ok = Gtk.STOCK_SAVE
            title = 'Export'

        file_chooser = Gtk.FileChooserDialog(
                title, self.gtk_window, action,
                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                 stock_ok, Gtk.ResponseType.OK)
            )
        filter_sysex = Gtk.FileFilter()
        filter_sysex.set_name('Sysex files (.syx)')
        filter_sysex.add_pattern('*.syx')
        file_chooser.add_filter(filter_sysex)

        if Gtk.FileChooserAction.SAVE:
            file_chooser.set_do_overwrite_confirmation(True)

        if folder:
            file_chooser.set_current_folder(folder)
        if proposed_name:
            file_chooser.set_current_name('%s.syx'%(proposed_name))

        result = file_chooser.run()
        if result == Gtk.ResponseType.OK:
            filename = file_chooser.get_filename()
            if not self.config.has_section('Import-Export'):
                self.config.add_section('Import-Export')
            self.config.set('Import-Export', 'folder', path.dirname(filename))

        return (result, file_chooser)
项目:gdebi    作者:linuxmint    | 项目源码 | 文件源码
def on_open_activate(self, widget):
        #print "open"
        # build dialog
        self.window_main.set_sensitive(False)
        fs = Gtk.FileChooserDialog(parent=self.window_main,
                                   buttons=(Gtk.STOCK_CANCEL,
                                            Gtk.ResponseType.CANCEL,
                                            Gtk.STOCK_OPEN,
                                            Gtk.ResponseType.OK),
                                   action=Gtk.FileChooserAction.OPEN,
                                   title=_("Open Software Package"))
        fs.set_default_response(Gtk.ResponseType.OK)
        # set filter
        filter = Gtk.FileFilter()
        filter.add_pattern("*.deb")
        filter.set_name(_("Software packages"))
        #fs.add_filter(filter)
        fs.set_filter(filter)
        # run it!
        res = fs.run()
        fs.hide()
        if res == Gtk.ResponseType.OK:
            #print fs.get_filename()
            self.open(fs.get_filename())
        fs.destroy()
        self.window_main.set_sensitive(True)
项目:games_nebula    作者:yancharkin    | 项目源码 | 文件源码
def cb_button_run(self, button):

        self.main_window.hide()

        while Gtk.events_pending():
            Gtk.main_iteration()

        dialog = Gtk.FileChooserDialog(
            _("Choose a file to execute"),
            self.main_window,
            Gtk.FileChooserAction.OPEN,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        dialog.set_current_folder(self.wineprefix_path + '/drive_c')

        #filter1 = Gtk.FileFilter()
        #filter1.set_name("DOS/Windows executable")
        #filter1.add_mime_type("application/x-ms-dos-executable")
        #dialog.add_filter(filter1)

        file_filter = Gtk.FileFilter()
        file_filter.set_name("*.exe, *.msi, *.bat")
        file_filter.add_pattern("*.exe")
        file_filter.add_pattern("*.msi")
        file_filter.add_pattern("*.bat")
        dialog.add_filter(file_filter)

        response = dialog.run()

        if response == Gtk.ResponseType.OK:

            file_path = dialog.get_current_folder()

            if '.exe' in dialog.get_filename().split('/')[-1]:
                command = '$WINELOADER "' + dialog.get_filename() + '"'
            elif '.msi' in dialog.get_filename().split('/')[-1]:
                command = '$WINELOADER msiexec /i "' + dialog.get_filename() + '"'
            elif '.bat' in dialog.get_filename().split('/')[-1]:
                command = '$WINELOADER start /unix "' + dialog.get_filename() + '"'

            dialog.destroy()

            while Gtk.events_pending():
                Gtk.main_iteration()

            os.system('cd "' + file_path + '" && ' + command)

        elif response == Gtk.ResponseType.CANCEL:
            dialog.destroy()

        self.main_window.show()
项目:jcchess    作者:johncheetham    | 项目源码 | 文件源码
def add_engine(self, widget, data=None):
        dialog = Gtk.FileChooserDialog(
            _("Add UCI Engine.."),
            gv.gui.get_window(),
            Gtk.FileChooserAction.OPEN,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             Gtk.STOCK_OPEN, Gtk.ResponseType.OK)
        )
        dialog.set_default_response(Gtk.ResponseType.OK)
        dialog.set_current_folder(os.path.expanduser("~"))

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            fname = dialog.get_filename()
            # print "attempting to add new engine"
            path = dialog.get_filename()
            # use a new uci object so not to mess with main game engine
            u = uci.Uci("0")
            u.set_engine("addengine", path)
            errmsg, name = u.test_engine(path)
            if errmsg != "":
                err_dialog = Gtk.Dialog(_("Error Adding Engine"), None, 0,
                                        (Gtk.STOCK_OK, Gtk.ResponseType.OK))
                err_dialog.set_default_size(380, -1)
                lbl = Gtk.Label(label=errmsg)
                lbl.show()
                al = Gtk.Alignment.new(xalign=0.0, yalign=0.5,
                                       xscale=0.0, yscale=0.0)
                al.set_padding(20, 20, 20, 20)
                al.add(lbl)
                al.show()
                err_dialog.vbox.pack_start(al, True, False, 0)
                response = err_dialog.run()
                err_dialog.destroy()
            else:
                self.liststore.append([name, path])
                self.add_engine_to_list([name, path, {}])

        dialog.destroy()

    # Called from this module by clicking 'configure' button
    # or from gui.py by selecting configure engine from menu
项目:PyFlowChart    作者:steelcowboy    | 项目源码 | 文件源码
def open_file(self, widget):
        """Runs an open file dialog, then instructs the CourseManager 
        to load the chosen file.

        Returns:
            1 if successful, 0 otherwise.
        """
        if not self.course_manager.saved:
            dialog = self.create_exit_confirm_dialog()
            confirm_response = dialog.run()
            dialog.destroy()

            if confirm_response == Gtk.ResponseType.CANCEL: 
                return 0 

        while True:
            open_dialog = Gtk.FileChooserDialog("Please choose a file", self,
                Gtk.FileChooserAction.OPEN,
                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                 Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

            open_dialog.set_current_folder(self.chart_dir)

            response = open_dialog.run()

            if response == Gtk.ResponseType.OK:
                self.filename = open_dialog.get_filename()
                self.course_manager.saved = True 

                self.course_manager.courses = {}
                if self.course_manager.store:
                    self.course_manager.store.clear()

                if not self.course_manager.load_file(self.filename):
                    fail_dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
                    Gtk.ButtonsType.OK, "Not a valid JSON file, please try again")
                    fail_dialog.run()
                    pass
                    fail_dialog.destroy()
                    open_dialog.destroy()
                else:
                    open_dialog.destroy()
                    return 1
            else:
                open_dialog.destroy()
                return 0