# coding=gbk
002 #__author__ = 'generated by py-ui4win'
003 import string, os, time
004 import threading
005
006 from PyUI import *
007 from MsgBox import *
008 from PyFrameBase import *
009 import UICommon
010 from CommonUtil import CommonUtils
011 from PyWin32Utils import PyWin32Util
012
013 import DownloadEaz
014
015 XP = 1
016 WIN7 = 2
017
018 def PyThreadDownloadEaz(PyClassInstance, ):
019 try:
020 PyClassInstance.DownloadEazFile()
021 except Exception, e:
022 PyLog().LogText(str(e))
023 PyLog().LogText('PyThreadExecute exit')
024
025
026 class MainFrame(PyFrameBase):
027 def __init__(self):
028 super(MainFrame, self).__init__()
029 self.clsName = self.__class__.__name__
030 self.skinFileName = self.__class__.__name__ + '.xml'
031 self.progress = 0
032 self.os = 0
033 self.progress_color = 0
034 self.eazfile_size = 0
035
036 def GetSkinFile(self):
037 return self.skinFileName
038
039 def GetWindowClassName(self):
040 return self.clsName
041
042 def OnExit(self, sendor, wParam, lParam):
043 self.ExitApp()
044
045 def OnPrepare(self, sendor, wParam, lParam):
046 self.LabelUIDescription = self.PyFindLabel("LabelUIDescription")
047 self.LabelUI6 = self.PyFindLabel("LabelUI6")
048 self.LabelUI4 = self.PyFindLabel("LabelUI4")
049 self.LabelUIOS = self.PyFindLabel("LabelUIOS")
050 self.LabelWaiting = self.PyFindLabel("LabelWaiting")
051 self.LabelUI5 = self.PyFindLabel("LabelUI5")
052 self.LabelUI2 = self.PyFindLabel("LabelUI2")
053 self.LabelUI3 = self.PyFindLabel("LabelUI3")
054 self.LabelUI12 = self.PyFindLabel("LabelUI12")
055 self.LabelUI11 = self.PyFindLabel("LabelUI11")
056 self.closebtn = self.PyFindButton("closebtn")
057 self.BtnDownloadTooSlow = self.PyFindButton("BtnDownloadTooSlow")
058 self.BtnWin7 = self.PyFindButton("BtnWin7")
059 self.BtnXP = self.PyFindButton("BtnXP")
060 self.ButtonUIReboot = self.PyFindButton("ButtonUIReboot")
061 self.adv1 = self.PyFindButton("adv1")
062 self.adv2 = self.PyFindButton("adv2")
063 self.adv3 = self.PyFindButton("adv3")
064 self.adv4 = self.PyFindButton("adv4")
065 self.adv5 = self.PyFindButton("adv5")
066 self.ProgressDownload = self.PyFindProgress("ProgressDownload")
067 self.ContainerUITitle = self.PyFindContainer("ContainerUITitle")
068 self.ContainerUIStep2 = self.PyFindContainer("ContainerUIStep2")
069 self.ContainerUIStep1 = self.PyFindContainer("ContainerUIStep1")
070 self.ContainerUIStep3 = self.PyFindContainer("ContainerUIStep3")
071 self.ContainerUIBottom = self.PyFindContainer("ContainerUIBottom")
072 self.VerticalLayoutUI1 = self.PyFindVerticalLayout("VerticalLayoutUI1")
073
074 self.ContainerUIStep2.SetVisible(False)
075 self.ContainerUIStep3.SetVisible(False)
076
077 def OnCustomTimer(self, wParam, lParam):
078 """
079 wParam: 时间id
080 """
081 if wParam == 2:
082 if self.progress_color == 0:
083 self.ProgressDownload.pControl.SetBorderColor(0xaa00000)
084 self.progress_color = 0xaa0000
085 else:
086 self.ProgressDownload.pControl.SetBorderColor(0)
087 self.progress_color = 0
088
089 def show_progress(self):
090 if self.download.has_error():
091 self.download.stop()
092 return
093 self.LabelWaiting.SetText('已经下载( %.1f / %.1f MB),请耐心等待...'%(float(self.download.get_all_download_bytes())/1024/1024, float(self.eazfile_size)/1024/1024))
094 percent = (self.download.get_all_download_bytes()*100)/self.eazfile_size
095 if self.percent < percent:
096 self.ProgressDownload.SetValue(percent)
097 self.percent = percent
098
099 def DownloadEazFile(self):
100 try:
101 self.percent = 0
102 url = ''
103 pattern = ''
104 if self.os == WIN7:
105 url = 'http://pan.baidu.com/share/link?shareid=2475901380&uk=70461429'
106 pattern = r'http:\\\\/\\\\/d\.pcs\.baidu\.com\\\\/file\\\\/f477e96d80f27717b821861ab4fa7b45\?fid=.*?&sh=1'
107 else:
108 url = 'http://pan.baidu.com/share/link?shareid=2423534928&uk=70461429'
109 pattern = r'http:\\\\/\\\\/d\.pcs\.baidu\.com\\\\/file\\\\/37c58125068409bf538e3321e5e46d57\?fid=.*?&sh=1'
110
111 self.download = DownloadEaz.EazDownload(url, pattern, self)
112 if self.download.get_file_info():
113 self.eazfile_size = self.download.file_size
114 if self.download.GetDownloadPath() is None:
115 self.LabelWaiting.SetText('磁盘空间太小啦')
116 self.SetTimer(2, 1000)
117 return
118 elif self.download.download_file(os.path.join(self.download.GetDownloadPath(),'os.eaz')):
119 if self.os == WIN7:
120 self.LabelUIDescription.SetText('已经准备好安装 Win7 系统到您的计算机')
121 else:
122 self.LabelUIDescription.SetText('已经准备好安装 XP 系统到您的计算机')
123 self.ButtonUIReboot.SetVisible(True)
124 self.ContainerUIStep1.SetVisible(False)
125 self.ContainerUIStep2.SetVisible(False)
126 self.ContainerUIStep3.SetVisible(True)
127 return
128
129 self.LabelWaiting.SetText('镜像下载出错啦')
130 #PyWinUtils().SetTimer(self.GetHWnd(), 2, 1000)
131 self.SetTimer(2, 1000)
132 except Exception, e:
133 PyLog().LogText('%s' % e)
134 self.LabelWaiting.SetText('镜像下载出错啦')
135 #PyWinUtils().SetTimer(self.GetHWnd(), 2, 1000)
136 self.SetTimer(2, 1000)
137
138 def OnBtnWin7orBtnXP(self, sendor, sType, wParam, lParam):
139 if sendor == "BtnWin7":
140 self.os = WIN7
141 self.LabelUIOS.SetBkImage('win7.jpg')
142 self.LabelUIDescription.SetText('正在下载 Win7 系统到您的计算机...')
143 else:
144 self.os = XP
145 self.LabelUIOS.SetBkImage('xp.jpg')
146 self.LabelUIDescription.SetText('正在下载 XP 系统到您的计算机...')
147 self.ProgressDownload.SetMaxValue(100)
148 self.ProgressDownload.SetValue(self.progress)
149 self.LabelWaiting.SetText('开始下载,请耐心等待')
150
151 self.ContainerUIStep1.SetVisible(False)
152 self.ContainerUIStep2.SetVisible(True)
153 self.ContainerUIStep3.SetVisible(False)
154
155 t = threading.Thread(target=PyThreadDownloadEaz,args=(self,))
156 t.start()
157
158 def OnNotify(self, sendor, sType, wParam, lParam):
159 if sType == DUI_MSGTYPE_CLICK:
160 if sendor == "BtnDownloadTooSlow":
161 PyWin32Util.ShellExcute(0, 'open', 'http://www.xiaoniuhui.com/index.php#!/%E5%B0%8F%E5%A6%9E%E4%BC%9A%E8%A3%85%E6%9C%BA', '', '', 1)
162 elif sendor == "BtnWin7" or sendor == "BtnXP":
163 self.OnBtnWin7orBtnXP(sendor, sType, wParam, lParam)
164 elif sendor == "ButtonUIReboot":
165 UICommon.ShowMessageBox(self.GetHWnd(), '准备安装', '重启安装部分未实现,请耐心等待...')
166 elif sendor == "adv1":
167 pass
168 elif sendor == "adv2":
169 pass
170 elif sendor == "adv3":
171 pass
172 elif sendor == "adv4":
173 pass
174 elif sendor == "adv5":
175 pass
176
177 if sType == DUI_MSGTYPE_ITEMSELECT:
178 pass
转载出处:人生苦短