示例#1
0
def update(label):
    # schedule next update
    GLib.timeout_add(1000, update, label)

    # don't update if not visible
    if not hasattr(label, "window") or not label.get_window().is_viewable():
        return

    netstat = Netstat()
    netstat.read_connections()
    netstats = netstat.format_connections()

    # XXX replace the shell commands with python code
    commands = [
        (_("Processes"), "ps wwu -C mpd".split()),
        (_("Files"), ["sh", "-c", "ls -ldh /etc/mpd.conf /var/lib/mpd "
                      "/var/lib/mpd/* /var/lib/mpd/*/*"]),
    ]
    outputs = [(title, subprocess.Popen(command,
                        stdout=subprocess.PIPE,
                        stderr=subprocess.PIPE
                        ).communicate())
           for title, command in commands]

    sections = [outputs[0], (_("Networking"), (netstats, "")), outputs[1]]
    text = '\n'.join(["<b>%s</b>\n<tt>%s</tt><i>%s</i>\n" %
              (title, escape_html(stdout), escape_html(stderr))
              for title, (stdout, stderr) in sections])
    label.set_markup(text.decode(locale.getpreferredencoding(),
                     'replace'))
示例#2
0
def update(label):
    # schedule next update
    GLib.timeout_add(1000, update, label)

    # don't update if not visible
    if not hasattr(label, "window") or not label.get_window().is_viewable():
        return

    netstat = Netstat()
    netstat.read_connections()
    netstats = netstat.format_connections()

    # XXX replace the shell commands with python code
    commands = [
        (_("Processes"), "ps wwu -C mpd".split()),
        (_("Files"), [
            "sh", "-c", "ls -ldh /etc/mpd.conf /var/lib/mpd "
            "/var/lib/mpd/* /var/lib/mpd/*/*"
        ]),
    ]
    outputs = [(title,
                subprocess.Popen(command,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE).communicate())
               for title, command in commands]

    sections = [outputs[0], (_("Networking"), (netstats, "")), outputs[1]]
    text = '\n'.join([
        "<b>%s</b>\n<tt>%s</tt><i>%s</i>\n" %
        (title, escape_html(stdout), escape_html(stderr))
        for title, (stdout, stderr) in sections
    ])
    label.set_markup(text.decode(locale.getpreferredencoding(), 'replace'))
示例#3
0
文件: artwork.py 项目: Mic92/sonata
 def fullscreen_cover_art_set_text(self):
     if self.status_is_play_or_pause():
         line1, line2 = self.get_current_song_text()
         self.fullscreenalbumlabel.set_text(misc.escape_html(line1))
         self.fullscreenalbumlabel2.set_text(misc.escape_html(line2))
         self.fullscreenalbumlabel.show()
         self.fullscreenalbumlabel2.show()
     else:
         self.fullscreen_cover_art_reset_text()
示例#4
0
 def populate(self):
     self.streamsdata.clear()
     streamsinfo = [{'name' : misc.escape_html(name),
             'uri' : misc.escape_html(uri)}
             for name, uri in zip(self.config.stream_names,
                          self.config.stream_uris)]
     streamsinfo.sort(key=lambda x: x["name"].lower()) # Remove case sensitivity
     for item in streamsinfo:
         self.streamsdata.append([Gtk.STOCK_NETWORK, item["name"], item["uri"]])
示例#5
0
 def populate(self):
     self.streamsdata.clear()
     streamsinfo = [{
         'name': misc.escape_html(name),
         'uri': misc.escape_html(uri)
     } for name, uri in zip(self.config.stream_names,
                            self.config.stream_uris)]
     streamsinfo.sort(
         key=lambda x: x["name"].lower())  # Remove case sensitivity
     for item in streamsinfo:
         self.streamsdata.append(
             [Gtk.STOCK_NETWORK, item["name"], item["uri"]])
示例#6
0
文件: test.py 项目: windfail/sonata
def on_song_change(songinfo):
    if songinfo:
        songlabel.set_markup("<b>Info for currently playing song:</b>"+
                     "\n%s" % escape_html(repr(songinfo)))
    else:
        songlabel.set_text("Currently not playing any song.")
    songlabel.show()
示例#7
0
    def searchfilter_key_pressed(self, widget):
        # We have something new to search, try first to cancel the previous
        # search.
        try:
            GLib.source_remove(self.refilter_handler_id)
        except TypeError: # self.refilter_handler_id is None
            pass

        text = widget.get_text()
        if text == '':
            # Nothing to search for, just display the whole model.
            self.view.set_model(self.store)
            return

        regex = misc.escape_html(text)
        regex = re.escape(regex)
        regex = '.*' + regex.replace(' ', ' .*').lower()
        filter_regex = re.compile(regex)

        def set_filtering_function(regex):
            # Creates a Gtk.TreeModelFilter
            filter_model = self.store.filter_new()
            filter_model.set_visible_func(self.model_filter_func, regex)
            self.view.set_model(filter_model)

        # Delay slightly the new search, in case something else is coming.
        self.refilter_handler_id = GLib.timeout_add(
            250, set_filtering_function, filter_regex)
示例#8
0
def on_song_change(songinfo):
	if songinfo:
		songlabel.set_markup("<b>Info for currently playing song:</b>"+
				     "\n%s" % escape_html(repr(songinfo)))
	else:
		songlabel.set_text("Currently not playing any song.")
	songlabel.show()
示例#9
0
    def searchfilter_key_pressed(self, widget):
        # We have something new to search, try first to cancel the previous
        # search.
        try:
            GLib.source_remove(self.refilter_handler_id)
        except TypeError:  # self.refilter_handler_id is None
            pass

        text = widget.get_text()
        if text == '':
            # Nothing to search for, just display the whole model.
            self.view.set_model(self.store)
            return

        regex = misc.escape_html(text)
        regex = re.escape(regex)
        regex = '.*' + regex.replace(' ', ' .*').lower()
        filter_regex = re.compile(regex)

        def set_filtering_function(regex):
            # Creates a Gtk.TreeModelFilter
            filter_model = self.store.filter_new()
            filter_model.set_visible_func(self.model_filter_func, regex)
            self.view.set_model(filter_model)

        # Delay slightly the new search, in case something else is coming.
        self.refilter_handler_id = GLib.timeout_add(250,
                                                    set_filtering_function,
                                                    filter_regex)
示例#10
0
文件: info.py 项目: fstiewitz/sonata
    def _update_song(self, songinfo):
        artistlabel = self.info_labels['artist']
        tracklabel = self.info_labels['track']
        albumlabel = self.info_labels['album']
        filelabel = self.info_labels['file']

        for name in ['title', 'date', 'genre']:
            label = self.info_labels[name]
            label.set_text(songinfo.get(name, ''))

        tracklabel.set_text(str(songinfo.track))
        artistlabel.set_text(misc.escape_html(songinfo.artist))
        albumlabel.set_text(misc.escape_html(songinfo.album))

        path = os.path.join(self.config.current_musicdir, songinfo.file)
        if os.path.exists(path):
            filelabel.set_text(path)
            self._editlabel.show()
        else:
            filelabel.set_text(songinfo.file)
            self._editlabel.hide()
示例#11
0
    def _update_song(self, songinfo):
        artistlabel = self.info_labels['artist']
        tracklabel = self.info_labels['track']
        albumlabel = self.info_labels['album']
        filelabel = self.info_labels['file']

        for name in ['title', 'date', 'genre']:
            label = self.info_labels[name]
            label.set_text(songinfo.get(name, ''))

        tracklabel.set_text(str(songinfo.track))
        artistlabel.set_text(misc.escape_html(songinfo.artist))
        albumlabel.set_text(misc.escape_html(songinfo.album))

        path = os.path.join(self.config.current_musicdir, songinfo.file)
        if os.path.exists(path):
            filelabel.set_text(path)
            self._editlabel.show()
        else:
            filelabel.set_text(songinfo.file)
            self._editlabel.hide()
示例#12
0
def update(label):
	# schedule next update
	gobject.timeout_add(1000, update, label)

	# don't update if not visible
	if not label.window or not label.window.is_viewable():
		return

	commands = [("Processes", ["sh", "-c", "ps wwu -C mpd"]),
		    ("Networking", ["sh", "-c", "netstat -Watue --numeric-hosts | egrep ':6600|^Proto'"]),
		    ("Files", ["sh", "-c", "ls -lRh /etc/mpd.conf /var/lib/mpd"]),
		    ]
	outputs = [(title, subprocess.Popen(command, 
					    stdout=subprocess.PIPE,
					    stderr=subprocess.PIPE
					    ).communicate())
		   for title, command in commands]
	text = '\n'.join(["<b>%s</b>\n<tt>%s</tt><i>%s</i>\n" %
			  (title, escape_html(stdout), escape_html(stderr))
			  for title, (stdout, stderr) in outputs])
	label.set_markup(text.decode(locale.getpreferredencoding(), 
				     'replace'))
示例#13
0
    def populate(self):
        if self.connected():
            self.playlistsdata.clear()
            playlistinfo = []
            playlists = self.mpd.listplaylists()
            if playlists is None:
                playlists = self.mpd.lsinfo()
            for item in playlists:
                if 'playlist' in item:
                    playlistinfo.append(misc.escape_html(item['playlist']))

            # Remove case sensitivity
            playlistinfo.sort(key=lambda x: x.lower())
            for item in playlistinfo:
                self.playlistsdata.append([Gtk.STOCK_DIRECTORY, item])

            self.populate_playlists_for_menu(playlistinfo)
示例#14
0
文件: playlists.py 项目: Mic92/sonata
    def populate(self):
        if self.connected():
            self.playlistsdata.clear()
            playlistinfo = []
            playlists = self.mpd.listplaylists()
            if playlists is None:
                playlists = self.mpd.lsinfo()
            for item in playlists:
                if 'playlist' in item:
                    playlistinfo.append(misc.escape_html(item['playlist']))

            # Remove case sensitivity
            playlistinfo.sort(key=lambda x: x.lower())
            for item in playlistinfo:
                self.playlistsdata.append([Gtk.STOCK_DIRECTORY, item])

            self.populate_playlists_for_menu(playlistinfo)
