Formatting Text to the Tkinter Progressbar - python-3.x

I got to know about adding the text to the progress bar as per this question:
Displaying percentage in ttk progressbar
It helps me but I need a few more adjustments to do to the answer.
I need the text (the percentage) to appear on the left side of the progressbar.
For this, I added 'side':'left' to the layout format for Horizontal.TProgressbar.label.
As under:
style.layout('text.Horizontal.TProgressbar',
[('Horizontal.Progressbar.trough',
{'children': [('Horizontal.Progressbar.pbar',
{'side': 'left', 'sticky': 'ns'})],
'sticky': 'nswe'}),
('Horizontal.Progressbar.label', {'side':'left','sticky': ''})])
However, this moves the text to extreme left. It overlaps the progressbar border and is not clearly readable.
I need to adjust the font and font color of this text. How do we change that?

To change the space between the label and the border you can add a padding element to the layout
style.layout('text.Horizontal.TProgressbar',
[('Horizontal.Progressbar.trough',
{'children': [('Horizontal.Progressbar.pbar',
{'side': 'left', 'sticky': 'ns'})],
'sticky': 'nswe'}),
('Horizontal.Progressbar.padding', {'side':'left'}),
('Horizontal.Progressbar.label', {'side':'left','sticky': ''})])
Then configure the padding with
style.configure('text.Horizontal.TProgressbar', padding=4)
You can change the font and color of the text using style.configure with the font and foreground options:
style.configure('text.Horizontal.TProgressbar', foreground="red", font='Arial 20')
There is a full example of creating such a progressbar in my answer to Progressbar with Percentage Label?.

Related

Fit minimal size of a QDockPanel after QLabel content update

I have a QDockWidget with a QGroupBox as the top widget, with QVBoxLayout applied. This contains a QChartView and a QLabel.
The QLabel contains a text composed of several lines of different length.
First, I would like to have the QChartView the same width and height as the QLabel.
Second, as the content of the QLabel is updated by setText(...) in a Slot method, its content changes in height and width. So I would like to update the width and height of the QChartView above it.
For the moment, I only achieved to grow the entire DockPanel to accomodate longer and wider QLabel content, but not to shrink back when this content is narrower and less wide...
I did play with a lot of things, without real success (here a snippet of the Slot method that updates the QLabel content...):
self.fkChartView.hide()
self.pPDetailsLabel.hide()
self.pPDetailsLabel.parent().hide()
self.pPDetailsLabel.setText(self.canvas.grayScottModel.getPearsonPatternDescription(specie=type))
self.pPDetailsLabel.updateGeometry()
self.pPDetailsLabel.parent().updateGeometry()
self.pPDetailsLabel.parent().update()
self.pPDetailsDock.updateGeometry()
self.pPDetailsDock.update()
self.pPDetailsLabel.show()
self.pPDetailsLabel.parent().show()
# print(self.pPDetailsLabel.sizeHint())
self.fkChartView.setMinimumHeight(self.pPDetailsLabel.size().width())
self.fkChartView.setMaximumHeight(self.pPDetailsLabel.size().width())
self.fkChartView.setMinimumWidth(self.pPDetailsLabel.size().width())
self.fkChartView.setMaximumWidth(self.pPDetailsLabel.size().width())
self.fkChartView.updateGeometry()
self.fkChartView.show()
self.fkChartView.updateGeometry()
self.fkChartView.update()
I tried to hide the widgets, so they forget their sizes and/or sizeHint (not sure).
I tried a few updateGeometry() and update() too, but it does not seem to help.
An idea, anyone?
I had it working as intended in the end by doing this in the slot method that updates the content of the QLabel:
self.fkChartView.hide()
self.pPDetailsLabel.setText(self.canvas.grayScottModel.getPearsonPatternDescription(specie=type))
self.pPDetailsLabel.adjustSize()
self.pPDetailsLabel.parent().adjustSize()
# Sets the dimensions of the chart folowing the label width
self.fkChartView.setMinimumHeight(self.pPDetailsLabel.size().width())
self.fkChartView.setMaximumHeight(self.pPDetailsLabel.size().width())
self.fkChartView.setMinimumWidth(self.pPDetailsLabel.size().width())
self.fkChartView.setMaximumWidth(self.pPDetailsLabel.size().width())
self.fkChartView.adjustSize()
self.fkChartView.show()
self.pPDetailsDock.adjustSize()
So I first hide the QChartView, so its dimensions do not interfere,
then all the magic happens thanks to the adjustSize() call. I do this on the QLabel after its content has been updated,
then on its parent (the top QGroupBox in my QDockWidget).
The QChartView still hidden, I force its dimensions,
then show it and
finally adjust the size of the QDockWidget.
It does precisely what I want:
if text is broader, the chart expands but stays square,
if text is narrower, chart shrinks, but stays square.
Total height of the dock adjusts also to fit, without staying the longer and longer it had to be to accomodate for a big former QLabel content.

