Zren / plasma-applet-commandoutput

https://store.kde.org/p/1166510/
GNU General Public License v2.0
87 stars 18 forks source link

Clarify whitespace interventions #12

Closed AndydeCleyre closed 4 years ago

AndydeCleyre commented 5 years ago

I use this applet to display currently playing track information, and want to control the width, because if my panel changes size every few seconds it distracts me from work. So I use a monospace font, and implement a "resize" function, which pads the outside with spaces, or truncates the content.

The first problem is the auto-trimming (like Python's str.strip), but I work around that by adding some outer character, like - to either side.

That worked until I discovered I could color the content, using html-like markup (Qstring?). So for example, the script might alternately be outputting these two lines:

<font color="#a94d37">-  The Beatles  -</font>
<font color="#a94d37">-I am the Walrus-</font>

Both strings are exactly the same length. The resulting presentation is colored. But the consecutive spaces are "squeezed" (even though they are not at the beginning or end of the string).

So the representation (colored) becomes:

- The Beatles -
-I am the Walrus-

They differ in size by two characters, because the consecutive spaces in the middle of the string have been reduced to a single space per grouping.

How can we prevent these interventions?

Zren commented 5 years ago

Use https://store.kde.org/p/998887/, though it seems opening that widget's config freezes plasma (infinite loop?) so if you want to edit it, open up the following file after installing it:

~/.local/share/plasma/plasmoids/org.kde.plasma.mediacontrollercompact/contents/ui/configGeneral.qml

Then add id: pageColumn to the first ColumnLayout and change implicitWidth: mainColumn.implicitWidth to implicitWidth: pageColumn.implicitWidth.

2019-03-15___21-43-45

Restart plasma with killall plasmashell; kstart5 plasmashell to reload the panel.

You can then open up ExpandedRepresentation.qml and delete the buttons. Basically delete the Column { id: playerControls } and everything after it.

2019-03-15___21-49-25

Just make sure you don't delete the final 3 closing tags.

2019-03-15___21-52-57

Zren commented 5 years ago

As for what actually controls the widget's width in a panel, the Layout.preferredWidth: output.implicitWidth in the Plasmoid.fullRepresentation item is what you need to look at.

Use Layout.preferredWidth: 234, or Layout.preferredWidth: 234 * units.devicePixelRatio if you want to code properly for HiDPI, will make it 234px wide.

https://github.com/Zren/plasma-applet-commandoutput/blob/master/package/contents/ui/main.qml#L94

AndydeCleyre commented 5 years ago

I don't think what you've suggested will function as well for me as what I have. My playback information falls back to information reported by Last.fm if no local players are found (so it is accurate even if some other device is playing the music).

AndydeCleyre commented 4 years ago

For reference, this is the script I wish I could use colors with (see the def and commented call for colorize), without having this applet/Qt delete characters from the middle.

The now_playing function can be mocked by having it return

{
    'title': "A Great Song",
    'artist': "A Pretty Good Musician",
    'album': "A Hit or Miss Album",
    'status': "Playing"
}
AndydeCleyre commented 4 years ago

Hey, it seems that if the new official color setting is used, white space is preserved!