本文整理汇总了Python中PyQt4.Qt.QFileDialog.getExistingDirectory方法的典型用法代码示例。如果您正苦于以下问题:Python QFileDialog.getExistingDirectory方法的具体用法?Python QFileDialog.getExistingDirectory怎么用?Python QFileDialog.getExistingDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QFileDialog
的用法示例。
在下文中一共展示了QFileDialog.getExistingDirectory方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: select_database
# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getExistingDirectory [as 别名]
def select_database(uim):
dlg = QFileDialog()
opt = QFileDialog.ShowDirsOnly
if uim.hs.db_dpath is None:
db_dpath = str(dlg.getExistingDirectory(caption='Open/New Database', options=opt))
else:
db_dpath = str(dlg.getExistingDirectory(\
caption='Open/New Database', options=opt, directory=uim.hs.db_dpath))
return db_dpath
示例2: selectDirectory
# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getExistingDirectory [as 别名]
def selectDirectory(self):
directory = QFileDialog.getExistingDirectory(QFileDialog())
if len(directory) > 0:
directory = pathlib.Path(directory).resolve()
if directory.exists():
self._rddtDataExtractor.defaultPath = directory
self.directoryBox.setText(str(directory))
self.setUnsavedChanges(True)
示例3: _select_other_dialog
# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getExistingDirectory [as 别名]
def _select_other_dialog(self):
path = str(QFileDialog.getExistingDirectory(self, "Select purrlog", self.dirname))
if not path:
return
if not Purr.Purrer.is_purrlog(path):
QMessageBox.warning(self, "Invalid purrlog",
"The path you have selected, <tt>%s</tt>, does not refer to a valid purrlog." % Kittens.utils.collapseuser(
path))
return
self.load_path = path
self.wother.setText(Kittens.utils.collapseuser(path))
self.checkCompleteness()
示例4: _showAddDirectoryDialog
# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getExistingDirectory [as 别名]
def _showAddDirectoryDialog(self):
dd = str(QFileDialog.getExistingDirectory(self, "PURR: Add a directory to monitor")).strip()
if dd:
# adds a watched directory. Default initial setting of 'watching' is POUNCE if all
# directories are in POUNCE state, or WATCHED otherwise.
watching = max(Purr.WATCHED,
min([state for path, state in self.purrer.watchedDirectories()] or [Purr.WATCHED]))
self.purrer.addWatchedDirectory(dd, watching)
self.purrpipes[dd] = Purr.Pipe.open(dd)
self.wdirlist.add(dd, watching)
# update dialogs since dir list has changed
dirs = [path for path, state in self.purrer.watchedDirectories()]
self.new_entry_dialog.setDefaultDirs(*dirs)
self.view_entry_dialog.setDefaultDirs(*dirs)
示例5: browseDirectories
# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getExistingDirectory [as 别名]
def browseDirectories(self):
"""Slot method for the browse button of library page. """
# Determine what directory to open.
if self.w.assy.filename:
odir = os.path.dirname(self.w.assy.filename)
else:
from utilities.prefs_constants import workingDirectory_prefs_key
odir = env.prefs[workingDirectory_prefs_key]
fdir = QFileDialog.getExistingDirectory(self, "Choose library directory", odir)
libDir = str(fdir)
if libDir and os.path.isdir(libDir):
env.prefs[self.libPathKey] = libDir
self.dirView.setRootPath(libDir)
#Refresh GL-thumbView display
self.newModel = None
self.elemGLPane.updateModel(self.newModel)
示例6: stepSaveAs
# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getExistingDirectory [as 别名]
def stepSaveAs(self, phase = 0):
if phase == 0:
self.setWindowTitle(QString(u'Сохранение файла'))
self.progressBar.setValue(90)
self.emitStep(self.stepSaveAs, 1)
return
saveCat = QFileDialog.getExistingDirectory(None, u"Сохранить в каталог",
u"./logs",
QFileDialog.ShowDirsOnly
| QFileDialog.DontResolveSymlinks);
print("save to " + saveCat)
QtCore.QFile.remove( saveCat+'/' + getFile)
if False == QtCore.QFile.copy(getFile, saveCat+'/' + getFile):
print("error");
QtCore.QFile.remove( getFile)
app.closeAllWindows()
示例7: __init__
# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getExistingDirectory [as 别名]
def __init__(self, title=_('Choose Files'),
filters=[],
add_all_files_filter=True,
parent=None,
modal=True,
name='',
mode=QFileDialog.ExistingFiles,
default_dir=u'~',
no_save_dir=False,
combine_file_and_saved_dir=False
):
QObject.__init__(self)
ftext = ''
if filters:
for filter in filters:
text, extensions = filter
extensions = ['*'+(i if i.startswith('.') else '.'+i) for i in
extensions]
ftext += '%s (%s);;'%(text, ' '.join(extensions))
if add_all_files_filter or not ftext:
ftext += 'All files (*)'
if ftext.endswith(';;'):
ftext = ftext[:-2]
self.dialog_name = name if name else 'dialog_' + title
self.selected_files = None
self.fd = None
if combine_file_and_saved_dir:
bn = os.path.basename(default_dir)
prev = dynamic.get(self.dialog_name,
expanduser(u'~'))
if os.path.exists(prev):
if os.path.isfile(prev):
prev = os.path.dirname(prev)
else:
prev = expanduser(u'~')
initial_dir = os.path.join(prev, bn)
elif no_save_dir:
initial_dir = expanduser(default_dir)
else:
initial_dir = dynamic.get(self.dialog_name,
expanduser(default_dir))
if not isinstance(initial_dir, basestring):
initial_dir = expanduser(default_dir)
if not initial_dir or (not os.path.exists(initial_dir) and not (
mode == QFileDialog.AnyFile and (no_save_dir or combine_file_and_saved_dir))):
initial_dir = select_initial_dir(initial_dir)
self.selected_files = []
use_native_dialog = 'CALIBRE_NO_NATIVE_FILEDIALOGS' not in os.environ
with SanitizeLibraryPath():
opts = QFileDialog.Option()
if not use_native_dialog:
opts |= QFileDialog.DontUseNativeDialog
if mode == QFileDialog.AnyFile:
f = unicode(QFileDialog.getSaveFileName(parent, title,
initial_dir, ftext, "", opts))
if f:
self.selected_files.append(f)
elif mode == QFileDialog.ExistingFile:
f = unicode(QFileDialog.getOpenFileName(parent, title,
initial_dir, ftext, "", opts))
if f and os.path.exists(f):
self.selected_files.append(f)
elif mode == QFileDialog.ExistingFiles:
fs = QFileDialog.getOpenFileNames(parent, title, initial_dir,
ftext, "", opts)
for f in fs:
f = unicode(f)
if not f:
continue
if not os.path.exists(f):
# QFileDialog for some reason quotes spaces
# on linux if there is more than one space in a row
f = unquote(f)
if f and os.path.exists(f):
self.selected_files.append(f)
else:
if mode == QFileDialog.Directory:
opts |= QFileDialog.ShowDirsOnly
f = unicode(QFileDialog.getExistingDirectory(parent, title, initial_dir, opts))
if os.path.exists(f):
self.selected_files.append(f)
if self.selected_files:
self.selected_files = [unicode(q) for q in self.selected_files]
saved_loc = self.selected_files[0]
if os.path.isfile(saved_loc):
saved_loc = os.path.dirname(saved_loc)
if not no_save_dir:
dynamic[self.dialog_name] = saved_loc
self.accepted = bool(self.selected_files)
示例8: run_scanner
# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getExistingDirectory [as 别名]
def run_scanner(self, pressed):
# Startup
self.ui.scan_progressBar.setValue(0)
scan_path = str(QFileDialog.getExistingDirectory(self, u"انتخاب پوشه برای اسکن"))
self.ui.checkedFiles.clear()
self.ui.checkedFiles.append(u'<font color=blue>شروع…</font>')
if 'WINDIR' in os.environ and scan_path == '':
scan_path = os.environ['WINDIR']
elif scan_path == '':
self.WarningEvent(u'پوشهای برای اسکن انتخاب نشده',u'اخطار')
return
# Compromised marker
compromised = False
c = 0
# Compiling yara rules
if os.path.exists('regin_rules.yar'):
self.ui.checkedFiles.append(u'<font color=green>آماه سازی …</font>')
self.ui.checkedFiles.append(u'<font color=green>ممکن است عملیات کمی زمانبر باشد... صبور باشید</font>')
QtGui.QApplication.processEvents()
rules = yara.compile('regin_rules.yar')
else:
self.WarningEvent(u'فایل مربوط به مشخصات بدافزار یافت نشد',u'اخطار')
return
QtGui.QApplication.processEvents()
x = value = 0
for root, dirs, files in os.walk(scan_path):
for f in files:
x = x+1
x = 100.0/x
for root, directories, files in scandir.walk(scan_path, onerror=walkError, followlinks=False):
# Loop through files
for filename in files:
try:
# Get the file and path
filePath = os.path.join(root,filename)
# Counter
c += 1
self.ui.checkedFiles.append(u"[اسکن فایلِ] %s" % filePath.decode('utf-8'))
QtGui.QApplication.processEvents()
file_size = 0
try:
file_size = os.stat(filePath).st_size
except:
pass
# File Name Checks -------------------------------------------------
for file in EVIL_FILES:
if file in filePath:
# print "\bREGIN File Name MATCH: %s" % filePath
compromised = True
# Yara Check -------------------------------------------------------
if 'rules' in locals():
if file_size < 500000:
try:
matches = rules.match(filePath)
if matches:
for match in matches:
# print "\bREGIN Yara Rule MATCH: %s FILE: %s" % ( match, filePath)
compromised = True
except Exception, e:
print e
# Hash Check -------------------------------------------------------
if file_size < 500000:
if sha256(filePath) in EVIL_HASHES:
# print "\bREGIN SHA256 Hash MATCH: %s FILE: %s" % ( sha256(filePath), filePath)
compromised = True
# CRC Check --------------------------------------------------------
try:
if file_size <= 11:
continue
# Code from Paul Rascagneres
fp = open(filePath, 'r')
SectorSize=fp.read(2)[::-1]
MaxSectorCount=fp.read(2)[::-1]
MaxFileCount=fp.read(2)[::-1]
FileTagLength=fp.read(1)[::-1]
CRC32custom=fp.read(4)[::-1]
fp.close()
fp = open(filePath, 'r')
data=fp.read(0x7)
crc = binascii.crc32(data, 0x45)
crc2 = '%08x' % (crc & 0xffffffff)
if CRC32custom.encode('hex') == crc2:
# print "\bREGIN Virtual Filesystem MATCH: %s" % filePath
#.........这里部分代码省略.........
示例9: __init__
# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getExistingDirectory [as 别名]
def __init__(
self,
title=_("Choose Files"),
filters=[],
add_all_files_filter=True,
parent=None,
modal=True,
name="",
mode=QFileDialog.ExistingFiles,
default_dir="~",
no_save_dir=False,
):
QObject.__init__(self)
ftext = ""
if filters:
for filter in filters:
text, extensions = filter
extensions = ["*" + (i if i.startswith(".") else "." + i) for i in extensions]
ftext += "%s (%s);;" % (text, " ".join(extensions))
if add_all_files_filter or not ftext:
ftext += "All files (*)"
if ftext.endswith(";;"):
ftext = ftext[:-2]
self.dialog_name = name if name else "dialog_" + title
self.selected_files = None
self.fd = None
if no_save_dir:
initial_dir = os.path.expanduser(default_dir)
else:
initial_dir = dynamic.get(self.dialog_name, os.path.expanduser(default_dir))
if not isinstance(initial_dir, basestring):
initial_dir = os.path.expanduser(default_dir)
self.selected_files = []
use_native_dialog = "CALIBRE_NO_NATIVE_FILEDIALOGS" not in os.environ
with SanitizeLibraryPath():
opts = QFileDialog.Option()
if not use_native_dialog:
opts |= QFileDialog.DontUseNativeDialog
if mode == QFileDialog.AnyFile:
f = unicode(QFileDialog.getSaveFileName(parent, title, initial_dir, ftext, "", opts))
if f:
self.selected_files.append(f)
elif mode == QFileDialog.ExistingFile:
f = unicode(QFileDialog.getOpenFileName(parent, title, initial_dir, ftext, "", opts))
if f and os.path.exists(f):
self.selected_files.append(f)
elif mode == QFileDialog.ExistingFiles:
fs = QFileDialog.getOpenFileNames(parent, title, initial_dir, ftext, "", opts)
for f in fs:
f = unicode(f)
if not f:
continue
if not os.path.exists(f):
# QFileDialog for some reason quotes spaces
# on linux if there is more than one space in a row
f = unquote(f)
if f and os.path.exists(f):
self.selected_files.append(f)
else:
if mode == QFileDialog.Directory:
opts |= QFileDialog.ShowDirsOnly
f = unicode(QFileDialog.getExistingDirectory(parent, title, initial_dir, opts))
if os.path.exists(f):
self.selected_files.append(f)
if self.selected_files:
self.selected_files = [unicode(q) for q in self.selected_files]
saved_loc = self.selected_files[0]
if os.path.isfile(saved_loc):
saved_loc = os.path.dirname(saved_loc)
if not no_save_dir:
dynamic[self.dialog_name] = saved_loc
self.accepted = bool(self.selected_files)