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

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

项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
def on_btImportSccprofile_clicked(self, *a):
        # Create filters
        f1 = Gtk.FileFilter()
        f1.set_name("SC-Controller Profile or Archive")
        f1.add_pattern("*.sccprofile")
        f1.add_pattern("*.sccprofile.tar.gz")

        # Create dialog
        d = Gtk.FileChooserNative.new(_("Import Profile..."),
                self.window, Gtk.FileChooserAction.OPEN)
        d.add_filter(f1)
        if d.run() == Gtk.ResponseType.ACCEPT:
            if d.get_filename().endswith(".tar.gz"):
                self.import_scc_tar(d.get_filename())
            else:
                self.import_scc(d.get_filename())
项目: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()
项目:Ebook-Viewer    作者:michaldaniel    | 项目源码 | 文件源码
def __add_filters(self, dialog, importing):
        """
        Adds filters to indicate opening only .epub files.
        :param dialog:
        """
        if not importing:
            self.__add_native(dialog)
            if os.path.exists("/usr/bin/ebook-convert"):
                self.__add_imports(dialog)
        else:
            self.__add_imports(dialog)

        filter_any = Gtk.FileFilter()
        filter_any.set_name(_("Any files"))
        filter_any.add_pattern("*")
        dialog.add_filter(filter_any)
项目:dell-recovery    作者:dell    | 项目源码 | 文件源码
def provide_dell_recovery_file_chooser_picked(self, widget=None):
        """Called when a file is selected on the add dell-recovery page"""

        ok_button = self.builder_widgets.get_object('builder_add_ok')
        filefilter = Gtk.FileFilter()
        filefilter.add_pattern("*.deb")
        self.file_dialog.set_filter(filefilter)

        ret = self.run_file_dialog()
        if ret is not None:
            import apt_inst
            import apt_pkg
            control = apt_inst.DebFile(ret).control.extractdata("control")
            sections = apt_pkg.TagSection(control)
            if sections["Package"] != 'dell-recovery':
                self.add_dell_recovery_deb = ''
            else:
                self.add_dell_recovery_deb = ret

        if self.add_dell_recovery_deb:
            ok_button.set_sensitive(True)
项目: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()
项目: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)
项目: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()
项目: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()
项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
def on_btSaveAs_clicked(self, *a):
        # Grab stuff
        tvProfiles  = self.builder.get_object("tvProfiles")
        model, iter = tvProfiles.get_selection().get_selected()

        # Determine format
        f = Gtk.FileFilter()
        if self._needs_package():
            f.set_name("SC-Controller Profile Archive")
            fmt = "sccprofile.tar.gz"
        else:
            f.set_name("SC-Controller Profile")
            fmt = "sccprofile"
        f.add_pattern("*.%s" % (fmt,))

        # Create dialog
        d = Gtk.FileChooserNative.new(_("Export to File..."),
                self.window, Gtk.FileChooserAction.SAVE)
        d.add_filter(f)
        d.set_do_overwrite_confirmation(True)
        # Set default filename
        d.set_current_name("%s.%s" % (model[iter][2], fmt))
        if d.run() == Gtk.ResponseType.ACCEPT:
            fn = d.get_filename()
            if len(os.path.split(fn)[-1].split(".")) < 2:
                # User wrote filename without extension
                fn = "%s.%s" % (fn, fmt)

            if self._needs_package():
                if self._export_package(model[iter][1], fn):
                    self.window.destroy()
            else:
                if self._export(model[iter][1], fn):
                    self.window.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()
项目: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()
项目:sbrick-controller    作者:wintersandroid    | 项目源码 | 文件源码
def add_filters(dialog):
        filter_text = Gtk.FileFilter()
        filter_text.set_name("JSON files")
        filter_text.add_pattern("*.json")
        dialog.add_filter(filter_text)

        filter_any = Gtk.FileFilter()
        filter_any.set_name("Any files")
        filter_any.add_pattern("*")
        dialog.add_filter(filter_any)
项目:Ebook-Viewer    作者:michaldaniel    | 项目源码 | 文件源码
def __add_native(self, dialog):
        filter_text = Gtk.FileFilter()
        filter_text.set_name(_("ePub files"))
        for extension in constants.NATIVE:
            filter_text.add_pattern("*" + extension.upper())
            filter_text.add_pattern("*" + extension.lower())
        dialog.add_filter(filter_text)
项目:Ebook-Viewer    作者:michaldaniel    | 项目源码 | 文件源码
def __add_imports(self, dialog):
        filter_text = Gtk.FileFilter()
        filter_text.set_name(_("Importable files"))
        for extension in constants.IMPORTABLES:
            filter_text.add_pattern("*" + extension.upper())
            filter_text.add_pattern("*" + extension.lower())
        dialog.add_filter(filter_text)
