Top 100+ Pygtk Interview Questions And Answers
Question 1. What Is Pygtk?
Answer :
PyGTK (a.K.A python-gtk or gtk-python) is a set of bindings to the GTK+ person interface toolkit for the Python language. The primary web page to look for more statistics on those bindings is . There, new releases, news, reference doctors, tutorials, programs built on top of.
Python is an interpreted language with a very smooth syntax, high-stage records structures, dynamic typing, object orientated traits and normally desirable performance.
GTK+ is a graphical consumer interface toolkit, which incorporates user interface additives (hereafter called via the standard call widgets) and a framework for handling activities which are produced upon those components.
A binding is code (usually a library) that allows you to get admission to capabilities that were coded in some other language. In our case, GTK+ become written in C, and applications written in C can use native GTK+. For a Python application with the intention to create packages the use of the GTK+ framework, a unique library has for use. This library is PyGTK.
Question 2. How Do I Get The Very Latest Pygtk Source Code [from Git]?
Answer :
PyGTK is kept in gnome git; the module name for PyGTK is "pygtk". The module call for gnome-python is "gnome-python", so to test it out, kind:
git clone git://git.Gnome.Org/pygtk
and probable:
git clone git://git.Gnome.Org/gnome-python
git clone git://git.Gnome.Org/gnome-python-laptop
git clone git://git.Gnome.Org/gnome-python-extras
Please observe that to apply PyGTK you depend upon recent code for GTK+ , GLib, atk, pango, Python. How recent precisely those dependencies need to be depends in large part at the modern-day target for the PyGTK development team. In popular, CVS HEAD will use the trendy CVS, but ask on the mailing listing if issues stand up.
Python Interview Questions
Question 3. How Do I Extend Pygtk (or The Art Of Wrapping)?
Answer :
In order to make a brand new wrapper for PyGObject/PyGTK, you can use this FAQ as a guiding principle or checklist. Don't omit out FAQ 6.3 which has a hyperlink to a web article, additionally.
Let's call the library "foo" (how original)
1) foo.Defs.
Use h2defs.Py determined in pyobject/codegen/ on all your _public_ headers for the library.
H2defs.Py /usr/include/foo-1.Zero/*.H > foo.Defs
2) foomodule.C
Use atkmodule.C as a template. Replace all instances of atk with foo.
You most probably won't use any constants (considering they require extra work), so simply comment out pyatk_add_constants (m, "ATK_");
three) foo.Override
You also can use atkmodule.C as a template for the override document.
Remove the only feature in there (atk_relation_new) and update the atk headers along with your personal.
Don't overlook to replace the modulename too.
4) Makefile.Am
AUTOMAKE_OPTIONS=1.Five
INCLUDES = $(PYTHON_INCLUDES) $(FOO_CFLAGS)
# foo module
pyexec_LTLIBRARIES = foomodule.Los angeles
foomodule_la_LDFLAGS = -module -keep away from-model -export-symbols-regex initfoo
foomodule_la_LIBADD = $(FOO_LIBS)
foomodule_la_SOURCES = foomodule.C
nodist_foomodule_la_SOURCES = foo.C
foo.C: foo.Defs foo.Override
CLEANFILES = foo.C
EXTRA_DIST = foo.Override
.Defs.C:
(cd $(srcdir)
&& $(PYTHON) codegen/codegen.Py
--override $*.Override
--prefix py$* $*.Defs) > gen-$*.C
&& cp gen-$*.C $*.C
&& rm -f gen-$*.C
---
Should be enough so one can get began
5) configure.In
Copy pygobjects configure and get rid of pointless stuff. Should be trivial. Don't forget about to outline a FOO_LIBS and FOO_CFLAGS
PKG_CHECK_MODULES(FOO, foo >= 1.2,,)
AC_SUBST(FOO_CFLAGS)
AC_SUBST(FOO_LIBS)
Finally, replica autogen.Sh and optimistically you may have maximum functions wrapped.
Eventually you may have to wrap some features via hand, functions that the code generator cannot handle. Mostly features with inout params (**) and GSList/GList parameters.
Question four. How Do I Compile Pygtk Or Gnome-python From Svn?
Answer :
You need the GTK+ 2.X libraries, as you'd expect (see FAQ 21.2). There are 3 packages you need to construct:
gnome-python/pygtk
gnome-python/pyorbit
gnome-python/gnome-python
You need to run
./autogen.Sh
make
make installation
in every of those, in that order. If you want to construct from SVN, you might want to look at a build script. James recommends jhbuild (also in GNOME svn).
If you want to install them to a separate prefix, eg in case you do not have write get right of entry to to /usr/nearby, use --prefix as an argument to autogen.Sh or configure, eg:
./configure --prefix /home/user/prefix
And then, take into account to set PYTHONPATH before going for walks this system, eg:
export PYTHONPATH=/home/user/prefix/lib/python2.3/website online-applications
Then you could ultimately run your program.
Python Tutorial
Question 5. How Do I Search Bugzilla For Pygtk Bugs?
Answer :
You may then specify the model, OS and every other relevant data.
If I am seeking to do a wellknown query, it helps to "pick all" in those boxes by way of clicking on the primary access and then shift clicking at the remaining entry. You may additionally need to prompt all the 'Status' entries to look resolved insects, and so forth.
Once you have got configured a majority of these parameters, go to the Text information section, input your search phrases in the Description or Summary bins, and click on 'Submit Query'.
PHP Interview Questions
Question 6. My Programs Configure Says: No Package 'pygtk-2.Zero' Found?
Answer :
That's because the configure script can't locate the mounted model of pygtk-2.0.
If you construct pygtk to your personal, from source, then you definitely need to write the subsequent before jogging the configure script:
export PKG_CONFIG_PATH=/usr/nearby/lib/pkgconfig
Or, update /usr/local with the prefix you installed pygtk to. /usr/local is however the default and most usually used one.
If you probably did no longer install it from source then it means that you forgot to install the devel/dev package deal. For Red Hat primarily based distributions (Fedora, SuSe, Mandrake and so forth) you need to install pygtk2-devel and for debian based totally distributions you want to put in pythonX.Y-gtk2-dev, wherein X.Y stands for the python version you are the use of.
Question 7. Is There A Pygtk For Macos X?
Answer :
There are methods of strolling PyGTK on OS X.
One way is strolling it with native help, which continues to be in early ranges of improvement and isn't feature entire but. There are currently (as of June 2008) no to be had binaries for GTK+ jogging natively under OSX, so that you want to assemble GTK+ your self. The instructions right here tell you how to build GTK+, but not PyGTK; after following the steps right here you furthermore may have to do "jhbuild construct meta-gtk-osx-python".
The second way is the usage of Apple's X11 server, that is in the direction of different Unix structures for portability, but might not combine very well with the rest of the OS X computing device. If you are going for walks Mac OS X 10.3 (Panther) or above X11 is available as an elective function from the set up CDs.
PHP Tutorial Ruby on Rails Interview Questions
Question eight. Does Pygtk Have Timers?
Answer :
sure! The feature you are looking for is gobject.Timeout_add() (or gobject.Timeout_add_seconds() for longer durations).
Question 9. How Do I Install Pygtk-2 And Pygtk-zero Side By Side In The Same System?
Answer :
It used to be that if you established PyGTK-2 and PyGTK-0.X in a equal model of Python, the packages that required PyGTK-0.X might forestall running. This happened due to the fact Python would import PyGTK-2 preferentially, and the names of the modules are the same: 'gtk'.
(There are 3 one-of-a-kind approaches particular to resolve this problem, but I will now not endorse techniques 2 and 3 except you're unable to improve to a version that supports approach 1).
• Method 1 (the "pygtk.Pth" approach)
(Note that RedHat 8.0 ships versions PRIOR to those, you'll need to either improve the device programs, or use technique 2 if you want to install PyGTK-zero and PyGTK-2 together on RH8.)
James has added to pygtk a mechanism that permits installation of both pygtk and pygtk2 to work facet by side. This method ought to be obvious - you could deploy each versions and surely require one or the other for each application you need (the default being the one you install final), as in keeping with faq 2.4. It is carried out via the usage of a pygtk.Pth report that shows that's the default (which one `import gtk' makes use of) version.
Note that pygtk.Pth most effective works if you use the *default python installation course* - if you specify a --prefix to configure it will not paintings and you may *must use approach 2*!
Method 2 (PYTHONPATH):
You can set up the two conflicting versions to a unique prefix. When configuring pygtk2, use something like:
./configure --prefix=/usr/neighborhood/gtk2/
All pygtk2 documents might be hooked up in this situation to
/usr/neighborhood/gtk2/lib/pythonX.Y/web page-applications/
With X.Y replaced through the predominant and minor numbers to your python model. You will then want to adjust PYTHONPATH (or sys.Route) to have a look at the proper version for this system you need to run. If it requires pygtk2, you could use some thing like:
export PYTHONPATH=/usr/local/gtk2/lib/pythonX.Y/web page-applications/:$PYTHONPATH
Ubuntu Certified Professional Interview Questions
Question 10. If I Installed Pygtk-0 And Pygtk-2 In Parallel (the usage of Pygtk.Pth) How Do I Indicate Which One My Script Should Use?
Answer :
The new versions of PyGTK offer a pygtk module in which you could call a way require() that lets in you to request one version or the opposite:
pygtk.Require("1.2") # for pygtk-0
and
pygtk.Require("2.0") # for pygtk2
Note which you must do that earlier than importing the gtk or gnome modules:
# To require 2.0
import pygtk
pygtk.Require("2.0")
import gtk, gtk.Glade, gnome, gnome.Ui
or:
# To require 1.2
import pygtk
pygtk.Require("1.2")
import gtk, libglade, gnome, gnome.Ui
Ruby on Rails Tutorial
Question eleven. Which Versions Of Pygtk Support Parallel Install Using The Pygtk.Pth Method?
Answer :
James Henstridge and Johan Dahlin applied parallel installation help in variations:
- pygtk-zero.6.10
- gnome-python-1.Four.3
- pygtk2-1.99.Thirteen
So any model same to or later than this is quality. Note that 0.6.10 and 1.Four.Three had insects in it, and you have to upgrade to zero.6.Eleven and 1.4.4 if feasible.
Django Interview Questions
Question 12. For Some Users Import Libglade (or Gdk) Is Working And For Some Users It's Not?
Answer :
It's feasible that on the top of your script you've got #!/usr/bin/env python because the script interpreter line. This searches the course for python, in preference to hardcoding it to unique location, that's useful. However, a few structures had been found with multiple variations of Python, considered one of which works with GTK1 and one among which handiest works with GTK2.
Figure out which one is running for your customers, and change their script interpreter or direction to apply that one.
Python Interview Questions
Question thirteen. How Do I Get My 1.2 Gladefiles To Work With 2.Zero?
Answer :
There is a application covered with libglade 2.Zero.X known as libglade-convert in order to do a quite right process at converting the interface report to the new layout. You need to be able to edit the report in glade 1.1 after that.
Dave notes that you will probably should redo all your conversation containers, seeing that they're going to be transformed without a number of the GTK 2 matters, together with an appropriate active vicinity interface and GTK 2 button snap shots. You'll also need to redo your timber and lists to comply with GTK 2. A reasonably sized challenge will take around eight hours to do that to. Even in case you don't "make installation" libglade 2.Zero.X, you may use the Python report included (but renamed) within the distribution.
Django Tutorial
Question 14. When I Connect To A Signal, My Handler Gets Called But Reports "xxx Takes No Arguments (1 Given)"?
Answer :
Signal callbacks have unique signatures. This way that after a signal is emitted, it'll ship to the callback characteristic a number of parameters. The first parameter is the widget which generated the occasion, and the rest vary relying on what signal is being emitted.
To handle a callback, your feature signature, consequently, should take this under consideration. Often you do not even want to apply any of the arguments, simply cause an motion on a certain sign; an clean way to do this is using a variable argument listing (*args) and ignoring them to your method:
def on_win_delete(*args):
print "Deleted, and who cares why"
w = gtk.Window()
w.Connect("delete-occasion", on_win_delete)
If you are attaching to a way, make certain to offer the same old self in the technique definition, and specifying self.On_foo_signal because the function to attach to.
Question 15. How Do I Detect That A Mouse Or Keyboard Event Has Been Triggered?
Answer :
The correct manner is to hook to a number of the fundamental event signals after which act upon receiving them. The alerts you need to look for are:
mouse movement
key presses
button presses
However, many widgets don't have their event mask properly set, so they'll forget about these events. The following instance indicates how it should be performed for a GtkWindow, including the necessary event mask, after which hooking to the alerts. Note that you could must regulate the wakeup feature to deal with the timer operations you will need for a screensaver.
Def wakeup(widget, event):
print "Event number %d woke me up" % event.Type
gtk.Gdk.SCROLL_MASK)
w.Join("movement-notify-occasion", wakeup)
w.Connect("key-press-event", wakeup)
w.Join("button-press-occasion", wakeup)
w.Connect("scroll-event", wakeup)
w.Show()
gtk.Foremost()
Note that mouse "scroll-wheel" occasions are implemented as button clicks inside the Xorg X11R6 server (button 4 for scroll up, button five for scroll down).
GNU Image Manipulation Program(GIMP) Interview Questions
Question sixteen. I've Fiddled With The Mask But Nothing Happened. Why?
Answer :
One not unusual mistakes is to confuse gdk event TYPEs with MASKs. The kind variety indicates precisely which gdk occasion was generated, but it isn't always without delay associated with the event mask:
<jamesh_> yeah. A range of the mask cover a couple of events and some events are selected with the aid of unique mask
All event mask constants end with _MASK, and that could be a precise rule to recall. When doing add_events, you do NOT want gtk.Gdk.BUTTON_PRESS)
This is the best command:
widget.Add_events(gtk.Gdk.POINTER_MOTION_MASK instance is specially tricky due to the fact the use of BUTTON_PRESS will genuinely permit the pointer movement masks; this happens due to the fact the of the numeric constants used. Remember _MASK.)
TurboGears Tutorial
Question 17. Which Widgets Are Unable To Receive Events Or Be Styled?
Answer :
sure widgets did not have related X windows, and for this reason were unable to address occasions or be styled and coloured. These widgets are (add a Gtk in front in the event that they look surprising):
Alignment
AspectFrame
Arrow
Bin
HBox
VBox
Frame
Image
Label
Pixmap
ScrolledWindow
HSeparator
VSeparator
Table
TurboGears Interview Questions
Question 18. I Attach A Callback To A Signal, But I Keep Getting An Error: "typeerror: Object Of Type X Is Not Callable"?
Answer :
When connecting an event handler, you should offer the characteristic name. A commonplace mistake is to bypass a call rather than the call. In other phrases, you must not upload parenthesis after the feature call.
#
# WRONG
button = gtk.Button(label="Quit")
button.Join("clicked", gtk.Main_quit())
As you can see, gtk.Main_quit() is a call, no longer the feature call. The accurate manner to do it would be:
# RIGHT
button = gtk.Button(label="Quit")
button.Connect("clicked", gtk.Main_quit)
Always keep in mind to apply gtk.Main_quit() rather than gtk.Mainquit() since the final one is deprecated.
PHP Interview Questions
Question 19. I Want My Callback To Execute, But Not The Default Callback (or, How To I Stop Gtk From Doing The Default Action When Doing X)?
Answer :
Many instances, you are customizing behaviour of a widget, or changing a coverage in GTK, and the default motion it does it now not what you need. To get around this, we depend on a essential point in GTK: that GTK, in addition to applications, specially makes use of signals to get things achieved inside the interface.
The procedure to disable a default movement is:
Find out what signal is being emitted and dealt with with the aid of the default handler. Many times the sign seeing that you'll be hooking to it already, and staring at the default movement take place after yours.
Call widget.Emit_stop_by_name("signal_name") (to stop the sign emission inside the contemporary widget)
return True (to make sure that the signal won't propagate into discern handlers that may be the real culprits for the default action)
An example of this usage changed into pronounced by means of Graham Ashton. He had custom designed a keypress handler for a window, however each time the person induced the Alt-arrow combination he become dealing with, the focus moved around among the widgets within the interface (as is the default behaviour).
The answer changed into clearly calling window.Emit_stop_by_name("key_press_event") and returning True.
Lisp programming Tutorial
Question 20. When Creating A New Signal, How Do I Define One Of The Signal Arguments As Python Data?
Answer :
When you upload your signal the use of gobject.Signal_new(), use gobject.TYPE_PYOBJECT as the kind for the argument being passed in:
gobject.Signal_new("signal", ClassName,
gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE,
(gobject.TYPE_PYOBJECT,))
And then you may emit the sign with Python items:
mydict =
mydict["foo"] = "bar"
class_instance.Emit("sign", mydict)
And get them when you join on the alternative aspect:
def signal_cb(example, mydict):
print mydict["foo"]
class_instance.Join("signal", signal_cb)
Lisp programming Interview Questions
Question 21. How Do I Specify User Data To A Signal?
Answer :
widget.Connect("my_signal", handler, userdata [, ...])
As you could see, you can bypass as many gadgets as userdata; the feature will obtain the equal number of user facts arguments.
Question 22. Why Does Handling Expose Events Break Drag-n-drop?
Answer :
If you are calling
queue_draw_area(x_beg, y_beg, x_end, y_end)
to your expose_event handler, do not. It appears to interrupt event propagation which reasons drag and drop to no longer paintings any greater.
WxPython Tutorial
Question 23. How Do I Pass Extra Data To A Signal Handler?
Answer :
The signal connection methods join() and connect_after() take an optional 1/3 parameter that can be used to supply more information to a sign handler callback. Any Python item can be exceeded so that you can use a list, tuple or dictionary if you need to bypass more than one greater values. Since the sign handler function will receive the widget that emitted the signal as its first parameter, frequently it is handy to pass a second related widget as the more facts.
Suppose you've got a dialog with an access widget. If you need the dialog response handler to do something with the access value, you may connect to the reaction signal like this
conversation.Connect('response', on_dialog_response, access)
This lets you effortlessly get admission to strategies of the entry widget within the signal handler, possibly to get the text in the entry
def on_dialog_response(widget, response, access):
if reaction == gtk.RESPONSE.ACCEPT:
print 'Accepting', access.Get_text()
Something that would experience you up mainly in case you are new to Python programming is that you probably do not want to attempt to bypass the access textual content to the signal handler like this
# probable wrong!
Dialog.Join('response', on_dialog_response, access.Get_text())
The get_text() method is achieved while the sign is connected so this will bypass a consistent fee as the extra information. Usually you may need the sign handler to peer the modern-day nation of the access widget.
WxPython Interview Questions
Question 24. How To Construct My Own "faux" Gtk.Gdk.Occasion?
Answer :
It's very easy. Let's go create a keypress occasion that is similar to if the person has pressed Ctrl+Enter:
occasion = gtk.Gdk.Event(gtk.Gdk.KEY_PRESS)
occasion.Keyval = gtk.Keysyms.Return
occasion.Nation = gtk.Gdk.CONTROL_MASK
event.Time = zero # assign modern-day time
widget_that_should_accept_signal.Emit('key_press_event', occasion)
the final line "passes" the signal to the widget we want to address this fake event.
Ruby on Rails Interview Questions
Question 25. How Do I Pass Data To A Signal Handler In Glade?
Answer :
In principle, you need to fill in the Object column while specifying a callback to connect to the signal. In GtkBuilder mode, you may simplest specify items that Glade is aware of approximately. This is enough for imposing things like the encapsulation pattern confirmed elsewhere in iit, used to offer a callback everything it needs to characteristic in, as an instance, a mobile renderer callback, by way of passing the TreeModel as user facts.
In practice, do not even try. Pygtk 2 and Glade are both too buggy to attempt this. Manually join any indicators that need person data.
Question 26. How Do I Change Font Properties On Gtk.Labels And Other Widgets?
Answer :
label = gtk.Label("MyLabel")
label.Modify_font(pango.FontDescription("sans forty eight"))
This approach applies to all widgets that use textual content, so that you can exchange the textual content of gtk.Entry and other widgets inside the identical way.
Note that, a few widgets are simplest bins for others, like gtk.Button. For those you'll must get the child widget. For a gtk.Button do this:
if button.Get_use_stock():
label = button.Toddler.Get_children()[1]
elif isinstance(button.Child, gtk.Label):
label = button.Infant
else:
increase ValueError("button does no longer have a label")
Basic C Interview Questions
Question 27. Why Don't My Style Changes Apply Only To The Widget I Requested It From?
Answer :
Ricardo Lenzi writes:
get_style() returns an object what aways have the modern-day style of widget. If you want to store an static style, use get_style().Reproduction() rather:
style = widget.Get_style().Copy()
This has some quite ordinary outcomes. If you're growing a window with many gtk.Label's, as an example, and also you adjust the actual style object (no longer a copy() if it), all widgets will subsequently trade style (while they may be redrawn by means of GTK+).
Ubuntu Certified Professional Interview Questions
Question 28. How Do I Use The Style Object?
Answer :
Each widget has an buddies style item that can be manipulted. The primary method is get_style(), which returns a GtkStyle item, and the related set_style(style_object).
The style is shared between widgets of the equal kind (XXX: is that this authentic?). To exchange the style of simplest one widget to your software, the style object gives a duplicate() technique, which returns a new replica of the GdkStyle, that may me changed and set_style() returned to the desired widget.
All attributes of a fashion may be get and set independently with the aid of direct access. The most crucial attributes of style are the colours (see faq four.6):
fg
bg
mild
darkish
mid
text
base
black
white
And the font and bg_pixmap attributes.
Question 29. How Do I Change The Colour Of A Widget (or How Do I Get A Gdkcolor)?
Answer :
There is a few confusion about GdkColor and how it's miles created. There are both the GdkColor() class and colour_alloc() that appear to do the right element, but they're both duds (as some distance as I can tell).
The proper way of making a colour is getting the colormap from the widget and using it to allocate a brand new shade using the GtkColorMap's alloc method:
e = gtk.Entry()
map = e.Get_colormap()
colour = map.Alloc_color("pink") # light pink
This manner you turn out to be with a purple GdkColor in the variable colour. Apart from the X11 rgb.Txt names, you may also use hex triplets:
colour = map.Alloc_color("#FF9999") # light red
The subsequent step is understanding how to control GtkStyle's color attributes, that are without a doubt dictionaries: every characteristic maps some of extraordinary gtk constants that indicate states:
gtk.STATE_NORMAL, the everyday state of the widget.
Gtk.STATE_ACTIVE, a clicked button or checkbutton, etc.
Gtk.STATE_INSENSITIVE, whilst the widget is insensitive (set_sensitive(zero))
gtk.STATE_PRELIGHT, when onmouseovered
gtk.STATE_SELECTED, whilst a part of the widget is chosen (text in a GtkEntry, or a selected radiobutton)
So, to trade the default border of our entry above to red:
style = e.Get_style().Reproduction()
fashion.Bg[gtk.STATE_NORMAL] = shade
e.Set_style(style)
Final trace: the default colour for a GtkEntry historical past is gray84.
Python Automation Testing Interview Questions
Question 30. How Do I Get A Graphics Context, Or Gdkgc?
Answer :
Use the new_gc() technique of GdkWindow (no longer GtkWindow, observe):
gdkwin = widget.Window
gc = gdkwin.New_gc()
Question 31. How Does The Alloc() Method To The Gdkcolormap Work?
Answer :
gdk.Colormap.Alloc_color can take some of codecs:
cmap = widget.Get_colormap()
shade = cmap.Alloc_color("#FFCCAA")
coloration = cmap.Alloc_color("red")
color = cmap.Alloc_color(zero, 0, 65535)
Note that the third format uses a tuple to specify the individual values for Red, Green and Blue (RGB), each object being an integer from zero to 65535 (corresponding, consequently, to 0x0-0xFF).
Question 32. How Do I Use Pango Instead Of Gdkfont For Font Handling In A Gtkdrawingarea?
Answer :
Create a font description with pango. You will then need a pango format for the textual content you need to show. You have to inform the layout which font description to apply and draw it with the draw_layout() technique in preference to the draw_text() method.
Import pango
# create a font description
font_desc = pango.FontDescription('Serif 12')
# create a format to your drawing area
format = darea.Create_pango_layout('hiya pango!')
# tell the format which font description to use
layout.Set_font_description(font_desc)
# draw the text with the draw_layout technique
darea.Window.Draw_layout(gc, x, y, format)
You can find out approximately the scale of the text via the use of the get_pixel_size() technique out of your pango format object. E.G.:
# get the pixel size of a layout
text_width, text_height = layout.Get_pixel_size()
Question 33. How Do I Get Antialiased Fonts In Gtk+?
Answer :
The authentic core font rendering engine in XFree86 didn't help AA fonts. However, for GTK+ 2.Zero onwards, the Xft font rendering backend may be used to render antialiased fonts. To choose it the usage of GTK+2.Zero, use:
export GDK_USE_XFT=1
It's on by way of default on 2.2 onwards, and in 2.4 the center engine is not used by GTK+.
Note that the Xft backend is an awful lot better at producing scaled variations of the fonts. The purpose is that the middle X font system, while you operate scalable fonts, will render the whole set of glyphs as bitmaps at the requested size while you open the font (which is not rapid or a good use of reminiscence -- it quite massive for massive factor sizes or fonts with big insurance, such as with Asian fonts).
Django Interview Questions
Question 34. Does Pygtk Support Truetype Fonts?
Answer :
If your X server does, the solution is sure. X calls for the freetype module be loaded to be able to cope with TTF fonts, however all put up-4.Zero servers include the module by using default.
Question 35. What Units Does Pango Use To Define Sizes And Widths?
Answer :
Pango makes use of a constant referred to as pango.SCALE to transform among pixels and pango's local unit. You can use pango.PIXELS() to convert from the local unit returned to pixels, or just divide.
Question 36. Can I Find Out How Long (wide) A String Is In A Certain Font?
Answer :
In PyGTK2, you may use pango calls to find out how wide a string could be, using the pango context of the widget that includes (or in an effort to contain) your textual content:
context = widget.Get_pango_context()
metrics = context.Get_metrics('font name, 12')
width = pango.PIXELS(metrics.Get_approximate_char_width() * n_chars)
For a monospaced font, this should be quite correct. You can then use widget.Set_size_request() in case you would really like to set that width as the minimum width for the widget/view.
In PyGTK-0.6, you can ask the font at once how lengthy a given string is going to be, as well as how excessive. Retrieve the font object from the fashion, after which query it with the string in question:
font = widget.Get_style().Font
h = font.Height(my_string)
w = font.Width(my_string)
The strategies return pixel counts. You can then set the scale manually to any characteristic of those parameters. For instance, to make a widget twice as huge and as excessive as the string you measured with, use:
widget.Set_usize(w*2, h*2)
GNU Image Manipulation Program(GIMP) Interview Questions
Question 37. Why Does Fontselection's Set_font_name Return False?
Answer :
It needs to be delivered to a window before the font lists are populated.
>>> w = gtk.Window()
>>> f = gtk.FontSelection()
>>> f.Get_font_name()
'Sans 10'
>>> f.Set_font_name('Sans 12')
False
>>> w.Upload(f)
>>> f.Set_font_name('Sans 12')
True
Once added to the window, the end result will certainly be True.
Question 38. Can I Pass Strings Of Unicode Instance To Gtk Or Do I Need To Convert Them To Utf8?
Answer :
No you do not have do manually convert your strings in utf8. PyGTK will do that for you.
Label.Set_text(u'abc')
So the above is indeed valid and no longer most effective to labels however to any widget.
Question 39. How Do I Check If A Widget Is Currently Sensitive?
Answer :
In pygtk, you get homes through calling the get_property() approach:
if widget.Get_property('touchy') == zero:
print "I'm insensitive!"
Note: In historic variations of pygtk (zero.6.X) you can get admission to them the usage of a dictionary interface, this become eliminated within the 2.X series.
More currently (considering PyGTK 2.Eight) the subsequent method may be used:
if now not widget.Props.Sensitive:
print "I'm insensitive!"
Question 40. Where Is Get_state() In Pygtk 0.6.X?
Answer :
James Henstridge factors out that there's no get_state() function in gtk 1.2.
And consequently no manner to wrap it in pygtk. There are actually a number of nation constants described in gtk:
gtk.STATE_ACTIVE
gtk.STATE_NORMAL
gtk.STATE_SELECTED
gtk.STATE_INSENSITIVE
gtk.STATE_PRELIGHT
however they may be for use with set_state(). In pygtk2, get_state() is carried out and wrapped.
TurboGears Interview Questions

