Tag Info

Hot answers tagged

12

Your problem is a very common one, therefore there are tons of solutions (sheds, queues with multiprocessing or threading, worker pools, ...) Since it is so common, there is also a python build-in solution (in 3.2, but backported here: http://pypi.python.org/pypi/futures) called concurrent.futures. 'Futures' are available in many languages, therefore ...


10

Here we go: First you need to find the default background color for the the current theme. Then you can inject it into the current css for the GtkToolbar class. # Get the default window background color for the the current theme. win_style_context = window.get_style_context() bg = win_style_context.lookup_color('theme_bg_color')[1].to_string() # Then we ...


9

You can do this easily from NetworkManager's pygi bindings: from gi.repository import NetworkManager, NMClient nmc = NMClient.Client.new() devs = nmc.get_devices() for dev in devs: if dev.get_device_type() == NetworkManager.DeviceType.WIFI: for ap in dev.get_access_points(): print ap.get_ssid() Or from DBus directly, see ...


7

Here's an example that has context from gi.repository import Gtk class Handler: def onDeleteWindow(self, *args): Gtk.main_quit(*args) def addNotebookClick(self, *args): vbox = builder.get_object("attachtome") mynote = builder.get_object("notebook1") temp = Gtk.Box() mynote.reparent(temp) ...


7

Just to make sure that the Gtk way is also present in an answer: The equivalent of gtk.timeout_add(PING_FREQUENCY * 1000, self.doWork) in gobject introspection (PyGI) is: from gi.repository import GLib GLib.timeout_add(PING_FREQUENCY * 1000, self.doWork) However, when checking something regularly every x seconds, you should use ...


6

Here's some working code for a transparent WebKit window. from gi.repository import WebKit, Gtk, Gdk import signal class BackgroundPaneCallbacks: pass class BackgroundPaneWebview(WebKit.WebView): def __init__(self): WebKit.WebView.__init__(self) self.set_transparent(True) ...


6

You can move content area (GtkVBox) from GtkDialog to another GtkContainer, and then append to GtkNotebook - using gtk.Widget.reparent() method. about = Gtk.AboutDialog() about.set_program_name ("Application") about.set_copyright ("Author") box = Gtk.VBox () about.vbox.reparent (box) notebook.append_page (box, Gtk.Label("About")) about.destroy () With ...


6

Here's another option using GIO's I/O Scheduler (I've never used it before from Python, but the example below seems to run fine). from gi.repository import GLib, Gio, GObject import time def slow_stuff(job, cancellable, user_data): print "Slow!" for i in xrange(5): print "doing slow stuff..." time.sleep(0.5) print "finished ...


4

If you only care about running under GNOME & Unity you should be able to hook into the session manager DBus interface. That not only gives you a “about to log out” message via the QueryEndSession and EndSession signals, but also allows you to block logout/shutdown until you're done cleaning up if you want, via EndSessionResponse. I'm not sure to what ...


4

Think I've cracked the code after dir()-ing everything I could find in the GObject class => G_SIGNAL_RUN_FIRST is found in the GSignalFlags enum, which translates to GObject.SignalFlags.RUN_FIRST. This is consistent, so G_SIGNAL_MATCH_ID found in the enum GSignalMatchType translates to GObject.SignalMatchType.ID. Not entirely obvious, but easy enough once ...


4

As per previous comments, the translation you asked would be as follows: from gi.repository import GObject __gsignals__ = {'cell-edited': (GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT, ...


3

A Gtk.TreeStore and Gtk.ListStore are different in that a Gtk.ListStore is a flat list where you append rows as a list, whereas a Gtk.TreeStore holds parent/child data, so it takes the parent as Gtk.TreeIter and a list as row. parent_iter = treestore.append(None, ["parent row"]) treestore.append(parent_iter, ["child row"]) ...


3

I do not know a nice answer, but I have a work-around for you: The basic idea is that you need a container widget as the parent widget in each page (do not place e.g. a label directly in the page), and you can hide/show everything except the container (If you hide the container as well, the page will disappear). This solution should work for otherwise ...


3

You can use pageNum = notebook.get_current_page() which will give you the current page number. and use textview = notebook.get_nth_page(pageNum) to get the widget on that page.


3

I get the same error as you if I run the plugin code directly without Gedit. As it is described in the manual you linked, you need to make a .plugin file for your plugin code. Place your plugin code and the .plugin file into ~/.local/share/gedit/plugins. Restart Gedit. Open Gedit > Edit > Preferences > Plugins and look for your plugin. Set the checkmark ...


2

To answer your question, the typelib you need for developing gedit plugins is contained in the gedit package itself. $ apt-file search Gedit-3.0.typelib gedit: /usr/lib/gedit/girepository-1.0/Gedit-3.0.typelib But when using python either interactively or from a script, from gi.repository import Gedit searches /usr/lib/girepository-1.0/ rather than ...


2

I had to do this for my appshowdown application, and I would not try to do it all by hand. What I did was make a new project with the correct name, and then paste in my custom code, and change a couple references to the old name in there. I then copied over the files for the gui, and did a find and replace on those for the new name. It depends on how ...


2

You can either do something like this: bus = dbus.SessionBus() bus.call_on_disconnection(your_method_to_do_stuff) Or you can connect to the NameLost signal on the org.FreeDesktop.DBus interface. The former doesn't let you pass additional arguments, and your method can only take the bus connection object itself as an argument. The latter is a bit more ...


2

You can set the font in a textview using GTK+'s built-in button and dialog for this, Gtk.FontButton(): #!/usr/bin/python from gi.repository import Gtk class TextViewWindow: def __init__(self): self.window = Gtk.Window() self.window.set_default_size(400, 400) main_vbox = Gtk.VBox(homogeneous=False, spacing=0) ...


2

The Keybinder library does exactly this. If you check pull requests there are requests in for examples using pygi, one of which is me for py3k.


2

The reference manual you are quoting is not for python. I'm aware, that with gobject introspection, no python manual is available anymore (only a tutorial), but this manual does not document the python mapped functionality. A lot of functions from C have not been made accessible from other languages. One way you might want to go, if you do not require Gio, ...


2

Use the introspected Gio API to read a file, with its asynchronous methods, and when making the initial call, do it as a timeout with GLib.timeout_add_seconds(3, call_the_gio_stuff) where call_the_gio_stuff is a function which returns False. The timeout here is necessary to add (a different number of seconds may be required, though), because while the Gio ...


2

You can also use GLib.idle_add(callback) to call the long running task once the GLib Mainloop finishes all it's higher priority events (which I believe includes building the UI).


2

You should try the following: According to the Launchpad's Help Launchpad satisfies your package's Build-Depends using: the most recent versions of the packages in the PPA you're uploading to all sections of the primary Ubuntu archive -- i.e. main, restricted, universe and multiverse optionally: other PPAs in Launchpad. Note: If you're already familiar ...


2

If you want the function to be run most of the time the toggle signal is emitted, and not when you manually toggle it (e.g. when loading saved settings and displaying the appropriate state), then you need to block and unblock the signal. To do so you'll need the handle_id that was returned when the signal was connected to the function. Just assign a ...


2

One has to use GLib.timeout_add(10, handler_timeout) inside the indicator code, where 10 - is 10 milliseconds, time between refreshing, and handler_timeout - function to be called at each refresh. Inside this function one can do all the needed stuff, like checking for clipboard changes and editing the menu.


2

There is intentionally no way to easily discover them. We don't want an interaction with the indicators that is not a menu and an icon. This consistency is important to the type of experience that we're trying to create. The wiki page has information on the design rational of the menubar.


2

I followed this article for running a Firefox-based test framework on a server earlier this year. The Xvfb-stuff is pretty simple, we just need to make sure to turn the access controls off so X doesn't get all uppity. Something like this should get you going: sudo apt-get install xvfb sudo Xvfb :10 -ac export DISPLAY=:10 # run your gubbins Though you ...


1

It is better to ask one question per... err... question. Python's standard library has threading module which has a Timer class which does exactly what you need. Documentation. Regarding push vs pull - it is definitely better when your application receives a notification when something happens (push) instead of checking if something happened every second ...


1

I think it bears noting that this is a convoluted way to do what @mhall suggested. Essentially, you've got a run this then run that function of async_call. If you want to see how it works, you can play with the sleep timer and keep clicking the button. It's essentially the same as @mhall's answer except that there's example code. Based on this which ...



Only top voted, non community-wiki answers of a minimum length are eligible