项目:ez_gpg    作者:sgnn7    | 项目源码 | 文件源码
def _set_keyfile_filter(dialog):
        filter_keys = Gtk.FileFilter()
        filter_keys.set_name("Armored keys")
        filter_keys.add_pattern("*.asc")
        filter_keys.add_pattern("*.key")
        filter_keys.add_pattern("*.pub")
        dialog.add_filter(filter_keys)

        filter_any = Gtk.FileFilter()
        filter_any.set_name("Any files")
        filter_any.add_pattern("*")
        dialog.add_filter(filter_any)
项目:ez_gpg    作者:sgnn7    | 项目源码 | 文件源码
def _set_save_keyfile_filter(dialog):
        filter_armor_key = Gtk.FileFilter()
        filter_armor_key.set_name("Armored key")
        filter_armor_key.add_pattern("*.asc")
        dialog.add_filter(filter_armor_key)

        filter_binary_key = Gtk.FileFilter()
        filter_binary_key.set_name("Encoded key")
        filter_binary_key.add_pattern("*.gpg")
        dialog.add_filter(filter_binary_key)
项目:chromecast-player    作者:wa4557    | 项目源码 | 文件源码
def add_filters(self, dialog):
        filter_text = Gtk.FileFilter()
        filter_text.set_name("Video/Audio files")
        filter_text.add_mime_type("video/*")
        filter_text.add_mime_type("audio/*")
        dialog.add_filter(filter_text)
项目:ghetto_omr    作者:pohzhiee    | 项目源码 | 文件源码
def add_filters(self, dialog):
        filter_text = Gtk.FileFilter()
        filter_text.set_name("Text files")
        filter_text.add_mime_type("text/plain")
        dialog.add_filter(filter_text)

        filter_py = Gtk.FileFilter()
        filter_py.set_name("Python files")
        filter_py.add_mime_type("text/x-python")
        dialog.add_filter(filter_py)

        filter_any = Gtk.FileFilter()
        filter_any.set_name("Any files")
        filter_any.add_pattern("*")
        dialog.add_filter(filter_any)
项目:ghetto_omr    作者:pohzhiee    | 项目源码 | 文件源码
def add_filters(self, dialog):
        filter_text = Gtk.FileFilter()
        filter_text.set_name("Text files")
        filter_text.add_mime_type("text/plain")
        dialog.add_filter(filter_text)

        filter_py = Gtk.FileFilter()
        filter_py.set_name("Python files")
        filter_py.add_mime_type("text/x-python")
        dialog.add_filter(filter_py)

        filter_any = Gtk.FileFilter()
        filter_any.set_name("Any files")
        filter_any.add_pattern("*")
        dialog.add_filter(filter_any)
项目:MTTT    作者:roxana-lafuente    | 项目源码 | 文件源码
def _add_dir_filters(self, dialog):
        """@brief     Add folder filters for folder choosing."""
        # TODO: Allow to only choose folders
        filter_text = Gtk.FileFilter()

        filter_any = Gtk.FileFilter()
        filter_any.set_name("Any files")
        filter_any.add_pattern("*")
        dialog.add_filter(filter_any)
项目:MTTT    作者:roxana-lafuente    | 项目源码 | 文件源码
def _add_file_filters(self, dialog):
        """@brief     Add file filters for file choosing."""
        filter_text = Gtk.FileFilter()

        filter_any = Gtk.FileFilter()
        filter_any.set_name("Any files")
        filter_any.add_pattern("*")
        dialog.add_filter(filter_any)
