pyton GUI, pygtk wxPython
kf701
|
1#
kf701 发表于 2008-01-16 18:14
pyton GUI, pygtk wxPythonpython gtk #!/usr/bin/env python #-*- encoding:utf-8 -*- import pygtk import gtk import gobject def leave_term(): import os try: if os.fork() > 0: os._exit(0) except OSError, error: os._exit(1) # end of function leave_term class main_win: def destroy(self,widget,data=None): gtk.main_quit() def delete_event(self, widget, event, data=None): return False def __init__(self): # main window self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.set_title('kf701 timer') self.window.set_default_size(200,200) self.window.set_border_width(100) self.window.set_position(gtk.WIN_POS_CENTER) self.window.set_keep_above(True) self.window.connect("delete_event", self.delete_event) self.window.connect("destroy",self.destroy) self.window.set_skip_taskbar_hint(True) # box self.box1 = gtk.VBox(False, 0) self.box1.set_spacing( 20 ) self.window.add(self.box1) self.box1.show() # label self.label = gtk.Label("One Hour pass, You must Have a Rest Now!") self.label.show() self.box1.pack_start(self.label,False,False,0) # button self.ok_btn = gtk.Button("OK, Work Again") self.ok_btn.connect("clicked", self.hide_window, "xxx") self.ok_btn.show() self.box1.pack_end(self.ok_btn,False,False,0) self.timeout = 60*60*1000 # default 1 hour def main_loop(self): gobject.timeout_add(self.timeout, self.time_func) gtk.main() def set_timeout(self, time): self.timeout = time*1000 return def time_func(self): self.window.show() return False # stop timeout def hide_window(self, widget, data): self.window.hide() gobject.timeout_add(self.timeout, self.time_func) return False # end of class main_win if __name__ == "__main__": leave_term() win = main_win() win.set_timeout(60*60) # seconds win.main_loop() python wxWidget #!/usr/bin/env python # -*- coding: utf-8 -*- # generated by wxGlade 0.5 on Mon Jan 21 15:54:47 2008 from /tmp/xxx.py import wx def leave_term(): import os try: if os.fork() > 0: os._exit(0) except OSError, error: os._exit(1) # end of function leave_term class MyFrame(wx.Frame): def __init__(self, *args, **kwds): # begin wxGlade: MyFrame.__init__ kwds["style"] = wx.CAPTION|wx.CLOSE_BOX|wx.MINIMIZE_BOX|wx.MAXIMIZE_BOX|wx.STAY_ON_TOP|wx.SYSTEM_MENU|wx.RESIZE_BORDER|wx.CLIP_CHILDREN wx.Frame.__init__(self, *args, **kwds) self.label_1 = wx.StaticText(self, -1, "One Hour pass, You must Have a Rest Now!") self.button_1 = wx.Button(self, -1, "Ok, Work Again") self.__set_properties() self.__do_layout() self.timer = wx.Timer(self) self.timer.Start(1000*60*60) self.Bind(wx.EVT_TIMER, self.time_func) self.Bind(wx.EVT_BUTTON, self.onbtn, self.button_1) # end wxGlade def __set_properties(self): # begin wxGlade: MyFrame.__set_properties self.SetTitle("kf701 timer") self.SetSize((480, 272)) # end wxGlade def __do_layout(self): # begin wxGlade: MyFrame.__do_layout sizer_1 = wx.BoxSizer(wx.VERTICAL) sizer_1.Add(self.label_1, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 10) sizer_1.Add(self.button_1, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 10) self.SetSizer(sizer_1) sizer_1.Fit(self) self.Layout() self.Centre() # end wxGlade def time_func(self, event): print "time func" self.Show() self.timer.Stop() def onbtn(self, event): # wxGlade: MyFrame. print "hide window and timer" self.Hide() self.timer.Start(-1) # end of class MyFrame class MyApp(wx.App): def OnInit(self): wx.InitAllImageHandlers() frame_1 = MyFrame(None, -1, "") self.SetTopWindow(frame_1) #frame_1.Show() return 1 # end of class MyApp if __name__ == "__main__": leave_term() app = MyApp(0) app.MainLoop() |