wxDialogCheckUpdate.py
上传用户:lswyart
上传日期:2008-06-12
资源大小:3441k
文件大小:8k
源码类别:

杀毒

开发平台:

Visual C++

  1. #Boa:Dialog:wxDialogUpdateChecker
  2. #-----------------------------------------------------------------------------
  3. # Name:        wxDialogCheckUpdate.py
  4. # Product:     ClamWin Free Antivirus
  5. #
  6. # Author:      alch [alch at users dot sourceforge dot net]
  7. #
  8. # Created:     2004/22/04
  9. # Copyright:   Copyright alch (c) 2004
  10. # Licence:     
  11. #   This program is free software; you can redistribute it and/or modify
  12. #   it under the terms of the GNU General Public License as published by
  13. #   the Free Software Foundation; either version 2 of the License, or
  14. #   (at your option) any later version.
  15. #   This program is distributed in the hope that it will be useful,
  16. #   but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. #   GNU General Public License for more details.
  19. #   You should have received a copy of the GNU General Public License
  20. #   along with this program; if not, write to the Free Software
  21. #   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. #-----------------------------------------------------------------------------
  23. from wxPython.wx import *
  24. from wxPython.html import *
  25. import os
  26. import wxDialogUtils
  27. def create(parent, config, version, url, changelog):
  28.     return wxDialogUpdateChecker(parent, config, version, url, changelog)
  29. [wxID_WXDIALOGUPDATECHECKER, wxID_WXDIALOGUPDATECHECKERBUTTONCLOSE, 
  30.  wxID_WXDIALOGUPDATECHECKERBUTTONDOWNLOAD, 
  31.  wxID_WXDIALOGUPDATECHECKERCHECKBOXDONTCHECK, 
  32.  wxID_WXDIALOGUPDATECHECKERSTATICLINEHTML, 
  33.  wxID_WXDIALOGUPDATECHECKERSTATICTEXTANNOUNCE, 
  34.  wxID_WXDIALOGUPDATECHECKERSTATICTEXTCHANGELOG, 
  35.  wxID_WXDIALOGUPDATECHECKERSTATICTEXTINSTRUCTIONS, 
  36. ] = map(lambda _init_ctrls: wxNewId(), range(8))
  37. class wxDialogUpdateChecker(wxDialog):
  38.     def _init_ctrls(self, prnt):
  39.         # generated method, don't edit
  40.         wxDialog.__init__(self, id=wxID_WXDIALOGUPDATECHECKER,
  41.               name='wxDialogUpdateChecker', parent=prnt, pos=wxPoint(229, 314),
  42.               size=wxSize(324, 272),
  43.               style=wxDEFAULT_DIALOG_STYLE|wxSTAY_ON_TOP|wxMINIMIZE_BOX,
  44.               title='ClamWin Update')
  45.         self.SetClientSize(wxSize(316, 245))
  46.         EVT_CHAR_HOOK(self, self.OnCharHook)
  47.         EVT_INIT_DIALOG(self, self.OnInitDialog)
  48.         self.staticTextAnnounce = wxStaticText(id=wxID_WXDIALOGUPDATECHECKERSTATICTEXTANNOUNCE,
  49.               label='An update of ClamWin Free Antivirus has been released. Please click on Download button and download the latest version %s',
  50.               name='staticTextAnnounce', parent=self, pos=wxPoint(13, 8),
  51.               size=wxSize(296, 40), style=wxST_NO_AUTORESIZE)
  52.         self.staticTextAnnounce.SetForegroundColour(wxColour(170, 0, 0))
  53.         self.staticTextAnnounce.SetToolTipString('')
  54.         self.staticTextAnnounce.SetFont(wxFont(8, wxSWISS, wxNORMAL, wxBOLD,
  55.               False, 'MS Shell Dlg'))
  56.         self.staticTextInstructions = wxStaticText(id=wxID_WXDIALOGUPDATECHECKERSTATICTEXTINSTRUCTIONS,
  57.               label='After you download the latest version setup file simply run it and install over the existing version.',
  58.               name='staticTextInstructions', parent=self, pos=wxPoint(13, 50),
  59.               size=wxSize(296, 28), style=0)
  60.         self.staticTextInstructions.SetForegroundColour(wxColour(0, 0, 0))
  61.         self.staticTextInstructions.SetToolTipString('')
  62.         self.staticTextChangelog = wxStaticText(id=wxID_WXDIALOGUPDATECHECKERSTATICTEXTCHANGELOG,
  63.               label='List Of Changes in Version %s:',
  64.               name='staticTextChangelog', parent=self, pos=wxPoint(13, 80),
  65.               size=wxSize(296, 13), style=wxST_NO_AUTORESIZE)
  66.         self.staticTextChangelog.SetToolTipString('')
  67.         self.staticLineHtml = wxStaticLine(id=wxID_WXDIALOGUPDATECHECKERSTATICLINEHTML,
  68.               name='staticLineHtml', parent=self, pos=wxPoint(9, 96),
  69.               size=wxSize(296, 85), style=0)
  70.         self.staticLineHtml.Show(False)
  71.         self.staticLineHtml.SetToolTipString('')
  72.         self.checkBoxDontCheck = wxCheckBox(id=wxID_WXDIALOGUPDATECHECKERCHECKBOXDONTCHECK,
  73.               label='&Do Not Check for Updates in Future',
  74.               name='checkBoxDontCheck', parent=self, pos=wxPoint(16, 190),
  75.               size=wxSize(288, 13), style=0)
  76.         self.checkBoxDontCheck.SetValue(False)
  77.         self.checkBoxDontCheck.SetToolTipString('')
  78.         EVT_CHECKBOX(self.checkBoxDontCheck,
  79.               wxID_WXDIALOGUPDATECHECKERCHECKBOXDONTCHECK,
  80.               self.OnCheckBoxDontCheckCheckbox)
  81.         self.buttonDownload = wxButton(id=wxID_WXDIALOGUPDATECHECKERBUTTONDOWNLOAD,
  82.               label='&Download', name='buttonDownload', parent=self,
  83.               pos=wxPoint(143, 212), size=wxSize(75, 23), style=0)
  84.         self.buttonDownload.SetToolTipString('')
  85.         EVT_BUTTON(self.buttonDownload,
  86.               wxID_WXDIALOGUPDATECHECKERBUTTONDOWNLOAD, self.OnButtonDownload)
  87.         self.buttonClose = wxButton(id=wxID_WXDIALOGUPDATECHECKERBUTTONCLOSE,
  88.               label='Close', name='buttonClose', parent=self, pos=wxPoint(230,
  89.               212), size=wxSize(75, 23), style=0)
  90.         self.buttonClose.SetToolTipString('')
  91.         EVT_BUTTON(self.buttonClose, wxID_WXDIALOGUPDATECHECKERBUTTONCLOSE,
  92.               self.OnButtonClose)
  93.     def __init__(self, parent, config, version, url, changelog):        
  94.         self._init_ctrls(parent)
  95.         self.html = wxHtmlWindow(parent = self, id = -1, pos = self.staticLineHtml.GetPosition(), 
  96.                     size = self.staticLineHtml.GetSize(), style = wxSTATIC_BORDER)
  97.         
  98.         #move window above tray
  99.         try:
  100.             import win32gui, win32api, win32con
  101.             hwnd = win32gui.FindWindow("Shell_TrayWnd", "")
  102.             hwnd = win32gui.FindWindowEx(hwnd, 0, "TrayNotifyWnd", "")     
  103.             rect = win32gui.GetWindowRect(hwnd)
  104.             size = self.GetSize()
  105.             self.Move((win32api.GetSystemMetrics(win32con.SM_CXSCREEN) - size.GetWidth(), rect[1] - size.GetHeight() - 5))
  106.         except Exception, e:
  107.             print e
  108.             self.Center(wxBOTH)
  109.         
  110.         
  111.         # set window icons
  112.         icons = wxIconBundle()
  113.         icons.AddIconFromFile('img/FrameIcon.ico', wxBITMAP_TYPE_ICO)
  114.         self.SetIcons(icons)
  115.                 
  116.         self._url = url
  117.         self._config = config
  118.         self.html.AppendToPage(changelog)        
  119.         self.staticTextAnnounce.SetLabel(self.staticTextAnnounce.GetLabel() % version)
  120.         self.staticTextChangelog.SetLabel(self.staticTextChangelog.GetLabel() % version)
  121.         
  122.         self.checkBoxDontCheck.SetValue(not int(self._config.Get('Updates', 'CheckVersion')))
  123.                         
  124.     def OnCharHook(self, event):
  125.         if event.GetKeyCode() == WXK_ESCAPE:
  126.             self.EndModal(wxID_OK)
  127.         else:
  128.             event.Skip()  
  129.     def OnInitDialog(self, event):
  130.         #self.textCtrl.SetInsertionPoint(0)                        
  131.         #self.textCtrl.ShowPosition(0)
  132.         event.Skip()
  133.     def OnButtonClose(self, event):
  134.         self._config.Set('Updates', 'CheckVersion', not self.checkBoxDontCheck.GetValue())
  135.         self.EndModal(wxID_OK)
  136.         event.Skip()
  137.     def OnButtonDownload(self, event):
  138.         self._config.Set('Updates', 'CheckVersion', not self.checkBoxDontCheck.GetValue())
  139.         self.EndModal(wxID_OK)
  140.         wxDialogUtils.wxGoToInternetUrl(self._url)
  141.         event.Skip()
  142.     def OnCheckBoxDontCheckCheckbox(self, event):
  143.         event.Skip()
  144.     
  145.         
  146.         
  147. if __name__ == '__main__':
  148.     import Utils, Config
  149.     currentDir = Utils.GetCurrentDir(True)
  150.     os.chdir(currentDir)        
  151.     Utils.CreateProfile()
  152.     config_file = os.path.join(Utils.GetProfileDir(True),'ClamWin.conf')                          
  153.     config = Config.Settings(config_file)    
  154.     b = config.Read()
  155.     version, url, changelog = Utils.GetOnlineVersion(config)
  156.         
  157.     app = wxPySimpleApp()
  158.    
  159.     dlg = create(None, config, version, url, changelog)
  160.     try:
  161.         dlg.ShowModal()                    
  162.     finally:
  163.         dlg.Destroy()
  164.             
  165.     app.MainLoop()
  166.