How can I call the Ubuntu One authentication python script from a button using Glade?
what I need to do is call a python script such as: $ python u1file.py login
How can I call the Ubuntu One authentication python script from a button using Glade?
what I need to do is call a python script such as: $ python u1file.py login
Gtk is a UI toolkit that is meant to be an event-driven framework. So the best approach would be to wait for some event to happen to execute your python code.
On Glade you can add widgets to a GtkWindow (that is also a widget), and widgets do emit what is called signals. Signals are events that indicate that something has happened. This action can be the user clicked on a button, typed some text, resized the window, etc.
A very simple example can be found here [1]
And here is a part I extracted
In the properties section, head to the signals tab having previously seleted some widget on the editor, for example a button.
As you can see in the image above, every signal has a name and can be binded to a "handler". Inside your code you have to create a function with the same name you choosed as your handle, in this case "on_window_destroy"
Then your code should look similar to this:
class TutorialApp(object):
def __init__(self):
builder = gtk.Builder()
builder.add_from_file("tutorial.xml")
# Here we do the binding
builder.connect_signals({ "on_window_destroy" : my_custom_handler })
self.window = builder.get_object("window")
self.window.show()
def my_custom_handler(self, widget):
# Excecute whatever python code you want here :D
if __name__ == "__main__":
app = TutorialApp()
gtk.main()
Source
http://www.micahcarrick.com/gtk-glade-tutorial-part-1.html [1]
Import the script like you would do with any other module/package in Python.
import u1file
ui1file.login()
See Hernantz answer if you don't know how to connect to a button.
Would this do what you want? This is basically the equivalent of typing python scriptname.py
in a terminal.
import os
os.system("python sriptname.py")