Achieving a facebook-like modal dialog in GTK+ (linux) - python

Ideally, the transparent border.
Here's an example of what i'd like to achieve:
Notice the transparent border.
Now i suppose I could use cairo to create a rectangle with transparency, and put a borderless non-transparent window inside, mimic'ing that effect - which I would if i knew the window would have a fixed dimension. However, if the inner window grows, it'll grow out of the transparent rectangle.
How should one approach such task?

Making window frames is really the job of the window manager (at least under X11, don't know how it works on windows).
But have a look at the GtkBin, GtkBox or GtkMisc widgets. Pack the dialog inside it as a single widget, and use padding to give it a size. Read up on GTK+ drawing model. You will probably need to set a flag and define your own expose-event handler to re-draw your frame.

Related

Qt QScrollBar change background Color

I was working on Qt Designer and I wanted to edit the background color (if possible a gradient) of QScrollBar but I don't know how to do it properly.
When I add any background color the whole widget changes color uniformly and becomes solid.
I was trying to change the color of the area behind the bar and arrow buttons only.
Unfortunately, with many complex widgets you can't just change a property with stylesheet without all the necessary implementation.
QScrollBar is one of those widgets, and in order to achieve background customization through stylesheets, at least all the following have to be provided too:
overall background color
add/sub-page color
handle color
add/sub-line ("arrow buttons") colors
To make the widget more visually responsive, borders (with pseudo-states for pressed/enabled/hover states) should also be provided, and adding images for arrow buttons is usually suggested (small arrows can be obtained through css border tricks, though).
The starting point is the official Qt stylesheet example documentation, which has a section for customizing QScrollBar.
Note that using a QProxyStyle is not an option, as many styles draw scrollbars in different ways, and sometimes they even ignore some "official" style functions like drawControl, because they take care of the whole painting within the drawComplexControl, using private functions.

PYGTK Resizing permissions

I want to set a window's size, and then be able to resize it while the program is running. I've been able to make the window large, but I can't resize it smaller than the original set size. For a different project, I would also like to know how to make it so the window is not resizable at all.
For the first question: Gtk.Window.resize(width, height) should work. If you use set_size_request(width, height), you cannot resize your window smaller than these values.
For the second question: Gtk.Window.set_resizable(False)

Change the color of a pixel in a canvas, Tkinter, Python

Someone know if it's possible to change the color of a pixel in a canvas without using un object, so without using something like canvas.create_oval or canvas.create_rectangle ?
There is no way to color a pixel other than to create a 1x1 pixel object of some sort. And yes, at some point you will experience performance problems. The canvas simply wasn't designed to be used this way.
If you're really needing to create a large area in which you can manage individual pixels, you can create a canvas with a single image that is the same size as the canvas. You can then set the color of individual pixels on the image through the photo image interface.
Within tkinter itself, it's impossible.
Even if you manage to change a pixel on canvas window (which is possible with X11 and Windows APIs in a platform-dependent way), you'd have to ensure it's repainted properly.
You can, of course, place a frame of size 1x1 over the canvas, with a background color you want. This way, pixel is "changed" and no canvas object is created. If there's a real (though strange) problem behind a question, this trick could be a solution.

Resizing frames in Tkinter

I have been making a small program with the Tkinter module in python, and I was wondering whether it was possible or not to resize a frame in my program with the mouse. As in, the user can drag the frame border and it will resize itself.
Your use of terminology makes the question unclear. Windows which may be resized by the user are called Toplevel windows. These are what appear as rectangular windows on the display, with a frame around them, typically a title bar, and edges or corners that can be grabbed and resized.
The term Frame refers to a container widget that must be inside a Toplevel or one of its descendents. A Frame has the ability to be resized but you have to write the code to let you interactively resize them. For example, you could place a little grip widget in one or more corners, and writing bindings to the press, motion and release of a mouse button.
Depending on the effect you are looking for, you might want a PanedWindow which is a container that includes a sash that lets you adjust the proportion of space between two other widgets.

Widget Transparency in PyGTK?

What is the best way to have transparency of specific widgets in a PyGTK application? I do not want to use themes because the transparency of each of the widgets will be changing through animation.
The only thing I can find is to use cairo to draw widgets with an Alpha, but I can't figure out how to do this. Is there perhaps a better way to do this as well?
Thanks!
Assuming that your program runs under composition manager, you could get per-widget transparency by manipulating widget's X window. Look at gtk.gdk.Window.set_opacity().
Note, it is not gtk.Window; you can get this object by getting its window property (buttonWidget.window), but only when widget is realized and only when widget does handle events -- gtk.Label does not have its own X window for instance.
If you need to work also when you don't have composition manager, drawing your widgets by yourself is the only option -- but you don't necessarily have to use cairo; drawing pixel by pixel on the bare X window will also work.

Categories