pygtk

How to put arbitrary widgets into a gtk.Menu?

守給你的承諾、 提交于 2019-12-06 01:04:14
问题 How can any gtk.Widget (eg. a progress bar) be put into a gtk.Menu as one of the menu items? 回答1: Quoting from the PyGTK documentation: The gtk.MenuItem and its derived widget subclasses are the only valid children of menus. So the answer is: You can't. But: As a gtk.MenuItem is a subclass of gtk.Bin it can hold any valid child widget. If you create a MenuItem without a label: item = gtk.MenuItem() you can add most gtk.Widget subclasses as a child to item . 来源: https://stackoverflow.com

How to set default button in PyGTK?

强颜欢笑 提交于 2019-12-06 00:56:21
问题 I have very simple window where I have 2 buttons - one for cancel, one for apply. How to set the button for apply as default one? (When I press enter, "apply" button is pressed) However, I want to set focus to the first input widget (I can't use grab_focus() on the button) Any suggestions? Edit: After wuub 's answer it works visually good. However, when I press the button in different widget, it doesn't run callback of the default button. Example code: import os, sys, pygtk, gtk def run

What's the newest way to develop gnome panel applets (using python)

China☆狼群 提交于 2019-12-05 22:41:47
问题 Today I've switched to GNOME (from XFCE) and found some of the cool stuff missing and I would like to (try to) do them on my own. I tried to find information on how to develop Gnome applets (items you place within the panel) and most likely in Python, but it's not a hard limitation. I found the article 'Gnome applets with Python', but it seems quite old (2004). The first thing mentioned there is bonobo (whatever it is), but Gnome page on Bonobo discourages it. Gnome site has a page on applet

JSON encode/decode GTK enums

痞子三分冷 提交于 2019-12-05 18:44:27
I have to save various properties of custom GTK elements to a file for future use and decided to use JSON because of the simple format and nesting of dicts. Many properties are GTK enums, like gtk.PAGE_ORIENTATION_PORTRAIT , gtk.ANCHOR_CENTER and pango.ALIGN_LEFT . They have a unique name which can be retrieved with obj.value_name to get a valid JSON type. Currently I have 2 methods for each of my elements: to_str() to get the value_name and from_str() which maps the str to the enum again. I would like to automate this so I don't forget to call these and clean up the code a bit. The

Adding GUI Window to python opencv2 program with pygtk3

风格不统一 提交于 2019-12-05 17:42:59
I have completed a program using Python and Opencv2. Now, I wants to add a GUI Window to my program. I am having some experience with PyGtk3. So, I modified my code to adopt with PyGtk3. But, I got errors. So, I tried a simple program to find out the actual mistake. My testing code is, import pygtk pygtk.require('2.0') import gtk import numpy as np import cv2 builder = gtk.Builder() builder.add_from_file("GUI.glade") window = builder.get_object("window1") window.set_title("Single Object Tracking") window.connect("delete-event", gtk.main_quit) window.show_all() img = cv2.imread('Birds.jpg') cv2

gtk idle_add not running?

你。 提交于 2019-12-05 13:15:36
I have a two-thread application: GUI, and some background work. I'm trying to send requests to the main thread to do GUI updates (move a progress bar), but it doesn't seem to work. I've boiled it down to a really minimal example: import pygtk pygtk.require('2.0') import glib import gtk import threading import sys import time def idle(): sys.stderr.write('Hello from another world.\n') sys.stderr.flush() gtk.main_quit() def another_thread(): time.sleep(1) glib.idle_add(idle) thread = threading.Thread(target=another_thread) thread.start() gtk.main() This should, I thought, print something to

Interacting with a gtk.container while gtk.main() is executing?

佐手、 提交于 2019-12-05 11:50:52
Experimenting with a battery monitor icon at the moment in Python using pygtk and egg.trayicon to create an icon to display a battery icon/tooltip. I seem to be able to add the icon and the tooltip text, but when it then reaches the gtk.main() stage I need a way to modify these so it can then show the updated values. I've tried gobject.idle_add() and gobject.timeout_add() without much luck, not sure where to go from this. Anyone got any ideas? EDIT : Perhaps not the clearest of questions. I need to loop, fetching information from acpi while running and apply it to widgets inside the gtk

Python AppIndicator bindings -> howto check if the menu is open?

柔情痞子 提交于 2019-12-05 11:22:32
问题 Here is a minimal example of an AppIndicator: #!/usr/bin/python import gobject import gtk import appindicator if __name__ == "__main__": ind = appindicator.Indicator("example-simple-client", "gtk-execute", appindicator.CATEGORY_APPLICATION_STATUS) ind.set_status (appindicator.STATUS_ACTIVE) menu = gtk.Menu() menu_items = gtk.MenuItem('Quit') menu.append(menu_items) menu_items.connect("activate", gtk.main_quit) menu_items.show() ind.set_menu(menu) gtk.main() Unfortunately the documentation on

Enter-Notify-Event Signal not working on gtk.ToolButton

北战南征 提交于 2019-12-05 11:12:14
On a happy (if not irrevelent) note, this is the absolute last obstacle in this particular project. If I fix this, I have my first significant dot release (1.0), and the project will be going public. Thanks to everyone here on SO for helping me through this project, and my other two (the answers help across the board, as they should). Now, to the actual question... I have a toolbar in my application (Python 2.7, PyGTK) which has a number of gtk.ToolButton objects on it. These function just fine. I have working "clicked" events tied to them. However, I need to also connect them to "enter-notify

How to work with threads in pygtk

假装没事ソ 提交于 2019-12-05 10:28:19
I have a problem with threads in pygtk. My application consist of a program that downloads pictures off the internet and then displays it with pygtk. The problem is that in order to do this and keep the GUI responsive, I need to use threads. So I got into a callback after the user clicked on the button "Download pictures" and I call the method to download the pictures that is within that same class. thread.start_new_thread(self.images_download, (path,pages) This won't work. The only way I get my program to get into the thread is by using gtk.threads_init() Before starting any thread. Now it