question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CPU widget is changing width, unable to fix width of widget

See original GitHub issue

The issue:

When CPU changed to more than 10% or less then 10%, widget change width which is changing all bar. I expect that width of CPU widget should be fixed (it should not be change their width). I similar topic suggestion is to use monospace font. I tried Consolas - issue is the same. Now I use TerminessTTF Nerd Font and as I understand is is monospace (please correct me if I wrong). Using this TerminessTTF Nerd Font helped to fix width of Net widget. But not for CPU.

image

image

How to fix width of CPU widget? Thank you!

qtile --version
0.21.0
qtile config
import os
import subprocess
from typing import List  # noqa: F401

from libqtile import hook

from libqtile.extension.dmenu import DmenuRun
from libqtile.extension.window_list import WindowList
from libqtile.bar import Bar

# import layout objects
from libqtile.layout.columns import Columns
from libqtile.layout.xmonad import MonadTall
from libqtile.layout.xmonad import MonadThreeCol
from libqtile.layout.xmonad import MonadWide
from libqtile.layout.stack import Stack
from libqtile.layout.floating import Floating
from libqtile.layout.max import Max


# import widgets and bar
from libqtile.widget.groupbox import GroupBox
from libqtile.widget.currentlayout import CurrentLayout
from libqtile.widget.window_count import WindowCount
from libqtile.widget.windowname import WindowName
from libqtile.widget.prompt import Prompt
from libqtile.widget.cpu import CPU
from libqtile.widget.volume import Volume
from libqtile.widget.memory import Memory
from libqtile.widget.net import Net
from libqtile.widget.systray import Systray
from libqtile.widget.clock import Clock
from libqtile.widget.spacer import Spacer
from libqtile.widget.battery import Battery




from libqtile.config import Click, Drag, Group, Key, Match, Screen, ScratchPad, DropDown
from libqtile.lazy import lazy
from libqtile.utils import guess_terminal

from colors import gruvbox
from unicodes import left_half_circle, right_half_circle

# clipboard
# import pyperclip


mod = "mod4"
terminal = guess_terminal()
home = os.path.expanduser("~")
qtileDir = f"{home}/.config/qtile"

# clipboard
# clipboard = pyperclip.paste()

