comparison orpg/gametree/nodehandlers/forms.py @ 175:fd6415b8243e alpha

Traipse Alpha 'OpenRPG' {100112-01} 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 Tue, 12 Jan 2010 19:51:39 -0600
parents ff6cbd2b7620
children 537a6bbac9bd
comparison
equal deleted inserted replaced
174:ff6cbd2b7620 175:fd6415b8243e
329 self.Bind(wx.EVT_CHECKBOX, self.on_button, id=F_MULTI) 329 self.Bind(wx.EVT_CHECKBOX, self.on_button, id=F_MULTI)
330 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)
331 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)
332 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) 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 if obj.xml.get('class') not in ['rpg_grid_handler', 'textctrl_handler']: do = 'None'
354 elif end[0] == '' or start[0] != end[0]: do = 'Root'
355 elif start == end: do = 'Child'
356 elif start != end: do = 'Parent'
357 if do == 'Root':
358 complete = "!@"
359 for e in end:
360 if e != '': complete += e +'::'
361 complete = complete + obj.xml.get('name') + '@!'
362 elif do == 'Parent':
363 while start[0] == end[0]:
364 top = start[0]
365 del end[0], start[0]
366 if len(start) == 0 or len(end) == 0: break
367 complete = "!#" + top + "::"
368 for e in end: complete += e +'::'
369 complete = complete + obj.xml.get('name') + '#!'
370 elif do == 'Child':
371 while start[0] == end[0]:
372 del end[0], start[0]
373 if len(start) == 0 or len(end) == 0: break
374 complete = "!!"
375 for e in end: complete += e +'::'
376 complete = complete + obj.xml.get('name') + '!!'
377 if do != 'None': self.text.AppendText(complete); self.on_text(evt)
378 self.do_tree.Destroy()
379 if do == 'None':
380 wx.MessageBox('Invalid Reference', 'Error')
381 ##### #####
382
383 def on_text(self,evt):
384 id = evt.GetId()
385 if id == P_TITLE:
386 txt = self.title.GetValue()
387 if not len(txt): return
388 self.handler.xml.set('name',txt)
389 self.handler.rename(txt)
390 if id == F_TEXT:
391 txt = self.text.GetValue()
392 #txt = strip_text(txt) ##Does not seem to exist.
393 self.handler.text_elem.text = txt
394
395 def on_button(self,evt):
396 self.handler.text_elem.set("multiline",str(bool2int(evt.Checked())))
397
398 def on_raw_button(self,evt):
399 self.handler.text_elem.set("raw_mode",str(bool2int(evt.Checked())))
400
401 def on_hide_button(self,evt):
402 self.handler.text_elem.set("hide_title",str(bool2int(evt.Checked())))
403
404 def on_send_button(self,evt):
405 self.handler.text_elem.set("send_button",str(bool2int(evt.Checked())))
406
407
408 #######################
409 ## listbox handler
410 #######################
411 #
412 # Updated by Snowdog (April 2003)
413 # Now includesan option to remove the title from
414 # text when sent to the chat.
415 #
416 L_DROP = 0
417 L_LIST = 1
418 L_RADIO = 2
419 L_CHECK = 3
420 L_ROLLER = 4
421
422 class listbox_handler(node_handler):
423 """
424 <nodehandler class="listbox_handler" module="forms" name="">
425 <list type="1" send_button='0' hide_title='0'>
426 <option value="" selected="" >Option Text I</option>
427 <option value="" selected="" >Option Text II</option>
428 </list>
429 </nodehandler>
430 """
431 def __init__(self,xml,tree_node):
432 node_handler.__init__(self,xml,tree_node)
433 self.list_reload()
434 #print xml
435 #print self.tree.GetItemParent(tree_node)
436 if self.list.get("send_button") == "": self.list.set("send_button","0")
437 if self.list.get("hide_title") == "": self.list.set("hide_title","0")
438 if self.list.get("raw_mode") == "": self.list.set("raw_mode","0")
439
440 def list_reload(self):
441 self.list = self.xml.find('list')
442 self.options = self.list.findall('option')
443 self.captions = []
444 for opt in self.options:
445 if opt.get('caption') == None: opt.set('caption', '')
446 self.captions.append(opt.get('caption'))
447
448 def get_design_panel(self,parent):
449 return listbox_edit_panel(parent,self)
450
451 def get_use_panel(self,parent):
452 return listbox_panel(parent,self)
453
454 def get_type(self):
455 return int(self.list.get("type"))
456
457 def set_type(self,type):
458 self.list.set("type",str(type))
459
460 def is_hide_title(self):
461 return int(self.list.get("hide_title", 0))
462
463 def is_raw_send(self):
464 return int(self.list.get("raw_mode",0))
465
466 # single selection methods
467 def get_selected_node(self):
468 for opt in self.options:
469 if opt.get("selected") == "1": return opt
470 return None
471
472 def get_selected_index(self):
473 i = 0
474 for opt in self.options:
475 if opt.get("selected") == "1": return i
476 i += 1
477 return 0
478
479 def get_selected_text(self):
480 node = self.get_selected_node()
481 if node: return node.text
482 else: return ""
483
484 # mult selection methods
485 def get_selections(self):
486 opts = []
487 for opt in self.options:
488 if opt.get("selected") == "1": opts.append(opt)
489 return opts
490
491 def get_selections_text(self):
492 opts = []
493 for opt in self.options:
494 if opt.get("selected") == "1": opts.append(opt.text)
495 return opts
496
497 def get_selections_index(self):
498 opts = []
499 i = 0
500 for opt in self.options:
501 if opt.get("selected") == "1": opts.append(i)
502 i += 1
503 return opts
504
505 # setting selection method
506 def set_selected_node(self,index,selected=1):
507 if self.get_type() != L_CHECK: self.clear_selections()
508 self.options[index].set("selected", str(bool2int(selected)))
509
510 def clear_selections(self):
511 for opt in self.options: opt.set("selected","0")
512
513 # misc methods
514 def get_options(self):
515 opts = []
516 for opt in self.options: opts.append(opt.text)
517 return opts
518
519 def get_captions(self):
520 captions = []
521 for opt in self.options: captions.append(opt.get("caption"))
522 self.captions = captions
523 return captions
524
525 def get_option(self, index):
526 return self.options[index].text
527
528 def get_caption(self, index):
529 captions = self.get_captions()
530 return captions[index] or ''
531
532 def add_option(self, caption, value):
533 elem = Element('option')
534 elem.set("value","0")
535 elem.set('caption', caption)
536 elem.set("selected","0")
537 elem.text = value
538 self.list.append(elem)
539 self.list_reload()
540
541 def remove_option(self,index):
542 self.list.remove(self.options[index])
543 self.list_reload()
544
545 def edit_option(self, index, value):
546 self.options[index].text = value
547
548 def edit_caption(self, index, value):
549 self.options[index].set('caption', value)
550 self.captions[index] = value
551
552 def has_send_button(self):
553 if self.list.get("send_button") == '0': return False
554 else: return True
555
556 def get_size_constraint(self):
557 if self.get_type() == L_DROP: return 0
558 else: return 1
559
560 def tohtml(self):
561 opts = self.get_selections_text()
562 text = ""
563 if not self.is_hide_title(): text = "<b>"+self.xml.get("name")+":</b> "
564 comma = ", "
565 text += comma.join(opts)
566 return text
567
568 def get_value(self):
569 return "\n".join(self.get_selections_text())
570
571 def on_send_to_chat(self, evt):
572 txt = self.get_selected_text()
573 txt = self.chat.ParseMap(txt, self.xml)
574 if not self.is_raw_send():
575 self.chat.ParsePost(self.tohtml(), True, True)
576 return 1
577 actionlist = self.get_selections_text()
578 for line in actionlist:
579 line = self.chat.ParseMap(line, self.xml)
580 if(line != ""):
581 if line[0] != "/": ## it's not a slash command
582 self.chat.ParsePost(line, True, True)
583 else:
584 action = line
585 self.chat.chat_cmds.docmd(action)
586 return 1
587
588
589 F_LIST = wx.NewId()
590 F_SEND = wx.NewId()
591
592
593 class listbox_panel(wx.Panel):
594 def __init__(self, parent, handler):
595 wx.Panel.__init__(self, parent, -1)
596 self.handler = handler
597 self.chat = handler.chat
598 opts = []
599 values = handler.get_options()
600 captions = handler.get_captions()
601 for value in values:
602 if captions[values.index(value)] != '': opts.append(captions[values.index(value)])
603 else: opts.append(value)
604 cur_opt = handler.get_selected_text()
605 type = handler.get_type()
606 label = handler.xml.get('name')
607
608 if type == L_DROP:
609 self.list = wx.ComboBox(self, F_LIST, cur_opt, choices=opts, style=wx.CB_READONLY)
610 if self.list.GetSize()[0] > 200:
611 self.list.Destroy()
612 self.list = wx.ComboBox(self, F_LIST, cur_opt, size=(200, -1), choices=opts, style=wx.CB_READONLY)
613 elif type == L_LIST: self.list = wx.ListBox(self,F_LIST,choices=opts)
614 elif type == L_RADIO: self.list = wx.RadioBox(self,F_LIST,label,choices=opts,majorDimension=3)
615 elif type == L_CHECK:
616 self.list = wx.CheckListBox(self,F_LIST,choices=opts)
617 self.set_checks()
618
619 for i in handler.get_selections_text():
620 if type == L_DROP: self.list.SetValue( i )
621 else: self.list.SetStringSelection( i )
622 if type == L_DROP: sizer = wx.BoxSizer(wx.HORIZONTAL)
623 else: sizer = wx.BoxSizer(wx.VERTICAL)
624
625 if type != L_RADIO:
626 sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND)
627 sizer.Add(wx.Size(5,0))
628 sizer.Add(self.list, 1, wx.EXPAND)
629 if handler.has_send_button():
630 sizer.Add(wx.Button(self, F_SEND, "Send"), 0, wx.EXPAND)
631 self.Bind(wx.EVT_BUTTON, self.handler.on_send_to_chat, id=F_SEND)
632 self.sizer = sizer
633 self.SetSizer(sizer)
634 self.SetAutoLayout(True)
635 self.Fit()
636 parent.SetSize(self.GetBestSize())
637
638 if type == L_DROP: self.Bind(wx.EVT_COMBOBOX, self.on_change, id=F_LIST)
639 elif type == L_LIST: self.Bind(wx.EVT_LISTBOX, self.on_change, id=F_LIST)
640 elif type == L_RADIO: self.Bind(wx.EVT_RADIOBOX, self.on_change, id=F_LIST)
641 elif type == L_CHECK:self.Bind(wx.EVT_CHECKLISTBOX, self.on_check, id=F_LIST)
642 self.type = type
643
644 def on_change(self,evt):
645 self.handler.set_selected_node(self.list.GetSelection())
646
647 def on_check(self,evt):
648 for i in xrange(self.list.GetCount()): self.handler.set_selected_node(i, bool2int(self.list.IsChecked(i)))
649
650 def set_checks(self):
651 for i in self.handler.get_selections_index(): self.list.Check(i)
652
653
654 BUT_ADD = wx.NewId()
655 BUT_REM = wx.NewId()
656 BUT_REF = wx.NewId()
657 BUT_EDIT = wx.NewId()
658 F_TYPE = wx.NewId()
659 F_NO_TITLE = wx.NewId()
660 LIST_CTRL = wx.NewId()
661
662 class listbox_edit_panel(wx.Panel):
663 def __init__(self, parent, handler):
664 wx.Panel.__init__(self, parent, -1)
665 self.handler = handler
666 self.parent = parent
667 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL)
668
669 self.text = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
670
671 self.listbox = wx.ListCtrl(self, LIST_CTRL, style=wx.LC_REPORT)
672 self.listbox.InsertColumn(0, 'Caption')
673 self.listbox.InsertColumn(1, 'Value')
674 self.listbox.SetColumnWidth(0, 75)
675 self.listbox.SetColumnWidth(1, 300)
676 self.reload_options()
677
678 opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List']
679 self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts)
680 self.type_radios.SetSelection(handler.get_type())
681
682 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
683 self.send_button.SetValue(handler.has_send_button())
684
685 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro")
686 self.raw_send.SetValue(handler.is_raw_send())
687
688 self.hide_title = wx.CheckBox(self, F_NO_TITLE, " Hide Title")
689 self.hide_title.SetValue(handler.is_hide_title())
690
691 but_sizer = wx.BoxSizer(wx.HORIZONTAL)
692 but_sizer.Add(wx.Button(self, BUT_ADD, "Add"), 1, wx.EXPAND)
693 but_sizer.Add(wx.Size(10,10))
694 but_sizer.Add(wx.Button(self, BUT_EDIT, "Edit"), 1, wx.EXPAND)
695 but_sizer.Add(wx.Size(10,10))
696 but_sizer.Add(wx.Button(self, BUT_REM, "Remove"), 1, wx.EXPAND)
697
698 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
699 sizer.Add(self.text, 0, wx.EXPAND)
700 sizer.Add(wx.Size(10,10))
701 sizer.Add(self.type_radios, 0, wx.EXPAND)
702 sizer.Add(wx.Size(10,10))
703 sizer.Add(self.send_button, 0 , wx.EXPAND)
704 sizer.Add(self.hide_title, 0, wx.EXPAND)
705 sizer.Add(self.raw_send, 0, wx.EXPAND)
706 sizer.Add(wx.Size(10,10))
707 sizer.Add(wx.StaticText(self, -1, "Options:"), 0, wx.EXPAND)
708 sizer.Add(self.listbox,1,wx.EXPAND);
709 sizer.Add(but_sizer,0,wx.EXPAND)
710
711 self.SetSizer(sizer)
712 self.SetAutoLayout(True)
713 self.Fit()
714 parent.SetSize(self.GetBestSize())
715
716 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
717 self.Bind(wx.EVT_BUTTON, self.on_edit, id=BUT_EDIT)
718 self.Bind(wx.EVT_BUTTON, self.on_remove, id=BUT_REM)
719 self.Bind(wx.EVT_BUTTON, self.on_add, id=BUT_ADD)
720 self.Bind(wx.EVT_RADIOBOX, self.on_type, id=F_TYPE)
721 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_NO_TITLE)
722 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
723 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND)
724
725 def on_type(self,evt):
726 self.handler.set_type(evt.GetInt())
727
728 def on_add(self,evt):
729 self.dlg = wx.Frame(self, -1, 'Text', size=(300,150))
730 edit_panel = wx.Panel(self.dlg, -1)
731 sizer = wx.GridBagSizer(1, 2)
732 edit_panel.SetSizer(sizer)
733 caption_text = wx.StaticText(edit_panel, -1, 'Caption')
734 self.caption_entry = wx.TextCtrl(edit_panel, -1, '')
735 value_text = wx.StaticText(edit_panel, -1, 'Value')
736 self.value_entry = wx.TextCtrl(edit_panel, -1, '')
737 button_ok = wx.Button(edit_panel, wx.ID_OK)
738 button_cancel = wx.Button(edit_panel, wx.ID_CANCEL)
739 button_ref = wx.Button(edit_panel, BUT_REF, "Reference")
740 sizer.Add(caption_text, (0,0))
741 sizer.Add(self.caption_entry, (0,1), span=(1,3), flag=wx.EXPAND)
742 sizer.Add(value_text, (1,0))
743 sizer.Add(self.value_entry, (1,1), span=(1,3), flag=wx.EXPAND)
744 sizer.Add(button_ok, (3,0))
745 sizer.Add(button_cancel, (3,1))
746 sizer.Add(button_ref, (3,2), flag=wx.EXPAND)
747 self.Bind(wx.EVT_BUTTON, self.on_reference, id=BUT_REF)
748 self.Bind(wx.EVT_BUTTON, self.on_add_option, id=wx.ID_OK)
749 self.Bind(wx.EVT_BUTTON, self.on_edit_cancel, id=wx.ID_CANCEL)
750 self.dlg.Show()
751
752 def on_add_option(self, evt):
753 self.handler.add_option(self.caption_entry.GetValue(), self.value_entry.GetValue())
754 self.reload_options()
755 self.dlg.Destroy()
756 return
334 757
335 ## EZ_Tree Core TaS - Prof.Ebral ## 758 ## EZ_Tree Core TaS - Prof.Ebral ##
336 def on_reference(self, evt, car=None): 759 def on_reference(self, evt, car=None):
337 self.do_tree = wx.Frame(self, -1, 'Tree') 760 self.do_tree = wx.Frame(self, -1, 'Tree')
338 self.ez_tree = orpg.gametree.gametree 761 self.ez_tree = orpg.gametree.gametree
372 del end[0], start[0] 795 del end[0], start[0]
373 if len(start) == 0 or len(end) == 0: break 796 if len(start) == 0 or len(end) == 0: break
374 complete = "!!" 797 complete = "!!"
375 for e in end: complete += e +'::' 798 for e in end: complete += e +'::'
376 complete = complete + obj.xml.get('name') + '!!' 799 complete = complete + obj.xml.get('name') + '!!'
377 if do != 'None': self.text.AppendText(complete); self.on_text(evt)
378 self.do_tree.Destroy()
379 if do == 'None':
380 wx.MessageBox('Invalid Reference', 'Error')
381 ##### #####
382
383 def on_text(self,evt):
384 id = evt.GetId()
385 if id == P_TITLE:
386 txt = self.title.GetValue()
387 if not len(txt): return
388 self.handler.xml.set('name',txt)
389 self.handler.rename(txt)
390 if id == F_TEXT:
391 txt = self.text.GetValue()
392 #txt = strip_text(txt) ##Does not seem to exist.
393 self.handler.text_elem.text = txt
394
395 def on_button(self,evt):
396 self.handler.text_elem.set("multiline",str(bool2int(evt.Checked())))
397
398 def on_raw_button(self,evt):
399 self.handler.text_elem.set("raw_mode",str(bool2int(evt.Checked())))
400
401 def on_hide_button(self,evt):
402 self.handler.text_elem.set("hide_title",str(bool2int(evt.Checked())))
403
404 def on_send_button(self,evt):
405 self.handler.text_elem.set("send_button",str(bool2int(evt.Checked())))
406
407
408 #######################
409 ## listbox handler
410 #######################
411 #
412 # Updated by Snowdog (April 2003)
413 # Now includesan option to remove the title from
414 # text when sent to the chat.
415 #
416 L_DROP = 0
417 L_LIST = 1
418 L_RADIO = 2
419 L_CHECK = 3
420 L_ROLLER = 4
421
422 class listbox_handler(node_handler):
423 """
424 <nodehandler class="listbox_handler" module="forms" name="">
425 <list type="1" send_button='0' hide_title='0'>
426 <option value="" selected="" >Option Text I</option>
427 <option value="" selected="" >Option Text II</option>
428 </list>
429 </nodehandler>
430 """
431 def __init__(self,xml,tree_node):
432 node_handler.__init__(self,xml,tree_node)
433 self.list_reload()
434 #print xml
435 #print self.tree.GetItemParent(tree_node)
436 if self.list.get("send_button") == "": self.list.set("send_button","0")
437 if self.list.get("hide_title") == "": self.list.set("hide_title","0")
438 if self.list.get("raw_mode") == "": self.list.set("raw_mode","0")
439
440 def list_reload(self):
441 self.list = self.xml.find('list')
442 self.options = self.list.findall('option')
443 self.captions = []
444 for opt in self.options:
445 if opt.get('caption') == None: opt.set('caption', '')
446 self.captions.append(opt.get('caption'))
447
448 def get_design_panel(self,parent):
449 return listbox_edit_panel(parent,self)
450
451 def get_use_panel(self,parent):
452 return listbox_panel(parent,self)
453
454 def get_type(self):
455 return int(self.list.get("type"))
456
457 def set_type(self,type):
458 self.list.set("type",str(type))
459
460 def is_hide_title(self):
461 return int(self.list.get("hide_title", 0))
462
463 def is_raw_send(self):
464 return int(self.list.get("raw_mode",0))
465
466 # single selection methods
467 def get_selected_node(self):
468 for opt in self.options:
469 if opt.get("selected") == "1": return opt
470 return None
471
472 def get_selected_index(self):
473 i = 0
474 for opt in self.options:
475 if opt.get("selected") == "1": return i
476 i += 1
477 return 0
478
479 def get_selected_text(self):
480 node = self.get_selected_node()
481 if node: return node.text
482 else: return ""
483
484 # mult selection methods
485 def get_selections(self):
486 opts = []
487 for opt in self.options:
488 if opt.get("selected") == "1": opts.append(opt)
489 return opts
490
491 def get_selections_text(self):
492 opts = []
493 for opt in self.options:
494 if opt.get("selected") == "1": opts.append(opt.text)
495 return opts
496
497 def get_selections_index(self):
498 opts = []
499 i = 0
500 for opt in self.options:
501 if opt.get("selected") == "1": opts.append(i)
502 i += 1
503 return opts
504
505 # setting selection method
506 def set_selected_node(self,index,selected=1):
507 if self.get_type() != L_CHECK: self.clear_selections()
508 self.options[index].set("selected", str(bool2int(selected)))
509
510 def clear_selections(self):
511 for opt in self.options: opt.set("selected","0")
512
513 # misc methods
514 def get_options(self):
515 opts = []
516 for opt in self.options: opts.append(opt.text)
517 return opts
518
519 def get_captions(self):
520 captions = []
521 for opt in self.options: captions.append(opt.get("caption"))
522 self.captions = captions
523 return captions
524
525 def get_option(self, index):
526 return self.options[index].text
527
528 def get_caption(self, index):
529 captions = self.get_captions()
530 return captions[index] or ''
531
532 def add_option(self, caption, value):
533 elem = Element('option')
534 elem.set("value","0")
535 elem.set('caption', caption)
536 elem.set("selected","0")
537 elem.text = value
538 self.list.append(elem)
539 self.list_reload()
540
541 def remove_option(self,index):
542 self.list.remove(self.options[index])
543 self.list_reload()
544
545 def edit_option(self, index, value):
546 self.options[index].text = value
547
548 def edit_caption(self, index, value):
549 self.options[index].set('caption', value)
550 self.captions[index] = value
551
552 def has_send_button(self):
553 if self.list.get("send_button") == '0': return False
554 else: return True
555
556 def get_size_constraint(self):
557 if self.get_type() == L_DROP: return 0
558 else: return 1
559
560 def tohtml(self):
561 opts = self.get_selections_text()
562 text = ""
563 if not self.is_hide_title(): text = "<b>"+self.xml.get("name")+":</b> "
564 comma = ", "
565 text += comma.join(opts)
566 return text
567
568 def get_value(self):
569 return "\n".join(self.get_selections_text())
570
571 def on_send_to_chat(self, evt):
572 txt = self.get_selected_text()
573 txt = self.chat.ParseMap(txt, self.xml)
574 if not self.is_raw_send():
575 self.chat.ParsePost(self.tohtml(), True, True)
576 return 1
577 actionlist = self.get_selections_text()
578 for line in actionlist:
579 line = self.chat.ParseMap(line, self.xml)
580 if(line != ""):
581 if line[0] != "/": ## it's not a slash command
582 self.chat.ParsePost(line, True, True)
583 else:
584 action = line
585 self.chat.chat_cmds.docmd(action)
586 return 1
587
588
589 F_LIST = wx.NewId()
590 F_SEND = wx.NewId()
591
592
593 class listbox_panel(wx.Panel):
594 def __init__(self, parent, handler):
595 wx.Panel.__init__(self, parent, -1)
596 self.handler = handler
597 self.chat = handler.chat
598 opts = []
599 values = handler.get_options()
600 captions = handler.get_captions()
601 for value in values:
602 if captions[values.index(value)] != '': opts.append(captions[values.index(value)])
603 else: opts.append(value)
604 cur_opt = handler.get_selected_text()
605 type = handler.get_type()
606 label = handler.xml.get('name')
607
608 if type == L_DROP:
609 self.list = wx.ComboBox(self, F_LIST, cur_opt, choices=opts, style=wx.CB_READONLY)
610 if self.list.GetSize()[0] > 200:
611 self.list.Destroy()
612 self.list = wx.ComboBox(self, F_LIST, cur_opt, size=(200, -1), choices=opts, style=wx.CB_READONLY)
613 elif type == L_LIST: self.list = wx.ListBox(self,F_LIST,choices=opts)
614 elif type == L_RADIO: self.list = wx.RadioBox(self,F_LIST,label,choices=opts,majorDimension=3)
615 elif type == L_CHECK:
616 self.list = wx.CheckListBox(self,F_LIST,choices=opts)
617 self.set_checks()
618
619 for i in handler.get_selections_text():
620 if type == L_DROP: self.list.SetValue( i )
621 else: self.list.SetStringSelection( i )
622 if type == L_DROP: sizer = wx.BoxSizer(wx.HORIZONTAL)
623 else: sizer = wx.BoxSizer(wx.VERTICAL)
624
625 if type != L_RADIO:
626 sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND)
627 sizer.Add(wx.Size(5,0))
628 sizer.Add(self.list, 1, wx.EXPAND)
629 if handler.has_send_button():
630 sizer.Add(wx.Button(self, F_SEND, "Send"), 0, wx.EXPAND)
631 self.Bind(wx.EVT_BUTTON, self.handler.on_send_to_chat, id=F_SEND)
632 self.sizer = sizer
633 self.SetSizer(sizer)
634 self.SetAutoLayout(True)
635 self.Fit()
636 parent.SetSize(self.GetBestSize())
637
638 if type == L_DROP: self.Bind(wx.EVT_COMBOBOX, self.on_change, id=F_LIST)
639 elif type == L_LIST: self.Bind(wx.EVT_LISTBOX, self.on_change, id=F_LIST)
640 elif type == L_RADIO: self.Bind(wx.EVT_RADIOBOX, self.on_change, id=F_LIST)
641 elif type == L_CHECK:self.Bind(wx.EVT_CHECKLISTBOX, self.on_check, id=F_LIST)
642 self.type = type
643
644 def on_change(self,evt):
645 self.handler.set_selected_node(self.list.GetSelection())
646
647 def on_check(self,evt):
648 for i in xrange(self.list.GetCount()): self.handler.set_selected_node(i, bool2int(self.list.IsChecked(i)))
649
650 def set_checks(self):
651 for i in self.handler.get_selections_index(): self.list.Check(i)
652
653
654 BUT_ADD = wx.NewId()
655 BUT_REM = wx.NewId()
656 BUT_REF = wx.NewId()
657 BUT_EDIT = wx.NewId()
658 F_TYPE = wx.NewId()
659 F_NO_TITLE = wx.NewId()
660 LIST_CTRL = wx.NewId()
661
662 class listbox_edit_panel(wx.Panel):
663 def __init__(self, parent, handler):
664 wx.Panel.__init__(self, parent, -1)
665 self.handler = handler
666 self.parent = parent
667 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL)
668
669 self.text = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
670
671 self.listbox = wx.ListCtrl(self, LIST_CTRL, style=wx.LC_REPORT)
672 self.listbox.InsertColumn(0, 'Caption')
673 self.listbox.InsertColumn(1, 'Value')
674 self.listbox.SetColumnWidth(0, 75)
675 self.listbox.SetColumnWidth(1, 300)
676 self.reload_options()
677
678 opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List']
679 self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts)
680 self.type_radios.SetSelection(handler.get_type())
681
682 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
683 self.send_button.SetValue(handler.has_send_button())
684
685 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro")
686 self.raw_send.SetValue(handler.is_raw_send())
687
688 self.hide_title = wx.CheckBox(self, F_NO_TITLE, " Hide Title")
689 self.hide_title.SetValue(handler.is_hide_title())
690
691 but_sizer = wx.BoxSizer(wx.HORIZONTAL)
692 but_sizer.Add(wx.Button(self, BUT_ADD, "Add"), 1, wx.EXPAND)
693 but_sizer.Add(wx.Size(10,10))
694 but_sizer.Add(wx.Button(self, BUT_EDIT, "Edit"), 1, wx.EXPAND)
695 but_sizer.Add(wx.Size(10,10))
696 but_sizer.Add(wx.Button(self, BUT_REM, "Remove"), 1, wx.EXPAND)
697
698 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
699 sizer.Add(self.text, 0, wx.EXPAND)
700 sizer.Add(wx.Size(10,10))
701 sizer.Add(self.type_radios, 0, wx.EXPAND)
702 sizer.Add(wx.Size(10,10))
703 sizer.Add(self.send_button, 0 , wx.EXPAND)
704 sizer.Add(self.hide_title, 0, wx.EXPAND)
705 sizer.Add(self.raw_send, 0, wx.EXPAND)
706 sizer.Add(wx.Size(10,10))
707 sizer.Add(wx.StaticText(self, -1, "Options:"), 0, wx.EXPAND)
708 sizer.Add(self.listbox,1,wx.EXPAND);
709 sizer.Add(but_sizer,0,wx.EXPAND)
710
711 self.SetSizer(sizer)
712 self.SetAutoLayout(True)
713 self.Fit()
714 parent.SetSize(self.GetBestSize())
715
716 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
717 self.Bind(wx.EVT_BUTTON, self.on_edit, id=BUT_EDIT)
718 self.Bind(wx.EVT_BUTTON, self.on_remove, id=BUT_REM)
719 self.Bind(wx.EVT_BUTTON, self.on_add, id=BUT_ADD)
720 self.Bind(wx.EVT_RADIOBOX, self.on_type, id=F_TYPE)
721 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_NO_TITLE)
722 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
723 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND)
724
725 def on_type(self,evt):
726 self.handler.set_type(evt.GetInt())
727
728 def on_add(self,evt):
729 self.dlg = wx.Frame(self, -1, 'Text', size=(300,150))
730 edit_panel = wx.Panel(self.dlg, -1)
731 sizer = wx.GridBagSizer(1, 2)
732 edit_panel.SetSizer(sizer)
733 caption_text = wx.StaticText(edit_panel, -1, 'Caption')
734 self.caption_entry = wx.TextCtrl(edit_panel, -1, '')
735 value_text = wx.StaticText(edit_panel, -1, 'Value')
736 self.value_entry = wx.TextCtrl(edit_panel, -1, '')
737 button_ok = wx.Button(edit_panel, wx.ID_OK)
738 button_cancel = wx.Button(edit_panel, wx.ID_CANCEL)
739 button_ref = wx.Button(edit_panel, BUT_REF, "Reference")
740 sizer.Add(caption_text, (0,0))
741 sizer.Add(self.caption_entry, (0,1), span=(1,3), flag=wx.EXPAND)
742 sizer.Add(value_text, (1,0))
743 sizer.Add(self.value_entry, (1,1), span=(1,3), flag=wx.EXPAND)
744 sizer.Add(button_ok, (3,0))
745 sizer.Add(button_cancel, (3,1))
746 sizer.Add(button_ref, (3,2), flag=wx.EXPAND)
747 self.Bind(wx.EVT_BUTTON, self.on_reference, id=BUT_REF)
748 self.Bind(wx.EVT_BUTTON, self.on_add_option, id=wx.ID_OK)
749 self.Bind(wx.EVT_BUTTON, self.on_edit_cancel, id=wx.ID_CANCEL)
750 self.dlg.Show()
751
752 def on_add_option(self, evt):
753 self.handler.add_option(self.caption_entry.GetValue(), self.value_entry.GetValue())
754 self.reload_options()
755 self.dlg.Destroy()
756 return
757
758 ## EZ_Tree Core TaS - Prof.Ebral ##
759 def on_reference(self, evt, car=None):
760 self.do_tree = wx.Frame(self, -1, 'Tree')
761 self.ez_tree = orpg.gametree.gametree
762 self.temp_wnd = self.ez_tree.game_tree(self.do_tree, self.ez_tree.EZ_REF)
763 self.temp_wnd.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick)
764 self.temp_wnd.load_tree(settings.get("gametree"))
765 self.do_tree.Show()
766
767 def on_ldclick(self, evt):
768 self.rename_flag = 0
769 pt = evt.GetPosition()
770 (item, flag) = self.temp_wnd.HitTest(pt)
771 if item.IsOk():
772 obj = self.temp_wnd.GetPyData(item)
773 self.temp_wnd.SelectItem(item)
774 start = self.handler.xml.get('map').split('::')
775 end = obj.xml.get('map').split('::')
776 print obj.xml.get('class')
777 if obj.xml.get('class') != 'rpg_grid_handler' or obj.xml.get('class') != 'textctrl_handler': do = 'None'
778 elif end[0] == '' or start[0] != end[0]: do = 'Root'
779 elif start == end: do = 'Child'
780 elif start != end: do = 'Parent'
781 if do == 'Root':
782 complete = "!@"
783 for e in end:
784 if e != '': complete += e +'::'
785 complete = complete + obj.xml.get('name') + '@!'
786 elif do == 'Parent':
787 while start[0] == end[0]:
788 top = start[0]
789 del end[0], start[0]
790 if len(start) == 0 or len(end) == 0: break
791 complete = "!#" + top + "::"
792 for e in end: complete += e +'::'
793 complete = complete + obj.xml.get('name') + '#!'
794 elif do == 'Child':
795 while start[0] == end[0]:
796 del end[0], start[0]
797 if len(start) == 0 or len(end) == 0: break
798 complete = "!!"
799 for e in end: complete += e +'::'
800 complete = complete + obj.xml.get('name') + '!!'
801 if do != 'None': self.value_entry.AppendText(complete); self.reload_options() 800 if do != 'None': self.value_entry.AppendText(complete); self.reload_options()
802 self.do_tree.Destroy() 801 self.do_tree.Destroy()
803 if do == 'None': 802 if do == 'None':
804 wx.MessageBox('Invalid Reference', 'Error') 803 wx.MessageBox('Invalid Reference', 'Error')
805 ##### ##### 804 ##### #####