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

杀毒

开发平台:

Visual C++

  1. #-----------------------------------------------------------------------------
  2. #Boa:Dialog:wxAboutDlg
  3. #-----------------------------------------------------------------------------
  4. # Name:        wxDialogAbout.py
  5. # Product:     ClamWin Free Antivirus
  6. #
  7. # Author:      alch [alch at users dot sourceforge dot net]
  8. #
  9. # Created:     2004/19/03
  10. # Copyright:   Copyright alch (c) 2004
  11. # Licence:     
  12. #   This program is free software; you can redistribute it and/or modify
  13. #   it under the terms of the GNU General Public License as published by
  14. #   the Free Software Foundation; either version 2 of the License, or
  15. #   (at your option) any later version.
  16. #   This program is distributed in the hope that it will be useful,
  17. #   but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. #   GNU General Public License for more details.
  20. #   You should have received a copy of the GNU General Public License
  21. #   along with this program; if not, write to the Free Software
  22. #   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. from wxPython.wx import *
  24. from wxPython.lib.stattext import wxGenStaticText
  25. from wxPython.html import *
  26. import Process
  27. import os, time, tempfile, locale
  28. import wxDialogUtils, Utils, version
  29. def create(parent, config):
  30.     return wxAboutDlg(parent, config)
  31. [wxID_WXABOUTDLG, wxID_WXABOUTDLGBUTTONOK, 
  32.  wxID_WXABOUTDLGGENSTATICTEXTCLAMWINHOME2, wxID_WXABOUTDLGSTATICBITMAPCLAM, 
  33.  wxID_WXABOUTDLGSTATICBITMAPCLAMAV, wxID_WXABOUTDLGSTATICBITMAPCLAMWIN, 
  34.  wxID_WXABOUTDLGSTATICBITMAPFDLOGO, wxID_WXABOUTDLGSTATICBITMAPPYTHON, 
  35.  wxID_WXABOUTDLGSTATICBITMAPSUPPORT, wxID_WXABOUTDLGSTATICLINE1, 
  36.  wxID_WXABOUTDLGSTATICTEXTAUTHOR1, wxID_WXABOUTDLGSTATICTEXTCLAMVER, 
  37.  wxID_WXABOUTDLGSTATICTEXTCLAMWINHOME, wxID_WXABOUTDLGSTATICTEXTCOPYRIGHT, 
  38.  wxID_WXABOUTDLGSTATICTEXTDBUPDATED1, wxID_WXABOUTDLGSTATICTEXTDBUPDATED2, 
  39.  wxID_WXABOUTDLGSTATICTEXTDBUPDATED3, wxID_WXABOUTDLGSTATICTEXTFREESW, 
  40.  wxID_WXABOUTDLGSTATICTEXTWINCLAMVER, 
  41. ] = map(lambda _init_ctrls: wxNewId(), range(19))
  42. class wxAboutDlg(wxDialog):
  43.     def _init_ctrls(self, prnt):
  44.         # generated method, don't edit
  45.         wxDialog.__init__(self, id=wxID_WXABOUTDLG, name='wxAboutDlg',
  46.               parent=prnt, pos=wxPoint(340, 258), size=wxSize(471, 346),
  47.               style=wxDEFAULT_DIALOG_STYLE, title='About ClamWin Free Antivirus')
  48.         self.SetClientSize(wxSize(463, 319))
  49.         self.SetBackgroundColour(wxColour(255, 255, 255))
  50.         self.SetAutoLayout(false)
  51.         self.SetToolTipString('About ClamWin Free Antivirus')
  52.         self.Center(wxBOTH)
  53.         EVT_CHAR_HOOK(self, self.OnCharHook)
  54.         self.staticBitmapClamWin = wxStaticBitmap(bitmap=wxBitmap('img/Title.png',
  55.               wxBITMAP_TYPE_PNG), id=wxID_WXABOUTDLGSTATICBITMAPCLAMWIN,
  56.               name='staticBitmapClamWin', parent=self, pos=wxPoint(6, 8),
  57.               size=wxSize(256, 40), style=0)
  58.         self.staticBitmapClamWin.SetToolTipString('')
  59.         self.staticTextWinClamVer = wxStaticText(id=wxID_WXABOUTDLGSTATICTEXTWINCLAMVER,
  60.               label='Version '  + version.clamwin_version, name='staticTextWinClamVer', parent=self,
  61.               pos=wxPoint(13, 48), size=wxSize(52, 16), style=0)
  62.         self.staticTextWinClamVer.SetFont(wxFont(10, wxSWISS, wxNORMAL, wxBOLD,
  63.               False))
  64.         self.staticTextWinClamVer.SetToolTipString('')
  65.         self.staticTextClamVer = wxStaticText(id=wxID_WXABOUTDLGSTATICTEXTCLAMVER,
  66.               label='ClamAV Version gets here', name='staticTextClamVer',
  67.               parent=self, pos=wxPoint(13, 96), size=wxSize(291, 15), style=0)
  68.         self.staticTextClamVer.SetToolTipString('')
  69.         self.staticTextDBUpdated1 = wxStaticText(id=wxID_WXABOUTDLGSTATICTEXTDBUPDATED1,
  70.               label='Protecting from %i Viruses', name='staticTextDBUpdated1',
  71.               parent=self, pos=wxPoint(13, 112), size=wxSize(291, 15), style=0)
  72.         self.staticTextDBUpdated1.SetToolTipString('')
  73.         self.staticBitmapClam = wxStaticBitmap(bitmap=wxBitmap('img/Clam.png',
  74.               wxBITMAP_TYPE_PNG), id=wxID_WXABOUTDLGSTATICBITMAPCLAM,
  75.               name='staticBitmapClam', parent=self, pos=wxPoint(300, 10),
  76.               size=wxSize(162, 163), style=0)
  77.         self.staticBitmapClam.SetCursor(wxStockCursor(wxCURSOR_HAND))
  78.         self.staticBitmapClam.SetToolTipString('ClamWin Free Antivirus Homepage')
  79.         EVT_LEFT_DOWN(self.staticBitmapClam, self.OnClamWinHomePage)
  80.         self.staticBitmapSupport = wxStaticBitmap(bitmap=wxBitmap('img/Support.png',
  81.               wxBITMAP_TYPE_PNG), id=wxID_WXABOUTDLGSTATICBITMAPSUPPORT,
  82.               name='staticBitmapSupport', parent=self, pos=wxPoint(352, 190),
  83.               size=wxSize(88, 32), style=0)
  84.         self.staticBitmapSupport.SetToolTipString('Donate to ClamWin')
  85.         self.staticBitmapSupport.SetCursor(wxStockCursor(wxCURSOR_HAND))
  86.         EVT_LEFT_DOWN(self.staticBitmapSupport, self.OnDonateClamWin)
  87.         self.staticTextClamWinHome = wxStaticText(id=wxID_WXABOUTDLGSTATICTEXTCLAMWINHOME,
  88.               label='Website:', name='staticTextClamWinHome', parent=self,
  89.               pos=wxPoint(13, 68), size=wxSize(59, 15), style=0)
  90.         self.staticTextClamWinHome.SetToolTipString('')
  91.         self.genStaticTextClamWinHome2 = wxGenStaticText(ID=wxID_WXABOUTDLGGENSTATICTEXTCLAMWINHOME2,
  92.               label='http://www.clamwin.com', name='genStaticTextClamWinHome2',
  93.               parent=self, pos=wxPoint(69, 68), size=wxSize(187, 15),
  94.               style=wxTRANSPARENT_WINDOW)
  95.         self.genStaticTextClamWinHome2.SetForegroundColour(wxColour(0, 0, 255))
  96.         self.genStaticTextClamWinHome2.SetCursor(wxStockCursor(wxCURSOR_HAND))
  97.         self.genStaticTextClamWinHome2.SetToolTipString('ClamWin Free Antivirus Homepage')
  98.         EVT_LEFT_DOWN(self.genStaticTextClamWinHome2, self.OnClamWinHomePage)
  99.         self.staticTextAuthor1 = wxStaticText(id=wxID_WXABOUTDLGSTATICTEXTAUTHOR1,
  100.               label='Author: alch <alch@users.sourceforge.net>',
  101.               name='staticTextAuthor1', parent=self, pos=wxPoint(13, 173),
  102.               size=wxSize(235, 16), style=0)
  103.         self.staticTextAuthor1.SetToolTipString('')
  104.         self.staticTextCopyright = wxStaticText(id=wxID_WXABOUTDLGSTATICTEXTCOPYRIGHT,
  105.               label='Copyright (c) 2004 - 2006', name='staticTextCopyright',
  106.               parent=self, pos=wxPoint(13, 189), size=wxSize(155, 17), style=0)
  107.         self.staticTextCopyright.SetToolTipString('')
  108.         self.staticTextFreeSW = wxStaticText(id=wxID_WXABOUTDLGSTATICTEXTFREESW,
  109.               label='This program is free software', name='staticTextFreeSW',
  110.               parent=self, pos=wxPoint(13, 206), size=wxSize(171, 17), style=0)
  111.         self.staticTextFreeSW.SetToolTipString('')
  112.         self.staticLine1 = wxStaticLine(id=wxID_WXABOUTDLGSTATICLINE1,
  113.               name='staticLine1', parent=self, pos=wxPoint(-2, 228),
  114.               size=wxSize(480, 2), style=0)
  115.         self.staticBitmapClamAV = wxStaticBitmap(bitmap=wxBitmap('img/ClamAV.png',
  116.               wxBITMAP_TYPE_PNG), id=wxID_WXABOUTDLGSTATICBITMAPCLAMAV,
  117.               name='staticBitmapClamAV', parent=self, pos=wxPoint(13, 238),
  118.               size=wxSize(125, 37), style=0)
  119.         self.staticBitmapClamAV.SetToolTipString('ClamAV Homepage')
  120.         self.staticBitmapClamAV.SetCursor(wxStockCursor(wxCURSOR_HAND))
  121.         EVT_LEFT_DOWN(self.staticBitmapClamAV, self.OnClamAVHomePage)
  122.         self.staticBitmapFDLogo = wxStaticBitmap(bitmap=wxBitmap('img/FD-logo.png',
  123.               wxBITMAP_TYPE_PNG), id=wxID_WXABOUTDLGSTATICBITMAPFDLOGO,
  124.               name='staticBitmapFDLogo', parent=self, pos=wxPoint(169, 241),
  125.               size=wxSize(143, 33), style=0)
  126.         self.staticBitmapFDLogo.SetToolTipString('Finndesign Homepage')
  127.         self.staticBitmapFDLogo.SetCursor(wxStockCursor(wxCURSOR_HAND))
  128.         EVT_LEFT_DOWN(self.staticBitmapFDLogo, self.OnFDHomePage)
  129.         self.staticBitmapPython = wxStaticBitmap(bitmap=wxBitmap('img/PythonPowered.gif',
  130.               wxBITMAP_TYPE_GIF), id=wxID_WXABOUTDLGSTATICBITMAPPYTHON,
  131.               name='staticBitmapPython', parent=self, pos=wxPoint(341, 235),
  132.               size=wxSize(110, 44), style=0)
  133.         self.staticBitmapPython.SetToolTipString('Python Homepage')
  134.         self.staticBitmapPython.SetCursor(wxStockCursor(wxCURSOR_HAND))
  135.         EVT_LEFT_DOWN(self.staticBitmapPython, self.OnPythonHomepage)
  136.         self.buttonOK = wxButton(id=wxID_WXABOUTDLGBUTTONOK, label='OK',
  137.               name='buttonOK', parent=self, pos=wxPoint(192, 285),
  138.               size=wxSize(71, 23), style=0)
  139.         EVT_BUTTON(self.buttonOK, wxID_WXABOUTDLGBUTTONOK, self.OnOK)
  140.         self.staticTextDBUpdated2 = wxStaticText(id=wxID_WXABOUTDLGSTATICTEXTDBUPDATED2,
  141.               label='Virus DB Version: (main: %i; daily: %i)',
  142.               name='staticTextDBUpdated2', parent=self, pos=wxPoint(13, 128),
  143.               size=wxSize(291, 15), style=0)
  144.         self.staticTextDBUpdated2.SetToolTipString('')
  145.         self.staticTextDBUpdated3 = wxStaticText(id=wxID_WXABOUTDLGSTATICTEXTDBUPDATED3,
  146.               label='Updated: %s', name='staticTextDBUpdated3', parent=self,
  147.               pos=wxPoint(13, 144), size=wxSize(291, 16), style=0)
  148.         self.staticTextDBUpdated3.SetToolTipString('')
  149.     def __init__(self, parent,  config=None):
  150.         self._init_ctrls(parent)
  151.         self. config = config
  152.         self._SetClamVersion()
  153.         self._SetDBInfo()
  154.         self.SetDefaultItem(self.buttonOK)
  155.         self.buttonOK.SetDefault()
  156.         self.staticTextClamVer.SetSize(wxSize(255, 36));
  157.     def OnOK(self, event):
  158.         self.EndModal(wxID_OK)
  159.     def OnCharHook(self, event):
  160.         if event.GetKeyCode() == WXK_ESCAPE:
  161.             self.EndModal(wxID_CANCEL)
  162.         event.Skip()
  163.     def OnClamAVHomePage(self, event):
  164.         wxDialogUtils.wxGoToInternetUrl('http://www.clamav.net')
  165.         
  166.     def OnClamWinHomePage(self, event):
  167.         wxDialogUtils.wxGoToInternetUrl('http://www.clamwin.com')
  168.     def OnPythonHomepage(self, event):
  169.         wxDialogUtils.wxGoToInternetUrl('http://www.python.org')
  170.     def OnDonateClamWin(self, event):
  171.         wxDialogUtils.wxGoToInternetUrl('http://sourceforge.net/donate/index.php?group_id=105508')
  172.         
  173.     def OnFDHomePage(self, event):
  174.         wxDialogUtils.wxGoToInternetUrl('http://www.finndesign.fi')
  175.         
  176.     def _SetClamVersion(self):
  177.         if self.config is None: 
  178.             return
  179.         if not os.path.exists(self.config.Get('ClamAV', 'ClamScan')):
  180.             ver  = 'Could not locate ClamScan executable'
  181.         else:    
  182.             cmd = '"' + self.config.Get('ClamAV', 'ClamScan')  + '" --stdout --version'
  183.             proc = None
  184.             try:
  185.                 proc = Process.ProcessOpen(cmd)
  186.                 proc.wait()
  187.                 ver = proc.stdout.readline()            
  188.                 # remove date from the clamav version
  189.                 # for some reason it is 01/01/1970 for cygwin builds
  190.                 pos = ver.rfind('/')
  191.                 ver = ver[:pos]
  192.             except:
  193.                 ver = 'Unable to retrieve ClamAV version'        
  194.             if proc is not None:
  195.                 proc.close()        
  196.         self.staticTextClamVer.SetLabel(ver)
  197.         
  198.     def _SetDBInfo(self):
  199.         try:
  200.             dbpath =  self.config.Get('ClamAV', 'Database')
  201.             mainver, mainnumv = Utils.GetDBInfo(os.path.join(dbpath, 'main.cvd'))[:2]
  202.             if mainver is None:                
  203.                 raise Exception()
  204.             dailyver, dailynumv, updated = Utils.GetDBInfo(os.path.join(dbpath, 'daily.cvd'))
  205.             if dailyver is None:                          
  206.                 raise Exception()
  207.             else:
  208.                 # set user's locale
  209.                 loc = locale.setlocale(locale.LC_TIME, '')
  210.                 try:
  211.                     updatedstr = time.strftime('%H:%M %d %b %Y', time.localtime(updated))                                                    
  212.                 finally:
  213.                     # restore the locale back to what it was
  214.                     locale.setlocale(locale.LC_TIME, loc)
  215.         except:            
  216.             dailyver, dailynumv = (0, 0)      
  217.             mainver, mainnumv = (0, 0)      
  218.             updatedstr = 'Unable to retrieve database verison'        
  219.         self.staticTextDBUpdated1.SetLabel(self.staticTextDBUpdated1.GetLabel() % 
  220.             (mainnumv + dailynumv))
  221.         self.staticTextDBUpdated2.SetLabel(self.staticTextDBUpdated2.GetLabel() % 
  222.             (mainver, dailyver))
  223.         self.staticTextDBUpdated3.SetLabel(self.staticTextDBUpdated3.GetLabel() % 
  224.             updatedstr)
  225.     
  226.             
  227.