Drag-and-drop to canvas in wxPython - python

Do you know if there is an easy way to drag-and-drop elements (icons or buttons) into a canvas and create different drawings on it as a result?
The idea is to have a set of objects and let the user drag them into a drawing space.
In the worst case the user could just click on the icon/button, and then click on the canvas and draw the element in the position, but I think the dragging is more intuitive.

There is an example of something more or less like this here: http://wiki.wxpython.org/wxOGL Although it is about wxOGL, they recommend you to use either SimpleCanvas or FloatCanvas and adapt their examples.

I assume you are building a browser app? If so, the jQuery UI Droppable plugin provides most of the standard functionality, and is pretty easy to modify to fit custom needs. Here's the link: http://jqueryui.com/demos/droppable/

Related

How to remove borders on Tkinter buttons & frames?

I am currently building a simple app to encrypt files using AES encryption in python but the biggest downside of using Tkinter is the look of the UI. I did some research and found examples of what I want but do not know how to recreate it. (Example)
My problem is that when I replace buttons with images (like the OP of the Reddit post said he did in order to have a decent looking UI) I end up with an ugly bar of grey. (Image of the button)
I also want to remove the same type of bar with frames so if you have the answer for specifically that it would still be appreciated.
Support for for styles and themes has existed in tkinter for some time. A theme being a collection of styles for different widgets.
You can read more about style and themes here.
To the best of my knowledge, the standard widgets to not support rounded corners. All widgets have rectangular shapes.
You might be able to create something like that using a Canvas, but it would be a significant amount of work.
A more relevant point is that it might confuse your users if you don't reproduce the way the standard controls work.
UI elements are standardized for the same reason the controls in a car are; once you know one of them you can use all of them.

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: How to create a checkbox that has a flat look (bezel-less border).

I am working on a small app that has some checkboxes. The app will be run on Windows 7 machines with the Windows Classic theme set. This means that all the checkboxes will have bezeled borders as shown in the screenshot below:
I wonder if there is a way to set the check boxes to have no bezel. If that is not possible, is it possible to custom paint/draw check boxes with no bezel? I have not been able to find examples. Thanks!
It really depends on the platform and/or the theme, and whether the native widget supports alternate views and such. So, in other words, for questions about customizing the LnF of native widgets in general, the answer is "maybe" but it probably depends on a number of factors that are not under wx's control.
On the other hand, making custom controls is much easier than most people think it will be. For something like a checkbox you'll basically just need to provide an event handler for EVT_PAINT that draws the current state of the widget using a wx.PaintDC, plus handlers for mouse and keyboard events to interact with the user. There are several examples in the wx.lib package that you can use for inspiration, such as wx.lib.stattext or wx.lib.buttons.

Buttons in Glade, why are they square?

I'm new at GTK. I'm using Glade to make an interface and just want to insert objects (like buttons and others) into a container.
I've choosen GtkFixed so that all elements can be freely located and sized.
The problem is that when i drag a button for example, the button apparently gets it size from the parent (in this case the container) and takes a square shape.
Here's an image
I want the button to take the standard size, just like a rectangule or something. What i'm i doing wrong? I've checked some options in the container but can't figure out the way.
Thanks.
You have to remove the tick from Height request and Width request (I don't know the equivalent names in your language).
Besides, you should be aware that GtkFixed is difficult to use when the window can be resized. GtkBox is often easier.

Customize QTreeView items

I'm new to PySide and Qt at all, and now need to create an application which has a tree view with styled items. Each item needs two lines of text (different styles), and a button. Many items are supposed to be in the view, so I chose QTreeView over QTreeWidget. Now I managed to add simple text items (non-styled) to the QTreeView and have almost no idea about how to place several widgets on one item. Could you please give me an example of how to create such design?
I've found some samples on the Internet, that are similar to what I want, but they all are in C++, and it's not obvious how to convert delegates and other things to Python. I'm now really confused about it all...
I'd recomend you use simple QTreeWidget and insert complex widgets with setItemWidget. While Qt's widhets are alien, they are not so heavy to draw, but:
You shouldn't create delegates.
You shouldn't handle events (If you are going to place button in view and draw it using delegates, you had to handle all its events, such as mouseOver, focus changing, etc. It is a lot of work.

Categories