本文整理汇总了Python中AnyQt.QtCore.QSettings.setValue方法的典型用法代码示例。如果您正苦于以下问题:Python QSettings.setValue方法的具体用法?Python QSettings.setValue怎么用?Python QSettings.setValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtCore.QSettings
的用法示例。
在下文中一共展示了QSettings.setValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_plot
# 需要导入模块: from AnyQt.QtCore import QSettings [as 别名]
# 或者: from AnyQt.QtCore.QSettings import setValue [as 别名]
def save_plot(data, file_formats, filename=""):
_LAST_DIR_KEY = "directories/last_graph_directory"
_LAST_FILTER_KEY = "directories/last_graph_filter"
settings = QSettings()
start_dir = settings.value(_LAST_DIR_KEY, filename)
if not start_dir or \
(not os.path.exists(start_dir) and
not os.path.exists(os.path.split(start_dir)[0])):
start_dir = os.path.expanduser("~")
last_filter = settings.value(_LAST_FILTER_KEY, "")
filename, writer, filter = \
filedialogs.open_filename_dialog_save(start_dir, last_filter, file_formats)
if not filename:
return
try:
writer.write(filename, data)
except OSError as e:
mb = QMessageBox(
None,
windowTitle="Error",
text='Error occurred while saving file "{}": {}'.format(filename, e),
detailedText=traceback.format_exc(),
icon=QMessageBox.Critical)
mb.exec_()
else:
settings.setValue(_LAST_DIR_KEY, os.path.split(filename)[0])
settings.setValue(_LAST_FILTER_KEY, filter)
示例2: test_qsettings_type
# 需要导入模块: from AnyQt.QtCore import QSettings [as 别名]
# 或者: from AnyQt.QtCore.QSettings import setValue [as 别名]
def test_qsettings_type(self):
"""
Test if QSettings as exported by qtcompat has the 'type' parameter.
"""
with tempfile.NamedTemporaryFile("w+b", suffix=".ini",
delete=False) as f:
settings = QSettings(f.name, QSettings.IniFormat)
settings.setValue("bar", "foo")
self.assertEqual(settings.value("bar", type=str), "foo")
settings.setValue("frob", 4)
del settings
settings = QSettings(f.name, QSettings.IniFormat)
self.assertEqual(settings.value("bar", type=str), "foo")
self.assertEqual(settings.value("frob", type=int), 4)
示例3: save_plot
# 需要导入模块: from AnyQt.QtCore import QSettings [as 别名]
# 或者: from AnyQt.QtCore.QSettings import setValue [as 别名]
def save_plot(data, file_formats, filename=""):
_LAST_DIR_KEY = "directories/last_graph_directory"
_LAST_FILTER_KEY = "directories/last_graph_filter"
settings = QSettings()
start_dir = settings.value(_LAST_DIR_KEY, filename)
if not start_dir or \
(not os.path.exists(start_dir) and
not os.path.exists(os.path.split(start_dir)[0])):
start_dir = os.path.expanduser("~")
last_filter = settings.value(_LAST_FILTER_KEY, "")
filename, writer, filter = \
filedialogs.get_file_name(start_dir, last_filter, file_formats)
if not filename:
return
try:
writer.write(filename, data)
except Exception as e:
QMessageBox.critical(
None, "Error", 'Error occurred while saving file "{}": {}'.format(filename, e))
else:
settings.setValue(_LAST_DIR_KEY, os.path.split(filename)[0])
settings.setValue(_LAST_FILTER_KEY, filter)
示例4: _userconfirmed
# 需要导入模块: from AnyQt.QtCore import QSettings [as 别名]
# 或者: from AnyQt.QtCore.QSettings import setValue [as 别名]
def _userconfirmed():
session_hist = QSettings(filename, QSettings.IniFormat)
session_hist.beginGroup(namespace)
session_hist.setValue(
"{}/confirmed".format(message.persistent_id), True)
session_hist.sync()
示例5: check_for_updates
# 需要导入模块: from AnyQt.QtCore import QSettings [as 别名]
# 或者: from AnyQt.QtCore.QSettings import setValue [as 别名]
def check_for_updates():
settings = QSettings()
check_updates = settings.value('startup/check-updates', True, type=bool)
last_check_time = settings.value('startup/last-update-check-time', 0, type=int)
ONE_DAY = 86400
if check_updates and time.time() - last_check_time > ONE_DAY:
settings.setValue('startup/last-update-check-time', int(time.time()))
from Orange.version import version as current
class GetLatestVersion(QThread):
resultReady = pyqtSignal(str)
def run(self):
try:
request = Request('https://orange.biolab.si/version/',
headers={
'Accept': 'text/plain',
'Accept-Encoding': 'gzip, deflate',
'Connection': 'close',
'User-Agent': self.ua_string()})
contents = urlopen(request, timeout=10).read().decode()
# Nothing that this fails with should make Orange crash
except Exception: # pylint: disable=broad-except
log.exception('Failed to check for updates')
else:
self.resultReady.emit(contents)
@staticmethod
def ua_string():
is_anaconda = 'Continuum' in sys.version or 'conda' in sys.version
return 'Orange{orange_version}:Python{py_version}:{platform}:{conda}'.format(
orange_version=current,
py_version='.'.join(sys.version[:3]),
platform=sys.platform,
conda='Anaconda' if is_anaconda else '',
)
def compare_versions(latest):
version = pkg_resources.parse_version
if version(latest) <= version(current):
return
question = QMessageBox(
QMessageBox.Information,
'Orange Update Available',
'A newer version of Orange is available.<br><br>'
'<b>Current version:</b> {}<br>'
'<b>Latest version:</b> {}'.format(current, latest),
textFormat=Qt.RichText)
ok = question.addButton('Download Now', question.AcceptRole)
question.setDefaultButton(ok)
question.addButton('Remind Later', question.RejectRole)
question.finished.connect(
lambda:
question.clickedButton() == ok and
QDesktopServices.openUrl(QUrl("https://orange.biolab.si/download/")))
question.show()
thread = GetLatestVersion()
thread.resultReady.connect(compare_versions)
thread.start()
return thread