本文整理汇总了Python中gtk.FileFilter方法的典型用法代码示例。如果您正苦于以下问题:Python gtk.FileFilter方法的具体用法?Python gtk.FileFilter怎么用?Python gtk.FileFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gtk
的用法示例。
在下文中一共展示了gtk.FileFilter方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_open
# 需要导入模块: import gtk [as 别名]
# 或者: from gtk import FileFilter [as 别名]
def on_open(self, action):
chooser = gtk.FileChooserDialog(title="Open dot File",
action=gtk.FILE_CHOOSER_ACTION_OPEN,
buttons=(gtk.STOCK_CANCEL,
gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN,
gtk.RESPONSE_OK))
chooser.set_default_response(gtk.RESPONSE_OK)
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.RESPONSE_OK:
filename = chooser.get_filename()
chooser.destroy()
self.open_file(filename)
else:
chooser.destroy()
示例2: on_open
# 需要导入模块: import gtk [as 别名]
# 或者: from gtk import FileFilter [as 别名]
def on_open(self, action):
chooser = gtk.FileChooserDialog(title="Open dot File",
action=gtk.FILE_CHOOSER_ACTION_OPEN,
buttons=(gtk.STOCK_CANCEL,
gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN,
gtk.RESPONSE_OK))
chooser.set_default_response(gtk.RESPONSE_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.RESPONSE_OK:
filename = chooser.get_filename()
self.last_open_dir = chooser.get_current_folder()
chooser.destroy()
self.open_file(filename)
else:
chooser.destroy()
示例3: chooseFile
# 需要导入模块: import gtk [as 别名]
# 或者: from gtk import FileFilter [as 别名]
def chooseFile(self, default_dir=None,
filter_patterns=None):
dialog = gtk.FileChooserDialog(
title="Open File",
parent=self._win,
action=gtk.FILE_CHOOSER_ACTION_OPEN,
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
dialog.set_default_response(gtk.RESPONSE_OK)
patterns = self._str_to_obj(filter_patterns) or {"xml": "XML Files"}
for pattern in patterns:
file_filter = gtk.FileFilter()
file_filter.set_name(patterns[pattern])
file_filter.add_pattern('*.{}'.format(pattern))
dialog.add_filter(file_filter)
if default_dir is not None:
dialog.set_current_folder(os.path.expanduser(default_dir))
path = ""
response = dialog.run()
if response == gtk.RESPONSE_OK:
path = dialog.get_filename()
elif response == gtk.RESPONSE_CANCEL:
self.error("No files selected.")
dialog.destroy()
return path
示例4: openFile
# 需要导入模块: import gtk [as 别名]
# 或者: from gtk import FileFilter [as 别名]
def openFile(self, widget=None, default=False):
"""Reads from a config file. If default=True, open the tint2 default config."""
self.new()
if not default:
chooser = gtk.FileChooserDialog("Open Config File", self, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
chooser.set_default_response(gtk.RESPONSE_OK)
if self.curDir != None:
chooser.set_current_folder(self.curDir)
chooserFilter = gtk.FileFilter()
chooserFilter.set_name("All files")
chooserFilter.add_pattern("*")
chooser.add_filter(chooserFilter)
chooser.show()
response = chooser.run()
if response == gtk.RESPONSE_OK:
self.filename = chooser.get_filename()
self.curDir = os.path.dirname(self.filename)
else:
chooser.destroy()
return
chooser.destroy()
else:
self.filename = os.path.expandvars("$HOME/.config/tint2/tint2rc")
self.curDir = os.path.expandvars("$HOME/.config/tint2")
self.readTint2Config()
self.generateConfig()
self.updateStatusBar()
示例5: saveAs
# 需要导入模块: import gtk [as 别名]
# 或者: from gtk import FileFilter [as 别名]
def saveAs(self, widget=None, event=None):
"""Prompts the user to select a file and then saves the generated config file."""
self.generateConfig()
chooser = gtk.FileChooserDialog("Save Config File As...", self, gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK))
chooser.set_default_response(gtk.RESPONSE_OK)
if self.curDir != None:
chooser.set_current_folder(self.curDir)
chooserFilter = gtk.FileFilter()
chooserFilter.set_name("All files")
chooserFilter.add_pattern("*")
chooser.add_filter(chooserFilter)
chooser.show()
response = chooser.run()
if response == gtk.RESPONSE_OK:
self.filename = chooser.get_filename()
if os.path.exists(self.filename):
overwrite = confirmDialog(self, "This file already exists. Overwrite this file?")
if overwrite == gtk.RESPONSE_YES:
self.writeFile()
chooser.destroy()
return True
else:
self.filename = None
chooser.destroy()
return False
else:
self.writeFile()
chooser.destroy()
return True
else:
self.filename = None
chooser.destroy()
return False
示例6: _get_export_file_name
# 需要导入模块: import gtk [as 别名]
# 或者: from gtk import FileFilter [as 别名]
def _get_export_file_name(self):
sel = gtk.FileChooserDialog("Save...", self.canvas.get_toplevel(),
gtk.FILE_CHOOSER_ACTION_SAVE,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_SAVE, gtk.RESPONSE_OK))
sel.set_default_response(gtk.RESPONSE_OK)
sel.set_local_only(True)
sel.set_do_overwrite_confirmation(True)
sel.set_current_name("Unnamed.pdf")
filter = gtk.FileFilter()
filter.set_name("Embedded PostScript")
filter.add_mime_type("image/x-eps")
sel.add_filter(filter)
filter = gtk.FileFilter()
filter.set_name("Portable Document Graphics")
filter.add_mime_type("application/pdf")
sel.add_filter(filter)
filter = gtk.FileFilter()
filter.set_name("Scalable Vector Graphics")
filter.add_mime_type("image/svg+xml")
sel.add_filter(filter)
resp = sel.run()
if resp != gtk.RESPONSE_OK:
sel.destroy()
return None
file_name = sel.get_filename()
sel.destroy()
return file_name
示例7: askOpenFileGtk
# 需要导入模块: import gtk [as 别名]
# 或者: from gtk import FileFilter [as 别名]
def askOpenFileGtk(title, suffixes, initialDir):
fls = []
def run_dlg():
chooser = gtk.FileChooserDialog(title,
None, gtk.FILE_CHOOSER_ACTION_SAVE,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
chooser.set_default_response(gtk.RESPONSE_OK)
chooser.set_current_folder(initialDir)
chooser.set_current_name("world") # For some reason the Windows isn't closing if this line ins missing or the parameter is ""
# Add custom Filter
file_filter = gtk.FileFilter()
file_filter.set_name(_("Levels and Schematics"))
for suffix in suffixes:
file_filter.add_pattern("*." + suffix)
chooser.add_filter(file_filter)
# Add "All files" Filter
file_filter = gtk.FileFilter()
file_filter.set_name("All files")
file_filter.add_pattern("*")
chooser.add_filter(file_filter)
response = chooser.run()
if response == gtk.RESPONSE_OK:
fls.append(chooser.get_filename())
else:
fls.append(None)
chooser.destroy()
gtk.main_quit()
gtk.idle_add(run_dlg)
gtk.main()
return fls[0]
示例8: askOpenFileGtk
# 需要导入模块: import gtk [as 别名]
# 或者: from gtk import FileFilter [as 别名]
def askOpenFileGtk(title, suffixes, initialDir):
fls = []
def run_dlg():
chooser = gtk.FileChooserDialog(title,
None, gtk.FILE_CHOOSER_ACTION_SAVE,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
chooser.set_default_response(gtk.RESPONSE_OK)
chooser.set_current_folder(initialDir)
chooser.set_current_name("world") # For some reason the Windows isn't closing if this line ins missing or the parameter is ""
# Add custom Filter
file_filter = gtk.FileFilter()
file_filter.set_name(_("Levels and Schematics"))
for suffix in suffixes:
file_filter.add_pattern("*." + suffix)
chooser.add_filter(file_filter)
# Add "All files" Filter
file_filter = gtk.FileFilter()
file_filter.set_name("All files")
file_filter.add_pattern("*")
chooser.add_filter(file_filter)
response = chooser.run()
if response == gtk.RESPONSE_OK:
fls.append(chooser.get_filename())
else:
fls.append(None)
chooser.destroy()
gtk.main_quit()
gtk.idle_add(run_dlg)
gtk.main()
return fls[0]
示例9: on_license_button_clicked
# 需要导入模块: import gtk [as 别名]
# 或者: from gtk import FileFilter [as 别名]
def on_license_button_clicked(self, button):
log.debug("License button clicked.")
chooser = gtk.FileChooserDialog(_("Choose your FileBot license file"),
None,
gtk.FILE_CHOOSER_ACTION_OPEN,
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN,
gtk.RESPONSE_OK))
chooser.set_transient_for(self.pref_dialog)
chooser.set_property("skip-taskbar-hint", True)
chooser.set_local_only(False)
file_filter = gtk.FileFilter()
file_filter.set_name(_("FileBot license files"))
file_filter.add_pattern("*." + "psm")
chooser.add_filter(file_filter)
file_filter = gtk.FileFilter()
file_filter.set_name(_("All files"))
file_filter.add_pattern("*")
chooser.add_filter(file_filter)
# Run the dialog
response = chooser.run()
if response == gtk.RESPONSE_OK:
license = chooser.get_filenames()[0]
else:
chooser.destroy()
return
chooser.destroy()
# License file should definetly be under 10K
size = os.stat(license).st_size
if size > 10*1000:
e = user_messenger.InfoDialog("Error", "License file is too big.")
e.resize(220, 125)
e.run_async()
defer.returnValue()
with open(license, 'rb') as l:
license_data = l.read()
log.debug("Sending license data to server.")
result = yield client.filebottool.activate_filebot_license(license_data)
log.debug("Recieved reply from server: %s", result)
if result.startswith("FilebotLicenseError: "):
title = "Error with License File"
msg = result[21:]
else:
title = "Success!"
msg = result
dialog = user_messenger.InfoDialog(title, msg)
dialog.resize(220, 125)
dialog.run_async()
#########
# Section: Utilities
#########
示例10: run_dlg
# 需要导入模块: import gtk [as 别名]
# 或者: from gtk import FileFilter [as 别名]
def run_dlg():
chooser = gtk.FileChooserDialog(title,
None, gtk.FILE_CHOOSER_ACTION_SAVE,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_SAVE, gtk.RESPONSE_OK))
chooser.set_default_response(gtk.RESPONSE_OK)
chooser.set_current_folder(initialDir)
chooser.set_current_name(defaultName)
# Add custom Filter
if type(_filetype) in (list, tuple):
for i, filet in enumerate(_filetype):
if i % 2 == 0:
file_filter = gtk.FileFilter()
file_filter.set_name(filet)
if ";" in _suffix[i + 1]:
for _suff in _suffix.split(";"):
if _suff:
file_filter.add_pattern(_suff)
else:
file_filter.add_pattern(_suffix[i + 1])
chooser.add_filter(file_filter)
else:
file_filter = gtk.FileFilter()
file_filter.set_name(filetype[:filetype.index("\0")])
if "\0" in suffix and suffix.count("*.") > 1:
__suffix = suffix.split("\0")[:-2]
else:
__suffix = suffix
if type(__suffix) in (list, tuple):
for suff in __suffix:
file_filter.add_pattern("*." + suff)
else:
file_filter.add_pattern("*." + __suffix)
chooser.add_filter(file_filter)
# Add "All files" Filter
file_filter = gtk.FileFilter()
file_filter.set_name("All files")
file_filter.add_pattern("*")
chooser.add_filter(file_filter)
response = chooser.run()
if response == gtk.RESPONSE_OK:
fls.append(chooser.get_filename())
else:
fls.append(None)
chooser.destroy()
gtk.main_quit()