Hello all I’ve been learning python and pygtk I’ve recently run into an issue with a small program i was trying to make.
When you click the tray icon the first time my window appears as normal but after closing the window which I tried to set to be like a “minimize to tray” type thing it won’t open again only display a blank window instead of the one it shows originally.
import os
import gtk
import gobject
import datepicker
from dateutil import relativedelta
import datetime
import numberentry
class ShutdownTimer:
tray_tooltip = ''
timer_visible = False
timerui = gtk.Window()
def set_tooltip(self, string):
self.tray_tooltip = str(string)
def set_visible(self, v, visible):
self.timer_visible = visible
if self.timer_visible is True:
self.timerui.show_all()
else:
self.timerui.hide_all()
def set_up(self):
self.timerui.set_title("Shutdown Timer")
self.timerui.connect("destroy", self.set_visible, False)
self.row_one = gtk.HBox()
self.combo = gtk.combo_box_new_text()
self.combo.append_text("Shutdown")
self.combo.append_text("Hibernate")
self.combo.append_text("Suspend/Sleep")
self.combo.append_text("Restart")
self.combo.append_text("Cancel")
self.combo.set_active(0)
self.row_one.pack_start(self.combo, False, False)
hlbl = gtk.Label()
mlbl = gtk.Label()
hlbl.set_text("H:")
mlbl.set_text("M:")
self.hentry = numberentry.NumberEntry()
self.mentry = numberentry.NumberEntry()
submit = gtk.Button("Submit")
submit.connect("clicked", self.submit_action)
self.row_one.pack_start(hlbl, False, False)
self.row_one.pack_start(self.hentry, False, False)
self.row_one.pack_start(mlbl, False, False)
self.row_one.pack_start(self.mentry, False, False)
self.row_one.pack_start(submit, False, False)
self.row_one.show_all()
self.timerui.add(self.row_one)
def submit_action(self, action):
task = self.combo.get_active_text()
hours = int(self.hentry.get_text())
minus = int(self.mentry.get_text())
hourm = hours * 60
tmins = minus + hourm
tseconds = tmins * 60
print tseconds
date = datetime.datetime.now()
print date
future = datetime.timedelta(seconds=tseconds)
total = date+future
print total
print "%s scheduled for %s" % (task, total)
string = task + " scheduled for " + str(total)
md = gtk.MessageDialog(self.timerui, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE, string)
md.run()
md.destroy()
#print '%s - %s / %i:%i %s' % (action, date, hours, minutes, timePart)
#date_split = date.split("/")
#today = datetime.date.today(date_split[2],date_split[0], date_split[1])
#rd = relativedelta(today, datetime.date())
#print "Seconds to go: %(seconds)d" % rd.__dict__
def on_right_click(self, shutdown, status, action):
menu = gtk.Menu()
menu_item = gtk.MenuItem("Quit")
menu_item.connect("activate", lambda w: gtk.main_quit())
menu.append(menu_item)
menu_item.show()
menu_item = gtk.MenuItem("Show Window")
menu_item.connect("activate", self.set_visible, True)
menu.append(menu_item)
menu_item.show()
menu.popup(None, None, None, action, action)
def __init__(self):
self.status = gtk.StatusIcon()
home = os.getenv('HOME')
icon_path = home + '/.config/shutdowntimer/icons/32x32/tray_icon.png'
settings_path = home + '/.config/shutdowntimer/settings/'
self.status.set_from_file(icon_path)
self.status.set_visible(True)
self.status.connect("popup_menu", self.on_right_click)
self.status.connect("activate", self.set_visible, True)
self.set_up()
def main():
gtk.main()
return 0
if __name__ == "__main__":
ShutdownTimer()
main()
I’m sure i’ve got some issues going on in my code as far as formatting, commenting, and probably naming conventions but any help shedding light on my issue would be appreciated.. Thank you :)!
Sorry for wasting anyones time I managed to solve my issue by calling self.set_up() in this specific spot