The entire code is the below, I am a greenhand about Python, so…need your help
coding=utf8
import wx
import re
import urllib2
import time
import threading
class MyDialog(wx.Dialog):
def init(self):
wx.Dialog.init(self,None,-1,“Info”,size = (220,100),pos = wx.DefaultPosition)
self.text = wx.StaticText(self,-1,“请输入目的城市和出发城市”,(15,10))
self.text.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL,False))
self.okButton = wx.Button(self,wx.ID_OK,“OK”,(60,35))
self.okButton.SetDefault()
class QFrame(wx.Frame):
def init(self):
self.clickflag = False
self.qnum = 0
self.prehttpstring = ‘http://piao.kuxun.cn/search.php?T=Ticket&Cat=sale&From=’
self.httpstring = ‘’
wx.Frame.__init__(self,None,-1,'Ticket Seeker',size = (600,500),style = wx.DEFAULT_FRAME_STYLE^(wx.RESIZE_BORDER|wx.MAXIMIZE_BOX))
panel = wx.Panel(self,-1)
self.st1 = wx.StaticText(panel,-1,"目的城市:",(10,14))
self.st1.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL,False))
self.st2 = wx.StaticText(panel,-1,"出发城市:",(10,44))
self.st2.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL,False))
self.st3 = wx.StaticText(panel,-1,"返回结果如下:",(10,74))
self.st3.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL,False))
self.tc1 = wx.TextCtrl(panel,-1,"天水",(90,11))
self.tc1.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL,False))
self.tc2 = wx.TextCtrl(panel,-1,"北京",(90,41))
self.tc2.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL,False))
[self.bt](http://self.bt) = wx.Button(panel,-1,"查询",(260,10))
self.bt.Bind(wx.EVT_BUTTON, self.btClicked)
self.bt.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL,False))
self.cb = wx.CheckBox(panel,-1,"自动刷新",(370,15),(200,14))
self.cb.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL,False))
self.list = ['5条','10条','30条']
self.rb = wx.RadioBox(panel,-1,"请选择返回条数",(260,44),(160,45),self.list,3,wx.RA_SPECIFY_COLS)
self.rb.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL,False))
self.contents = wx.TextCtrl(panel, style=wx.TE_MULTILINE | wx.HSCROLL,size = (575,364),pos = (10,95))
self.contents.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL,False))
def query(self):
response = urllib2.urlopen(self.httpstring)
html = response.read()
res = re.findall('clickTicket.*?target',html)
res = res[0:self.qnum]
list = []
for rs in res:
tempString = re.sub('clickTicket\(', '', rs)
processedString = re.sub('\).*?target','',tempString)
list.append(processedString)
wx.CallAfter(self.contents.SetValue,'\n'.join(list))
def check(self):
while self.cb.IsChecked():
self.query()
time.sleep(2)
else:
self.query()
def btClicked(self,event):
if not self.tc1.GetValue() or not self.tc2.GetValue():
dlg = MyDialog()
dlg.ShowModal()
dlg.Destroy()
return
self.clickflag = True
self.httpstring = self.prehttpstring + self.tc2.GetValue() + '&q=' + self.tc1.GetValue()
self.t = threading.Thread(target = self.__run)
self.t.start()
def cbmonitor(self):
self.t2 = threading.Thread(target = self.__run2)
self.t2.start()
def rbwatcher(self):
self.t3 = threading.Thread(target = self.__run3)
self.t3.start()
def __run(self):
self.check()
def __run2(self):
while 1:
if self.clickflag == True and self.cb.IsChecked() == True:
self.query()
time.sleep(2)
def __run3(self):
while 1:
if self.rb.GetSelection() == 0:
self.qnum = 5
elif self.rb.GetSelection() == 1:
self.qnum = 10
else:
self.qnum = 30
time.sleep(0.5)
class App(wx.App):
def OnInit(self):
self.frame = QFrame()
self.frame.Center()
self.frame.cbmonitor()
self.frame.rbwatcher()
self.frame.Show()
return True
if name == ‘main’:
app = App()
app.MainLoop()
···
2009/1/14 Andrea Gavana andrea.gavana@gmail.com
Hi,
On Wed, Jan 14, 2009 at 10:41 AM, 4LGORITHM wrote:
Hi all,
Please look at this piece of code below,
class App(wx.App):
def OnInit(self):
self.frame = QFrame()
self.frame.Center()
self.frame.cbmonitor()
self.frame.rbwatcher()
self.frame.Show()
return True
if name == ‘main’:
app = App()
app.MainLoop()
The entire code can run in Eclipse, but can NOT run in command line(use
command of “python a.py”), anybody knows why? Please look at the snapshots
attached.
The traceback is not complete, there is actually no error shown in
there. Also, what is QFrame? What are the rbwatcher and cbmonitor
methods doing? Please provide more information as explained here:
http://wiki.wxpython.org/MakingSampleApps
Andrea.
“Imagination Is The Only Weapon In The War Against Reality.”
http://xoomer.alice.it/infinity77/
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users