473,320 Members | 1,766 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,320 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 8996
bartonc
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
bartonc
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:

http://www.pygtk.org/pygtk2tutorial/ch-GtkRcFiles.html

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. }
  5.  
  6. class "GtkRange" style "wide_range"
  7.  
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

6
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...
4
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...
6
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...
5
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...
1
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...
25
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...
14
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...
1
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...
0
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 ...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.