Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

Adding Ubuntu One Files support to your app

share|improve this question
add comment

3 Answers 3

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

Panels in Glade

In the properties section, head to the signals tab having previously seleted some widget on the editor, for example a button.

Glade signals

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]

share|improve this answer
add comment

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.

share|improve this answer
add comment

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")
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.