keys = [
  Key([], "Print", lazy.spawn('flameshot gui'), desc="Take screenshot"),
  # Microphone
  Key(
      [mod], "c", lazy.spawn(f"{qtileDir}/controllers/micControl.sh mute",),
      desc="Toggle mute the microphone",
  ),
  Key(
      ["shift"],
      "XF86AudioLowerVolume",
      lazy.spawn(
          f"{qtileDir}/controllers/micControl.sh down",
      ),
      desc="Decrease microphone volume",
  ),
  Key(
      ["shift"],
      "XF86AudioRaiseVolume",
      lazy.spawn(
          f"{qtileDir}/controllers/micControl.sh up",
      ),
      desc="Increase microphone volume",
  ),
  # Audio
  # Key([], "XF86AudioRaiseVolume",        lazy.spawn("amixer -c 0 -q set Master 2dB+")),
  # Key([], "XF86AudioLowerVolume",        lazy.spawn("amixer -c 0 -q set Master 2dB-")),
  Key([mod], "equal",        lazy.spawn("amixer -c 0 -q set Master 2dB+")),
  Key([mod], "minus",        lazy.spawn("amixer -c 0 -q set Master 2dB-")),
  Key([], "XF86AudioMute",        lazy.spawn("amixer -c 0 -q set Master toggle")),

  # Launch applications
  Key([mod], "w", lazy.spawn('firefox'), desc="Launch browser"),
  Key([mod, "shift"], "w", lazy.spawn('firefox -P home'), desc="Launch browser with home profile"),
  Key([mod], "backslash", lazy.spawn('vscodium'), desc="Launch vscodium"),
  Key([mod, "shift"], "t", lazy.spawn('telegram-desktop'), desc="Launch Telegram"),
  Key([mod, "shift"], "d", lazy.spawn('discord'), desc="Launch Discord"),
  Key([mod, "shift"], "s", lazy.spawn('slack'), desc="Launch Slack"),
  # Key([mod, "shift"], "k", lazy.spawn('keepassxc'), desc="Launch keepassxc"),
  Key([mod], "Return", lazy.spawn(terminal), desc="Launch terminal"),


  # VPN
  Key([mod, "shift"], "v", lazy.spawn('nmcli connection up wg0'), desc="Connect VPN"),
  Key([mod, "shift", "control"], "v", lazy.spawn('nmcli connection down wg0'), desc="Disconnect VPN"),

  # Music
  Key([mod, "control"], "1", lazy.spawn('mpv https://live.musopen.org:8085/streamvbr0'), desc="Play Classic Radio"),
  Key([mod, "control"], "2", lazy.spawn('mpv https://stream.radioparadise.com/aac-320'), desc="Play Radio Paradise"),
  Key([mod, "control"], "3", lazy.spawn('mpv https://gamaun.online:8015/radio'), desc="Play Radio Gamaun"),
  Key([mod, "control"], "0", lazy.spawn('pkill -f https'), desc="Stop radio"),

  # Clipboard
  Key([mod], "v", lazy.spawn('copyq menu'), desc="Launch CopyQ menu"),
  # Key(["mod1"], "v", lazy.spawn(f'firefox -P home {clipboard}'), desc="Open clipboard in home browser"),





  # Command prompt
  # Key([mod], "p", lazy.spawncmd(),
  #     desc="Spawn a command using a prompt widget"),

  # DmenuRun
  Key([mod], 'd', lazy.run_extension(DmenuRun(
      font="TerminessTTF Nerd Font",
      fontsize="20",
      dmenu_command="dmenu_run",
      dmenu_prompt=" ",
      dmenu_height=10,
      dmenu_lines=15,
      background=gruvbox['bg'],
      foreground=gruvbox['gray'],
      selected_foreground=gruvbox['dark-blue'],
      selected_background=gruvbox['bg'],
  ))),

  Key(["mod1"], 'quoteleft', lazy.run_extension(WindowList(
      all_groups=False,
      font="TerminessTTF Nerd Font",
      fontsize="20",
      dmenu_prompt=" ",
      dmenu_height=10,
      dmenu_ignorecase=True,
      # dmenu_lines=15,
      background=gruvbox['bg'],
      foreground=gruvbox['gray'],
      selected_foreground=gruvbox['dark-blue'],
      selected_background=gruvbox['bg'],
  ))),

  Key(["mod1", "shift"], 'quoteleft', lazy.run_extension(WindowList(
      all_groups=True,
      font="TerminessTTF Nerd Font",
      fontsize="20",
      dmenu_prompt=" ",
      dmenu_height=10,
      dmenu_ignorecase=True,
      # dmenu_lines=15,
      background=gruvbox['bg'],
      foreground=gruvbox['gray'],
      selected_foreground=gruvbox['dark-blue'],
      selected_background=gruvbox['bg'],
  ))),

  # Toggle floating and fullscreen
  Key([mod], "f", lazy.window.toggle_fullscreen(),
      desc="Toggle fullscreen mode"),
  Key([mod, "shift"], "space", lazy.window.toggle_floating(),
      desc="Toggle fullscreen mode"),
  
  Key(["mod1"], "i", lazy.layout.increase_ratio()),


  # Keybindings for resizing windows in MonadTall layout
  # Key([mod], "i", lazy.layout.grow()),
  # Key([mod], "m", lazy.layout.shrink()),
  # Key([mod], "n", lazy.layout.normalize()),
  # Key([mod], "o", lazy.layout.maximize()),
  # Key([mod, "control"], "space", lazy.layout.flip()),

  # Switch between windows
  # Key([mod], "h", lazy.layout.left(), desc="Move focus to left"),
  # Key([mod], "l", lazy.layout.right(), desc="Move focus to right"),
  # Key([mod], "j", lazy.layout.down(), desc="Move focus down"),
  # Key([mod], "k", lazy.layout.up(), desc="Move focus up"),
  # Key([mod], "space", lazy.layout.next(),
  #     desc="Move window focus to other window"),

  # Key([mod], "h",
  #          lazy.layout.shrink(),
  #          lazy.layout.decrease_nmaster(),
  #          desc='Shrink window (MonadTall), decrease number in master pane (Tile)'
  #          ),
  #      Key([mod], "l",
  #          lazy.layout.grow(),
  #          lazy.layout.increase_nmaster(),
  #          desc='Expand window (MonadTall), increase number in master pane (Tile)'
  #          ),

  # Move windows between left/right columns or move up/down in current stack.
  # Moving out of range in Columns layout will create new column.
  # Key([mod, "shift"], "h", lazy.layout.shuffle_left(),
  #     desc="Move window to the left"),
  # Key([mod, "shift"], "l", lazy.layout.shuffle_right(),
  #     desc="Move window to the right"),
  # Key([mod, "shift"], "j", lazy.layout.shuffle_down(),
  #     desc="Move window down"),
  # Key([mod, "shift"], "k", lazy.layout.shuffle_up(), desc="Move window up"),

  # Grow windows. If current window is on the edge of screen and direction
  # will be to screen edge - window would shrink.
  # Key([mod, "control"], "h", lazy.layout.grow_left(),
  #     desc="Grow window to the left"),
  # Key([mod, "control"], "l", lazy.layout.grow_right(),
  #     desc="Grow window to the right"),
  # Key([mod, "control"], "j", lazy.layout.grow_down(),
  #     desc="Grow window down"),
  # Key([mod, "control"], "k", lazy.layout.grow_up(), desc="Grow window up"),
  # Key([mod], "n", lazy.layout.normalize(), desc="Reset all window sizes"),

  # Toggle between split and unsplit sides of stack.
  # Split = all windows displayed
  # Unsplit = 1 window displayed, like Max layout, but still with
  # multiple stack panes
  # Key([mod, "shift"], "Return", lazy.layout.toggle_split(),
  #     desc="Toggle between split and unsplit sides of stack"),

  # Toggle between different layouts as defined below
  Key([mod], "Tab", lazy.next_layout(), desc="Toggle between layouts"),
  Key([mod], "q", lazy.window.kill(), desc="Kill focused window"),

  Key([mod, "control"], "r", lazy.reload_config(), desc="Reload the config"),
  Key([mod, "control"], "q", lazy.shutdown(), desc="Shutdown Qtile"),
  Key(["mod1"], "Tab", lazy.screen.toggle_group(), desc="Switch/toogle to previos group"),
  ### Window controls
       Key([mod], "j",
           lazy.layout.down(),
           desc='Move focus down in current stack pane'
           ),
       Key([mod], "k",
           lazy.layout.up(),
           desc='Move focus up in current stack pane'
           ),
       Key([mod, "shift"], "j",
           lazy.layout.shuffle_down(),
           lazy.layout.section_down(),
           desc='Move windows down in current stack'
           ),
       Key([mod, "shift"], "k",
           lazy.layout.shuffle_up(),
           lazy.layout.section_up(),
           desc='Move windows up in current stack'
           ),
       Key([mod], "h",
           lazy.layout.shrink(),
           lazy.layout.decrease_nmaster(),
           desc='Shrink window (MonadTall), decrease number in master pane (Tile)'
           ),
       Key([mod], "l",
           lazy.layout.grow(),
           lazy.layout.increase_nmaster(),
           desc='Expand window (MonadTall), increase number in master pane (Tile)'
           ),
       Key([mod], "n",
           lazy.layout.normalize(),
           desc='normalize window size ratios'
           ),
       Key([mod], "m",
           lazy.layout.maximize(),
           desc='toggle window between minimum and maximum sizes'
           ),
       Key([mod, "shift"], "f",
           lazy.window.toggle_floating(),
           desc='toggle floating'
           ),
       Key([mod], "f",
           lazy.window.toggle_fullscreen(),
           desc='toggle fullscreen'
           ),
       ### Stack controls
       Key([mod, "shift"], "Tab",
           lazy.layout.rotate(),
           lazy.layout.flip(),
           desc='Switch which side main pane occupies (XmonadTall)'
           ),
        Key([mod], "space",
           lazy.layout.next(),
           desc='Switch window focus to other pane(s) of stack'
           ),
       Key([mod, "shift"], "space",
           lazy.layout.toggle_split(),
           desc='Toggle between split and unsplit sides of stack'
           ),
       Key([mod, "shift"], "space", lazy.layout.flip()),

]

