I have an application where my DataFetch() class “Wraps” around my HBHTray() class for the purpose of interacting with the functions/variables of that class. Unfortunately, I can’t seem to be able to get the code to continue execution after my DataFetch() class makes a instance of HBHTray and calls it, and on the Start() method of HBHTray it hangs.
This is the relevant code:
class DataFetch(): # I need the DataFetch class to be wrapping around HBHTray so I can call/edit certain variables from within functions in DataFetch
def init(self):
self.Interval, self.Username, self.Password, self.CheckShoutBox = GetOptions('.tray')
self.Gui = HBHTray()
print '1'
self.Gui.Start()
print '2'
def Login(self):
pass # Do stuff (Eg: Edit self.Gui.StatusIcon state or call self.Gui.Notify()
def Start(self):
print 'hi!'
sleep(self.Interval)
print 'Hi!'
class HBHTray():
def init(self):
self.StatusIcon = gtk.StatusIcon()
self.StatusIcon.set_from_file('img')
self.StatusIcon.set_tooltip('No new messages')
self.Menu = gtk.Menu()
self.CheckBox = gtk.CheckMenuItem('Notify')
self.CheckBox.connect('activate', self.ChangeCheckBox)
self.CheckBox.set_active(True)
self.Menu.append(self.CheckBox)
self.MenuItem = gtk.ImageMenuItem('Options')
self.MenuItem.connect('activate', self.Options, self.StatusIcon)
self.Menu.append(self.MenuItem)
self.MenuItem = gtk.ImageMenuItem('About')
self.MenuItem.connect('activate', self.About, self.StatusIcon)
self.Menu.append(self.MenuItem)
self.MenuItem = gtk.ImageMenuItem('Quit')
self.MenuItem.connect('activate', self.Quit, self.StatusIcon)
self.Menu.append(self.MenuItem)
self.StatusIcon.connect('popup-menu', self.PopMenu, self.Menu)
self.StatusIcon.set_visible(1)
def PopMenu(self, widget, button, time, data = None):
if data:
data.show_all()
data.popup(None, None, gtk.status_icon_position_menu, 3, time, self.StatusIcon)
def Notify(self, message):
pynotify.init('null')
notification = pynotify.Notification('Something', message, 'dialogue')
notification.attach_to_status_icon(self.StatusIcon)
notification.show()
def Start(self):
gtk.main()
def About(self, a, b):
self.Notify('test')
def Options(self, a, b):
print a, b
def ChangeCheckBox(self, null):
pass
def Quit(self, a, b):
raise SystemExit
if name == 'main':
try:
gobject.threads_init() # Doesn't work?
Monitor = DataFetch()
Monitor.Start()
Sorry for the terrible formatting, Stack Overflow doesn't seem to like blank lines....
Anyways, though, "1" is printed, but "2" is not. So, gtk.main() is obviously where it's hanging. Is there any way to allow me to continue execution and have gtk go do it's own thing?
Turns out the problem was that I couldn’t find a working solution because I was utilizing the Thread module the wrong way and calling run() directly when I should have been calling start(). Because of that, I was thinking that nothing I did worked (especially with no error or complaint from anything) and figured it was a problem relating to how I was wrapping gtk.main()