comparison orpg/orpg_windows.py @ 23:551cd440acce traipse_dev

Final Dev build of the Day. Should reduce RAM usage more.
author sirebral
date Sat, 25 Jul 2009 21:05:18 -0500
parents 4385a7d0efd1
children c54768cffbd4
comparison
equal deleted inserted replaced
22:88cea66228d6 23:551cd440acce
41 41
42 def load_url(self,path): 42 def load_url(self,path):
43 img_type = self.get_type(path) 43 img_type = self.get_type(path)
44 try: 44 try:
45 data = urllib.urlretrieve(path) 45 data = urllib.urlretrieve(path)
46 if data: 46 if data: img = wx.Bitmap(data[0], img_type)
47 img = wx.Bitmap(data[0], img_type) 47 else: raise IOError, "Image refused to load!"
48 else: 48 except IOError, e: img = None
49 raise IOError, "Image refused to load!"
50 except IOError, e:
51 img = None
52 return img 49 return img
53 50
54 def load_file(self,path): 51 def load_file(self,path):
55 img_type = self.get_type(path) 52 img_type = self.get_type(path)
56 return wx.Bitmap(path, img_type) 53 return wx.Bitmap(path, img_type)
58 def get_type(self,file_name): 55 def get_type(self,file_name):
59 pos = string.rfind(file_name,'.') 56 pos = string.rfind(file_name,'.')
60 ext = string.lower(file_name[pos+1:]) 57 ext = string.lower(file_name[pos+1:])
61 img_type = 0 58 img_type = 0
62 # TaS - sirebral. Replaces 10 lines with 6 lines. 59 # TaS - sirebral. Replaces 10 lines with 6 lines.
63 recycle_bin = {"gif": wx.BITMAP_TYPE_GIF, "jpg": wx.BITMAP_TYPE_JPEG, "jpeg": wx.BITMAP_TYPE_JPEG, "bmp": wx.BITMAP_TYPE_BMP, "png": wx.BITMAP_TYPE_PNG} 60 recycle_bin = {"gif": wx.BITMAP_TYPE_GIF, "jpg": wx.BITMAP_TYPE_JPEG,
64 if recycle_bin.has_key(ext): 61 "jpeg": wx.BITMAP_TYPE_JPEG, "bmp": wx.BITMAP_TYPE_BMP, "png": wx.BITMAP_TYPE_PNG}
65 img_type = recycle_bin[ext] 62 if recycle_bin.has_key(ext): img_type = recycle_bin[ext]
66 else: 63 else: img_type = None ## this was imf_type = None. imf?
67 img_type = None ## this was imf_type = None. imf? 64 del recycle_bin; return img_type
68 recycle_bin = {}; return img_type
69 65
70 ################################ 66 ################################
71 ## Tabs 67 ## Tabs
72 ################################ 68 ################################
73 class orpgTabberWnd(FNB.FlatNotebook): 69 class orpgTabberWnd(FNB.FlatNotebook):
83 (tred, tgreen, tblue) = rgbcovert.rgb_tuple(tabtext) 79 (tred, tgreen, tblue) = rgbcovert.rgb_tuple(tabtext)
84 tabbedwindows = open_rpg.get_component("tabbedWindows") 80 tabbedwindows = open_rpg.get_component("tabbedWindows")
85 tabbedwindows.append(self) 81 tabbedwindows.append(self)
86 open_rpg.add_component("tabbedWindows", tabbedwindows) 82 open_rpg.add_component("tabbedWindows", tabbedwindows)
87 83
88 theme_dict = {'slanted&aqua': FNB.FNB_VC8, 'slanted&bw': FNB.FNB_VC8, 'flat&aqua': FNB.FNB_FANCY_TABS, 'flat&bw': FNB.FNB_FANCY_TABS, 'customflat': FNB.FNB_FANCY_TABS, 'customslant': FNB.FNB_VC8, 'slanted&colorful': FNB.FNB_VC8|FNB.FNB_COLORFUL_TABS, 'slant&colorful': FNB.FNB_VC8|FNB.FNB_COLORFUL_TABS} 84 theme_dict = {'slanted&aqua': FNB.FNB_VC8, 'slanted&bw': FNB.FNB_VC8, 'flat&aqua': FNB.FNB_FANCY_TABS,
85 'flat&bw': FNB.FNB_FANCY_TABS, 'customflat': FNB.FNB_FANCY_TABS, 'customslant': FNB.FNB_VC8,
86 'slanted&colorful': FNB.FNB_VC8|FNB.FNB_COLORFUL_TABS, 'slant&colorful': FNB.FNB_VC8|FNB.FNB_COLORFUL_TABS}
89 nbstyle |= theme_dict[tabtheme] 87 nbstyle |= theme_dict[tabtheme]
90 if style: 88 if style: nbstyle |= style
91 nbstyle |= style
92 self.SetWindowStyleFlag(nbstyle) 89 self.SetWindowStyleFlag(nbstyle)
93 90
94 #Tas - sirebral. Planned changes to the huge statement below. 91 #Tas - sirebral. Planned changes to the huge statement below.
95 if tabtheme == 'slanted&aqua': 92 if tabtheme == 'slanted&aqua':
96 self.SetGradientColourTo(wx.Color(0, 128, 255)) 93 self.SetGradientColourTo(wx.Color(0, 128, 255))
177 def OnIdle(self,event): 174 def OnIdle(self,event):
178 if self.auto: 175 if self.auto:
179 (screen_x,screen_y) = wx.GetMousePosition() 176 (screen_x,screen_y) = wx.GetMousePosition()
180 (x,y) = self.ScreenToClientXY(screen_x,screen_y) # translate coordinates 177 (x,y) = self.ScreenToClientXY(screen_x,screen_y) # translate coordinates
181 (w,h) = self.GetSizeTuple() 178 (w,h) = self.GetSizeTuple()
182 if x >= 0 and x < w and y >= 0 and y < h: 179 if x >= 0 and x < w and y >= 0 and y < h: self.OnMotion(x,y)
183 self.OnMotion(x,y)
184 event.Skip() 180 event.Skip()
185 181
186 def OnMotion(self,mouse_X,mouse_Y): 182 def OnMotion(self,mouse_X,mouse_Y):
187 # Gather some info using standard wxWindows calls 183 # Gather some info using standard wxWindows calls
188 (w,h) = self.GetClientSizeTuple() 184 (w,h) = self.GetClientSizeTuple()
274 self.Bind(wx.EVT_BUTTON, self.on_text_format, id=self.UNDER) 270 self.Bind(wx.EVT_BUTTON, self.on_text_format, id=self.UNDER)
275 self.Bind(wx.EVT_BUTTON, self.on_text_format, id=self.COLOR) 271 self.Bind(wx.EVT_BUTTON, self.on_text_format, id=self.COLOR)
276 272
277 def on_text_format(self,event): 273 def on_text_format(self,event):
278 id = event.GetId() 274 id = event.GetId()
279 if wx.Platform == '__WXMSW__': 275 if wx.Platform == '__WXMSW__': txt = self.text.GetLabel()
280 txt = self.text.GetLabel() 276 else: txt = self.text.GetValue()
281 else:
282 txt = self.text.GetValue()
283 (beg,end) = self.text.GetSelection() 277 (beg,end) = self.text.GetSelection()
284 if beg != end: 278 if beg != end: sel_txt = txt[beg:end]
285 sel_txt = txt[beg:end] 279 else: return
286 else:
287 return
288 print txt 280 print txt
289 # TaS - sirebral. Replaces 6 lines with 4 lines. 281 # TaS - sirebral. Replaces 6 lines with 4 lines.
290 recycle_bin = {self.BOLD: "b", self.ITALIC: "i", self.UNDER: "u"} 282 recycle_bin = {self.BOLD: "b", self.ITALIC: "i", self.UNDER: "u"}
291 if recycle_bin.has_key(id): 283 if recycle_bin.has_key(id):
292 sel_txt = "<" + recycle_bin[id] + ">" + sel_txt + "</" + recycle_bin[id] + ">" 284 sel_txt = "<" + recycle_bin[id] + ">" + sel_txt + "</" + recycle_bin[id] + ">"
293 recycle_bin = {} 285 del recycle_bin
294 286
295 elif id == self.COLOR: 287 elif id == self.COLOR:
296 hexcolor = self.r_h.do_hex_color_dlg(self) 288 hexcolor = self.r_h.do_hex_color_dlg(self)
297 if hexcolor: 289 if hexcolor:
298 sel_txt = "<font color='"+hexcolor+"'>"+sel_txt+"</font>" 290 sel_txt = "<font color='"+hexcolor+"'>"+sel_txt+"</font>"
299 self.color_button.SetBackgroundColour(hexcolor) 291 self.color_button.SetBackgroundColour(hexcolor)
300 292
301 txt = txt[:beg] + sel_txt + txt[end:] 293 txt = txt[:beg] + sel_txt + txt[end:]
302 # print txt 294 if wx.Platform == '__WXMSW__': txt = self.text.SetLabel(txt)
303 if wx.Platform == '__WXMSW__': 295 else: txt = self.text.SetValue(txt)
304 txt = self.text.SetLabel(txt)
305 else:
306 txt = self.text.SetValue(txt)
307 self.text.SetInsertionPoint(beg) 296 self.text.SetInsertionPoint(beg)
308 self.text.SetFocus() 297 self.text.SetFocus()
309 self.callback(wx.Event(self.text.GetId())) 298 self.callback(wx.Event(self.text.GetId()))
310 299
311 def set_text(self,txt): 300 def set_text(self,txt):
334 def OnLinkClicked(self, linkinfo): 323 def OnLinkClicked(self, linkinfo):
335 address = linkinfo.GetHref() 324 address = linkinfo.GetHref()
336 if address[:4] == "http": 325 if address[:4] == "http":
337 self.load_url(address) 326 self.load_url(address)
338 self.local = 0 327 self.local = 0
339 elif address[0] == "#" or self.local: 328 elif address[0] == "#" or self.local: self.base_OnLinkClicked(linkinfo)
340 self.base_OnLinkClicked(linkinfo) 329 else: self.load_url(self.path+address)
341 else:
342 self.load_url(self.path+address)
343 330
344 def load_url(self,path): 331 def load_url(self,path):
345 print path 332 print path
346 dlg = wx.ProgressDialog("HTML Document","Loading...",3,self) 333 dlg = wx.ProgressDialog("HTML Document","Loading...",3,self)
347 dlg.Update(1) 334 dlg.Update(1)
350 file = open(data[0]) 337 file = open(data[0])
351 dlg.Update(2) 338 dlg.Update(2)
352 self.SetPage(file.read()) 339 self.SetPage(file.read())
353 i = string.rfind(path,"/") 340 i = string.rfind(path,"/")
354 self.path = path[:i+1] 341 self.path = path[:i+1]
355 except: 342 except: wx.MessageBox("Invalid URL","Browser Error",wx.OK)
356 wx.MessageBox("Invalid URL","Browser Error",wx.OK)
357 #self.SetPage("<h3>Invalid URL</h3>")
358 dlg.Update(3) 343 dlg.Update(3)
359 dlg.Destroy() 344 dlg.Destroy()
360 345
361 def load_file(self,path): 346 def load_file(self,path):
362 self.LoadPage(path) 347 self.LoadPage(path)
371 def __init__(self, parent, opts, text, caption, selected=[], pos=wx.DefaultPosition): 356 def __init__(self, parent, opts, text, caption, selected=[], pos=wx.DefaultPosition):
372 wx.Dialog.__init__(self, parent, wx.ID_ANY, caption, pos, wx.DefaultSize) 357 wx.Dialog.__init__(self, parent, wx.ID_ANY, caption, pos, wx.DefaultSize)
373 sizers = { 'ctrls' : wx.BoxSizer(wx.VERTICAL), 'buttons' : wx.BoxSizer(wx.HORIZONTAL) } 358 sizers = { 'ctrls' : wx.BoxSizer(wx.VERTICAL), 'buttons' : wx.BoxSizer(wx.HORIZONTAL) }
374 self.opts = opts 359 self.opts = opts
375 self.list = wx.CheckListBox(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,opts) 360 self.list = wx.CheckListBox(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,opts)
376 for s in selected: 361 for s in selected: self.list.Check(s,1)
377 self.list.Check(s,1)
378 sizers['ctrls'].Add(wx.StaticText(self, -1, text), 0, 0) 362 sizers['ctrls'].Add(wx.StaticText(self, -1, text), 0, 0)
379 sizers['ctrls'].Add(wx.Size(10,10)) 363 sizers['ctrls'].Add(wx.Size(10,10))
380 sizers['ctrls'].Add(self.list, 1, wx.EXPAND) 364 sizers['ctrls'].Add(self.list, 1, wx.EXPAND)
381 sizers['buttons'].Add(wx.Button(self, wx.ID_OK, "OK"), 1, wx.EXPAND) 365 sizers['buttons'].Add(wx.Button(self, wx.ID_OK, "OK"), 1, wx.EXPAND)
382 sizers['buttons'].Add(wx.Size(10,10)) 366 sizers['buttons'].Add(wx.Size(10,10))
388 self.Bind(wx.EVT_BUTTON, self.on_ok, id=wx.ID_OK) 372 self.Bind(wx.EVT_BUTTON, self.on_ok, id=wx.ID_OK)
389 373
390 def on_ok(self,evt): 374 def on_ok(self,evt):
391 checked = [] 375 checked = []
392 for i in range(len(self.opts)): 376 for i in range(len(self.opts)):
393 if self.list.IsChecked(i): 377 if self.list.IsChecked(i): checked.append(i)
394 checked.append(i)
395 self.checked = checked 378 self.checked = checked
396 self.EndModal(wx.ID_OK) 379 self.EndModal(wx.ID_OK)
397 380
398 def get_selections(self): 381 def get_selections(self):
399 return self.checked 382 return self.checked
430 sizers['ctrls'].SetDimension(10,5,width-20,num*30) 413 sizers['ctrls'].SetDimension(10,5,width-20,num*30)
431 sizers['buttons'].SetDimension(10,(num*h)+5,width-20,25) 414 sizers['buttons'].SetDimension(10,(num*h)+5,width-20,25)
432 self.Bind(wx.EVT_BUTTON, self.on_ok, id=wx.ID_OK) 415 self.Bind(wx.EVT_BUTTON, self.on_ok, id=wx.ID_OK)
433 416
434 def on_ok(self,evt): 417 def on_ok(self,evt):
435 for i in range(len(self.ctrls)): 418 for i in range(len(self.ctrls)): self.vlist[i] = self.ctrls[i].GetValue()
436 self.vlist[i] = self.ctrls[i].GetValue()
437 self.EndModal(wx.ID_OK) 419 self.EndModal(wx.ID_OK)
438 420
439 def get_values(self): 421 def get_values(self):
440 return self.vlist 422 return self.vlist
441 423
535 (w,h) = self.GetClientSizeTuple() 517 (w,h) = self.GetClientSizeTuple()
536 self.sizer.SetDimension(10,10,w-20,h-20) 518 self.sizer.SetDimension(10,10,w-20,h-20)
537 519
538 def Update(self,pos,text=None): 520 def Update(self,pos,text=None):
539 self.gauge.SetValue(pos) 521 self.gauge.SetValue(pos)
540 if text: 522 if text: self.text.SetLabel(text)
541 self.text.SetLabel(text)
542 523
543 ######################### 524 #########################
544 #status frame window 525 #status frame window
545 ######################### 526 #########################
546 class status_bar(wx.StatusBar): 527 class status_bar(wx.StatusBar):
588 569
589 def set_connect_status(self,connect): 570 def set_connect_status(self,connect):
590 self.connect_status = connect 571 self.connect_status = connect
591 572
592 def Notify(self, event): 573 def Notify(self, event):
593 if self.window == 1: 574 if self.window == 1: self.bar0()
594 self.bar0() 575 elif self.window == 2: self.bar1()
595 elif self.window == 2:
596 self.bar1()
597 pass 576 pass
598 577
599 def bar1(self): 578 def bar1(self):
600 self.SetFieldsCount(1) 579 self.SetFieldsCount(1)
601 self.widths = [-1] 580 self.widths = [-1]
631 if wx.Platform == '__WXMSW__': 610 if wx.Platform == '__WXMSW__':
632 dlg = orpgProgressDlg(parent,title,text,range) 611 dlg = orpgProgressDlg(parent,title,text,range)
633 dlg.Centre() 612 dlg.Centre()
634 dlg.Show(1) 613 dlg.Show(1)
635 dlg.Raise() 614 dlg.Raise()
636 else: 615 else: dlg = wx.ProgressDialog(title,text,range,parent)
637 dlg = wx.ProgressDialog(title,text,range,parent)
638 return dlg 616 return dlg
639 617
640 def parseXml_with_dlg(parent,s,ownerDocument=None): 618 def parseXml_with_dlg(parent,s,ownerDocument=None):
641 "Parse xml with progress dialog" 619 "Parse xml with progress dialog"
642 dlg = do_progress_dlg(parent,"XML Parser","Reading Configuration Files...",2) 620 dlg = do_progress_dlg(parent,"XML Parser","Reading Configuration Files...",2)