本文整理汇总了Python中modules.postMsg函数的典型用法代码示例。如果您正苦于以下问题:Python postMsg函数的具体用法?Python postMsg怎么用?Python postMsg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了postMsg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remove
def remove(self, iter=None):
""" Remove the given track, or the selection if iter is None """
hadMark = self.tree.hasMark()
iters = [iter] if iter else list(self.tree.iterSelectedRows())
prev_iter = self.tree.get_prev_iter_or_parent(iters[0])
# reverse list, so that we remove children before their fathers
for iter in reversed(iters):
track = self.tree.getTrack(iter)
if track:
self.playtime -= track.getLength()
self.tree.removeRow(iter)
self.tree.selection.unselect_all()
if hadMark and not self.tree.hasMark():
modules.postMsg(consts.MSG_CMD_STOP)
# Select new track when old selected is deleted
if prev_iter:
self.tree.select(prev_iter)
else:
first_iter = self.tree.get_first_iter()
if first_iter:
self.tree.select(first_iter)
self.onListModified()
示例2: onAppStarted
def onAppStarted(self):
""" This is the real initialization function, called when the module has been loaded """
wTree = tools.prefs.getWidgetsTree()
self.playtime = 0
self.bufferedTrack = None
# Retrieve widgets
self.window = wTree.get_object('win-main')
columns = (('', [(gtk.CellRendererPixbuf(), gtk.gdk.Pixbuf), (gtk.CellRendererText(), TYPE_STRING)], True),
(None, [(None, TYPE_PYOBJECT)], False),
)
self.tree = TrackTreeView(columns, use_markup=True)
self.tree.enableDNDReordering()
self.tree.setDNDSources([DND_INTERNAL_TARGET])
wTree.get_object('scrolled-tracklist').add(self.tree)
# GTK handlers
self.tree.connect('exttreeview-button-pressed', self.onMouseButton)
self.tree.connect('tracktreeview-dnd', self.onDND)
self.tree.connect('key-press-event', self.onKeyboard)
self.tree.get_model().connect('row-deleted', self.onRowDeleted)
(options, args) = prefs.getCmdLine()
self.savedPlaylist = os.path.join(consts.dirCfg, 'saved-playlist')
self.paused = False
# Populate the playlist with the saved playlist
dump = None
if os.path.exists(self.savedPlaylist):
try:
dump = pickleLoad(self.savedPlaylist)
except:
msg = '[%s] Unable to restore playlist from %s\n\n%s'
log.logger.error(msg % (MOD_INFO[modules.MODINFO_NAME],
self.savedPlaylist, traceback.format_exc()))
if dump:
self.restoreTreeDump(dump)
log.logger.info('[%s] Restored playlist' % MOD_INFO[modules.MODINFO_NAME])
self.tree.collapse_all()
self.select_last_played_track()
self.onListModified()
commands, args = tools.separate_commands_and_tracks(args)
# Add commandline tracks to the playlist
if args:
log.logger.info('[%s] Filling playlist with files given on command line' % MOD_INFO[modules.MODINFO_NAME])
tracks = media.getTracks([os.path.abspath(arg) for arg in args])
playNow = not 'stop' in commands and not 'pause' in commands
modules.postMsg(consts.MSG_CMD_TRACKLIST_ADD, {'tracks': tracks, 'playNow': playNow})
elif 'play' in commands:
modules.postMsg(consts.MSG_CMD_TOGGLE_PAUSE)
# Automatically save the content at regular intervals
gobject.timeout_add_seconds(SAVE_INTERVAL, self.save_track_tree)
示例3: onModLoaded
def onModLoaded(self):
""" The module has been loaded """
txtRdrLen = gtk.CellRendererText()
columns = (('', [(gtk.CellRendererPixbuf(), gtk.gdk.Pixbuf), (txtRdrLen, gobject.TYPE_STRING), (gtk.CellRendererText(), gobject.TYPE_STRING)], True),
(None, [(None, gobject.TYPE_PYOBJECT)], False))
# The album length is written in a smaller font, with a lighter color
txtRdrLen.set_property('scale', 0.85)
txtRdrLen.set_property('foreground', '#909090')
self.tree = extTreeview.ExtTreeView(columns, True)
self.popup = None
self.cfgWin = None
self.expName = MOD_L10N
self.scrolled = gtk.ScrolledWindow()
self.cacheDir = os.path.join(consts.dirCfg, MOD_INFO[modules.MODINFO_NAME])
# Explorer
self.tree.setDNDSources([consts.DND_TARGETS[consts.DND_DAP_TRACKS]])
self.scrolled.add(self.tree)
self.scrolled.set_shadow_type(gtk.SHADOW_IN)
self.scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.scrolled.show()
# GTK handlers
self.tree.connect('drag-data-get', self.onDragDataGet)
self.tree.connect('key-press-event', self.onKeyPressed)
self.tree.connect('exttreeview-button-pressed', self.onButtonPressed)
modules.postMsg(consts.MSG_CMD_EXPLORER_ADD, {'modName': MOD_L10N, 'expName': self.expName, 'icon': consts.icoCdrom, 'widget': self.scrolled})
# Hide the album length when not drawing the root node
self.tree.get_column(0).set_cell_data_func(txtRdrLen, self.__drawAlbumLenCell)
示例4: timerFunc
def timerFunc(self):
""" Move a bit the scales to their target value """
isFinished = True
# Move the scales a bit
for i in xrange(10):
currLvl = self.scales[i].get_value()
targetLvl = self.targetLvls[i]
difference = targetLvl - currLvl
if abs(difference) <= 0.25:
newLvl = targetLvl
else:
newLvl = currLvl + (difference / 8.0)
isFinished = False
self.lvls[i] = newLvl
self.scales[i].set_value(newLvl)
# Set the equalizer to the new levels
modules.postMsg(consts.MSG_CMD_SET_EQZ_LVLS, {'lvls': self.lvls})
if isFinished:
self.timer = None
prefs.set(__name__, 'levels', self.lvls)
# Make sure labels are up to date (sometimes they aren't when we're done with the animation)
# Also unblock the handlers
for i in xrange(10):
self.scales[i].queue_draw()
self.scales[i].handler_unblock_by_func(self.onScaleValueChanged)
return False
return True
示例5: updateTree
def updateTree(self, discInfo):
""" Update the tree using disc information from the cache, if any """
cddb = self.getDiscFromCache(discInfo)
# Create fake CDDB information if needed
if cddb is None:
cddb = {"DTITLE": "%s / %s" % (consts.UNKNOWN_ARTIST, consts.UNKNOWN_ALBUM)}
for i in xrange(discInfo[DISC_NB_TRACKS]):
cddb["TTITLE%u" % i] = consts.UNKNOWN_TITLE
# Compute the length of each track
trackLen = [
int(round((discInfo[DISC_FRAME1 + i + 1] - discInfo[DISC_FRAME1 + i]) / 75.0))
for i in xrange(discInfo[DISC_NB_TRACKS] - 1)
]
trackLen.append(discInfo[DISC_LENGTH] - int(round(discInfo[DISC_FRAMEn] / 75.0)))
# Update the root of the tree
disc = cddb["DTITLE"].strip().decode("iso-8859-15", "replace")
artist, album = disc.split(" / ")
self.tree.setItem((0,), ROW_NAME, "%s" % tools.htmlEscape(disc))
self.tree.setItem((0,), ROW_LENGTH, "[%s]" % sec2str(sum(trackLen)))
# Update the explorer name
modules.postMsg(
consts.MSG_CMD_EXPLORER_RENAME, {"modName": MOD_L10N, "expName": self.expName, "newExpName": disc}
)
self.expName = disc
# Optional information
try:
date = int(cddb["DYEAR"].strip().decode("iso-8859-15", "replace"))
except:
date = None
try:
genre = cddb["DGENRE"].strip().decode("iso-8859-15", "replace")
except:
genre = None
# Update each track
for i, child in enumerate(self.tree.iterChildren((0,))):
title = cddb["TTITLE%u" % i].strip().decode("iso-8859-15", "replace")
# Create the corresponding Track object
track = CDTrack(str(i + 1))
track.setTitle(title)
track.setAlbum(album)
track.setArtist(artist)
track.setLength(trackLen[i])
track.setNumber(i + 1)
# Optional information
if date is not None:
track.setDate(date)
if genre is not None:
track.setGenre(genre)
# Fill the tree
self.tree.setItem(child, ROW_NAME, "%02u. %s" % (i + 1, tools.htmlEscape(title)))
self.tree.setItem(child, ROW_TRACK, track)
示例6: timerFunc
def timerFunc(self):
""" Move a bit the scales to their target value """
isFinished = True
# Disconnect handlers before moving the scales
for i in xrange(10):
self.scales[i].disconnect(self.handlers[i])
# Move the scales a bit
for i in xrange(10):
currLvl = self.scales[i].get_value()
targetLvl = self.targetLvls[i]
difference = targetLvl - currLvl
if abs(difference) <= 0.25:
newLvl = targetLvl
else:
newLvl = currLvl + (difference / 8.0)
isFinished = False
self.lvls[i] = newLvl
self.scales[i].set_value(newLvl)
# Reconnect the handlers
for i in xrange(10):
self.handlers[i] = self.scales[i].connect('value-changed', self.onScaleValueChanged, i)
# Set the equalizer to the new levels
prefs.set(__name__, 'levels', self.lvls)
modules.postMsg(consts.MSG_CMD_SET_EQZ_LVLS, {'lvls': self.lvls})
return not isFinished
示例7: onRemoveSelectedFolder
def onRemoveSelectedFolder(self, list):
""" Remove the selected media folder """
import gui
if list.getSelectedRowsCount() == 1:
remark = _('You will be able to add this root folder again later on if you wish so.')
question = _('Remove the selected entry?')
else:
remark = _('You will be able to add these root folders again later on if you wish so.')
question = _('Remove all selected entries?')
if gui.questionMsgBox(self.cfgWin, question, '%s %s' % (_('Your media files will not be deleted.'), remark)) == gtk.RESPONSE_YES:
for row in self.cfgList.getSelectedRows():
name = row[0]
modules.postMsg(consts.MSG_CMD_EXPLORER_REMOVE, {'modName': MOD_L10N, 'expName': name})
del self.folders[name]
# Remove the tree, if any, from the scrolled window
if self.currRoot == name:
self.currRoot = None
# Remove the saved state of the tree, if any
if name in self.treeState:
del self.treeState[name]
self.cfgList.removeSelectedRows()
示例8: onAppStarted
def onAppStarted(self):
""" Real initialization function, called when this module has been loaded """
self.currTrackLength = 0
self.sclBeingDragged = False
# Widgets
wTree = prefs.getWidgetsTree()
# self.btnStop = wTree.get_widget('btn-stop')
self.btnPlay = wTree.get_widget('btn-play')
# self.btnNext = wTree.get_widget('btn-next')
self.btnPrev = wTree.get_widget('btn-previous')
self.sclSeek = wTree.get_widget('scl-position')
self.btnVolume = wTree.get_widget('btn-volume')
self.lblElapsed = wTree.get_widget('lbl-elapsedTime')
self.lblRemaining = wTree.get_widget('lbl-remainingTime')
# Initial state
self.onStopped()
self.btnPlay.set_sensitive(False)
# GTK handlers
# self.btnStop.connect('clicked', lambda widget: modules.postMsg(consts.MSG_CMD_STOP))
# self.btnNext.connect('clicked', lambda widget: modules.postMsg(consts.MSG_CMD_NEXT))
self.btnPrev.connect('clicked', lambda widget: modules.postMsg(consts.MSG_CMD_PREVIOUS))
self.btnPlay.connect('clicked', lambda widget: modules.postMsg(consts.MSG_CMD_TOGGLE_PAUSE))
self.sclSeek.connect('change-value', self.onSeekChangeValue)
# We need to keep the handler ID for this one to be able to disconnect it when needed
self.seekHandler = self.sclSeek.connect('value-changed', self.onSeekValueChanged)
self.volumeHandler = self.btnVolume.connect('value-changed', self.onVolumeValueChanged)
# We must make sure that the handler will be called: this is not the case if the new value is the same as the old one
volumeValue = prefs.get(__name__, 'volume', PREFS_DEFAULT_VOLUME)
if self.btnVolume.get_value() != volumeValue: self.btnVolume.set_value(volumeValue)
else: self.onVolumeValueChanged(self.btnVolume, volumeValue)
示例9: onMediaKey
def onMediaKey(self, appName, action):
""" A media key has been pressed """
if appName == consts.appName:
# if action == 'Stop': modules.postMsg(consts.MSG_CMD_STOP)
# elif action == 'Next': modules.postMsg(consts.MSG_CMD_NEXT)
if action == 'Previous': modules.postMsg(consts.MSG_CMD_PREVIOUS)
elif action in ['Play', 'Pause']: modules.postMsg(consts.MSG_CMD_TOGGLE_PAUSE)
示例10: tryToRestore
def tryToRestore(self, tracklist):
""" Check whether it's possible to restore playback """
(options, args) = prefs.getCmdLine()
# Ignore if the user provided its own tracks on the command line
if len(args) != 0:
return
# Ignore if no track was being played last time
if not self.playing or self.currTrack is None:
return
# Make sure the playlist is the same one
if len(tracklist) != len(self.currTracklist):
return
trackIdx = -1
for i in xrange(len(tracklist)):
if tracklist[i] != self.currTracklist[i]:
return
if tracklist[i] == self.currTrack:
trackIdx = i
# Once here, we know playback can be resumed
if trackIdx != -1:
if self.paused: modules.postMsg(consts.MSG_CMD_TRACKLIST_PLAY_PAUSE, {'idx': trackIdx, 'seconds': self.currPos})
else: modules.postMsg(consts.MSG_CMD_TRACKLIST_PLAY, {'idx': trackIdx, 'seconds': self.currPos})
示例11: onPopupMenu
def onPopupMenu(self, statusIcon, button, time):
""" The user asks for the popup menu """
if self.popupMenu is None:
wTree = loadGladeFile('StatusIconMenu.ui')
self.menuPlay = wTree.get_object('item-play')
self.menuStop = wTree.get_object('item-stop')
self.menuNext = wTree.get_object('item-next')
self.popupMenu = wTree.get_object('menu-popup')
self.menuPause = wTree.get_object('item-pause')
self.menuPrevious = wTree.get_object('item-previous')
self.menuSeparator = wTree.get_object('item-separator')
# Connect handlers
wTree.get_object('item-quit').connect('activate', lambda btn: modules.postQuitMsg())
wTree.get_object('item-preferences').connect('activate', lambda btn: modules.showPreferences())
self.menuPlay.connect('activate', lambda btn: modules.postMsg(consts.MSG_CMD_TOGGLE_PAUSE))
self.menuStop.connect('activate', lambda btn: modules.postMsg(consts.MSG_CMD_STOP))
self.menuNext.connect('activate', lambda btn: modules.postMsg(consts.MSG_CMD_NEXT))
self.menuPrevious.connect('activate', lambda btn: modules.postMsg(consts.MSG_CMD_PREVIOUS))
self.menuPause.connect('activate', lambda btn: modules.postMsg(consts.MSG_CMD_TOGGLE_PAUSE))
self.popupMenu.show_all()
# Enable only relevant menu entries
self.menuStop.set_sensitive(self.isPlaying)
self.menuNext.set_sensitive(self.isPlaying and self.trackHasNext)
self.menuPause.set_sensitive(self.isPlaying and not self.isPaused)
self.menuPrevious.set_sensitive(self.isPlaying and self.trackHasPrev)
self.menuPlay.set_sensitive((not (self.isPlaying or self.emptyTracklist)) or self.isPaused)
self.popupMenu.popup(None, None, gtk.status_icon_position_menu, button, time, statusIcon)
示例12: removeSelectedLibraries
def removeSelectedLibraries(self, list):
""" Remove all selected libraries """
import shutil
from gui import questionMsgBox
if list.getSelectedRowsCount() == 1:
remark = _('You will be able to recreate this library later on if you wish so.')
question = _('Remove the selected library?')
else:
remark = _('You will be able to recreate these libraries later on if you wish so.')
question = _('Remove all selected libraries?')
if questionMsgBox(self.cfgWindow, question, '%s %s' % (_('Your media files will not be removed.'), remark)) == gtk.RESPONSE_YES:
for row in list.getSelectedRows():
libName = row[0]
if self.currLib == libName:
self.currLib = None
# Remove the library from the disk
libPath = os.path.join(ROOT_PATH, libName)
if isdir(libPath):
shutil.rmtree(libPath)
# Remove the corresponding explorer
modules.postMsg(consts.MSG_CMD_EXPLORER_REMOVE, {'modName': MOD_L10N, 'expName': libName})
del self.libraries[libName]
# Remove tree states
self.removeTreeStates(libName)
# Clean up the listview
list.removeSelectedRows()
示例13: onSearch
def onSearch(self, query):
self.should_stop = False
self.found_something = False
# Transform whitespace-separated query into OR-regex.
regex = re.compile('|'.join(tools.get_pattern(word)
for word in query.split()), re.IGNORECASE)
for dir in self.get_search_paths() + [consts.dirBaseUsr]:
# Check if search has been aborted during filtering
if self.should_stop:
break
# Only search in home folder if we haven't found anything yet.
if dir == consts.dirBaseUsr and self.found_something:
break
results = self.search_dir(dir, query)
# Check if search has been aborted during searching
if results is None or self.should_stop:
break
dirs, files = self.filter_results(results, dir, regex)
if not self.should_stop and (dirs or files):
self.found_something = True
modules.postMsg(consts.MSG_EVT_SEARCH_APPEND,
{'results': (dirs, files), 'query': query})
modules.postMsg(consts.MSG_EVT_SEARCH_END)
示例14: onScroll
def onScroll(self, statusIcon, scrollEvent):
""" The mouse is scrolled on the status icon """
if scrollEvent.direction == gtk.gdk.SCROLL_UP or scrollEvent.direction == gtk.gdk.SCROLL_RIGHT:
self.volume = min(1.0, self.volume + 0.05)
else:
self.volume = max(0.0, self.volume - 0.05)
modules.postMsg(consts.MSG_CMD_SET_VOLUME, {'value': self.volume})
示例15: playPaths
def playPaths(self, tree, paths, replace):
"""
Replace/extend the tracklist
If the list 'paths' is None, use the current selection
"""
tracks = self.__getTracksFromPaths(tree, paths)
if replace: modules.postMsg(consts.MSG_CMD_TRACKLIST_SET, {'tracks': tracks, 'playNow': True})
else: modules.postMsg(consts.MSG_CMD_TRACKLIST_ADD, {'tracks': tracks})