groups = [
  Group('1', label="一", layout="stack"),
  Group('2', label="二", matches=[
        Match(wm_class='firefox')], layout="monadtall"),
  Group('3', label="三", layout="monadtall"),
  Group('4', label="四", matches=[
        Match(wm_class='vscodium')], layout="stack"),
  Group('5', label="五", matches=[Match(wm_class="telegram-desktop")], layout="monadtall"),
  Group('6', label="六", layout="monadtall"),
  Group('7', label="七", matches=[
        Match(wm_class='f5vpn')], layout="monadtall"),
  Group('8', label="八", layout="monadtall"),
  Group('9', label="九", matches=[
        Match(wm_class='keepassxc')], layout="monadtall"),
]

# # Append scratchpad with dropdowns to groups
# groups.append(ScratchPad('scratchpad', [
#     DropDown('term', 'kitty', width=0.4, height=0.5, x=0.3, y=0.1, opacity=1),
#     DropDown('mixer', 'pavucontrol', width=0.4,
#              height=0.6, x=0.3, y=0.1, opacity=1),
#     DropDown('pomo', 'pomotroid', x=0.4, y=0.2, opacity=1),
#     DropDown('bitwarden', 'bitwarden-desktop',
#              width=0.4, height=0.6, x=0.3, y=0.1, opacity=1),
# ]))
# # extend keys list with keybinding for scratchpad
# keys.extend([
#     Key(["control"], "1", lazy.group['scratchpad'].dropdown_toggle('term')),
#     Key(["control"], "2", lazy.group['scratchpad'].dropdown_toggle('mixer')),
#     Key(["control"], "3", lazy.group['scratchpad'].dropdown_toggle('pomo')),
#     Key(["control"], "4", lazy.group['scratchpad'].dropdown_toggle('bitwarden')),
# ])