示例#15
0
def parse(format, item, use_escape_html, wintitle=False, songpos=None):
    substrings = _return_substrings(format)
    text = "".join(
        _format_substrings(sub, item, wintitle, songpos) for sub in substrings)
    return misc.escape_html(text) if use_escape_html else text
示例#16
0
def parse(format, item, use_escape_html, wintitle=False, songpos=None):
    substrings = _return_substrings(format)
    text = "".join(_format_substrings(sub, item, wintitle, songpos)
            for sub in substrings)
    return misc.escape_html(text) if use_escape_html else text
示例#17
0
 def format(self, item, wintitle, songpos):
     path = item['file']
     full_path = re.match(r"^(http://|ftp://)", path)
     self.default = path if full_path else os.path.basename(path)
     self.default = misc.escape_html(self.default)
     return FormatCode.format(self, item, wintitle, songpos)
示例#18
0
 def searchfilter_loop(self):
     while self.filterbox_visible:
         # copy the last command or pattern safely
         self.filterbox_cond.acquire()
         try:
             while(self.filterbox_cmd_buf == '$$$DONE###'):
                 self.filterbox_cond.wait()
             todo = self.filterbox_cmd_buf
             self.filterbox_cond.release()
         except:
             todo = self.filterbox_cmd_buf
         self.current.freeze_child_notify()
         matches = Gtk.ListStore(*([int] + [str] * len(self.columnformat)))
         matches.clear()
         filterposition = self.current.get_visible_rect().height
         _model, selected = self.current_selection.get_selected_rows()
         filterselected = [path for path in selected]
         rownum = 0
         # Store previous rownums in temporary list, in case we are
         # about to populate the songfilter with a subset of the
         # current filter. This will allow us to preserve the mapping.
         prev_rownums = [song for song in self.filter_row_mapping]
         self.filter_row_mapping = []
         if todo == '$$$QUIT###':
             GLib.idle_add(self.searchfilter_revert_model)
             return
         elif len(todo) == 0:
             for row in self.currentdata:
                 self.filter_row_mapping.append(rownum)
                 rownum = rownum + 1
                 song_info = [row[0]]
                 for i in range(len(self.columnformat)):
                     song_info.append(row[i + 1])
                 matches.append(song_info)
         else:
             # this make take some seconds... and we'll escape the search
             # text because we'll be searching for a match in items
             # that are also escaped.
             todo = misc.escape_html(todo)
             todo = re.escape(todo)
             todo = '.*' + todo.replace(' ', ' .*').lower()
             regexp = re.compile(todo)
             rownum = 0
             if self.prevtodo in todo and len(self.prevtodo) > 0:
                 # If the user's current filter is a subset of the
                 # previous selection (e.g. "h" -> "ha"), search
                 # for files only in the current model, not the
                 # entire self.currentdata
                 subset = True
                 use_data = self.current.get_model()
                 if len(use_data) != len(prev_rownums):
                     # Not exactly sure why this happens sometimes
                     # so lets just revert to prevent a possible, but
                     # infrequent, crash. The only downside is speed.
                     subset = False
                     use_data = self.currentdata
             else:
                 subset = False
                 use_data = self.currentdata
             for row in use_data:
                 song_info = [row[0]]
                 for i in range(len(self.columnformat)):
                     song_info.append(row[i + 1])
                 # Search for matches in all columns:
                 for i in range(len(self.columnformat)):
                     if regexp.match(song_info[i + 1].lower()):
                         matches.append(song_info)
                         if subset:
                             self.filter_row_mapping.append(
                                 prev_rownums[rownum])
                         else:
                             self.filter_row_mapping.append(rownum)
                         break
                 rownum = rownum + 1
         if self.prevtodo == todo or self.prevtodo == "RETAIN_POS_AND_SEL":
             # mpd update, retain view of treeview:
             retain_position_and_selection = True
             if self.plpos:
                 filterposition = self.plpos
                 self.plpos = None
         else:
             retain_position_and_selection = False
         self.filterbox_cond.acquire()
         self.filterbox_cmd_buf = '$$$DONE###'
         try:
             self.filterbox_cond.release()
         except:
             pass
         GLib.idle_add(self.searchfilter_set_matches, matches,
                       filterposition, filterselected,
                       retain_position_and_selection)
         self.prevtodo = todo
示例#19
0
 def __mod__(self, args):
     # FIXME: cover the case of single and dictionary argument
     args = tuple(misc.escape_html(x) for x in args)
     return unicode(self)%args
示例#20
0
 def format(self, item, wintitle, songpos):
     path = item['file']
     full_path = re.match(r"^(http://|ftp://)", path)
     self.default = path if full_path else os.path.basename(path)
     self.default = misc.escape_html(self.default)
     return FormatCode.format(self, item, wintitle, songpos)
 def __escape(cls, item):
     if isinstance(item, cls):
         # these are not the bad characters you are looking for.
         return item
     else:
         return misc.escape_html(item)