473,231 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

How to use Styles in PyGTK

The GTK includes a class gtk.Style which affects the look of widgets in a nice and efficient way. However, I have found no clues on how to modify the style within the application. I am trying to find a tutorial that explains how to use and modify the gtk.Style objects. There is also a class gtk.RcStyle, and I'm trying to find out how it relates to gtk.Style.

The related problem is as follows:

I am developing an application that will run on a PDA and it requires some special layouts and looks for the widgets. The PDA has a touch sensitive screen and the application is used by pressing on the display with the finger tips. Because of this I need to make some UI elements really big so that they are easy to click on. I also need to make some customization on the default widgets in order to create an optimal UI. In order to save effort I want the widgets to lay out and respond to interaction in the default way, but I want to entirely control the drawing of the widgets in each of their states. I want to write the entire application in Python.

The question is:

I want to make a vertical scrollbar 40 pixels wide, so that it is easy to use with the finger tips. I find an attribute named "slider-width" listed in gtk.Range Style Properties in the GTK class reference. However, in the API reference I find no clue whatsoever on how to manipulate that value, or even in which construct it is stored in or how to read it. I need to know 1) how I can read the "slider-width" property of a gtk.VScrollbar and 2) how can I change the value.
Sep 19 '07 #1
3 8987
6,596 Expert 4TB
If the use of PyGTK.Style is not clear from here, I may be able to help a bit (it's not too different from other frameworks). But that may not be what you are looking for.

In wxPython, we are allowed to subclass most wrapped objects (and that's probably true of PyGTK, as well). In that case, the underlying API function that sets the width (or other attribute) may be overridden. I'm looking into a simple way to set the width of a vertical scrollbar.

It looks like the scrollbar is descended from Range() so that you may call Range.method() (or Adjustment.method()) and attributes directly on the scrollbar object. For example:
Expand|Select|Wrap|Line Numbers
  1. myVScrollBar.adjustment.lower = 0
I hope that's not too confusing. GUI programming is really just advanced OOP and GTK doesn't seem to be the most well planned implementation.
Sep 19 '07 #2
6,596 Expert 4TB
I'm looking into a simple way to set the width of a vertical scrollbar.
All GTK widgets have a standard set of "properties". As in:
Expand|Select|Wrap|Line Numbers
  1. "width-request"    Read-Write    The width request of the widget, or -1 if natural request should be used.
These are probably set in the creation method and might be accessed as normal attributes. It is hard to tell looking at the manual, but I'm sure it is covered is any beginning GTK book or tutorial.

I remember that Tkinter uses
Expand|Select|Wrap|Line Numbers
  1. myWidget.config("BG"=RED)
for example.
That interface was also written with access methods that allowed
Expand|Select|Wrap|Line Numbers
  1. myWidget["BG"] = RED
as I recall.
Sep 19 '07 #3
I had a similar problem with developing for a PDA-style device as well, and scoured the docs for a few days to come up with the answer:

Unfortunately, the answer is not as easy as you would like, but it is doable.
1) how I can read the "slider-width" property of a gtk.VScrollbar
This is pretty easy, just do
Expand|Select|Wrap|Line Numbers
  1. v_scrollbar.style_get_property("slider-width")
2) how can I change the value.
Not so easy. Since slider-width is a read-only style property (look in the docs at pygtk.org, it specifies), you have to specify it through a gtk.RcStyle. The way to do that is, either via a file or string, write out a resource file which changes the default style of the widgets in a particular way. This is rather complicated, and I don't really completely understand it, but the documentation contains an ok, if not very complete, tutorial on how to do this nestled away here:


Reading this little three-part tutorial, with example, should give you a general idea of how rc files are written. I would also recommend reading, after that, both the pygtk and gtk references for the RcStyle class:

http://www.pygtk.org/docs/pygtk/class-gtkrcstyle.html (pygtk ref)
http://library.gnome.org/devel/gtk/u...rce-Files.html (gtk ref)

The gtk version of the documentation has a better explanation of what exactly an rc style does, while the pygtk version really is mostly useful so you know all the function calls.

What will get you the behavior you want is this in your rc file:
Expand|Select|Wrap|Line Numbers
  1. style "wide_range"
  2. {
  3.     GtkRange::slider-width = 40
  4. }
  6. class "GtkRange" style "wide_range"
and this in your code, in an appropriate init statement for your whole gui:
Expand|Select|Wrap|Line Numbers
  1. gtk.rc_parse(your_filename_here.rc)
(tested in gtk 2.12 on a windows XP machine)

What this will do, specifically, is change the slider width of all instances of gtk.Range or it's subclasses (of which VScrollbar is one). If you read the references above, you should be able to figure out how to make that more specific if desired, it involves using either "widget" or "widget_class" where "class" is in the resource file described above.

From what I read in the gtk reference, it seems like the difference between an RcStyle and a Style is that the RcStyle class, in addition to being created by this funky notation, is only a partial specification of a style (for instance, just the slider width). Gtk combines all the RcStyles applied to a class via the RcStyle files into one nice happy Style object which everything gets.

It's worth noting that it is possible that your device has a theme which somehow overwrites your changes. I don't know too much about that, unfortunately, but if it doesn't work right away on the device check if it works on a desktop as well.

One last note: class names in resource files should follow the gtk class naming convention, NOT the pygtk class naming convention:
(ex. GtkRange in lieu of gtk.Range). It should be pretty easy to figure out after that.
Aug 14 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Edwin Young | last post by:
Hi, I'm writing a fractal-generating program in a mixture of C and Python. Python handles all the GUI parts using PyGTK. After finishing the calculations, I have a buffer containing the RGB data...
by: j_mckitrick | last post by:
Hi all. Here is a tiny container for one of each combo box, along with the glade file. Just 2 widgets, so hopefully not too large. How the heck do I get the selection from the ComboBox, as...
by: Mark Mitchell | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I have a program written in python that tells me it requires PyGTK, so I DLed, ./configure, make, make install and the process seems to go ok. Some...
by: Egbert Bouwman | last post by:
As a newby to PyGTK I already have produced some gui's I like, but I have difficulties in finding out what method or other instrument I need for doing various things. I have not yet found the...
by: Thomas Bartkus | last post by:
I am experimenting (flailing around?) with glade and python. Both under MS Windows and Linux. I understand why I want to "import gtk" It gives me access to the critical gui program loop...
by: TPJ | last post by:
GUI's etc: PyGtk on Windows "(...) So if someone develops mainly for X and just wants to make sure that it is not impossible to run on Windows, you can use PyGTK. (...)", July 2nd, 1999 pyGTK...
by: Rod W | last post by:
I'm just starting out on Python but my primary goal is to provide applications with some user interface (GUI). Can someone point me to a good comparison of whether I should use wxPython (with...
by: krishnakant Mane | last post by:
hello, I will be writing some code in PyGTK to run on linux. but I want to know if there are any installers or distutils available for PyGTK on windows? I have heard that installing gimp or even...
by: He Jibo | last post by:
Hi, Everyone, Could someone help me how to install pygtk? I get some problems with it. Here is the error I get while install pygtk: https://netfiles.uiuc.edu/jibohe2/error.GIF?uniq=-k6678k ...
by: Michael Palmer | last post by:
On Sep 16, 12:30 pm, binaryjesus <coolman.gu...@gmail.comwrote: I haven't tried it myself, but I came across a blog post the other day that describes a way of building windows installers for...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.