本文整理汇总了Python中gi.repository.Gtk.FileFilter方法的典型用法代码示例。如果您正苦于以下问题:Python Gtk.FileFilter方法的具体用法?Python Gtk.FileFilter怎么用?Python Gtk.FileFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.Gtk
的用法示例。
在下文中一共展示了Gtk.FileFilter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: quick_add_filter
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import FileFilter [as 别名]
def quick_add_filter(self, name, patterns):
"""
Add a filter for displaying files, this is useful in conjunction
with :py:meth:`.run_quick_open`.
:param str name: The name of the filter.
:param patterns: The pattern(s) to match.
:type patterns: list, str
"""
if not isinstance(patterns, (list, tuple)):
patterns = (patterns,)
new_filter = Gtk.FileFilter()
new_filter.set_name(name)
for pattern in patterns:
new_filter.add_pattern(pattern)
self.add_filter(new_filter)
示例2: on_import_click
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import FileFilter [as 别名]
def on_import_click(self, widget):
fcd = Gtk.FileChooserDialog(
'Select a colorscheme', self.parent,
Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
filter = Gtk.FileFilter()
filter.set_name("JSON colorscheme")
filter.add_mime_type("application/json")
fcd.add_filter(filter)
response = fcd.run()
if response == Gtk.ResponseType.OK:
self.color_list = color.get_color_list(fcd.get_filename(), True)
self.render_buttons()
self.render_sample()
fcd.destroy()
示例3: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import FileFilter [as 别名]
def __init__(self, main_window, open_project):
self.builder = Gtk.Builder()
self.builder.set_translation_domain(i18n().get_ts_domain())
script_dir = os.path.dirname(__file__)
rel_path = "gui_layout.glade"
abs_path = os.path.join(script_dir, rel_path)
self.builder.add_objects_from_file(abs_path,
("filechooserdialog_open", ""))
self.dialog = self.builder.get_object("filechooserdialog_open")
self.dialog.set_transient_for(main_window)
filter_json = Gtk.FileFilter()
filter_json.add_pattern("*.json")
filter_json.set_name("JSON")
self.dialog.add_filter(filter_json)
filter_all = Gtk.FileFilter()
filter_all.add_pattern("*")
filter_all.set_name(_("All Files"))
self.dialog.add_filter(filter_all)
self.open_project = open_project
self.builder.connect_signals(self)
if sys.platform == "win32":
translate_gui(self.builder)
示例4: __show_file_chooser
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import FileFilter [as 别名]
def __show_file_chooser(self, button):
""" Tworzenie dialogu wyboru pliku obrazu
"""
dialog = Gtk.FileChooserDialog("Please choose a file", self, Gtk.FileChooserAction.OPEN, (
Gtk.STOCK_CANCEL
, Gtk.ResponseType.CANCEL
, Gtk.STOCK_OPEN
, Gtk.ResponseType.OK
))
filters = {
"application/x-cd-image": "CD/DVD image"
}
for key, val in filters.items():
filter_text = Gtk.FileFilter()
filter_text.set_name(val)
filter_text.add_mime_type(key)
dialog.add_filter(filter_text)
response = dialog.run()
if response == Gtk.ResponseType.OK:
self.path.set_text(dialog.get_filename())
elif response == Gtk.ResponseType.CANCEL:
print("Cancel clicked")
dialog.destroy()
示例5: add_filter_nmap
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import FileFilter [as 别名]
def add_filter_nmap(dialog):
filter_text = Gtk.FileFilter()
filter_text.set_name("nmap/masscan XML files")
filter_text.add_mime_type("text/xml")
dialog.add_filter(filter_text)
filter_text = Gtk.FileFilter()
filter_text.set_name("smap json files")
filter_text.add_mime_type("application/json")
filter_text.add_mime_type("text/xml")
dialog.add_filter(filter_text)
filter_any = Gtk.FileFilter()
filter_any.set_name("Any files")
filter_any.add_pattern("*")
dialog.add_filter(filter_any)
示例6: add_pic_dialog_filters
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import FileFilter [as 别名]
def add_pic_dialog_filters(dialog):
"""Add file filters for images to a file chooser dialog."""
allPictures = Gtk.FileFilter()
allPictures.set_name(_("All pictures"))
allPictures.add_mime_type('image/png')
allPictures.add_mime_type('image/jpeg')
allPictures.add_mime_type('image/bmp')
allPictures.add_mime_type('image/svg')
allPictures.add_mime_type('image/tiff')
pngPictures = Gtk.FileFilter()
pngPictures.set_name(_("PNG images"))
pngPictures.add_mime_type('image/png')
jpegPictures = Gtk.FileFilter()
jpegPictures.set_name(_("JPEG images"))
jpegPictures.add_mime_type('image/jpeg')
dialog.add_filter(allPictures)
dialog.add_filter(pngPictures)
dialog.add_filter(jpegPictures)
示例7: select_image
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import FileFilter [as 别名]
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()
示例8: on_file
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import FileFilter [as 别名]
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()
示例9: on_new_subtitle_clicked
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import FileFilter [as 别名]
def on_new_subtitle_clicked(self):
dialog = Gtk.FileChooserDialog("Please choose a subtitle file...", self.win,
Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
if self.fn:
dialog.set_current_folder(os.path.dirname(self.fn))
filter_py = Gtk.FileFilter()
filter_py.set_name("Subtitles")
filter_py.add_pattern("*.srt")
filter_py.add_pattern("*.vtt")
dialog.add_filter(filter_py)
response = dialog.run()
if response == Gtk.ResponseType.OK:
print("Open clicked")
print("File selected: " + dialog.get_filename())
self.select_subtitles_file(dialog.get_filename())
elif response == Gtk.ResponseType.CANCEL:
print("Cancel clicked")
self.subtitle_combo.set_active(0)
dialog.destroy()
示例10: on_download_subtitle_clicked
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import FileFilter [as 别名]
def on_download_subtitle_clicked(self):
dialog = Gtk.FileChooserDialog("Please choose a subtitle file...", self.win,
Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
if self.fn:
dialog.set_current_folder(os.path.dirname(self.fn))
filter_py = Gtk.FileFilter()
filter_py.set_name("Subtitles")
filter_py.add_pattern("*.srt")
filter_py.add_pattern("*.vtt")
dialog.add_filter(filter_py)
response = dialog.run()
if response == Gtk.ResponseType.OK:
print("Open clicked")
print("File selected: " + dialog.get_filename())
self.select_subtitles_file(dialog.get_filename())
elif response == Gtk.ResponseType.CANCEL:
print("Cancel clicked")
self.subtitle_combo.set_active(0)
dialog.destroy()
示例11: export_selected
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import FileFilter [as 别名]
def export_selected(self):
def to_csv(value):
if value is None:
return ''
elif isinstance(value, memoryview):
return ''
return str(value)
dlg = Gtk.FileChooserDialog(
'Export Selection', self.win, Gtk.FileChooserAction.SAVE,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
file_filter = Gtk.FileFilter()
file_filter.set_name('CSV files')
file_filter.add_mime_type('text/csv')
dlg.add_filter(file_filter)
dlg.set_current_name('export.csv')
if dlg.run() == Gtk.ResponseType.ACCEPT:
with open(dlg.get_filename(), 'w') as f:
writer = csv.writer(f)
for row in self._selection.get_export_data():
writer.writerow(list(map(to_csv, row)))
dlg.destroy()
示例12: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import FileFilter [as 别名]
def __init__(self, *args, **kwargs):
super(FileDialog, self).__init__(*args, **kwargs)
self.set_titlebar(Gtk.HeaderBar(show_close_button=True))
self.set_title("Open File")
self.add_button("_Open", Gtk.ResponseType.OK)
self.add_button("_Cancel", Gtk.ResponseType.CANCEL)
self.set_default_response(Gtk.ResponseType.OK)
#TODO Add file filters based on extensions given in INI
filefiler = Gtk.FileFilter()
filefiler.add_pattern('*.ngc')
filefiler.set_name('G-code')
self.add_filter(filefiler)
filefiler = Gtk.FileFilter()
filefiler.add_pattern('*')
filefiler.set_name('All Files')
self.add_filter(filefiler)
self.show_all()
示例13: __add_filters
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import FileFilter [as 别名]
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)
示例14: on_open
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import FileFilter [as 别名]
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()
示例15: __open_file_chooser
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import FileFilter [as 别名]
def __open_file_chooser(parent, mimetype, action=Gtk.FileChooserAction.OPEN):
file_chooser = Gtk.FileChooserNative()
file_chooser.set_action(action)
file_chooser.set_transient_for(parent)
filter_json = Gtk.FileFilter()
filter_json.set_name(mimetype["name"])
filter_json.add_mime_type(mimetype["type"])
file_chooser.add_filter(filter_json)
response = file_chooser.run()
if response == Gtk.ResponseType.ACCEPT:
filename = file_chooser.get_filename()
return filename
file_chooser.destroy()
return None