for i in groups:
  keys.extend([
      # mod1 + letter of group = switch to group
      Key([mod], i.name, lazy.group[i.name].toscreen(),
          desc="Switch to group {}".format(i.name)),

      # Or, use below if you prefer not to switch to that group.
      # mod1 + shift + letter of group = move focused window to group
      Key([mod, "shift"], i.name, lazy.window.togroup(i.name),
          desc="move focused window to group {}".format(i.name)),
  ])

layouts = [
  Stack(
      border_normal=gruvbox['dark-gray'],
      border_focus=gruvbox['blue'],
      border_width=2,
      num_stacks=1,
      margin=10,
  ),
  MonadTall(
      border_normal=gruvbox['dark-gray'],
      border_focus=gruvbox['blue'],
      margin=10,
      border_width=2,
      single_border_width=2,
      single_margin=10,
  ),
  # Columns(
  #     border_normal=gruvbox['dark-gray'],
  #     border_focus=gruvbox['blue'],
  #     border_width=2,
  #     border_normal_stack=gruvbox['dark-gray'],
  #     border_focus_stack=gruvbox['dark-blue'],
  #     border_on_single=2,
  #     margin=10,
  #     margin_on_single=10,
  # ),
  MonadThreeCol(),
  MonadWide()
]

floating_layout = Floating(
  border_normal=gruvbox['dark-gray'],
  border_focus=gruvbox['dark-yellow'],
  border_width=4,
  float_rules=[
      *Floating.default_float_rules,
      Match(wm_class='ssh-askpass'),  # ssh-askpass
      Match(title='pinentry'),  # GPG key password entry
      Match(wm_class="pavucontrol"),
      Match(wm_class="zoom"),
      Match(wm_class="kdenlive"),
      Match(wm_class="crow"),
      Match(title='Qalculate!'),        # qalculate-gtk
      Match(title='floating'),        # floating terminal


  ])

# Drag floating layouts.
mouse = [
  Drag([mod], "Button1", lazy.window.set_position_floating(),
       start=lazy.window.get_position()),
  Drag([mod], "Button3", lazy.window.set_size_floating(),
       start=lazy.window.get_size()),
  Click([mod], "Button2", lazy.window.bring_to_front())
]
widget_defaults = dict(
  font='TerminessTTF Nerd Font',
  fontsize=40,
  padding=10,
  foreground=gruvbox['bg'],
)

extension_defaults = widget_defaults.copy()

