Python - Custom styling in wxPython - python

Is there some way I can create custom styles in wxPython? I searched all the docs and websites referring to wxPython styling and could find nothing. Do I have to create the custom style using the wxPython canvas?

wxPython uses native widgets in its core widgets as much as possible. Most of the widgets are going to be "native" to the system you are using, so unfortunately you can't fully manipulate how the control paints itself.
Sometimes, you can modify widgets via the methods mentioned in the documentation, such as using SetBackgroundColour() or SetForegroundColour(). Depending on your OS's widget, they may or may not work.
The other option is to use the wx.PaintDC, wx.ClientDC, wx.WindowDC, wx.ScreenDC and/or wx.MemoryDC to draw custom widgets directly.

Related

tkinter custom widget collecting

I'm searching for a tkinter custom widget collection that I can include in a application designer I'm writing in 100% Python but haven't had much luck yet. I figured out a way to do a table for instance, but would like to save myself the work if there's a good implementation out there.
I found a couple of packages for pure Python custom widget creation with a little more searching online. One is Python megawidgets, at pmw.sourceforge.net, which, according to their documentation:
"is a toolkit for building high-level compound widgets in Python using the Tkinter module. It consists of a set of base classes and a library of flexible and extensible megawidgets built on this foundation. These megawidgets include notebooks, comboboxes, selection widgets, panes widgets, scrollable widgets, and dialog windows."
A different approach is writing custom widgets yourself using the Widget Construction Kit, at effbot.org/zone/wck.htm. This provides a base Widget class with primitive drawing methods, such as for borders, text, and colors, along with a basic but complete set of event definitions for binding your event handlers to your custom widgets. It has some good advice on doing animated widgets, such as drag and drop.
If anybody knows of any other packages of widgets or construction toolkit APIs, feel free to post it here. Developers will appreciate having a larger selection in a single location.

WxPython: Setting the background of buttons with wx.Brush

I have search far and wide on how you can paint the background color of a button or GenButton with a pattern such as lines or cross hatch. I have seen examples of wx DirectContext so that you can draw objects with patterns instead of just solid colors but it seems that this is only for specific shapes and not the color of button objects. Does the dc or gc library allow to paint on these objects. I know that I have to create an event handler for OnPaint and OnResize but I may be missing some steps so that it applies this to the button itself.
The wxPython package uses native widgets in its core widgets as much as possible. Thus, the wx.Button widget is going to be a native widget that you can only modify via the methods mentioned in the documentation. As Igor mentioned, you can try using SetBackgroundColour() or SetForegroundColour(), although depending on your platform's button widget, they may or may not work.
What you really want is a custom widget. I recommend checking out the GenericButtons, PlateButton and GradientButton for examples. You might even be able to use a GenericButton directly and paint its background as you mentioned.
wx.Button object represents a native control. And so unfortunately you can't manipulate how the native control paints itself.
You can try SetBackgroundColour()/SetForegroundColour() but this is as far as you can go.

wxpython beautiful widgets

As I was looking into the widget creations tutorial in wxpython. I saw that all of them has the window look but I want a widget like the one you can see on windows 7 (clock widget etc.) or like the one advanced systemcare has.
So my question how can I make such a widget in wxpython if I can at all?
wxPython will look like the OS's native widgets. If you need to do something more advanced, then you'll have to write your own widget. There are lots of examples of custom widgets included with wxPython. Take a look at anything in wx.lib.agw. All of those are custom made widgets, written in Python.
Here are a couple of other links:
http://wiki.wxpython.org/CreatingCustomControls
http://zetcode.com/wxpython/customwidgets/

Custom Qt Widgets with python for Qt Designer

I am trying to write a custom widget for the Qt Designer using only Python. I was following a couple of tutorials I found online but none of them were working or anything close to what I would call to be a minimum working example.
So my questions are:
What steps are involved to make a a custom widget appear in the Widget Box of Qt Designer?
If you can spare the time: Please provide a minimum working example (like a widget with a label in it saying "A truly minimal working Qt custom widget example").
Or is it maybe not possible at all to include a custom widget using only python?
There are very few examples available on how to make a custom widget in pyqt. I wrote this article with a working example: Making a Custom Widget in PyQt
Here is the answer to your question #3: How do I use promote to in Qt Designer in pyqt4?
I am using PySide and it works the same way. This method works directly with your Python custom widget code. You do not need to write any separate plugin code.
After you have promoted your custom widget, you can right click on it and add your signals with "Change signals/slots..."
I would recommend putting all you widgets in a YourCostumWidgetsPack.UI file, and then when you load this file in Qt Designer, in addition to the UI you are working. It will load all your custom widget information.
I found this article to be your answer: https://doc.qt.io/archives/qq/qq26-pyqtdesigner.html
But, I haven't been able to install it in Qt Designer though :D

PyQt4 Custom Widgets

Are there any good PyQt4 custom widgets like at Qt-Apps.org?
I would like to start making PyQt custom widgets but online resources that I find don't seem to be clear
For example, Trolltech's and Zetcode's don't seem to be related in any way at all.
Thanks for any input :)
There should be PyQt examples of all C++ Qt examples in your PyQt4 distribution. I have them here: /usr/share/doc/python-qt4-doc/examples. Theye are quite good for the start. When you understand them, it should also be fairly easy for you to port some C++ examples to PyQt code or turn C++ custom widgets to C++.
online resources about PyQt aren't really that rampant, so any information/projects would be welcomed. Don't hesitate to post links to your upcoming widgets or anything else.
I would be really glad to work on that with you as i'm learning more about pyqt as well.
Are you looking for tutorials on making custom PyQt widgets, or looking for a library of them?
I've been developing a library of reusable custom widgets if that's what you're looking for - at somepoint will be getting to the tutorials, but they aren't there yet.
Check out projexsoftware.com, specifically the ProjexUI framework:
http://dev.projexsoftware.com/projects/projexui
http://docs.projexsoftware.com/sdk-reference/projexui-sdk
In looking at it, I'll need to get some images up there...but there's a Calendar widget, Gantt Chart, View plugin system, Node view, Chart widgets, along with a number of extensions to the base Qt widget classes.
Also the easiest way to see the majority of the widgets is in the Qt Designer - so if you have it setup to work with PyQt plugins, wherever you install the projexui library you can add the /path/to/projexui/designer/build to your PYQTDESIGNERPATH and it'll load designer with our plugins.

Categories