Modifying a GUI started with Glade - python

I am just starting to learn Glade with pyGTK. Since Glade makes XML files instead of actual python code, is there a good way to start a project with Glade and then hand code more or tweak it?
Are there times or reasons it would be preferrable to hand code all of it instead of starting with glade?

GUI's created with glade are accessible in the code in two way: libglade or gtkbuilder. I cannot comment much on the differences between the two, other than that gtkbuilder is newer; there are a lot of pages on google that show how to migrate from libglade to gtkbuilder.
Using gtkbuilder, you can create your GUI object by retrieving it from the the XML file using gtkbuilder. This creates the object with all of the settings you set in glade. You now have an GUI object which you can manipulate via it's regular interface.
builder = gtk.Builder()
builder.add_from_file(glade_path)
builder.connect_signals(self)
main_window = builder.get_object("main_window")
main_window.show()
text_box1 = builder.get_object("textbox1")
text_box1.set_text("enter your name")
Line 3 shows how signal handlers are attached when loaded from glade. Essentially, it looks for the function you specified for the signal in the glade interface and attached to it; if the function isn't provided, you'll see a warning on the command line.

How much do you know about glade and pygtk? Glade creates xml files but you load these using gtk.Builder in python. You can easily tweak any widgets you created with glade in python. Read these tutorials to understand how to do it better. You just need to learn more about pygtk and glade and it will be obvious.

Related

Load webpage in Python GUI window

I've searched on Google and StackOverflow but am having trouble finding the answer, even though it seems like it should be easy to do.
How can I use Python to load a URL into its own window, rather than in a browser? I imagine this should be trivial in Tkinter or some other GUI package.
Yeah. that's very easy with QWebView in PyQt/PySide
You basically instantiate a new QWebView and pass the url to it
QWebView.load(QUrl('http://www.www.pythoncentral.io'))
you can read more here
http://pythoncentral.io/pyside-pyqt-tutorial-qwebview/
and also in the pyQt docs
http://pyqt.sourceforge.net/Docs/PyQt4/qwebview.html
A new option would be: pywebview
pywebview is a lightweight cross-platform wrapper around a webview
component that allows to display HTML content in its own native GUI
window. It gives you power of web technologies in your desktop
application, hiding the fact that GUI is browser based.
See here:
https://github.com/r0x0r/pywebview

Getting events while using Qt Designer

I am developing an application which uses treeview. Initially, I used Qt designer for the GUI and after, compiled the ui file into python. Until now everything was just fine. Now I want to copy and paste the file on pressing Copy and Paste buttons simultaneously.
I watched and read many tutorials but they used re implementation of QPushButton. I can't adopt this technique because I used designer to create GUI and cant make changes in that file. Please help me to figure out that how can i use QEvents of my treeview.
I hope my question is clear.

Creating a multi-screen application using Qt Designer

I'm using Qt Designer to create UI designs which I'm then converting into python code. Since I'm quite new to Qt I'd like to ask: is there a way I could implement a multi-screen application? I.e. having a next button clicked and getting a new set of options/widgets etc within the same window.
To be honest, I was developing using Kivy, and as slick as that is (especially with multiple screens) it depends on PyGame, which proves to be an enormous portability headache, so I had to switch to something else, and PyQt was the next feasible option (or so it seems).
It's called a QWizard. It is not called a multi screen application, but if you search for wizard instead, you find lots of information.
Links
Example with C++ code
[PyQt QWizard documentation] http://pyqt.sourceforge.net/Docs/PyQt4/qwizard.html

wx xrc + aui manager

Is it possible, and if so, how(links, tutorials) to use XRC to load aui-elements?
I want to create a somewhat advanced interface for a program, without wanting to do everything in-code.
Greetings
I don't think XRC supports AUI (either the C++ or the pure Python version found in wx.agw.aui). However, you should be able to mix XRC items with AUI. See http://wxpython-users.1045709.n5.nabble.com/xrc-aui-toolbar-problem-test-attached-td2344498.html
Basically you just create the frame and other items that ARE supported in XRC and then add the AUI code on top.

How to handle a glade project with many windows

I'm working on a PyGTK/glade application that currently has 16 windows/dialogs and is about 130KB, and will eventually have around 25 windows/dialogs and be around 200KB. Currently, I'm storing all the windows in one monolithic glade file. When I run a window I call it like...
self.wTree = gtk.glade.XML("interface.glade", "WindowXYZ")
I wonder if it would be a better idea to split each window into it's own glade file. Instead of one glade file with 25 windows/dialogs I'd have 25 glade files with one window/dialog each and call it like so:
self.wTree = gtk.glade.XML("windowxyz.glade")
What do you guys think is the best way to do this? Is one method more resource intensive than another? One thing that would be nice about going to individual glade files is that naming widgets would be easier. For example, I name all my OK buttons "windowxyz_ok", but I could change it to simply "ok" instead. Makes things simpler. The downside is that it may be a bit less convenient to make changes to different windows.
I'm open to any and all arguments. Thanks!
In my projects, I always have one window per glade file. I'd recommend the same for your project.
The following are the two main reasons:
It will be faster and use less memory, since each call to gtk.glade.XML() parses the whole thing. Sure you can pass in the root argument to avoid creating the widget tree for all windows, but you'd still have to parse all the XML, even if you're not interested in it.
Conceptually its easier to understand if have one toplevel per window. You easily know which filename a given dialog/window is in just by looking at the filename.
Did you take some timings to find out whether it makes a difference?
The problem is that, as far as I understand it, Glade always creates all widgets when it parses an XML file, so if you open the XML file and only read a single widget, you are wasting a lot of resources.
The other problem is that you need to re-read the file if you want to have another instance of that widget.
The way I did it before was to put all widgets that were created only once (like the about window, the main window etc) into one glade file, and separate glade files for widgets that needed to be created several times.
I use different glade files for different windows. But I keep dialog associated with a window in the same glade file. As you said, the naming problem is annoying.
I have one glade file with 2 windows. It's about 450kb in size and I have not seen any slowdowns using libglademm with GTKmm.

Categories