screens = [
  Screen(
      top=Bar(
          [
              left_half_circle(gruvbox['bg']),
              GroupBox(
                  disable_drag=True,
                  active=gruvbox['gray'],
                  inactive=gruvbox['dark-gray'],
                  highlight_method='line',
                  block_highlight_text_color=gruvbox['red'],
                  borderwidth=0,
                  fontsize=45,
                  highlight_color=gruvbox['bg'],
                  background=gruvbox['bg']
              ),
              right_half_circle(gruvbox['bg']),
              Spacer(length=5),
              
              left_half_circle(gruvbox['dark-magenta']),
              WindowCount(
                  text_format='缾 {num}',
                  background=gruvbox['dark-magenta'],
                  show_zero=True
              ),
              right_half_circle(gruvbox['dark-magenta']),
              Spacer(length=5),

              left_half_circle(gruvbox['dark-blue']),
              CurrentLayout(
                  background=gruvbox['dark-blue'],
              ),
              right_half_circle(gruvbox['dark-blue']),
              Spacer(length=5),

              Prompt(
                  foreground=gruvbox['fg']
              ),
              WindowName(foreground=gruvbox['fg']),


              Spacer(length=200),

              Systray(
                  padding=15,
                  background='#00000000',
                  icon_size=45
              ),
              Spacer(length=10),
              left_half_circle(gruvbox['dark-yellow']),
              Battery(
                  charge_char='',
                  discharge_char='',
                  empty_char='',
                  full_char='',
                  unknown_char='',
                  notify_below=0.1,
                  update_interval=30,
                  low_background=gruvbox['dark-magenta'],
                  background=gruvbox['dark-yellow'],
                  format='{char} {percent:2.0%} {hour:d}:{min:02d}'),
              right_half_circle(gruvbox['dark-yellow']),
              Spacer(length=10),
              left_half_circle(gruvbox['dark-cyan']),
              Volume(
                     fmt=' {}',
                     background=gruvbox['dark-cyan'],
                     emoji=False),
              right_half_circle(gruvbox['dark-cyan']),
              Spacer(length=10),
              left_half_circle(gruvbox['blue']),
              CPU(
                  format=' {load_percent}%',
                  background=gruvbox['blue'],
              ),
              right_half_circle(gruvbox['blue']),
              Spacer(length=10),

              left_half_circle(gruvbox['magenta']),
              Memory(
                  # format=' {MemUsed: .0f}{mm}/{MemTotal: .0f}{mm}',
                  format=' {MemUsed: .0f}{mm}',
                  background=gruvbox['magenta']),
              right_half_circle(gruvbox['magenta']),
              Spacer(length=10),

              left_half_circle(gruvbox['cyan']),
              Net(
                  background=gruvbox['cyan'],
                  format='龍 {down} ↓↑ {up}',
                  padding=1
              ),
              right_half_circle(gruvbox['cyan']),
              Spacer(length=10),

              left_half_circle(gruvbox['dark-blue']),
              Clock(
                  background=gruvbox['dark-blue'],
                  format=' %d-%m %a %H:%M'),
              right_half_circle(gruvbox['dark-blue'])
          ],
          margin=[10, 10, 5, 10],
          background='#00000000',
          opacity=1,
          size=60,
      ),
  ),
]

dgroups_key_binder = None
dgroups_app_rules = []  # type: List
follow_mouse_focus = True
bring_front_click = ''
cursor_warp = False
auto_fullscreen = True
focus_on_window_activation = "smart"
reconfigure_screens = True
auto_minimize = True
wmname = "LG3D"


@hook.subscribe.startup_once
def autostart():
  home = os.path.expanduser('~/.config/qtile/autostart.sh')
  subprocess.run([home])

# TODO: hot keys from LARBS
# TODO: hot keys for applications (keepassxc, slack, work(discord, slack, browser, vscodium))
# TODO: shutdown menu ( libqtile.extension.CommandSet)
# TODO: modalall, how to wide window
# TODO: modalall, toogle master and slave windows
# TODO: monadall, how to set number of master windows
# TODO: monadtreecol configure colors
# TODO: monadwide configure colors, how to set number of master windows
# TODO: sound does not encrese with shortcut
# TODO: configure key to open clipboard content in home browser
# TODO: how to change size of floating window
# TODO: floating terminal
# TODO: floating calculator

Required:

  • I have searched past issues to see if this bug has already been reported.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
elParaguayocommented, Jul 11, 2022

@elParaguayo Thank you, it works!

Great!

It is no obvious solution for me. In Net widget it works without such setting.

Actually, the Net widget uses the same trick, it’s just hidden in the main code of the widget. https://github.com/qtile/qtile/blob/6620786f801f56fc61716514139044108eaef743/libqtile/widget/net.py#L126-L133

I also did not find such setting in documentation or some where in examples. Could you please explain what is :>5.2f about? Is it python formatting (what does it do) or it is qtile?

This is python string formatting.

  • The : is the start of the formatting block
  • > means we want to right align the formatted text (i.e. padding will be on the left hand side)
  • 5.2f means we’re taking a floating point number (indicated by f), we want the minimum length of the formatted text to be 5 characters (the 5) and we want to show 2 decimal places (.2).
1reaction
elParaguayocommented, Jul 11, 2022

Sure - you can post a new issue as it will trigger the broader conversation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set QWidget width? - c++ - Stack Overflow
If the width won't change afterwards, you can use setFixedWidth : widget->setFixedWidth(165);. Similarly, to change the height without changing the width, ...
Read more >
Feature request : fix the size of widgets · Issue #2379 · qtile/qtile
A boolean or a way to fix the size of the widget to prevent the giggling of others widgets when the value of...
Read more >
Understanding constraints - Flutter documentation
A widget gets its own constraints from its parent. A constraint is just a set of 4 doubles: a minimum and maximum width,...
Read more >
How To Set The Height And Width of Widgets - YouTube
How To Set The Height And Width of Widgets - Python Kivy GUI Tutorial #4. 39K views 2 years ago. Codemy ...
Read more >
Widgets - Datadog Docs
Widgets are building blocks for your dashboards. They are categorized into three types. Generic widgets to graph data from Datadog products: Change ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found