tjajab
November 13th, 2008, 02:13 PM
Hello, I am trying to create a simple backup application which uses glade for the GUI. When the user presses a button, a new thread will be started backup will be made, using system.os('cp -au ...').
My problem is that the thread does not start until I quit the program (main thread?). I guess this is a locking issue. I also would like my thread to access the statusbar of my main object to tell the user how it is progressing. My code setup looks like this:
class BackupThread ( threading.Thread ):
def __init__ ( self, statusbar ):
self.statusbar = statusbar
threading.Thread.__init__ ( self )
def run ( self ):
self.statusbar.push(1, "Backup started ...")
os.system('gksudo "cp -au {SOME ARGUMENTS HERE}"')
self.statusbar.push(1, "Backup finished ...")
class Backup:
def on_window_destroy(self, widget, data=None):
gtk.main_quit()
def on_backupButton_clicked(self, widget, data=None):
self.backupThread = BackupThread(self.statusbar).start()
def __init__(self):
builder = gtk.Builder()
builder.add_from_file("backup.xml")
self.window = builder.get_object("window")
self.statusbar = builder.get_object("statusbar")
builder.connect_signals(self)
self.events=list()
if __name__ == "__main__":
editor = Backup()
editor.window.show()
gtk.main()
My problem is that the thread does not start until I quit the program (main thread?). I guess this is a locking issue. I also would like my thread to access the statusbar of my main object to tell the user how it is progressing. My code setup looks like this:
class BackupThread ( threading.Thread ):
def __init__ ( self, statusbar ):
self.statusbar = statusbar
threading.Thread.__init__ ( self )
def run ( self ):
self.statusbar.push(1, "Backup started ...")
os.system('gksudo "cp -au {SOME ARGUMENTS HERE}"')
self.statusbar.push(1, "Backup finished ...")
class Backup:
def on_window_destroy(self, widget, data=None):
gtk.main_quit()
def on_backupButton_clicked(self, widget, data=None):
self.backupThread = BackupThread(self.statusbar).start()
def __init__(self):
builder = gtk.Builder()
builder.add_from_file("backup.xml")
self.window = builder.get_object("window")
self.statusbar = builder.get_object("statusbar")
builder.connect_signals(self)
self.events=list()
if __name__ == "__main__":
editor = Backup()
editor.window.show()
gtk.main()