How to set and preserve minimal width? - python

I use some wx.ListCtrl classes in wx.LC_REPORT mode, augmented with ListCtrlAutoWidthMixin.
The problem is: When user double clicks the column divider (to auto resize column), column width is set to match the width of contents. This is done by the wx library and resizes column to just few pixels when the control is empty.
I tried calling
self.SetColumnWidth(colNumber, wx.LIST_AUTOSIZE_USEHEADER)
while creating the list, but it just sets the initial column width, not the minimum allowed width.
Anyone succeeded with setting column minimal width?
EDIT: Tried catching
wx.EVT_LEFT_DCLICK
with no success. This event isn't generated when user double clicks column divider. Also tried with
wx.EVT_LIST_COL_END_DRAG
this event is generated, usually twice, for double click, but I don't see how can I retrieve information about new size, or how to differentiate double click from drag&drop. Anyone has some other ideas?

Honestly, I've stopped using the native wx.ListCtrl in favor of using ObjectListView. There is a little bit of a learning curve, but there are lots of examples. This would be of interest to your question.

Ok, after some struggle I got working workaround for that. It is ugly from design point of view, but works well enough for me.
That's how it works:
Store the initial width of column.
self.SetColumnWidth(colNum, wx.LIST_AUTOSIZE_USEHEADER)
self.__columnWidth[colNum] = self.GetColumnWidth(c)
Register handler for update UI event.
wx.EVT_UPDATE_UI(self, self.GetId(), self.onUpdateUI)
And write the handler function.
def onUpdateUI(self, evt):
for colNum in xrange(0, self.GetColumnCount()-1):
if self.GetColumnWidth(colNum) < self.__columnWidth[colNum]:
self.SetColumnWidth(colNum, self.__columnWidth[colNum])
evt.Skip()
The self.GetColumnCount() - 1 is intentional, so the last column is not resized. I know this is not an elegant solution, but it works well enough for me - you can not make columns too small by double clicking on dividers (in fact - you can't do it at all) and double-clicking on the divider after last column resizes the last column to fit list control width.
Still, if anyone knows better solution please post it.

Related

In wxpython, how to set position of objects within a wxScrolledWindow

I am writing a kicad plugin, and I need to create a GUI for this plugin. Because kicad uses wxpython, that is what I am using.
I have already figured out that placing my ui items using the layout sizers just isn't gonna give me the control I need to create the window I want. I know I can set the position of elements, and have been using that to create the ui I need.
The problem however, is that my window gets bigger than what would be reasonable (in some situations). Therefore I want to make it scrollable.
I have been playing around with wxformbuilder, and I found the wxScrolledWindow. That got me this far:
This is roughly what I want, except, when you want to place stuff within the scrolledWindow, you have to place one of the "sizers" in it (as far as I can tell at least), in which you place your buttons. The problem with that is, that, to my knowledge, setting the position of buttons in any of the sizers just has no effect at all.
So, my question is: how do I achieve this effect? and, is this even possible?
edit:
As an example of what I am trying to put within the scrolledwindow, this is a rough version of the ui I want to create (and want to be scrollable). (I want to eventually have, probably an icon button above each of the checkbox columns to indicate what they are for).
The final result would need to look something like this (the white squares being small images / buttons, also, in reality being not on the window bar,but in its own not scrolling section):
An example of something I wasn't able to achieve using sizers is, getting those checkboxes so close together, without making them appear off center. Different widgets seem to have different sizes, and checkboxes without border are especially small, so they end up appearing off center, example:
Also, those images above each column of checkboxes, which don't scroll, need to line up with the X coordinates of those scrolling checkboxes, which also seems very non trivial. Though also really hard to get right if I could give everything exact coords, so I might need to give up on that specific idea of making those not scrollable.

Is there a combo box "findText" equivalent for QTreeView?

I'm using PyQt5 (Python of course) and I was able to easily find the entry programatically in the combo box. I just passed the string to "findText" method. But I don't see anything in the QTreeView class documentation on how to select one row based on what I know is a file being displayed there. I looked at keyboardSearch() but just now realized that's used when you type letters on the keyboard (duh). I see a setSelection() method that takes a rectangle, but I have no idea how I would know dimensions or coordinates of a rectangle with the selection I want? Especially since I have sorting enabled so the rows can change order.
Any help would be much appreciated!
Justin

Tkinter's .grid() not aligning things, I'm at my wits end

I've been working on a program for a while, that deals with taking users input, and at one point, making a table with it, and asking them to edit anything they need to. I'm using Tkinter, and it's too late for me to change that. I have 3 frames, the first being a Pmw Scrolled Frame, the second being left_frame, inside of the main one, and the third is right_frame. On the left side I have a bunch of Labels, and then on the right, I have several OptionMenus and Entries. The problem is, no matter what I try, I cannot seem to make them aligned. I have been at this forever. Here is the relevant code: http://pastebin.com/S7yMmacG
You can ignore all of the functions there, they work and are unrelated to the alignment, sorry if it's messy. As for seeing what is actually happening, he is an image of the issue
https://i.imgur.com/y2ctoDq.jpg
I've tried using .pack(), .place(), but none of it works. If anyone could help that would be amazing, I have been at this forever and I really don't know what to do at this point. Thanks
they are not alligned because all your updating them to row
in grid we have .grid(row=x,cloumn=x)
let say for description label and feild to be aligned they should have same row and different column
keep discription label at row=0 and column=0 and its textfeild at row=0 and column=1
and they all should belong to same frame . please not to use different frames for this purpose
to have fixed width for column you have grid_configure
you can change by myframe.grid_congfigure(column=0,minsize=150)
this size will be constant throughout the frame for column 0
you can learn from docs

wxpython update wx.statictext inside wx.gridsizer

I am using a Flexgridsizer that contains a mix of statictexts and buttons within it. My flexgridsizer contains 1 column of statictext that never changes, 3 columns that update constantly (sometimes a tenth of a second) and the last column has all buttons that remain the same -- I have about 12 rows.
When I push "go" on my code, the three statictext columns update constantly. I do this by self.text1.SetLabel('newtext'). This works great. However, I initially set up the gridsizer so the statictext is centered. Therefore, when i run my code, after updating each cell, i run self.panel.Layout(). This helps get my columns centered again.
The problem with this is that since I do so much updating, it causes my buttons in the last column to look like they are moving left and right (since it appears to be resetting the layout of the buttons). I want the buttons to "stay still". To fix this, I removed the self.panel.Layout() BUT this now makes all my text be right-justified.
Is there any way to apply the Layout() to just specific columns of the gridsizer? I really need to keep the gridsizer if possible. I have also seen the "noautoresize" but one of my columns experiences texts of different lengths at each update.
Any thoughts? Thanks!
Try setting the StaticText size to something specific, like (100, -1). That way it should stay the same unless you happen to apply a string that's greater than the size you set. I'm not sure what happens then, but probably it would get truncated. However, if you're updating it so fast that you can't read it to begin with, I don't think this will be an issue.

How can I make the icons in an IconView spread out evenly?

I have a gtk.IconView with several icons in it. Sometimes I will resize the window to see more icons. When I do this, the extra space generated isn't distributed evenly between all the columns. Instead, it all gets put on the right until there's enough space for a new column.
I'm not seeing anything in the documentation that would let me do this automatically. Do I need to check for resize signals and then manually set the column and row spacings? If so, which resize signal do I use.
Here's a picture of what I mean. I've marked the extra space in red.
This is what I'd like to see (of course, with the gaps actually evenly spaced, unlike my poor MS Paint job).
We have encountered that problem in Ubuntu Accomplishments Viewer, and as we managed to solve it, I'll present our solution.
The trick is to place the GtkIconView in a GtkScrolledWindow, and set it's hscrollbar_policy to "always". Then, a check-resize signal has to be used, to react when the user resizes the window (note that it must be checked if the size has changed, for the signal is emitted also when e.g. the window is dragged around). When the size changes, the model used by GtkIconView has to be cleared and recreated, as this triggers GtkIconView properly reallocating the newly gained space (or shrinking). Also, as the result the horizontal scrollbar will never be seen, as the GtkIconView uses exactly that much space as the GtkScrolledWindow uses.
Yeap, it seems after a very fat look that you will need to do that on your own. And regardeing the signal, I'd check for GtkContainer::check-resize.
Use the event size_allocate.
I defined my class :
class toto(Gtk.IconView):
def __init__(self):
super(toto,self).__init__()
self.connect("size_allocate",self.resize)
self.set_columns(4)
Then I modify the number of working columns
def resize(self,_iv,_rect):
print("X",rect.x)
print("Y",rect.y)
print("W",rect.width)
print("H",rect.height)
# calculate number of columns, let's say 3
_cols=3
self.set_columns(_cols)
Seems working for me

Categories