Hey all,
Kind of new to this mailing list and only messed with python a bit.
Want to create a taskbar icon that I can click on and run backup bat file,
found some code on internet that does this using wx libraries. But when i
run it the dos (black box) stays open how can i get rid of this?
Thanks
Code:
import sys, wx, os
ID_ICON_TIMER = wx.NewId()
OPEN_BACKUP=wx.NewId()
# OPEN_PREFS=wx.NewId()
SYS_OUT="";
BACKY="";
class MailTaskBarIcon(wx.TaskBarIcon):
def __init__(self, parent):
wx.TaskBarIcon.__init__(self)
self.parentApp = parent
self.noMailIcon = wx.Icon("nomail.png",wx.BITMAP_TYPE_PNG)
self.youHaveMailIcon =
wx.Icon("mail-message-new.png",wx.BITMAP_TYPE_PNG)
self.CreateMenu()
self.SetIconImage()
def CreateMenu(self):
self.Bind(wx.EVT_TASKBAR_RIGHT_UP, self.ShowMenu)
""" Setup binds from butttons to commands """
self.Bind(wx.EVT_MENU, self.parentApp.OpenBackup, id=OPEN_BACKUP)
# self.Bind(wx.EVT_MENU, self.parentApp.OpenPrefs, id=OPEN_PREFS)
self.menu=wx.Menu()
self.menu.Append(OPEN_BACKUP, "BackupFiles","This will backup your
files.")
# self.menu.Append(OPEN_PREFS, "Open Preferences")
self.menu.AppendSeparator()
self.menu.Append(wx.ID_EXIT, "Close App")
def ShowMenu(self,event):
self.PopupMenu(self.menu)
def SetIconImage(self, BACKY=False):
if BACKY:
self.SetIcon(self.youHaveMailIcon, SYS_OUT)
else:
self.SetIcon(self.noMailIcon, SYS_OUT)
"""
Main functionality of software, sets up software taskbar icon and all the
rest
action of buttons open backup
"""
class MailFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, -1, title, size = (1, 1),
style=wx.FRAME_NO_TASKBAR|wx.NO_FULL_REPAINT_ON_RESIZE)
self.tbicon = MailTaskBarIcon(self)
self.tbicon.Bind(wx.EVT_MENU, self.exitApp, id=wx.ID_EXIT)
self.Show(True)
def exitApp(self,event):
self.tbicon.RemoveIcon()
self.tbicon.Destroy()
sys.exit()
def OpenBackup(self,event):
BACKY=True
fs=os.system("F:\+Christian\Backup.bat")
SYS_OUT=SYS_OUT = fs
#def OpenPrefs(self,event):
# pass
#---------------- run the program -----------------------
def main(argv=None):
app = wx.App(0)
frame = MailFrame(None, -1, 'Backup Files')
frame.Center(wx.BOTH)
frame.Show(False)
app.MainLoop()
if __name__ == '__main__':
main()
--
Christian Kortenhorst
mod: +353-(0)87-6183349
home: +353-(0)1-4966287
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Python Ireland" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.ie/group/pythonireland?hl=en
-~----------~----~----~----~------~----~------~--~---