本文整理汇总了Python中preferences.Preferences.load方法的典型用法代码示例。如果您正苦于以下问题:Python Preferences.load方法的具体用法?Python Preferences.load怎么用?Python Preferences.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类preferences.Preferences
的用法示例。
在下文中一共展示了Preferences.load方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testSaveLoad
# 需要导入模块: from preferences import Preferences [as 别名]
# 或者: from preferences.Preferences import load [as 别名]
def testSaveLoad(self):
prefs = Preferences('prefstest.conf')
self.assertEqual(None, prefs.btDevice)
self.assertEqual('bluetooth', prefs.connectionMethod)
self.assertEqual('', prefs.customDevice)
self.assertEqual(0, prefs.gammuIndex)
prefs.btDevice = BluetoothDevice('00:00:00:00', 42, 'deviceName', 'serviceName')
prefs.connectionMethod = 'connection'
prefs.customDevice = '/dev/rfcomm0'
prefs.gammuIndex = 2
prefs.save()
prefsLoaded = Preferences('prefstest.conf')
prefsLoaded.load()
self.assertNotEqual(None, prefsLoaded.btDevice, "Device has not been loaded")
self.assertEqual('00:00:00:00', prefsLoaded.btDevice.address)
self.assertEqual(42, prefsLoaded.btDevice.port)
self.assertEqual('deviceName', prefsLoaded.btDevice.deviceName)
self.assertEqual('serviceName', prefsLoaded.btDevice.serviceName)
self.assertEqual('connection', prefsLoaded.connectionMethod)
self.assertEqual('/dev/rfcomm0', prefsLoaded.customDevice)
self.assertEqual(2, prefsLoaded.gammuIndex)
示例2: MainFrame
# 需要导入模块: from preferences import Preferences [as 别名]
# 或者: from preferences.Preferences import load [as 别名]
#.........这里部分代码省略.........
if not os.path.exists(self.metaDir):
wx.MessageBox('Path "' + self.rootDir + '" is no valid root dir.', \
'Error', wx.OK | wx.ICON_ERROR)
self.UpdateRootDir(None)
return
if not os.path.exists(self.dbFile):
wx.MessageBox('Cannot find database file "' + self.dbFile + '".', \
'Error', wx.OK | wx.ICON_ERROR)
self.UpdateRootDir(None)
return
if not os.path.exists(self.sigFile):
dial = wx.MessageBox('Cannot find database signature file "' + self.sigFile + '".\n\nUse database without verification?', \
'Warning', wx.YES_NO | wx.ICON_WARNING | wx.NO_DEFAULT)
if not dial == wx.YES:
self.UpdateRootDir(None)
return
else:
cs = Checksum()
cs.calculateForFile(self.dbFile)
if not cs.isValidUsingSavedFile(self.sigFile):
dial = wx.MessageBox('Database or database signature file have been corrupted.\n\nUse database without verification?', \
'Warning', wx.YES_NO | wx.ICON_WARNING | wx.NO_DEFAULT)
if not dial == wx.YES:
self.UpdateRootDir(None)
return
# close eventually existing previous instance
self.list.ClearInstance()
self.SetStatusBarText()
# load preferences or create default ones
self.preferences = Preferences()
if os.path.exists(self.preferencesFile):
self.preferences.load(self.preferencesFile)
else:
self.preferences.save(self.preferencesFile)
def OnPreferences(self, event):
if self.preferences is None:
wx.MessageBox('Import or Open directory before you can access its preferences.', \
'Error', wx.OK | wx.ICON_ERROR)
return
preferencesDialog = PreferencesDialog(self, self.preferences)
preferencesDialog.ShowModal()
self.preferences.save(self.preferencesFile)
def OnExit(self, event):
self.Close(True)
def Import(self):
# do not care about previous content: reset meta directory and database files
if os.path.exists(self.metaDir):
if os.path.exists(self.dbFile):
os.remove(self.dbFile)
if os.path.exists(self.sigFile):
os.remove(self.sigFile)
if os.path.exists(self.preferencesFile):
os.remove(self.preferencesFile)
else:
os.mkdir(self.metaDir)
# if on windows platform, hide directory
if platform.system() == 'Windows':
os.system('attrib +h "' + self.metaDir + '"')
self.preferences = Preferences()
preferencesDialog = PreferencesDialog(self, self.preferences)
示例3: MusicGuru
# 需要导入模块: from preferences import Preferences [as 别名]
# 或者: from preferences.Preferences import load [as 别名]
class MusicGuru(MusicGuruBase, ApplicationBase):
LOGO_NAME = 'mg_logo'
def __init__(self):
appdata = str(QDesktopServices.storageLocation(QDesktopServices.DataLocation))
MusicGuruBase.__init__(self, appdata)
ApplicationBase.__init__(self)
if not op.exists(appdata):
os.makedirs(appdata)
logging.basicConfig(filename=op.join(appdata, 'debug.log'), level=logging.WARNING)
self.prefs = Preferences()
self.prefs.load()
self.selectedBoardItems = []
self.selectedLocation = None
self.mainWindow = MainWindow(app=self)
self.locationsPanel = LocationsPanel(app=self)
self.detailsPanel = DetailsPanel(app=self)
self.ignoreBox = IgnoreBox(app=self)
self.progress = Progress(self.mainWindow)
self.aboutBox = AboutBox(self.mainWindow, self)
self.connect(self.progress, SIGNAL('finished(QString)'), self.jobFinished)
self.connect(self, SIGNAL('applicationFinishedLaunching()'), self.applicationFinishedLaunching)
#--- Private
def _placeDetailsPanel(self):
# locations panel must be placed first
if self.detailsPanel.isVisible():
return
desktop = QApplication.desktop()
w = self.locationsPanel.width()
h = self.detailsPanel.height()
x = self.locationsPanel.x()
windowBottom = self.locationsPanel.frameGeometry().y() + self.locationsPanel.frameGeometry().height()
y = windowBottom
self.detailsPanel.move(x, y)
self.detailsPanel.resize(w, h)
def _placeIgnoreBox(self):
if self.ignoreBox.isVisible():
return
desktop = QApplication.desktop()
windowWidth = self.mainWindow.frameGeometry().width()
frameWidth = self.ignoreBox.frameGeometry().width() - self.ignoreBox.width()
w = windowWidth - frameWidth
h = self.ignoreBox.height()
x = self.mainWindow.x()
windowBottom = self.mainWindow.frameGeometry().y() + self.mainWindow.frameGeometry().height()
y = min(windowBottom, desktop.height() - h)
self.ignoreBox.move(x, y)
self.ignoreBox.resize(w, h)
def _placeLocationsPanel(self):
if self.locationsPanel.isVisible():
return
desktop = QApplication.desktop()
w = self.locationsPanel.width()
windowHeight = self.mainWindow.frameGeometry().height()
frameHeight = self.locationsPanel.frameGeometry().height() - self.locationsPanel.height()
h = windowHeight - frameHeight - self.detailsPanel.frameGeometry().height()
windowRight = self.mainWindow.frameGeometry().x() + self.mainWindow.frameGeometry().width()
x = min(windowRight, desktop.width() - w)
y = self.mainWindow.y()
self.locationsPanel.move(x, y)
self.locationsPanel.resize(w, h)
def _setup_as_registered(self):
self.prefs.registration_code = self.registration_code
self.prefs.registration_email = self.registration_email
self.prefs.save()
self.mainWindow.actionRegister.setVisible(False)
self.aboutBox.registerButton.hide()
self.aboutBox.registeredEmailLabel.setText(self.prefs.registration_email)
def _startJob(self, jobid, func):
title = JOBID2TITLE[jobid]
try:
j = self.progress.create_job()
self.progress.run(jobid, title, func, args=(j, ))
except job.JobInProgressError:
msg = "A previous action is still hanging in there. You can't start a new one yet. Wait a few seconds, then try again."
QMessageBox.information(self.mainWindow, "Action in progress", msg)
#--- Public
def addLocation(self, path, name, removeable):
def do(j):
MusicGuruBase.AddLocation(self, path, name, removeable, j)
error_msg = self.CanAddLocation(path, name)
if error_msg:
QMessageBox.warning(self.mainWindow, "Add Location", error_msg)
return
self._startJob(JOB_ADD, do)
def addLocationPrompt(self):
dialog = AddLocationDialog(self)
result = dialog.exec_()
if result == QDialog.Accepted:
self.addLocation(dialog.locationPath, dialog.locationName, dialog.isLocationRemovable)
#.........这里部分代码省略.........