Repository: qtile/qtile

Issue:
Width parameter of widgets
The width parameter is used very inconsistently by different widgets. There are three bugs (which can easily be fixed) and a potential problem (for some users).
The bugs are:
- The Backlight and Battery widget's `__init__` methods take the width as an argument but do not include it when calling the super classes `__init__` method.
- The WindowName widget calls the super classes `__init__` method with a width of `bar.STRETCH` and doesn't give the user a chance to change that.

This leads me to the problem, which however might be desired behavior: Some of the other widgets call the super classes `__init__` method with a width of `bar.CALCULATED`,  also  without giving the user the possibility to change that. While this is less problematic than the three bugs mentioned above, some users might want to set a specific width for some widgets (or even `bar.STRETCH`).
So I was wondering, whether the width parameter should be exposed for all widgets, or if there is a specific reason for it not being changeable by the user.
By the way: the following widgets do not expose the width parameter: AGroupBox, GroupBox, Maildir, Pacman, Prompt, ThermalSensor,  Systray, Volume and YahooWeather.



Discussion:
Hi Tim,

Widgets that place a variable amount of text clearly need to be able to set
their width.

I don't know of any reason that you would want to fix this other than maybe
to constrain the space that it consumes,  but then that could impact it's
usefulness.

Some, such as window name clearly lend themselves to doubling up as a
spacers, but one observation of this property is that it limits the space
it can consume to available bar space, whereas widgets that are left to
calculate do push other widgets off the screen.

I don't know if changing this would provide any advantages.

I would suggest that removing the width property from the battery widget
might be appropriate.

Cheers

Craig

On 2 November 2012 17:49, TimNN notifications@github.com wrote:

> The width parameter is used very inconsistently by different widgets.
> There are three bugs (which can easily be fixed) and a potential problem
> (for some users).
> The bugs are:
> - The Backlight and Battery widget's **init** methods take the width
>   as an argument but do not include it when calling the super classes
>   **init** method.
> - The WindowName widget calls the super classes **init** method with a
>   width of bar.STRETCH and doesn't give the user a chance to change that.
> 
> This leads me to the problem, which however might be desired behavior:
> Some of the other widgets call the super classes **init** method with a
> width of bar.CALCULATED, also without giving the user the possibility to
> change that. While this is less problematic than the three bugs mentioned
> above, some users might want to set a specific width for some widgets (or
> even bar.STRETCH).
> So I was wondering, whether the width parameter should be exposed for all
> widgets, or if there is a specific reason for it not being changeable by
> the user.
> By the way: the following widgets do not expose the width parameter:
> AGroupBox, GroupBox, Maildir, Pacman, Prompt, ThermalSensor, Systray,
> Volume and YahooWeather.
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/qtile/qtile/issues/181.

Ok, this makes sense,

However I would still allow the user to change the width of the window name widget, so it can be set to a fixed value.


Resolving patch:
diff --git a/libqtile/widget/backlight.py b/libqtile/widget/backlight.py
--- a/libqtile/widget/backlight.py
+++ b/libqtile/widget/backlight.py
@@ -28,8 +28,8 @@ class Backlight(base._TextBox):
         ('update_delay', .2, 'The delay in seconds between updates'),
     )
 
-    def __init__(self, width=bar.CALCULATED, **config):
-        base._TextBox.__init__(self, "LIGHT", **config)
+    def __init__(self, **config):
+        base._TextBox.__init__(self, "LIGHT", bar.CALCULATED, **config)
 
     def _configure(self, qtile, bar):
         base._TextBox._configure(self, qtile, bar)
diff --git a/libqtile/widget/battery.py b/libqtile/widget/battery.py
--- a/libqtile/widget/battery.py
+++ b/libqtile/widget/battery.py
@@ -104,8 +104,8 @@ class Battery(_Battery):
         *_Battery.defaults.defaults
     )
 
-    def __init__(self, low_percentage=0.10, width=bar.CALCULATED, **config):
-        base._TextBox.__init__(self, "BAT", **config)
+    def __init__(self, low_percentage=0.10, **config):
+        base._TextBox.__init__(self, "BAT", bar.CALCULATED, **config)
         self.low_percentage = low_percentage
 
     def _configure(self, qtile, bar):
diff --git a/libqtile/widget/windowname.py b/libqtile/widget/windowname.py
--- a/libqtile/widget/windowname.py
+++ b/libqtile/widget/windowname.py
@@ -14,8 +14,8 @@ class WindowName(base._TextBox):
         ("foreground", "ffffff", "Foreground colour."),
     )
 
-    def __init__(self, **config):
-        base._TextBox.__init__(self, width=bar.STRETCH, **config)
+    def __init__(self, width=bar.STRETCH, **config):
+        base._TextBox.__init__(self, width=width, **config)
 
     def _configure(self, qtile, bar):
         base._TextBox._configure(self, qtile, bar)


Test patch: