本文整理汇总了Python中PySide.QtCore.QFile类的典型用法代码示例。如果您正苦于以下问题:Python QFile类的具体用法?Python QFile怎么用?Python QFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, parent=None):
super(IPHelper, self).__init__(parent)
f = QFile(os.path.join(os.path.split(__file__)[0], 'iphelper.ui'))
loadUi(f, self)
f.close()
self.ipAddress = None
# create validators
validator = QRegExpValidator(QRegExp('\d{,3}'))
self.uiFirstTetTXT.setValidator(validator)
self.uiSecondTetTXT.setValidator(validator)
self.uiThirdTetTXT.setValidator(validator)
self.uiFourthTetTXT.setValidator(validator)
# build a map of the buttons
self.buttons = [None]*16
self.signalMapper = QSignalMapper(self)
self.signalMapper.mapped.connect(self.tetMap)
for button in self.findChildren(QPushButton):
match = re.findall(r'^uiTrellis(\d{,2})BTN$', button.objectName())
if match:
i = int(match[0])
self.buttons[i] = button
if i >= 12:
self.signalMapper.setMapping(button, i)
button.clicked.connect(self.signalMapper.map)
self.tetMap(12)
示例2: findOrSaveConfig
def findOrSaveConfig(self):
infile = QFile('ui/config_path.ui')
infile.open(QFile.ReadOnly)
loader = QUiLoader()
dialog = loader.load(infile, self.window)
infile.close()
def browse():
path = QFileDialog.getSaveFileName(dialog, u"Choose or create a configuration file", dialog.pathBox.text())[0]
if path != '':
dialog.pathBox.setText(path)
def cancel():
dialog.hide()
def ok():
autodetectPort = dialog.autodetect.checkState() == Qt.Checked
configPath = os.path.expanduser(dialog.pathBox.text())
dialog.hide()
self.start(configPath, autodetectPort)
dialog.show()
dialog.pathBox.setText(os.path.expanduser('~/.config/tangelo/tangelo.conf'))
dialog.browseButton.clicked.connect(browse)
dialog.cancelButton.clicked.connect(cancel)
dialog.okButton.clicked.connect(ok)
示例3: __init__
def __init__(self):
self.loader = QUiLoader()
infile = QFile("resources/loading.ui")
infile.open(QFile.ReadOnly)
self.window = self.loader.load(infile, None)
infile.close()
self.overrides = {'personID':self.window.personID,
'paID':self.window.paID,
'maID':self.window.maID,
'sex':self.window.sex,
'affected':self.window.affected,
'n_local_aff':self.window.n_local_aff,
'n_local_desc':self.window.n_local_desc,
'nicki_d':self.window.nicki_d,
'is_root':self.window.is_root,
'is_leaf':self.window.is_leaf,
'generation':self.window.generation}
self.requiredForCalculateD = set(['personID','paID','maID','sex','affected'])
self.header = []
self.lowerHeader = []
self.window.browseInputButton.clicked.connect(self.browseInput)
self.window.inputField.textChanged.connect(self.switchPrograms)
self.window.browseOutputButton.clicked.connect(self.browseOutput)
self.window.outputField.textChanged.connect(self.switchPrograms)
self.window.programBox.currentIndexChanged.connect(self.switchPrograms)
self.window.runButton.clicked.connect(self.go)
self.switchPrograms()
self.window.buttonBox.setEnabled(False)
self.window.show()
示例4: loadDialog
def loadDialog(file_name):
loader = QUiLoader()
the_file = QFile(file_name)
the_file.open(QFile.ReadOnly)
ret_val = loader.load(the_file)
the_file.close()
return ret_val
示例5: loadWindowFromFile
def loadWindowFromFile(file_name):
'''Load the window definition from the resource ui file'''
loader = QUiLoader()
ui_file = QFile(file_name)
ui_file.open(QFile.ReadOnly)
the_window = loader.load(ui_file)
ui_file.close()
return the_window
示例6: getContent
def getContent(path):
file = QFile(path)
if not file.open(QIODevice.ReadOnly | QIODevice.Text):
return
ts = QTextStream(file)
ts.setCodec("UTF-8")
res = ts.readAll()
return res
示例7: loadHyperlinkDialog
def loadHyperlinkDialog(self):
''' Load dialog from ui file for defining hyperlink '''
loader = QUiLoader()
ui_file = QFile(':/hyperlink.ui') # UI_DIALOG_FILE)
ui_file.open(QFile.ReadOnly)
self.hyperlink_dialog = loader.load(ui_file)
ui_file.close()
self.hyperlink_dialog.accepted.connect(self.hyperlinkChanged)
self.hlink_field = self.hyperlink_dialog.findChild(QLineEdit, 'hlink')
示例8: LogFilePositionSource
class LogFilePositionSource(QGeoPositionInfoSource):
def __init__(self, parent):
QGeoPositionInfoSource.__init__(self, parent)
self.logFile = QFile(self)
self.timer = QTimer(self)
self.timer.timeout.connect(self.readNextPosition)
self.logFile.setFileName(translate_filename('simplelog.txt'))
assert self.logFile.open(QIODevice.ReadOnly)
self.lastPosition = QGeoPositionInfo()
def lastKnownPosition(self, fromSatellitePositioningMethodsOnly):
return self.lastPosition
def minimumUpdateInterval(self):
return 100
def startUpdates(self):
interval = self.updateInterval()
if interval < self.minimumUpdateInterval():
interval = self.minimumUpdateInterval()
self.timer.start(interval)
def stopUpdates(self):
self.timer.stop()
def requestUpdate(self, timeout):
# For simplicity, ignore timeout - assume that if data is not available
# now, no data will be added to the file later
if (self.logFile.canReadLine()):
self.readNextPosition()
else:
self.updateTimeout.emit()
def readNextPosition(self):
line = self.logFile.readLine().trimmed()
if not line.isEmpty():
data = line.split(' ')
hasLatitude = True
hasLongitude = True
timestamp = QDateTime.fromString(str(data[0]), Qt.ISODate)
latitude = float(data[1])
longitude = float(data[2])
if timestamp.isValid():
coordinate = QGeoCoordinate(latitude, longitude)
info = QGeoPositionInfo(coordinate, timestamp)
if info.isValid():
self.lastPosition = info
# Currently segfaulting. See Bug 657
# http://bugs.openbossa.org/show_bug.cgi?id=657
self.positionUpdated.emit(info)
示例9: testBug909
def testBug909(self):
fileName = QFile(adjust_filename('bug_909.ui', __file__))
loader = QUiLoader()
main_win = loader.load(fileName)
self.assertEqual(sys.getrefcount(main_win), 2)
fileName.close()
tw = QTabWidget(main_win)
main_win.setCentralWidget(tw)
main_win.show()
示例10: __load_ui
def __load_ui(self):
ui_path = os.path.dirname(__file__)
ui_path = os.path.join(ui_path, "MainWindow.ui")
ui_file = QFile(ui_path)
ui_file.open(QFile.ReadOnly)
ui_loader = QtUiTools.QUiLoader()
self.__ui = ui_loader.load(ui_file, None)
ui_file.close()
self.__ui.answerTableWidget.setHorizontalHeaderLabels([self.tr("Question"), self.tr("Answer")])
示例11: createWidget
def createWidget(self):
# Override the existing widget
# TODO: Do I need to delete anything explicitly?
infile = QFile('ui/process_widget.ui')
infile.open(QFile.ReadOnly)
loader = QUiLoader()
self.widget = loader.load(infile, Globals.mainWindow.window)
infile.close()
self.updateWidget(True)
示例12: download_file
def download_file(self, path, setting):
version_file = self.settings['base_url'].format(self.selected_version())
location = self.get_setting('download_dir').value
versions = re.findall('v(\d+)\.(\d+)\.(\d+)', path)[0]
minor = int(versions[1])
if minor >= 12:
path = path.replace('node-webkit', 'nwjs')
self.progress_text = 'Downloading {}'.format(path.replace(version_file, ''))
url = QUrl(path)
file_name = setting.save_file_path(self.selected_version(), location)
archive_exists = QFile.exists(file_name)
#dest_files_exist = False
# for dest_file in setting.dest_files:
# dest_file_path = os.path.join('files', setting.name, dest_file)
# dest_files_exist &= QFile.exists(dest_file_path)
forced = self.get_setting('force_download').value
if archive_exists and not forced:
self.continue_downloading_or_extract()
return
self.out_file = QFile(file_name)
if not self.out_file.open(QIODevice.WriteOnly):
error = self.out_file.error().name
self.show_error('Unable to save the file {}: {}.'.format(file_name,
error))
self.out_file = None
self.enable_ui()
return
mode = QHttp.ConnectionModeHttp
port = url.port()
if port == -1:
port = 0
self.http.setHost(url.host(), mode, port)
self.http_request_aborted = False
path = QUrl.toPercentEncoding(url.path(), "!$&'()*+,;=:@/")
if path:
path = str(path)
else:
path = '/'
# Download the file.
self.http_get_id = self.http.get(path, self.out_file)
示例13: readModel
def readModel(self,fileName):
file = QFile(fileName)
if (file.open(QIODevice.ReadOnly | QIODevice.Text)):
xmlReader = QXmlSimpleReader()
xmlReader.setContentHandler(self)
xmlReader.setErrorHandler(self)
xmlSource = QXmlInputSource(file)
xmlReader.parse(xmlSource)
return self.modelData
else:
return None
示例14: findTangelo
def findTangelo():
infile = QFile('ui/find_tangelo.ui')
infile.open(QFile.ReadOnly)
loader = QUiLoader()
dialog = loader.load(infile, None)
infile.close()
if sys.platform.startswith('win'):
Globals.pythonPath = subprocess.Popen(['where', 'python'], stdout=subprocess.PIPE).communicate()[0].strip()
Globals.tangeloPath = subprocess.Popen(['where', 'tangelo'], stdout=subprocess.PIPE).communicate()[0].strip()
else:
Globals.pythonPath = subprocess.Popen(['which', 'python'], stdout=subprocess.PIPE).communicate()[0].strip()
Globals.tangeloPath = subprocess.Popen(['which', 'tangelo'], stdout=subprocess.PIPE).communicate()[0].strip()
if os.path.exists(Globals.pythonPath):
dialog.pythonPathBox.setText(Globals.pythonPath)
if os.path.exists(Globals.tangeloPath):
dialog.tangeloPathBox.setText(Globals.tangeloPath)
def pythonBrowse():
path = QFileDialog.getOpenFileName(dialog, u"Find python", dialog.pythonPathBox.text())[0]
if path != '':
dialog.pythonPathBox.setText(path)
def tangeloBrowse():
path = QFileDialog.getOpenFileName(dialog, u"Find tangelo", dialog.tangeloPathBox.text())[0]
if path != '':
dialog.tangeloPathBox.setText(path)
def cancel():
dialog.hide()
sys.exit()
def ok():
Globals.pythonPath = os.path.expanduser(dialog.pythonPathBox.text())
Globals.tangeloPath = os.path.expanduser(dialog.tangeloPathBox.text())
if not os.path.exists(Globals.pythonPath):
Globals.criticalError("Sorry, that python interpreter doesn't exist.")
return
if not os.path.exists(Globals.tangeloPath):
Globals.criticalError("Sorry, that tangelo executable doesn't exist.")
return
Globals.mainWindow = Overview()
Globals.mainWindow.refresh()
dialog.hide()
dialog.show()
dialog.tangeloBrowse.clicked.connect(tangeloBrowse)
dialog.pythonBrowse.clicked.connect(pythonBrowse)
dialog.cancelButton.clicked.connect(cancel)
dialog.okButton.clicked.connect(ok)
示例15: TestQFileSignalBlocking
class TestQFileSignalBlocking(unittest.TestCase):
'''Test case for blocking the signal QIODevice.aboutToClose()'''
def setUp(self):
#Set up the needed resources - A temp file and a QFile
self.called = False
handle, self.filename = mkstemp()
os.close(handle)
self.qfile = QFile(self.filename)
def tearDown(self):
#Release acquired resources
os.remove(self.filename)
del self.qfile
def callback(self):
#Default callback
self.called = True
def testAboutToCloseBlocking(self):
#QIODevice.aboutToClose() blocking
QObject.connect(self.qfile, SIGNAL('aboutToClose()'), self.callback)
self.assert_(self.qfile.open(QFile.ReadOnly))
self.qfile.close()
self.assert_(self.called)
self.called = False
self.qfile.blockSignals(True)
self.assert_(self.qfile.open(QFile.ReadOnly))
self.qfile.close()
self.assert_(not self.called)