Compatibility with latest qtile, fixes to widgets, etc...
This commit is contained in:
		
							parent
							
								
									a033bde573
								
							
						
					
					
						commit
						6a265ea3b6
					
				
					 6 changed files with 78 additions and 50 deletions
				
			
		| 
						 | 
				
			
			@ -7,7 +7,7 @@ import notify2
 | 
			
		|||
import six
 | 
			
		||||
from dbus import DBusException
 | 
			
		||||
from libqtile import widget
 | 
			
		||||
from libqtile.window import Internal
 | 
			
		||||
from libqtile.backend.x11.window import Internal
 | 
			
		||||
from libqtile.bar import Bar
 | 
			
		||||
from notify2 import Notification, URGENCY_NORMAL
 | 
			
		||||
from libqtile.log_utils import logger
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,7 +18,7 @@ from libqtile.widget.currentlayout import CurrentLayoutIcon
 | 
			
		|||
from libqtile.widget.graph import _Graph
 | 
			
		||||
from libqtile.widget.tasklist import TaskList
 | 
			
		||||
from libqtile.widget.wlan import get_status
 | 
			
		||||
from libqtile.window import Window
 | 
			
		||||
from libqtile.backend.x11.window import Window
 | 
			
		||||
 | 
			
		||||
from kuro.utils.general import notify, BUTTON_LEFT, BUTTON_MIDDLE, BUTTON_RIGHT, BUTTON_DOWN, BUTTON_UP, BUTTON_MUTE, \
 | 
			
		||||
    call_process
 | 
			
		||||
| 
						 | 
				
			
			@ -260,6 +260,7 @@ class MediaWidget(base.InLoopPollText):
 | 
			
		|||
        ('on_text_pause', ' {}', 'The pattern for the text if music is paused.'),
 | 
			
		||||
        ('on_text_stop', ' {}', 'The pattern for the text if music is stopped.'),
 | 
			
		||||
        ('update_interval', 1, 'The update interval.'),
 | 
			
		||||
        ('max_chars_per_player', 50, 'Maximum characters of text per player.'),
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
    player_icons = {
 | 
			
		||||
| 
						 | 
				
			
			@ -333,7 +334,7 @@ class MediaWidget(base.InLoopPollText):
 | 
			
		|||
 | 
			
		||||
    def cmd_update_custom_player(self, player_name, data):
 | 
			
		||||
        # Update firefox player
 | 
			
		||||
        if player_name == "firefox":
 | 
			
		||||
        if player_name.startswith("firefox"):
 | 
			
		||||
            if data['playing'] and data['muted']:
 | 
			
		||||
                self.custom_player_data['firefox']['showing'] = True
 | 
			
		||||
                self.custom_player_data['firefox']['state'] = MediaWidget.Status.PAUSED
 | 
			
		||||
| 
						 | 
				
			
			@ -355,8 +356,11 @@ class MediaWidget(base.InLoopPollText):
 | 
			
		|||
        players = []
 | 
			
		||||
 | 
			
		||||
        # Playerctl players
 | 
			
		||||
        command = ["playerctl", "-l"]
 | 
			
		||||
        result = self.call_process(command)
 | 
			
		||||
        try:
 | 
			
		||||
            result = self.call_process(["playerctl", "-l"])
 | 
			
		||||
        except subprocess.CalledProcessError:
 | 
			
		||||
            result = None
 | 
			
		||||
 | 
			
		||||
        if result:
 | 
			
		||||
            players.extend([x for x in result.split("\n") if x])
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -398,8 +402,14 @@ class MediaWidget(base.InLoopPollText):
 | 
			
		|||
 | 
			
		||||
                    text = "Unknown"
 | 
			
		||||
                    if cmd_result in ["Playing", "Paused"]:
 | 
			
		||||
                        artist = self.call_process(['playerctl', '-p', player, 'metadata', 'artist']).strip()
 | 
			
		||||
                        title = self.call_process(['playerctl', '-p', player, 'metadata', 'title']).strip()
 | 
			
		||||
                        try:
 | 
			
		||||
                            artist = self.call_process(['playerctl', '-p', player, 'metadata', 'artist']).strip()
 | 
			
		||||
                        except subprocess.CalledProcessError:
 | 
			
		||||
                            artist = None
 | 
			
		||||
                        try:
 | 
			
		||||
                            title = self.call_process(['playerctl', '-p', player, 'metadata', 'title']).strip()
 | 
			
		||||
                        except subprocess.CalledProcessError:
 | 
			
		||||
                            title = None
 | 
			
		||||
 | 
			
		||||
                        if artist and title:
 | 
			
		||||
                            text = "{} - {}".format(artist, title)
 | 
			
		||||
| 
						 | 
				
			
			@ -419,13 +429,17 @@ class MediaWidget(base.InLoopPollText):
 | 
			
		|||
 | 
			
		||||
    def _get_formatted_text(self, status):
 | 
			
		||||
        if status[0] == MediaWidget.Status.PLAYING:
 | 
			
		||||
            return self.on_text_play.format(status[1])
 | 
			
		||||
            res = self.on_text_play.format(status[1])
 | 
			
		||||
        elif status[0] == MediaWidget.Status.PAUSED:
 | 
			
		||||
            return self.on_text_pause.format(status[1])
 | 
			
		||||
            res = self.on_text_pause.format(status[1])
 | 
			
		||||
        elif status[0] == MediaWidget.Status.STOPPED:
 | 
			
		||||
            return self.on_text_stop.format(status[1])
 | 
			
		||||
            res = self.on_text_stop.format(status[1])
 | 
			
		||||
        else:
 | 
			
		||||
            return "Unknown"
 | 
			
		||||
            res = "Unknown"
 | 
			
		||||
        res = pangocffi.markup_escape_text(res)
 | 
			
		||||
        if len(res) > self.max_chars_per_player:
 | 
			
		||||
            res = res[:self.max_chars_per_player] + "..."
 | 
			
		||||
        return res
 | 
			
		||||
 | 
			
		||||
    def draw(self):
 | 
			
		||||
        super(MediaWidget, self).draw()
 | 
			
		||||
| 
						 | 
				
			
			@ -437,7 +451,12 @@ class MediaWidget(base.InLoopPollText):
 | 
			
		|||
            return self.off_text
 | 
			
		||||
        else:
 | 
			
		||||
            for player in status.keys():
 | 
			
		||||
                icon = self.player_icons.get(player, player)
 | 
			
		||||
                # Shorten firefox.instance[0-9]+ to just firefox for icon finding
 | 
			
		||||
                if player.startswith("firefox"):
 | 
			
		||||
                    player_icon = "firefox"
 | 
			
		||||
                else:
 | 
			
		||||
                    player_icon = player
 | 
			
		||||
                icon = self.player_icons.get(player_icon, player_icon)
 | 
			
		||||
                text.append("{} {}".format(icon, self._get_formatted_text(status[player])))
 | 
			
		||||
 | 
			
		||||
        return " | ".join(text) if text else self.off_text
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,6 @@
 | 
			
		|||
from cairocffi.test_xcb import xcffib
 | 
			
		||||
from libqtile import hook
 | 
			
		||||
from libqtile.window import Window, Static
 | 
			
		||||
 | 
			
		||||
from libqtile.backend.x11.window import Window, Static
 | 
			
		||||
 | 
			
		||||
class KuroStatic(Static):
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue