我的申请是,我的数据Fetch()类“Wraps”在我的HBHTray()类左右,目的是与该类职能/变量互动。 不幸的是,在我的数据Fetch()班进行HBHTray和打电话后,我似乎无法继续执行该守则,也未能采用HBray(HBray)的开端方法。
这是相关的法典:
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?