Screenshot
I'm looking to recreate this in Python; I can't find a library that seems to have what I need. Are there any GUI libraries that might possibly have this? - I have scoured wxWidgets (which is my preferred gui library) but they have nothing similar.
I have a script already that uses a standard wxTreeCtrl but it has no provisions for adding additional icons at the tail end like this screen shot.
If no pre-existing gui library exists, any tips for my first steps in trying to create it myself?
you have few options
Use wx.lib.customtreectrl.CustomTreeCtrl
AppendItem of CustomTreeCtrl can take any wx widget, which is shown at end, so you can use that to affect e.g. tree.AppendItem(root, "item1", wnd=yourImageControl)
Use wx.gizmos.TreeListCtrl, you can have icons in separate columns and tree in first column
You can use wx.lib.mvctree , and supply your own Painter class or derive class from TreePainter, and override Paint method
Or most complex but most satisfying way is to write your own tree control, and if you have long term usage for such a control and you may need more custom changes, it will be best way and won't be much difficult. See mvtree for inspiration or customize that.
Instead of CustomTreeCtrl, I'd look into HyperTreeList. It is based on CustomTreeCtrl, but adds support for multiple columns. I'm not sure if it supports multiple icons in one column out of the box though.
Related
Studying Tkinter and I've only found tutorials on Tkinter without OOP, but looking at the Python.org documentation it looks like it's all in OOP. What's the benefit of using classes? It seems like more work and the syntax looks night and day from what I've learned so far.
This is going to be a really generic answer and most of the answers to this will be opinionated anyways. Speaking of which,the answer will likely be downvoted and closed because of this.
Anyways... Let's say you have a big GUI with a bunch of complicated logic sure you could write one huge file with hundreds, if not thousands of lines, and proxy a bunch of stuff through different functions and make it work. But, the logic is messy.
What if you could compartmentalize different sections of the GUI and all the logic surrounding them. Then, takes those components and aggregate them into the sum which makes the GUI?
This is exactly what you can use classes for in Tkinter. More generally, this is essentially what you use classes for - abstracting things into (reusable - instances) objects which provide a useful utility.
Example:
An app I built ages ago with Tkinter when I first learned it was a file moving program. The file moving program let you select the source / destination directory, had logging capabilities, search functions, monitoring processes for when downloads complete, and regex renaming options, unzipping archives, etcetera. Basically, everything I could think of for moving files.
So, what I did was I split the app up like this (at a high level)
1) Have a main which is the aggregate of the components forming the main GUI
Aggregates were essentially a sidebar, buttons / labels for selection various options split into their own sections as needed, and a scrolled text area for operation logging + search.
So, the main components were split like this:
2) A sidebar which had the following components
Section which contained the options for monitoring processes
Section which contained options for custom regular expressions or premade ones for renaming files
Section for various flag such as unpacking
3) A logging / text area section with search functionality build in + the options to dump (save) log files or view them.
That's a high level description of the "big" components which were comprised from the smaller components which were their own classes. So, by using classes I was able to wrap the complicated logic up into small pieces that were self contained.
Granted, you can do the same thing with functions, but you have "pieces" of a GUI which you can consider objects (classes) which fit together. So, it just makes for cleaner code / logic.
Like what pythonista just said...
OOP makes your GUI code more organized and if you need to create new windows eg.toplevel() you will find it extremely useful because you won't need to write all that code again and again and again... Plus if you have to use variables that are inside another function you will not need to declare it as a global. OOP with Tkinter is the best approach
I'm changing the look of some elements in my pyQt application using a QSS style sheet. This has the effect of overriding many other properties of those elements as well (as noted in the documentation and many tutorials).
Now, I would like to restore these overridden properties, but I haven't managed to find the "original" style sheets on my system where the default themes are defined. Using the information from these style sheets I could restore the rest of the original look.
Could somebody give me hint where to find these style sheets? Or is there a more elegant way to achieve my goals?
There are no default stylesheets. All the default styling is done by style plugins.
When a stylesheet is set, it creates an instance of QStyleSheetStyle (which is a subclass of QWindowsStyle) and passes it a reference to the current style. The QStyleSheetStyle will try to apply the QSS rules on top of the current style, but where this is not possible, it will fall back to the QWindowsStyle.
And this is where the problems start, because there is no simple way to determine what a particular QSS rule will do. Sometimes it will have a very precise effect, and other times it will completely clobber the normal styling. In addition, the exact outcome depends on what the current style is. So a QSS rule might look good on your own system, but there's no guarantee it will do so on others.
Using stylesheets is therefore always a compromise. Creating a custom QStyle would give you much more control, but stylesheets will usually be much easier to write and maintain. So it's a trade-off between convenience and precision.
However, there is a third option available. Do nothing. Respect the user's choice of widget styling - or at the very least, don't force them to accept yours.
I'm very new to wxpython, so this is probably an obvious question.
Let's say I wanted to create a program like an installation wizard which, when next is clicked, destroys the current set of widgets and creates a new set. However, the user must also be able to go back to a previous page.
Would I need classes for each page with their own __init__, could I just use a normal function, or is there a better way to do this?
There are a couple of valid approaches. The most obvious would be to just use wxPython's built-in wizard which can be found in wx.wizard. You might want to take a look at the documentation, the wiki or the wxPython demo for examples. You might also find this tutorial helpful:
http://www.blog.pythonlibrary.org/2011/01/27/wxpython-a-wizard-tutorial/
Of course the wizard is a bit limited, so if you needed something that gives you more flexibility, then you might want to look at rolling your own wizard. If you went with that approach, then yes, you would probably benefit from creating a base Page class that holds your assortment of widgets. Then as each page is shown, you can either Hide the previous page or Destroy it. Personally, I would just go with hiding it unless you had a lot of widgets per page.
This tutorial might help you get started down this path:
http://www.blog.pythonlibrary.org/2012/07/12/wxpython-how-to-create-a-generic-wizard/
I'm new to Python and PyQt. What is the best way to keep 4 QtTreeWidgets synchronized so that the items are the same as well as all the attributes of all the items? These widgets appear in different dialog boxes at different times during a session. For a number of reasons, I need to keep as much of the existing code, signals and layout as intact as possible. The Model/View division would be the obvious first place to go, but I don't want to touch any of the methods that are used to access or update the tree. I'm planning to refactor the whole thing in a few months, but I need something quickly to carry me until then.
Since each QTreeWidget is a convenience class, each has its own data. The UI is maintained in Qt Designer and I don't want to keep it that way.
When each dialog is initialized, the tree appears. The application has a singleton class that all dialogs can use to reference its variables/attributes.
In the initialization of each parent dialog, couldn't I check to see if a 'locationTree' attribute exists in the singleton. If not, I would need to populate it with its initial state and have the tree in the dialog use it or a copy of it. Any time the state of the dialog tree is altered in ways that I can trap, I'd like to update the singleton 'locationTree' to mirror the change. Although there's a clone method on a QTreeWidgetItem, I didn't see a corresponding method for the entire QTreeWidget.
How can I accomplish this with the least amount of change to the existing code base and GUI layout?
John
Yes using the MVC facilities is the way to go ...
Even though you are using QTreeWidget you are still working with a class derived from QAbstractItemView therefore the model() and setModel() calls are available. Take a model from one of the widgets that you are creating and then set it in the other widgets. Whenever you change the data in one of the widgets the other widgets will follow suit as they are using the same instance of model.
If you need to maintain the same selection state in all for widgets (which parts of the tree are open or close) that might be a little bit harder but it might actually work by using the same selectionModel selectionModel() and setSelectionModel()
I'm sure you're right that using Model/View is the best approach.
But without an idea of roughly how many items your tree widgets will have, and how frequently they'll be updated, it's hard to weigh up alternative approaches. Also, what version of Qt are you using?
If the number of updates and items are not huge, one approach is to introduce a class that inherits QObject (so it has signals and slots), and make it responsible for keeping all your QTreeWidgets in sync.
By connecting signals and slots for each QTreeWidget to a single other object, you avoid the nightmare of having every tree widget know about every other one.
i have quite a lot of experience with python and gst-python, but no experience with plain gstreamer.
does anyone know (well, someone on earth probably does but...) how to create a custom element? i got as far as
class MyElement(Element):
by intuition, but i have no idea what next...
simply what i was hoping for was a "replace this function with the thing you want to happen to every unit that this element is passed", but i am pretty certain that it will be FAR more complicated than that....
If you're creating a source element, you probably want to subclass gst.BaseSrc. Then, IIRC, the main thing you need to do is implement the do_create() virtual method. Don't forget to gobject.type_register() your class; you may also need to set the time format using set_format().
I second the recommendation to look at the Pitivi source code; it contains several GStreamer elements implemented in Python.