项目: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()
项目: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()
项目:apart-gtk    作者:alexheretic    | 项目源码 | 文件源码
def __init__(self, main_view: 'MainView', core: ApartCore, z_options: List[str]):
        Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL, expand=True, halign=Gtk.Align.CENTER)
        self.main_view = main_view
        self.core = core
        self.z_options = z_options

        self.title = Gtk.Label('', xalign=0.5)
        self.title.get_style_context().add_class('dim-label')

        self.image_label = Gtk.Label("Image File", xalign=1.0)
        self.image_label.get_style_context().add_class('dim-label')
        self.image_entry = Gtk.FileChooserButton(title='Select Image File')
        image_file_filter = Gtk.FileFilter()
        image_file_filter.set_name('Apart Image files')
        for z_option in z_options:
            image_file_filter.add_pattern('*.apt.*.{}'.format(z_option))
            if z_option == 'zst':  # also support .zstd from v0.14
                image_file_filter.add_pattern('*.apt.*.zstd')
        self.image_entry.add_filter(image_file_filter)
        self.image_entry.connect('selection-changed', lambda v: self.on_image_select())

        self.options = Gtk.Grid(row_spacing=6)
        self.options.get_style_context().add_class('new-clone-options')
        self.options.attach(self.title, left=0, top=0, width=2, height=1)
        self.options.attach(self.image_label, left=0, top=1, width=1, height=1)
        self.options.attach(self.image_entry, left=1, top=1, width=1, height=1)

        self.cancel_btn = Gtk.Button('Cancel')
        self.cancel_btn.connect('clicked', lambda v: self.main_view.show_progress())
        self.start_btn = Gtk.Button('Restore Partition')
        self.start_btn.set_sensitive(False)
        self.start_btn.connect('clicked', lambda v: self.user_confirm())

        self.buttons = Gtk.Box(halign=Gtk.Align.END)
        self.buttons.get_style_context().add_class('new-clone-buttons')
        self.buttons.add(self.cancel_btn)
        self.buttons.add(self.start_btn)

        self.add(self.options)
        self.options.attach_next_to(self.buttons, sibling=self.image_label,
                                    side=Gtk.PositionType.BOTTOM, width=2, height=1)
        self.last_part_info = None
项目:Remarkable    作者:jamiemcg    | 项目源码 | 文件源码
def save_pdf(self, html):
        chooser = Gtk.FileChooserDialog("Export PDF", None, Gtk.FileChooserAction.SAVE,
                                        (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                         Gtk.STOCK_OK, Gtk.ResponseType.OK))
        pdf_filter = Gtk.FileFilter()
        pdf_filter.add_pattern("*.pdf")
        pdf_filter.set_name("PDF Files")
        chooser.add_filter(pdf_filter)
        chooser.set_do_overwrite_confirmation(True)
        response = chooser.run()
        if response == Gtk.ResponseType.OK:
            file_name = chooser.get_filename()
            if not file_name.endswith(".pdf"):
                file_name += ".pdf"
            try:
                pdfkit.from_string(html, file_name, options= {'quiet': '', 'page-size': 'Letter',
                    'margin-top': '0.75in',
                    'margin-right': '0.75in',
                    'margin-bottom': '0.75in',
                    'margin-left': '0.75in',
                    'encoding': "UTF-8",
                    'javascript-delay' : '550',
                    'no-outline': None})
            except:
                try:
                    #Failed so try with no options
                    pdfkit.from_string(html, file_name)
                except:
                    #Pdf Export failed, show warning message
                    if not self.pdf_error_warning:
                        self.pdf_error_warning = True
                        print("\nRemarkable Error:\tPDF Export Failed!!")

                    pdf_fail_dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.ERROR,
                            Gtk.ButtonsType.CANCEL, "PDF EXPORT FAILED")
                    pdf_fail_dialog.format_secondary_text(
                            "File export to PDF was unsuccessful.")
                    pdf_fail_dialog.run()
                    pdf_fail_dialog.destroy()
        elif response == Gtk.ResponseType.CANCEL:
            pass

        chooser.destroy()
        self.window.set_sensitive(True)
项目:lightdm-settings    作者:linuxmint    | 项目源码 | 文件源码
def on_button_pressed(self, widget):
        dialog = Gtk.FileChooserDialog(title=_("Choose an Image File"),
                                       action=Gtk.FileChooserAction.OPEN,
                                       transient_for=self.get_toplevel(),
                                       buttons=(_("_Cancel"), Gtk.ResponseType.CANCEL,
                                                _("_Open"), Gtk.ResponseType.OK))

        filter_text = Gtk.FileFilter()
        filter_text.set_name(_("Image files"))
        filter_text.add_mime_type("image/*")
        dialog.add_filter(filter_text)

        backgrounds = "/usr/share/backgrounds"

        if os.path.exists(self.value):
            dialog.set_filename(self.value)

        if os.path.exists(backgrounds):
            dialog.add_shortcut_folder(backgrounds)

        box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.frame = Gtk.Frame(visible=False, no_show_all=True)
        preview = Gtk.Image(visible=True)

        box.pack_start(self.frame, False, False, 0)
        self.frame.add(preview)
        dialog.set_preview_widget(box)
        dialog.set_preview_widget_active(True)
        dialog.set_use_preview_label(False)

        box.set_margin_end(12)
        box.set_margin_top(12)
        box.set_size_request(320, -1)

        dialog.connect("update-preview", self.update_icon_preview_cb, preview)

        response = dialog.run()

        if response == Gtk.ResponseType.OK:
            filename = dialog.get_filename()
            self.bind_object.set_text(filename)

        dialog.destroy()