Exact border color and width of standard/system QLineEdit?

Does anyone know the border color of a standard/system QLineEdit? Black is/seems too dark. It looks like some shade of grey, but would like the exact color.
Also, is the border width 1px?
There is no "standard/system" border color nor border size. It depends on:
the OS;
the possible styling customization of the OS;
the Qt Style in use (which might or might not depend on the OS);
possible customization used with style sheets;
The color could be based on the colors of the current palette, but every style (and OS) use those colors in different ways, and in some cases they are even drawn using pixmaps.
The color roles that might be used for drawing borders are:
QPalette.WindowText
QPalette.Text
QPalette.Midlight
QPalette.Dark
QPalette.Mid
QPalette.Shadow
The frame width could be based on the PM_DefaultFrameWidth pixel metric, that can be queried with the following:
# within an existing QLineEdit instance
opt = QtWidgets.QStyleOptionFrame()
self.initStyleOption(opt)
border = opt.lineWidth
# without a QLineEdit, from any other widget
style = self.style()
# or from the app
opt = QtWidgets.QStyleOptionFrame()
style = QtWidgets.QApplication.style()
border = style.pixelMetric(QtWidgets.QStyle.PM_DefaultFrameWidth, opt)
But, as said above, the returned colors and values could not be consistent with the actual result, also because the style might do some ajdustments and add graphical effects that could increase/decrease the visible border width and change its appearance.

vim on iterm cannot open as full screen

I wonder about this bottom and left gap, and also wanna remove it
It occurs only when i open "vim", not Iterm itself
Is there any solution?
The general principle is that the screen of a terminal emulator is a grid where each cell has the same dimensions as the others and those dimensions are determined by the font and font size used. If the window's dimensions and the grid's dimension are incompatible, then the window can't be filled with the grid and you have that kind of gap.
In this case, the cell dimensions are 16px * 38px so the grid can only fit in a box whose dimensions are a multiple of 16 in width and a multiple of 38 in height.
Now, your screen's dimensions appear to be 1630px * 2862px, which is rather unusual. The width is not a multiple of 16 and the height is not a multiple of 38, so, with your current font settings it is impossible to fill the screen.
For that to be theoretically possible, you would need font settings that make individual cells 16.3px wide and 38.16px tall, or some other "impossible" ratio.
Note that you also have a padding, here, that effectively prevents the grid to ever fill the window anyway.
None of that is really a problem when the program you run in your terminal emulator doesn't paint the background of those cells but your Vim colorscheme does, which makes the effect described above apparent.
The only practical workarounds are:
Define the same background in Vim and in your terminal emulator.
Make Vim's background transparent.

Canvas background color not saved

Tkinter canvas.postscript is not saving the canvas background.
Sizes of the canvas that are used throughout the Python code:
w = 800
h = 600
Function to be assigned to "SAVE CANVAS' button:
def save_canvas():
canvas.update()
canvas.postscript(file= r'Z:\\...\FILE.ps', height=h, width=w, colormode='color')
When I click on the button that has the save_canvas command assign, the file that is saved has no background as assigned in the widget. I changed the color to orange, green, etc. draw on it. Everything looks ok, but saving is without background. Same with .jpeg/.png
What do I need to call for saving the background? I'll be needing this as the application I build require images as background as well.
I don't believe the postscript command is designed to preserve the background color of the canvas widget. It only saves the items that appear on the canvas.
A simple solution is to draw a rectangle that is the exact size of the canvas, and change the color of that rectangle.

PyQt - Keeping spacing at zero during window resize, grid layout

I'm making an emacs-esque toy text editor. At startup, there's one large window (a QTextEdit derivative) in the top center of the screen, with a minibuffer (QLineEdit derivative) underneath. Both of the actual editing widgets are contained in the grids of parent classes called Window and MiniWindow (Window also keeps track of a QLabel that appears directly beneath the QTextEdit).
My Window object is at location 1, 1 in the grid, and my MiniWindow object is at 2, 1. I've set content margins to 0 and spacing to 0, which looks great at first, but when I try to grow the window by dragging on the corner, this starts to happen:
As you can see, the screen is divided into two rows (as it should be), but half of the vertical length of the screen is dedicated to each row. What I need is for the top Window to stretch its length during resizing so that it is always adjacent to the MiniWindow underneath. Is there some other option I need to be setting?
Nevermind, got it.
I was having this problem because the QLineEdit object was in the grid of my container class, MiniWindow. The height of a MiniWindow object is free to vary with the window resizing in a way that a QLineEdit alone would not be. The fix was set to the maximumHeight of MiniWindow to approximately the height of a QLineEdit, which is around 16.
Works great now.

Resources