comparison orpg/gametree/nodehandlers/forms.py @ 173:0dde29a41614 alpha

Traipse Alpha 'OpenRPG' {100107-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Keeping up with Beta) New Features: Added Bookmarks Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager New TrueDebug Class in orpg_log (See documentation for usage) Portable Mercurial Tip of the Day added, from Core and community New Reference Syntax added for custom PC sheets New Child Reference for gametree New Parent Reference for gametree New Gametree Recursion method, mapping, context sensitivity, and effeciency.. New Features node with bonus nodes and Node Referencing help added Dieroller structure from Core Added 7th Sea die roller method; ie [7k3] = [7d10.takeHighest(3).open(10)] New 'Mythos' System die roller added Added new vs. die roller method for WoD; ie [3v3] = [3d10.vs(3)]. Includes support for Mythos roller New EZ_Tree Reference system. Push a button, Traipse the tree, get a reference (Alpha!!) Fixes: Fix to Text based Server Fix to Remote Admin Commands Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Fix to Map from gametree not showing to all clients Fix to gametree about menus Fix to Password Manager check on startup Fix to PC Sheets from tool nodes. They now use the tabber_panel Fixed Whiteboard ID to prevent random line or text deleting. Modified ID's to prevent non updated clients from ruining the fix. default_manifest.xml renamed to default_upmana.xml Fix to Update Manager; cleaner clode for saved repositories Fixes made to Settings Panel and no reactive settings when Ok is pressed Fixes to Alternity roller's attack roll. Uses a simple Tuple instead of a Splice Fix to Use panel of Forms and Tabbers. Now longer enters design mode
author sirebral
date Thu, 07 Jan 2010 01:53:12 -0600
parents bf799efe7a8a
children ff6cbd2b7620
comparison
equal deleted inserted replaced
170:b7206781c254 173:0dde29a41614
30 30
31 from containers import * 31 from containers import *
32 import orpg.minidom as minidom 32 import orpg.minidom as minidom
33 from orpg.orpg_xml import xml 33 from orpg.orpg_xml import xml
34 from wx.lib.scrolledpanel import ScrolledPanel 34 from wx.lib.scrolledpanel import ScrolledPanel
35 from orpg.tools.settings import settings
35 36
36 def bool2int(b): 37 def bool2int(b):
37 #in wxPython 2.5+, evt.Checked() returns True or False instead of 1.0 or 0. 38 #in wxPython 2.5+, evt.Checked() returns True or False instead of 1.0 or 0.
38 #by running the results of that through this function, we convert it. 39 #by running the results of that through this function, we convert it.
39 #if it was an int already, nothing changes. The difference between 1.0 40 #if it was an int already, nothing changes. The difference between 1.0
279 F_MULTI = wx.NewId() 280 F_MULTI = wx.NewId()
280 F_SEND_BUTTON = wx.NewId() 281 F_SEND_BUTTON = wx.NewId()
281 F_RAW_SEND = wx.NewId() 282 F_RAW_SEND = wx.NewId()
282 F_HIDE_TITLE = wx.NewId() 283 F_HIDE_TITLE = wx.NewId()
283 F_TEXT = wx.NewId() 284 F_TEXT = wx.NewId()
285 T_BUT_REF = wx.NewId()
284 286
285 class textctrl_edit_panel(wx.Panel): 287 class textctrl_edit_panel(wx.Panel):
286 def __init__(self, parent, handler): 288 def __init__(self, parent, handler):
287 wx.Panel.__init__(self, parent, -1) 289 wx.Panel.__init__(self, parent, -1)
288 self.handler = handler 290 self.handler = handler
295 self.raw_send.SetValue(handler.is_raw_send()) 297 self.raw_send.SetValue(handler.is_raw_send())
296 self.hide_title = wx.CheckBox(self, F_HIDE_TITLE, " Hide Title") 298 self.hide_title = wx.CheckBox(self, F_HIDE_TITLE, " Hide Title")
297 self.hide_title.SetValue(handler.is_hide_title()) 299 self.hide_title.SetValue(handler.is_hide_title())
298 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button") 300 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
299 self.send_button.SetValue(handler.has_send_button()) 301 self.send_button.SetValue(handler.has_send_button())
302 button_ref = wx.Button(self, T_BUT_REF, "Reference")
300 303
301 sizer.Add(wx.StaticText(self, P_TITLE, "Title:"), 0, wx.EXPAND) 304 sizer.Add(wx.StaticText(self, P_TITLE, "Title:"), 0, wx.EXPAND)
302 sizer.Add(self.title, 0, wx.EXPAND) 305 sizer.Add(self.title, 0, wx.EXPAND)
303 sizer.Add(wx.Size(10,10)) 306 sizer.Add(wx.Size(10,10))
304 sizer.Add(self.multi, 0, wx.EXPAND) 307 sizer.Add(self.multi, 0, wx.EXPAND)
305 sizer.Add(self.raw_send, 0, wx.EXPAND) 308 sizer.Add(self.raw_send, 0, wx.EXPAND)
306 sizer.Add(self.hide_title, 0, wx.EXPAND) 309 sizer.Add(self.hide_title, 0, wx.EXPAND)
307 sizer.Add(self.send_button, 0 , wx.EXPAND) 310 sizer.Add(self.send_button, 0 , wx.EXPAND)
311 sizer.Add(button_ref, 0)
308 sizer.Add(wx.Size(10,10)) 312 sizer.Add(wx.Size(10,10))
309 if handler.is_multi_line(): 313 if handler.is_multi_line():
310 sizer_style = wx.EXPAND 314 sizer_style = wx.EXPAND
311 text_style = wx.TE_MULTILINE 315 text_style = wx.TE_MULTILINE
312 multi = 1 316 multi = 1
324 self.Bind(wx.EVT_TEXT, self.on_text, id=F_TEXT) 328 self.Bind(wx.EVT_TEXT, self.on_text, id=F_TEXT)
325 self.Bind(wx.EVT_CHECKBOX, self.on_button, id=F_MULTI) 329 self.Bind(wx.EVT_CHECKBOX, self.on_button, id=F_MULTI)
326 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND) 330 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND)
327 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_HIDE_TITLE) 331 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_HIDE_TITLE)
328 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON) 332 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
333 self.Bind(wx.EVT_BUTTON, self.on_reference, id=T_BUT_REF)
334
335 ## EZ_Tree Core TaS - Prof.Ebral ##
336 def on_reference(self, evt, car=None):
337 self.do_tree = wx.Frame(self, -1, 'Tree')
338 self.ez_tree = orpg.gametree.gametree
339 self.temp_wnd = self.ez_tree.game_tree(self.do_tree, self.ez_tree.EZ_REF)
340 self.temp_wnd.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick)
341 self.temp_wnd.load_tree(settings.get("gametree"))
342 self.do_tree.Show()
343
344 def on_ldclick(self, evt):
345 self.rename_flag = 0
346 pt = evt.GetPosition()
347 (item, flag) = self.temp_wnd.HitTest(pt)
348 if item.IsOk():
349 obj = self.temp_wnd.GetPyData(item)
350 self.temp_wnd.SelectItem(item)
351 start = self.handler.xml.get('map').split('::')
352 end = obj.xml.get('map').split('::')
353 x = 0
354 if start[x] == end[x]:
355 try:
356 while start[x] == end[x]:
357 del end[x], start[x]
358 x += 1
359 except:
360 complete = "!!"
361 for e in end: complete += e +'::'
362 complete = complete + obj.xml.get('name') + '!!'
363 self.text.AppendText(complete); self.on_text(evt)
364 self.do_tree.Destroy()
365 ##### #####
329 366
330 def on_text(self,evt): 367 def on_text(self,evt):
331 id = evt.GetId() 368 id = evt.GetId()
332 if id == P_TITLE: 369 if id == P_TITLE:
333 txt = self.title.GetValue() 370 txt = self.title.GetValue()
375 </list> 412 </list>
376 </nodehandler> 413 </nodehandler>
377 """ 414 """
378 def __init__(self,xml,tree_node): 415 def __init__(self,xml,tree_node):
379 node_handler.__init__(self,xml,tree_node) 416 node_handler.__init__(self,xml,tree_node)
380 self.list = self.xml.find('list') 417 self.list_reload()
381 self.options = self.list.findall('option') 418 #print xml
419 #print self.tree.GetItemParent(tree_node)
382 if self.list.get("send_button") == "": self.list.set("send_button","0") 420 if self.list.get("send_button") == "": self.list.set("send_button","0")
383 if self.list.get("hide_title") == "": self.list.set("hide_title","0") 421 if self.list.get("hide_title") == "": self.list.set("hide_title","0")
384 if self.list.get("raw_mode") == "": self.list.set("raw_mode","0") 422 if self.list.get("raw_mode") == "": self.list.set("raw_mode","0")
423
424 def list_reload(self):
425 self.list = self.xml.find('list')
426 self.options = self.list.findall('option')
427 self.captions = []
428 for opt in self.options:
429 if opt.get('caption') == None: opt.set('caption', '')
430 self.captions.append(opt.get('caption'))
385 431
386 def get_design_panel(self,parent): 432 def get_design_panel(self,parent):
387 return listbox_edit_panel(parent,self) 433 return listbox_edit_panel(parent,self)
388 434
389 def get_use_panel(self,parent): 435 def get_use_panel(self,parent):
452 def get_options(self): 498 def get_options(self):
453 opts = [] 499 opts = []
454 for opt in self.options: opts.append(opt.text) 500 for opt in self.options: opts.append(opt.text)
455 return opts 501 return opts
456 502
457 def get_option(self,index): 503 def get_captions(self):
504 captions = []
505 for opt in self.options: captions.append(opt.get("caption"))
506 self.captions = captions
507 return captions
508
509 def get_option(self, index):
458 return self.options[index].text 510 return self.options[index].text
459 511
460 def add_option(self,opt): 512 def get_caption(self, index):
513 captions = self.get_captions()
514 return captions[index] or ''
515
516 def add_option(self, caption, value):
461 elem = Element('option') 517 elem = Element('option')
462 elem.set("value","0") 518 elem.set("value","0")
519 elem.set('caption', caption)
463 elem.set("selected","0") 520 elem.set("selected","0")
464 elem.text = opt 521 elem.text = value
465 self.list.append(elem) 522 self.list.append(elem)
466 self.options = self.list.findall('option') 523 self.list_reload()
467 524
468 def remove_option(self,index): 525 def remove_option(self,index):
469 self.list.remove(self.options[index]) 526 self.list.remove(self.options[index])
470 self.options = self.list.findall('option') 527 self.list_reload()
471 528
472 def edit_option(self,index,value): 529 def edit_option(self, index, value):
473 self.options[index].text = value 530 self.options[index].text = value
531
532 def edit_caption(self, index, value):
533 self.options[index].set('caption', value)
534 self.captions[index] = value
474 535
475 def has_send_button(self): 536 def has_send_button(self):
476 if self.list.get("send_button") == '0': return False 537 if self.list.get("send_button") == '0': return False
477 else: return True 538 else: return True
478 539
516 class listbox_panel(wx.Panel): 577 class listbox_panel(wx.Panel):
517 def __init__(self, parent, handler): 578 def __init__(self, parent, handler):
518 wx.Panel.__init__(self, parent, -1) 579 wx.Panel.__init__(self, parent, -1)
519 self.handler = handler 580 self.handler = handler
520 self.chat = handler.chat 581 self.chat = handler.chat
521 opts = handler.get_options() 582 opts = []
583 values = handler.get_options()
584 captions = handler.get_captions()
585 for value in values:
586 if captions[values.index(value)] != '': opts.append(captions[values.index(value)])
587 else: opts.append(value)
522 cur_opt = handler.get_selected_text() 588 cur_opt = handler.get_selected_text()
523 type = handler.get_type() 589 type = handler.get_type()
524 label = handler.xml.get('name') 590 label = handler.xml.get('name')
525 591
526 if type == L_DROP: 592 if type == L_DROP:
569 for i in self.handler.get_selections_index(): self.list.Check(i) 635 for i in self.handler.get_selections_index(): self.list.Check(i)
570 636
571 637
572 BUT_ADD = wx.NewId() 638 BUT_ADD = wx.NewId()
573 BUT_REM = wx.NewId() 639 BUT_REM = wx.NewId()
640 BUT_REF = wx.NewId()
574 BUT_EDIT = wx.NewId() 641 BUT_EDIT = wx.NewId()
575 F_TYPE = wx.NewId() 642 F_TYPE = wx.NewId()
576 F_NO_TITLE = wx.NewId() 643 F_NO_TITLE = wx.NewId()
644 LIST_CTRL = wx.NewId()
577 645
578 class listbox_edit_panel(wx.Panel): 646 class listbox_edit_panel(wx.Panel):
579 def __init__(self, parent, handler): 647 def __init__(self, parent, handler):
580 wx.Panel.__init__(self, parent, -1) 648 wx.Panel.__init__(self, parent, -1)
581 self.handler = handler 649 self.handler = handler
650 self.parent = parent
582 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL) 651 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL)
583 652
584 self.text = wx.TextCtrl(self, P_TITLE, handler.xml.get('name')) 653 self.text = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
585 654
586 opts = handler.get_options() 655 self.listbox = wx.ListCtrl(self, LIST_CTRL, style=wx.LC_REPORT)
587 self.listbox = wx.ListBox(self, F_LIST, choices=opts, style=wx.LB_HSCROLL|wx.LB_SINGLE|wx.LB_NEEDED_SB) 656 self.listbox.InsertColumn(0, 'Caption')
657 self.listbox.InsertColumn(1, 'Value')
658 self.listbox.SetColumnWidth(0, 75)
659 self.listbox.SetColumnWidth(1, 300)
660 self.reload_options()
661
588 opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List'] 662 opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List']
589 self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts) 663 self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts)
590 self.type_radios.SetSelection(handler.get_type()) 664 self.type_radios.SetSelection(handler.get_type())
591 665
592 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button") 666 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
634 708
635 def on_type(self,evt): 709 def on_type(self,evt):
636 self.handler.set_type(evt.GetInt()) 710 self.handler.set_type(evt.GetInt())
637 711
638 def on_add(self,evt): 712 def on_add(self,evt):
639 dlg = wx.TextEntryDialog(self, 'Enter option?','Add Option', '') 713 self.dlg = wx.Frame(self, -1, 'Text', size=(300,150))
640 if dlg.ShowModal() == wx.ID_OK: 714 edit_panel = wx.Panel(self.dlg, -1)
641 self.handler.add_option(dlg.GetValue()) 715 sizer = wx.GridBagSizer(1, 2)
642 dlg.Destroy() 716 edit_panel.SetSizer(sizer)
717 caption_text = wx.StaticText(edit_panel, -1, 'Caption')
718 self.caption_entry = wx.TextCtrl(edit_panel, -1, '')
719 value_text = wx.StaticText(edit_panel, -1, 'Value')
720 self.value_entry = wx.TextCtrl(edit_panel, -1, '')
721 button_ok = wx.Button(edit_panel, wx.ID_OK)
722 button_cancel = wx.Button(edit_panel, wx.ID_CANCEL)
723 button_ref = wx.Button(edit_panel, BUT_REF, "Reference")
724 sizer.Add(caption_text, (0,0))
725 sizer.Add(self.caption_entry, (0,1), span=(1,3), flag=wx.EXPAND)
726 sizer.Add(value_text, (1,0))
727 sizer.Add(self.value_entry, (1,1), span=(1,3), flag=wx.EXPAND)
728 sizer.Add(button_ok, (3,0))
729 sizer.Add(button_cancel, (3,1))
730 sizer.Add(button_ref, (3,2), flag=wx.EXPAND)
731 self.Bind(wx.EVT_BUTTON, self.on_reference, id=BUT_REF)
732 self.Bind(wx.EVT_BUTTON, self.on_add_option, id=wx.ID_OK)
733 self.Bind(wx.EVT_BUTTON, self.on_edit_cancel, id=wx.ID_CANCEL)
734 self.dlg.Show()
735
736 def on_add_option(self, evt):
737 self.handler.add_option(self.caption_entry.GetValue(), self.value_entry.GetValue())
643 self.reload_options() 738 self.reload_options()
739 self.dlg.Destroy()
740 return
741
742 ## EZ_Tree Core TaS - Prof.Ebral ##
743 def on_reference(self, evt, car=None):
744 self.do_tree = wx.Frame(self, -1, 'Tree')
745 self.ez_tree = orpg.gametree.gametree
746 self.temp_wnd = self.ez_tree.game_tree(self.do_tree, self.ez_tree.EZ_REF)
747 self.temp_wnd.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick)
748 self.temp_wnd.load_tree(settings.get("gametree"))
749 self.do_tree.Show()
750
751 def on_ldclick(self, evt):
752 self.rename_flag = 0
753 pt = evt.GetPosition()
754 (item, flag) = self.temp_wnd.HitTest(pt)
755 if item.IsOk():
756 obj = self.temp_wnd.GetPyData(item)
757 self.temp_wnd.SelectItem(item)
758 start = self.handler.xml.get('map').split('::')
759 end = obj.xml.get('map').split('::')
760 x = 0
761 if start[x] == end[x]:
762 try:
763 while start[x] == end[x]:
764 del end[x], start[x]
765 x += 1
766 except:
767 complete = "!!"
768 for e in end: complete += e +'::'
769 complete = complete + obj.xml.get('name') + '!!'
770 self.value_entry.SetValue(complete); self.reload_options()
771 self.do_tree.Destroy()
772 ##### #####
773
774 def on_edit_ok(self, evt):
775 self.handler.edit_caption(self.index, self.caption_entry.GetValue())
776 self.handler.edit_option(self.index, self.value_entry.GetValue())
777 self.reload_options()
778 self.dlg.Destroy()
779 component.add('tree', component.get('tree_back')) ## Backup
780 return
781
782 def on_edit_cancel(self, evt):
783 self.dlg.Destroy()
784 component.add('tree', component.get('tree_back')) ## Backup
785 return
644 786
645 def on_remove(self,evt): 787 def on_remove(self,evt):
646 index = self.listbox.GetSelection() 788 index = self.listbox.GetSelection()
647 if index >= 0: 789 if index >= 0:
648 self.handler.remove_option(index) 790 self.handler.remove_option(index)
649 self.reload_options() 791 self.reload_options()
650 792
651 def on_edit(self,evt): 793 def on_edit(self,evt):
652 index = self.listbox.GetSelection() 794 self.index = self.listbox.GetFocusedItem()
653 if index >= 0: 795 if self.index >= 0:
654 txt = self.handler.get_option(index) 796 self.dlg = wx.Frame(self, -1, 'Text', size=(300,150))
655 dlg = wx.TextEntryDialog(self, 'Enter option?','Edit Option', txt) 797 edit_panel = wx.Panel(self.dlg, -1)
656 if dlg.ShowModal() == wx.ID_OK: 798 sizer = wx.GridBagSizer(1, 2)
657 self.handler.edit_option(index,dlg.GetValue()) 799 edit_panel.SetSizer(sizer)
658 dlg.Destroy() 800 caption_text = wx.StaticText(edit_panel, -1, 'Caption')
659 self.reload_options() 801 self.caption_entry = wx.TextCtrl(edit_panel, -1, self.handler.get_caption(self.index))
802 value_text = wx.StaticText(edit_panel, -1, 'Value')
803 self.value_entry = wx.TextCtrl(edit_panel, -1, self.handler.get_option(self.index))
804 button_ok = wx.Button(edit_panel, wx.ID_OK)
805 button_cancel = wx.Button(edit_panel, wx.ID_CANCEL)
806 button_ref = wx.Button(edit_panel, BUT_REF, "Reference")
807 sizer.Add(caption_text, (0,0))
808 sizer.Add(self.caption_entry, (0,1), span=(1,3), flag=wx.EXPAND)
809 sizer.Add(value_text, (1,0))
810 sizer.Add(self.value_entry, (1,1), span=(1,3), flag=wx.EXPAND)
811 sizer.Add(button_ok, (3,0))
812 sizer.Add(button_cancel, (3,1))
813 sizer.Add(button_ref, (3,2), flag=wx.EXPAND)
814 self.Bind(wx.EVT_BUTTON, self.on_reference, id=BUT_REF)
815 self.Bind(wx.EVT_BUTTON, self.on_edit_ok, id=wx.ID_OK)
816 self.Bind(wx.EVT_BUTTON, self.on_edit_cancel, id=wx.ID_CANCEL)
817 self.dlg.Show()
660 818
661 def reload_options(self): 819 def reload_options(self):
662 self.listbox.Clear() 820 self.listbox.DeleteAllItems()
663 for opt in self.handler.get_options(): 821 values = self.handler.get_options()
664 self.listbox.Append(opt) 822 captions = self.handler.get_captions()
823 for index in range(len(values)):
824 self.listbox.Append((captions[index], values[index]))
665 825
666 def on_text(self,evt): 826 def on_text(self,evt):
667 id = evt.GetId() 827 id = evt.GetId()
668 txt = self.text.GetValue() 828 txt = self.text.GetValue()
669 if not len(txt): return 829 if not len(txt): return