pygtk

Python and GTK+: How to create garbage collector friendly objects?

泪湿孤枕 提交于 2019-12-11 07:44:36
问题 I started writing a small application in Python with GTK+ as my widget toolkit. Recently I decided to do some memory optimization and noticed that a most of PyGTK objects I create never gets released by garbage collector. This number keeps growing even if I open a window and properly destroy it afterward. Can someone point me in the right direction on how to create and handle GTK+ objects from Python. Am not using Glade or anything like that. Also I noticed that creating window like this:

Right-Click on a PyGTK Hbox in an Expander

淺唱寂寞╮ 提交于 2019-12-11 07:39:30
问题 I've got a gtk.Expander object, containing in its label a gtk.HBox, which packed a gtk.Image and a gtk.Label. I want to launch a Webbrowser when the HBox is right-clicked. Here is my code: def launchBrowser(widget, host, event): print event print host if event.type == gtk.gdk.BUTTON_PRESS: if event.button == 3: webbrowser.open(host, 1) print "right click" def addServer(self, loginfo): main_expand = gtk.Expander() main_led = gtk.Image() if int(loginfo["main"]) == 0: main_led.set_from_stock(gtk

Set position of image in a window using pygtk

谁都会走 提交于 2019-12-11 07:38:13
问题 Is it possible to set the position of an image using pygtk? import pygtk import gtk class Example: self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.image = gtk.Image() self.image.set_from_file("example.png") # Position goes here (it should, shouldn't it?) self.window.add(self.image) self.image.show() self.window.fullscreen() self.window.show_all() 回答1: GTK lays widgets out based on relative alignments and padding, not absolute pixel positions. Instances of gtk.Image have properties xalign,

Why is the notebook control not showing up in my window?

こ雲淡風輕ζ 提交于 2019-12-11 07:32:18
问题 Although I am not new to Python, this is my first attempt at using Glade to design the interface. My Python file looks like this: import gobject import gtk import gtk.glade class prefs_dialog: def __init__ (self): # Initialize the dialog self.window = gtk.glade.XML("file.glade").get_widget("prefs_dialog") self.window.show() pd = prefs_dialog() gtk.main() And the "file.glade" file looks like this: <?xml version="1.0"?> <glade-interface> <!-- interface-requires gtk+ 2.16 --> <!-- interface

Unpredictable results from os.path.join in windows

风流意气都作罢 提交于 2019-12-11 07:07:17
问题 So what I'm trying to do is to join something in the form of os.path.join('C:\path\to\folder', 'filename'). **edit : Actual code is : filename = 'creepy_%s.pcl' % identifier file = open(os.path.join(self.cache_dir, filename), 'w') where self.cache_dir is read from a file using configobj (returns string) and in the particular case is '\Documents and Settings\Administrator\creepy\cache' The first part is returned from a configuration file, using configobj. The second is a concatenation of 2

How to make column editable for particular child in pygtk

家住魔仙堡 提交于 2019-12-11 06:58:53
问题 In below picture you can see the 3 parent child window. actually I made one code which will show all child according to parent. that is showing correctly but i want username & password column editable for database parent only(like as 3rd window). other should not be editable. In my case all child of parent is editable. here is my code #!/usr/bin/env python import pygtk pygtk.require('2.0') import gtk, gobject import os import cairo, gio, pango, pangocairo, atk class BasicTreeViewExample: #

PyGTK leave-notify-event shouldn't be triggered if enter children

柔情痞子 提交于 2019-12-11 06:38:25
问题 Please see this code example: import gtk class MenuBox(gtk.EventBox): def __init__(self): super(MenuBox, self).__init__() self.set_visible_window(False) self.connect('enter-notify-event', self._on_mouse_enter) self.connect('leave-notify-event', self._on_mouse_leave) btn = gtk.Button('x') btn.set_border_width(12) self.add(btn) def _on_mouse_enter(self, wid, event): print '_on_mouse_enter' def _on_mouse_leave(self, *args): print '_on_mouse_leave' def main(): win = gtk.Window() win.connect(

Why does the Popen() function behave differently in Python and PyGTK?

♀尐吖头ヾ 提交于 2019-12-11 05:30:39
问题 I wrote these two lines in a Python program and they worked fine : subprocess.Popen("./prog infile outfile >/dev/null", cwd="/path/to/prog", stdout=subprocess.PIPE, shell=True) output = subprocess.Popen("prog1 infile1 2>/dev/null", stdout=subprocess.PIPE, shell=True).stdout.read() However these two lines of code do not work correctly in my PyGTK application. I invoke these lines from a handler called on the "row-activated" signal of a TreeView widget. Neither does prog write the outfile , nor

PyGtk Program is not responding on Windows

强颜欢笑 提交于 2019-12-11 05:07:42
问题 I just managed to get py2exe work on a Windows Virtual Machine but stumbled on another problem which I didn't have right after I installed GTK, Pango, Gobject etc. on that machine: When I launch a Python Script the window appears but it immediately stops responding. This happens too if I open a python interpreter and type: import gtk w = gtk.Window() w.show() I'm not allowed to post any images yet, but here's the link to a screenshot: http://i.stack.imgur.com/3RJ0n.png This is a problem for

Effect of PyGTK clipboard set_text persists only while process is running

社会主义新天地 提交于 2019-12-11 04:38:43
问题 I have the following script clip-test.py : #!/usr/bin/python import gtk gtk.Clipboard().set_text("exciting clipboard contents") gtk.Clipboard().set_can_store(None) # not sure if these last two lines are useful gtk.Clipboard().store() When I run this like so: python clip-test.py it doesn't work. The clipboard is unchanged. We can elucidate the issue by running it in interactive mode and not letting the process finish: python -i clip-test.py Before leaving interactive mode, try pasting