本文整理汇总了Python中tools.prefs.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: configure
def configure(self, parent):
""" Show the configuration window """
if self.cfgWin is None:
self.cfgWin = gui.window.Window("AudioCD.ui", "vbox1", __name__, MOD_L10N, 335, 270)
self.cfgWin.getWidget("btn-ok").connect("clicked", self.onBtnOk)
self.cfgWin.getWidget("btn-help").connect("clicked", self.onBtnHelp)
self.cfgWin.getWidget("chk-useCDDB").connect("toggled", self.onUseCDDBToggled)
self.cfgWin.getWidget("btn-clearCache").connect("clicked", self.onBtnClearCache)
self.cfgWin.getWidget("btn-cancel").connect("clicked", lambda btn: self.cfgWin.hide())
# Set up the combo box
combo = self.cfgWin.getWidget("combo-read-speed")
txtRenderer = gtk.CellRendererText()
combo.pack_start(txtRenderer, True)
combo.add_attribute(txtRenderer, "text", 0)
combo.set_sensitive(True)
txtRenderer.set_property("xpad", 6)
# Setup the liststore
store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_INT)
combo.set_model(store)
for speed in sorted(READ_SPEEDS.iterkeys()):
store.append(("%ux" % speed, speed))
if not self.cfgWin.isVisible():
self.cfgWin.getWidget("btn-ok").grab_focus()
self.cfgWin.getWidget("txt-device").set_text(prefs.get(__name__, "device", PREFS_DFT_DEVICE))
self.cfgWin.getWidget("chk-useCDDB").set_active(prefs.get(__name__, "use-cddb", PREFS_DFT_USE_CDDB))
self.cfgWin.getWidget("chk-useCache").set_sensitive(prefs.get(__name__, "use-cddb", PREFS_DFT_USE_CDDB))
self.cfgWin.getWidget("chk-useCache").set_active(prefs.get(__name__, "use-cache", PREFS_DFT_USE_CACHE))
self.cfgWin.getWidget("combo-read-speed").set_active(
READ_SPEEDS[prefs.get(__name__, "read-speed", PREFS_DFT_READ_SPEED)]
)
self.cfgWin.show()
示例2: showNotification
def showNotification(self):
""" Show the notification based on the current track """
self.timeout = None
# Can this happen?
if self.currTrack is None:
return False
# Contents
body = self.currTrack.formatHTMLSafe(prefs.get(__name__, 'body', PREFS_DEFAULT_BODY))
title = self.currTrack.format(prefs.get(__name__, 'title', PREFS_DEFAULT_TITLE))
# Icon
if self.currCover is None: img = consts.fileImgIcon64
else: img = self.currCover
if os.path.isfile(img): icon = 'file://' + img
else: icon = gtk.STOCK_DIALOG_INFO
# Create / Update the notification and show it
if self.notif is None: self.__createNotification(title, body, icon)
else: self.notif.update(title, body, icon)
## Catch errors that occur when pynotify is not installed properly
try:
self.notif.show()
except gobject.GError:
pass
return False
示例3: __loadAuthInfo
def __loadAuthInfo(id):
""" Load the login/password associated with id, either from the Gnome keyring or from the prefs """
try:
import gnomekeyring as gk
useGK = True
except:
useGK = False
# No Gnome keyring
if not useGK:
login = prefs.get(__name__, id + '_login', None)
passwd = prefs.get(__name__, id + '_passwd', None)
if login is not None and passwd is not None: return (login, b64decode(passwd))
else: return None
# From here we can use the Gnome keyring
__loadKeyring()
try: gk.create_sync(__keyring, None)
except gk.AlreadyExistsError: pass
token = prefs.get(__name__, id + '_gkToken', None)
if token is not None:
try:
login, passwd = gk.item_get_info_sync(__keyring, token).get_secret().split('\n')
return (login, passwd)
except:
pass
return None
示例4: modInit
def modInit(self):
""" Initialize the module """
self.lvls = prefs.get(__name__, 'levels', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
self.preset = prefs.get(__name__, 'preset', _('Flat'))
self.cfgWindow = None
modules.addMenuItem(_('Equalizer'), self.configure, '<Control>E')
示例5: showNotification
def showNotification(self):
""" Show the notification based on the current track """
self.timeout = None
# Can this happen?
if self.currTrack is None:
return False
# Contents
body = self.currTrack.formatHTMLSafe(prefs.get(__name__, 'body', PREFS_DEFAULT_BODY))
title = self.currTrack.format(prefs.get(__name__, 'title', PREFS_DEFAULT_TITLE))
# Icon
if self.currCover is None: img = os.path.join(consts.dirPix, 'decibel-audio-player-64.png')
else: img = self.currCover
if os.path.isfile(img): icon = 'file://' + img
else: icon = gtk.STOCK_DIALOG_INFO
# Create / Update the notification and show it
if self.notif is None: self.__createNotification(title, body, icon)
else: self.notif.update(title, body, icon)
self.notif.show()
return False
示例6: onBtnOk
def onBtnOk(self, btn):
""" Save new preferences """
# Skipping tracks
newSkipTrack = self.cfgWin.getWidget('chk-skipTrack').get_active()
oldSkipTrack = prefs.get(__name__, 'skip-track', PREFS_DEFAULT_SKIP_TRACK)
prefs.set(__name__, 'skip-track', newSkipTrack)
if oldSkipTrack != newSkipTrack and self.notif is not None:
if newSkipTrack: self.notif.add_action('stop', _('Skip track'), self.onSkipTrack)
else: self.notif.clear_actions()
# Timeout
newTimeout = int(self.cfgWin.getWidget('spn-duration').get_value())
oldTimeout = prefs.get(__name__, 'timeout', PREFS_DEFAULT_TIMEOUT)
prefs.set(__name__, 'timeout', newTimeout)
if oldTimeout != newTimeout and self.notif is not None:
self.notif.set_timeout(newTimeout * 1000)
# Other preferences
prefs.set(__name__, 'title', self.cfgWin.getWidget('txt-title').get_text())
(start, end) = self.cfgWin.getWidget('txt-body').get_buffer().get_bounds()
prefs.set(__name__, 'body', self.cfgWin.getWidget('txt-body').get_buffer().get_text(start, end))
self.cfgWin.hide()
示例7: onModLoaded
def onModLoaded(self):
""" The module has been loaded """
self.startTime = 0
self.paused = prefs.get(__name__, 'was-paused', False)
self.playing = prefs.get(__name__, 'was-playing', False)
self.currPos = prefs.get(__name__, 'position', 0)
self.currTrack = prefs.get(__name__, 'track', None)
self.currTracklist = prefs.get(__name__, 'tracklist', [])
示例8: updateFile
def updateFile(self, track):
""" Show the notification based on the given track """
output = open(prefs.get(__name__, "file", PREFS_DEFAULT_FILE), "w")
if track is None:
output.write("")
else:
output.write(track.format(prefs.get(__name__, "status", PREFS_DEFAULT_STATUS)))
output.close()
示例9: onAppStarted
def onAppStarted(self):
""" This is the real initialization function, called when the module has been loaded """
self.tree = None
self.currLib = None
self.cfgWindow = None
self.libraries = prefs.get(__name__, 'libraries', PREFS_DEFAULT_LIBRARIES)
self.treeState = prefs.get(__name__, 'tree-state', PREFS_DEFAULT_TREE_STATE)
# Scroll window
self.scrolled = gtk.ScrolledWindow()
self.scrolled.set_shadow_type(gtk.SHADOW_IN)
self.scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.scrolled.show()
示例10: main
def main():
log.logger.info('Started')
# Localization
locale.setlocale(locale.LC_ALL, '')
gettext.textdomain(consts.appNameShort)
gettext.bindtextdomain(consts.appNameShort, consts.dirLocale)
# Command line
prefs.setCmdLine((optOptions, optArgs))
# PyGTK initialization
gobject.threads_init()
gtk.window_set_default_icon_list(
gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon16),
gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon24),
gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon32),
gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon48),
gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon64),
gtk.gdk.pixbuf_new_from_file(consts.fileImgIcon128))
# Create the GUI
wTree = loadGladeFile('MainWindow.ui')
paned = wTree.get_object('pan-main')
window = wTree.get_object('win-main')
prefs.setWidgetsTree(wTree)
# RGBA support
try:
colormap = window.get_screen().get_rgba_colormap()
if colormap:
gtk.widget_set_default_colormap(colormap)
except:
log.logger.info('No RGBA support (requires PyGTK 2.10+)')
# Show all widgets and restore the window size BEFORE hiding some of them
# when restoring the view mode
# Resizing must be done before showing the window to make sure that the WM
# correctly places the window
if prefs.get(__name__, 'win-is-maximized', DEFAULT_MAXIMIZED_STATE):
window.maximize()
height = prefs.get(__name__, 'win-height', DEFAULT_WIN_HEIGHT)
window.resize(prefs.get(__name__, 'win-width', DEFAULT_WIN_WIDTH), height)
window.show_all()
# Restore sizes once more
#window.resize(prefs.get(__name__, 'win-width', DEFAULT_WIN_WIDTH), height)
paned.set_position(prefs.get(__name__, 'paned-pos', DEFAULT_PANED_POS))
# Initialization done, let's continue the show
gobject.idle_add(realStartup, window, paned)
gtk.main()
示例11: onNewTrack
def onNewTrack(self, track):
""" A new track is being played, try to retrieve the corresponding cover """
# Make sure we have enough information
if track.getArtist() == consts.UNKNOWN_ARTIST or track.getAlbum() == consts.UNKNOWN_ALBUM:
modules.postMsg(consts.MSG_CMD_SET_COVER, {'track': track, 'pathThumbnail': None, 'pathFullSize': None})
return
album = track.getAlbum().lower()
artist = track.getArtist().lower()
coverKey = artist + album
rawCover = None
self.currTrack = track
# Let's see whether we already have the cover
if coverKey in self.coverMap:
covers = self.coverMap[coverKey]
pathFullSize = covers[CVR_FULL]
pathThumbnail = covers[CVR_THUMB]
# Make sure the files are still there
if os.path.exists(pathThumbnail) and os.path.exists(pathFullSize):
modules.postMsg(consts.MSG_CMD_SET_COVER, {'track': track, 'pathThumbnail': pathThumbnail, 'pathFullSize': pathFullSize})
return
# Should we check for a user cover?
if not prefs.get(__name__, 'download-covers', PREFS_DFT_DOWNLOAD_COVERS) \
or prefs.get(__name__, 'prefer-user-covers', PREFS_DFT_PREFER_USER_COVERS):
rawCover = self.getUserCover(os.path.dirname(track.getFilePath()))
# Is it in our cache?
if rawCover is None:
rawCover = self.getFromCache(artist, album)
# If we still don't have a cover, maybe we can try to download it
if rawCover is None:
modules.postMsg(consts.MSG_CMD_SET_COVER, {'track': track, 'pathThumbnail': None, 'pathFullSize': None})
if prefs.get(__name__, 'download-covers', PREFS_DFT_DOWNLOAD_COVERS):
rawCover = self.getFromInternet(artist, album)
# If we still don't have a cover, too bad
# Otherwise, generate a thumbnail and a full size cover, and add it to our cover map
if rawCover is not None:
thumbnail = tempfile.mktemp() + '.png'
fullSizeCover = tempfile.mktemp() + '.png'
self.generateThumbnail(rawCover, thumbnail, 'PNG')
self.generateFullSizeCover(rawCover, fullSizeCover, 'PNG')
if os.path.exists(thumbnail) and os.path.exists(fullSizeCover):
self.coverMap[coverKey] = (thumbnail, fullSizeCover)
modules.postMsg(consts.MSG_CMD_SET_COVER, {'track': track, 'pathThumbnail': thumbnail, 'pathFullSize': fullSizeCover})
else:
modules.postMsg(consts.MSG_CMD_SET_COVER, {'track': track, 'pathThumbnail': None, 'pathFullSize': None})
示例12: __init__
def __init__(self, wtree, window):
""" Constructor """
self.wtree = wtree
self.paned = wtree.get_object('pan-main')
self.window = window
# Enable the right radio menu button
viewmode = prefs.get(__name__, 'view-mode', DEFAULT_VIEW_MODE)
if viewmode == consts.VIEW_MODE_FULL: self.wtree.get_object('menu-mode-full').set_active(True)
elif viewmode == consts.VIEW_MODE_LEAN: self.wtree.get_object('menu-mode-lean').set_active(True)
elif viewmode == consts.VIEW_MODE_MINI: self.wtree.get_object('menu-mode-mini').set_active(True)
elif viewmode == consts.VIEW_MODE_NETBOOK: self.wtree.get_object('menu-mode-netbook').set_active(True)
elif viewmode == consts.VIEW_MODE_PLAYLIST: self.wtree.get_object('menu-mode-playlist').set_active(True)
# Restore the size and the state of the window
if prefs.get(__name__, 'win-is-maximized', DEFAULT_MAXIMIZED_STATE):
self.window.maximize()
savedWidth = prefs.get(__name__, 'win-width', DEFAULT_WIN_WIDTH)
savedHeight = prefs.get(__name__, 'win-height', DEFAULT_WIN_HEIGHT)
savedPanPos = prefs.get(__name__, 'paned-pos', DEFAULT_PANED_POS)
self.window.resize(savedWidth, savedHeight)
self.paned.set_position(savedPanPos)
self.window.show_all()
# Restore the view mode
# We set the mode to VIEW_MODE_FULL in the preferences because the window is currently in this mode (initial startup state)
prefs.set(__name__, 'view-mode', consts.VIEW_MODE_FULL)
self.setViewMode(viewmode)
# Restore once again the size (may have been modified while restoring the view mode)
self.window.resize(savedWidth, savedHeight)
self.paned.set_position(savedPanPos)
# Finally connect the event handlers
self.window.connect('delete-event', self.onDelete)
self.window.connect('size-allocate', self.onResize)
self.window.connect('window-state-event', self.onState)
self.wtree.get_object('menu-mode-mini').connect('activate', self.onViewMode, consts.VIEW_MODE_MINI)
self.wtree.get_object('menu-mode-full').connect('activate', self.onViewMode, consts.VIEW_MODE_FULL)
self.wtree.get_object('menu-mode-lean').connect('activate', self.onViewMode, consts.VIEW_MODE_LEAN)
self.wtree.get_object('menu-mode-netbook').connect('activate', self.onViewMode, consts.VIEW_MODE_NETBOOK)
self.wtree.get_object('menu-mode-playlist').connect('activate', self.onViewMode, consts.VIEW_MODE_PLAYLIST)
self.wtree.get_object('menu-help').connect('activate', self.onHelp)
self.wtree.get_object('menu-about').connect('activate', self.onAbout)
self.wtree.get_object('menu-preferences').connect('activate', self.onShowPreferences)
self.wtree.get_object('menu-quit').connect('activate', lambda item: self.onDelete(window, None))
self.wtree.get_object('pan-main').connect('size-allocate', lambda win, rect: prefs.set(__name__, 'paned-pos', self.paned.get_position()))
示例13: __createNotification
def __createNotification(self, title, body, icon):
""" Create the Notification object """
import pynotify
if not pynotify.init(consts.appNameShort):
logger.error('[%s] Initialization of pynotify failed' % MOD_INFO[modules.MODINFO_NAME])
self.notif = pynotify.Notification(title, body, icon)
self.notif.set_urgency(pynotify.URGENCY_LOW)
self.notif.set_timeout(prefs.get(__name__, 'timeout', PREFS_DEFAULT_TIMEOUT) * 1000)
if prefs.get(__name__, 'skip-track', PREFS_DEFAULT_SKIP_TRACK):
self.notif.add_action('stop', _('Skip track'), self.onSkipTrack)
示例14: __format
def __format(self, string, track):
""" Replace the special fields in the given string by their corresponding value and sanitize the result """
result = track.format(string)
if len(prefs.get(__name__, 'sanitized-words', DEFAULT_SANITIZED_WORDS)) != 0:
lowerResult = result.lower()
for word in [w.lower() for w in prefs.get(__name__, 'sanitized-words', DEFAULT_SANITIZED_WORDS).split('\n') if len(w) > 2]:
pos = lowerResult.find(word)
while pos != -1:
result = result[:pos+1] + ('*' * (len(word)-2)) + result[pos+len(word)-1:]
lowerResult = lowerResult[:pos+1] + ('*' * (len(word)-2)) + lowerResult[pos+len(word)-1:]
pos = lowerResult.find(word)
return result
示例15: configure
def configure(self, parent):
""" Show the configuration window """
if self.cfgWindow is None:
from gui.window import Window
self.cfgWindow = Window('IMStatus.ui', 'vbox1', __name__, _(MOD_NAME), 440, 290)
# GTK handlers
self.cfgWindow.getWidget('rad-stopDoNothing').connect('toggled', self.onRadToggled)
self.cfgWindow.getWidget('rad-stopSetStatus').connect('toggled', self.onRadToggled)
self.cfgWindow.getWidget('btn-ok').connect('clicked', self.onBtnOk)
self.cfgWindow.getWidget('btn-cancel').connect('clicked', lambda btn: self.cfgWindow.hide())
self.cfgWindow.getWidget('btn-help').connect('clicked', self.onBtnHelp)
if not self.cfgWindow.isVisible():
self.cfgWindow.getWidget('txt-status').set_text(prefs.get(__name__, 'status-msg', DEFAULT_STATUS_MSG))
self.cfgWindow.getWidget('chk-updateOnPaused').set_active(prefs.get(__name__, 'update-on-paused', DEFAULT_UPDATE_ON_PAUSED))
self.cfgWindow.getWidget('chk-updateWhenAway').set_active(prefs.get(__name__, 'update-when-away', DEFAULT_UPDATE_WHEN_AWAY))
self.cfgWindow.getWidget('rad-stopDoNothing').set_active(prefs.get(__name__, 'stop-action', DEFAULT_STOP_ACTION) == STOP_DO_NOTHING)
self.cfgWindow.getWidget('rad-stopSetStatus').set_active(prefs.get(__name__, 'stop-action', DEFAULT_STOP_ACTION) == STOP_SET_STATUS)
self.cfgWindow.getWidget('txt-stopStatus').set_sensitive(prefs.get(__name__, 'stop-action', DEFAULT_STOP_ACTION) == STOP_SET_STATUS)
self.cfgWindow.getWidget('txt-stopStatus').set_text(prefs.get(__name__, 'stop-status', DEFAULT_STOP_STATUS))
self.cfgWindow.getWidget('txt-sanitizedWords').get_buffer().set_text(prefs.get(__name__, 'sanitized-words', DEFAULT_SANITIZED_WORDS))
self.cfgWindow.getWidget('btn-ok').grab_focus()
self.cfgWindow.show()