本文整理汇总了Python中quodlibet.util.print_w函数的典型用法代码示例。如果您正苦于以下问题:Python print_w函数的具体用法?Python print_w怎么用?Python print_w使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了print_w函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_dir_modules
def load_dir_modules(path, package, load_compiled=False):
"""Load all modules and packages in path (recursive).
Load pyc files if load_compiled is True.
In case the module is already loaded, doesn't reload it.
"""
# needed for pickle etc.
assert package in sys.modules
try:
modules = [e[0] for e in get_importables(path, load_compiled)]
except OSError:
util.print_w("%r not found" % path)
return []
# get_importables can yield py and pyc for the same module
# and we want to load it only once
modules = set(modules)
loaded = []
for name in modules:
try:
mod = load_module(name, package, path)
except Exception:
util.print_exc()
continue
if mod:
loaded.append(mod)
return loaded
示例2: _check
def _check(self, song):
old_threshold = Gst.debug_get_default_threshold()
Gst.debug_set_default_threshold(Gst.DebugLevel.NONE)
pipeline = Gst.parse_launch(
"uridecodebin uri=%s ! fakesink" % song("~uri"))
bus = pipeline.get_bus()
pipeline.set_state(Gst.State.PLAYING)
try:
while 1:
message = bus.timed_pop(Gst.SECOND * 10)
if not message or message.type == Gst.MessageType.ERROR:
if message:
debug = message.parse_error()[0].message
else:
debug = "timed out"
# only print a warning for platforms where we control
# the shipped dependencies.
if sys.platform == "darwin" or os.name == "nt":
print_w("GStreamer: Decoding %r failed (%s)" %
(song("~format"), debug))
break
if message.type == Gst.MessageType.EOS:
break
finally:
pipeline.set_state(Gst.State.NULL)
Gst.debug_set_default_threshold(old_threshold)
示例3: _exec_command
def _exec_command(self, command, args, no_ack=False):
self._command = command
if command not in self._commands:
print_w("Unhandled command %r, sending OK." % command)
command = "ping"
# Unhandled command, default to OK for now..
if not self._use_command_list:
self.ok()
elif self._command_list_ok:
self.write_line(u"list_OK")
return
cmd, do_ack, permission = self._commands[command]
if permission != (self.permission & permission):
raise MPDRequestError("Insufficient permission",
AckError.PERMISSION)
cmd(self, self.service, args)
if self._use_command_list:
if self._command_list_ok:
self.write_line(u"list_OK")
elif do_ack:
self.ok()
示例4: __lookup_cb
def __lookup_cb(self, lresult):
with self.__update_row(lresult.song) as entry:
entry.status = Status.DONE
entry.result = lresult
# count how many times each release ID is present and weight by the
# score
for release in lresult.releases:
id_ = release.id
# to prevent favoring releases which are a superset of
# the release we actually want (say 8 CD box containing
# every song of an artist), try to reduce the medium count.
score = score_release(release) / release.medium_count
self._release_scores.setdefault(id_, 0)
self._release_scores[id_] += score
# do the same again but group by directory
dir_ = lresult.song("~dirname")
release_scores = self._directory_scores.setdefault(dir_, {})
release_scores.setdefault(id_, 0)
release_scores[id_] += score
# update display
if lresult.releases:
self.__update_active_releases()
elif lresult.error:
entry.status = Status.ERROR
# we don't expose in the UI, so at least print it
print_w(lresult.error)
else:
entry.status = Status.UNKNOWN
self.__inc_done()
示例5: _check_feed
def _check_feed(self):
"""Validate stream a bit - failing fast where possible.
Constructs an equivalent(ish) HEAD request,
without re-writing feedparser completely.
(it never times out if reading from a stream - see #2257)"""
req = feedparser._build_urllib2_request(
self.uri, feedparser.USER_AGENT, None, None, None, None, {})
req.method = "HEAD"
opener = build_opener(feedparser._FeedURLHandler())
try:
result = opener.open(req)
ct_hdr = result.headers.get('Content-Type', "Unknown type")
content_type = ct_hdr.split(';')[0]
try:
status = result.status
except AttributeError:
print_w("Missing status code for feed %s" % self.uri)
else:
print_d("Pre-check: %s returned %s with content type '%s'" %
(self.uri, status, content_type))
if content_type not in feedparser.ACCEPT_HEADER:
print_w("Unusable content: %s. Perhaps %s is not a feed?" %
(content_type, self.uri))
return False
# No real need to check HTTP Status - errors are very unlikely
# to be a usable content type, and we should try to parse
finally:
opener.close()
return True
示例6: is_accel
def is_accel(event, *accels):
"""Checks if the given keypress Gdk.Event matches
any of accelerator strings.
example: is_accel(event, "<shift><ctrl>z")
"""
assert accels
if event.type != Gdk.EventType.KEY_PRESS:
return False
# ctrl+shift+x gives us ctrl+shift+X and accelerator_parse returns
# lowercase values for matching, so lowercase it if possible
keyval = event.keyval
if not keyval & ~0xFF:
keyval = ord(chr(keyval).lower())
default_mod = Gtk.accelerator_get_default_mod_mask()
for accel in accels:
accel_keyval, accel_mod = Gtk.accelerator_parse(accel)
# If the accel contains non default modifiers matching will
# never work and since no one should use them, complain
non_default = accel_mod & ~default_mod
if non_default:
print_w("Accelerator '%s' contains a non default modifier '%s'." %
(accel, Gtk.accelerator_name(0, non_default) or ""))
# Remove everything except default modifiers and compare
if (accel_keyval, accel_mod) == (keyval, event.state & default_mod):
return True
return False
示例7: __save
def __save(self, save, song, buffer, delete):
start, end = buffer.get_bounds()
text = buffer.get_text(start, end, True)
# First, write back to the tags.
song["lyrics"] = text.decode("utf-8")
try:
song.write()
except AudioFileError:
util.print_exc()
# Then, write to file.
# TODO: write to file only if could not write to tags, otherwise delete
# the file.
lyricname = song.lyric_filename
try:
os.makedirs(os.path.dirname(lyricname))
except EnvironmentError as err:
pass
try:
with open(lyricname, "w") as f:
f.write(text)
except EnvironmentError as err:
encoding = util.get_locale_encoding()
print_w(err.strerror.decode(encoding, "replace"))
delete.set_sensitive(True)
save.set_sensitive(False)
示例8: init
def init(app_id):
if not dbus:
return
try:
bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
manager = bus.get_object("org.gnome.SessionManager",
"/org/gnome/SessionManager")
iface = dbus.Interface(manager, "org.gnome.SessionManager")
client_path = iface.RegisterClient(app_id, "")
if client_path is None:
# https://github.com/quodlibet/quodlibet/issues/2435
print_w("Broken session manager implementation, likely LXDE")
return
client = bus.get_object("org.gnome.SessionManager", client_path)
client_priv = dbus.Interface(client,
"org.gnome.SessionManager.ClientPrivate")
def end_session_cb(*args):
print_d("GSM sent EndSession: going down")
client_priv.EndSessionResponse(True, "")
app.quit()
def query_end_session_cb(*args):
print_d("GSM sent QueryEndSession")
client_priv.EndSessionResponse(True, "")
client_priv.connect_to_signal("QueryEndSession", query_end_session_cb)
client_priv.connect_to_signal("EndSession", end_session_cb)
except dbus.DBusException:
print_d("Connecting with the gnome session manager failed")
else:
print_d("Connected with gnome session manager: %s" % client_path)
示例9: plugin_songs
def plugin_songs(self, songs):
# Check this is a launch, not a configure
if self.chosen_site:
url_pat = self.get_url_pattern(self.chosen_site)
pat = Pattern(url_pat)
urls = set()
for song in songs:
# Generate a sanitised AudioFile; allow through most tags
subs = AudioFile()
for k in (USER_TAGS + MACHINE_TAGS):
vals = song.comma(k)
if vals:
try:
encoded = unicode(vals).encode('utf-8')
subs[k] = (encoded if k == 'website'
else quote_plus(encoded))
# Dodgy unicode problems
except KeyError:
print_d("Problem with %s tag values: %r"
% (k, vals))
url = str(pat.format(subs))
if not url:
print_w("Couldn't build URL using \"%s\"."
"Check your pattern?" % url_pat)
return
# Grr, set.add() should return boolean...
if url not in urls:
urls.add(url)
website(url)
示例10: show_uri
def show_uri(label, uri):
"""Shows a uri. The uri can be anything handled by GIO or a quodlibet
specific one.
Currently handled quodlibet uris:
- quodlibet:///prefs/plugins/<plugin id>
Args:
label (str)
uri (str) the uri to show
Returns:
True on success, False on error
"""
parsed = urlparse(uri)
if parsed.scheme == "quodlibet":
if parsed.netloc != "":
print_w("Unknown QuodLibet URL format (%s)" % uri)
return False
else:
return __show_quodlibet_uri(parsed)
else:
# Gtk.show_uri_on_window exists since 3.22
if hasattr(Gtk, "show_uri_on_window"):
from quodlibet.qltk import get_top_parent
return Gtk.show_uri_on_window(get_top_parent(label), uri, 0)
else:
return Gtk.show_uri(None, uri, 0)
示例11: _update_avahi
def _update_avahi(self):
assert self._avahi
port_num = get_port_num()
try:
self._avahi.register(app.name, port_num, "_mpd._tcp")
except AvahiError as e:
print_w(str(e))
示例12: _enable_server
def _enable_server(self):
port_num = get_port_num()
print_d("Starting MPD server on port %d" % port_num)
self._server = MPDServer(app, self, port_num)
try:
self._server.start()
except ServerError as e:
print_w(str(e))
示例13: _sent
def _sent(self, session, task, data):
try:
self.istream = session.send_finish(task)
print_d('Sent {1} request to {0}'.format(self._uri,
self.message.method))
self.emit('sent', self.message)
except GLib.GError as e:
print_w('Failed sending request to {0}'.format(self._uri))
self.emit('send-failure', e)
示例14: port_activate
def port_activate(entry, *args):
try:
port_num = int(entry.get_text())
except ValueError as e:
print_w(str(e))
else:
if get_port_num() != port_num:
set_port_num(port_num)
self._refresh()
示例15: MusicFile
def MusicFile(filename):
"""Returns a AudioFile instance or None"""
loader = get_loader(filename)
if loader is not None:
try:
return loader(filename)
except AudioFileError:
print_w("Error loading %r" % filename)
util.print_exc()