comparison orpg/mapper/miniatures_handler.py @ 118:217fb049bd00 alpha

Traipse Alpha 'OpenRPG' {091028-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: Adds Bookmarks (Alpha) with cool Smiley Star and Plus Symbol images! Changes made to the map for increased portability. SnowDog has changes planned in Core, though. Added an initial push to the BCG. Not much to see, just shows off how it is re-writing Main code. Fix to remote admin commands Minor fix to texted based server, works in /System/ folder Some Core changes to gametree to correctly disply Pretty Print, thanks David! Fix to Splitter Nodes not being created. Added images to Plugin Control panel for Autostart feature Fix to massive amounts of images loading; from Core fix to gsclient so with_statement imports Added 'boot' command to remote admin Prep work in Pass tool for remote admin rankings and different passwords, ei, Server, Admin, Moderator, etc. Remote Admin Commands more organized, more prep work. Added Confirmation window for sent nodes. Minor changes to allow for portability to an OpenSUSE linux OS (hopefully without breaking) {091028} 00: Made changes to gametree to start working with Element Tree, mostly from Core Minor changes to Map to start working with Element Tree, from Core Preliminary changes to map efficiency, from FlexiRPG Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Changes to main.py to start working with Element Tree
author sirebral
date Wed, 28 Oct 2009 14:24:54 -0500
parents af6bf998f425
children 9314d63c0941
comparison
equal deleted inserted replaced
117:0f18d16f3fe7 118:217fb049bd00
40 from grid import GRID_ISOMETRIC 40 from grid import GRID_ISOMETRIC
41 import os 41 import os
42 42
43 from orpg.tools.orpg_settings import settings 43 from orpg.tools.orpg_settings import settings
44 44
45 LABEL_TOOL = wx.NewId() 45 from xml.etree.ElementTree import ElementTree, Element
46 from xml.etree.ElementTree import fromstring, tostring
47
48 SHOW_LABELS_TOOL = wx.NewId()
49 AUTO_LABEL_TOOL = wx.NewId()
46 LAYER_TOOL = wx.NewId() 50 LAYER_TOOL = wx.NewId()
47 MIN_LIST_TOOL = wx.NewId() 51 MIN_LIST_TOOL = wx.NewId()
48 MIN_TOOL = wx.NewId() 52 MIN_TOOL = wx.NewId()
49 MIN_URL = wx.NewId() 53 MIN_URL = wx.NewId()
50 SERIAL_TOOL = wx.NewId() 54 SERIAL_TOOL = wx.NewId()
101 105
102 def __init__(self, parent, id, canvas): 106 def __init__(self, parent, id, canvas):
103 self.sel_min = None 107 self.sel_min = None
104 self.auto_label = 1 108 self.auto_label = 1
105 self.use_serial = 1 109 self.use_serial = 1
106 self.auto_label_cb = None
107 self.canvas = canvas 110 self.canvas = canvas
108 self.settings = settings 111 self.settings = settings
109 self.mini_rclick_menu_extra_items = {} 112 self.mini_rclick_menu_extra_items = {}
110 self.background_rclick_menu_extra_items = {} 113 self.background_rclick_menu_extra_items = {}
111 base_layer_handler.__init__(self, parent, id, canvas) 114 base_layer_handler.__init__(self, parent, id, canvas)
117 self.tooltip_delay_miliseconds = 500 120 self.tooltip_delay_miliseconds = 500
118 self.tooltip_timer = wx.CallLater(self.tooltip_delay_miliseconds, self.on_tooltip_timer) 121 self.tooltip_timer = wx.CallLater(self.tooltip_delay_miliseconds, self.on_tooltip_timer)
119 self.tooltip_timer.Stop() 122 self.tooltip_timer.Stop()
120 dt = myFileDropTarget(self) 123 dt = myFileDropTarget(self)
121 self.canvas.SetDropTarget(dt) 124 self.canvas.SetDropTarget(dt)
125 self.tooltip = wx.ToolTip('')
122 #wxInitAllImageHandlers() 126 #wxInitAllImageHandlers()
123 127
124 def build_ctrls(self): 128 def build_ctrls(self):
125 base_layer_handler.build_ctrls(self) 129 base_layer_handler.build_ctrls(self)
126 # add controls in reverse order! (unless you want them after the default tools) 130 # add controls in reverse order! (unless you want them after the default tools)
127 self.auto_label_cb = wx.CheckBox(self, wx.ID_ANY, ' Auto Label ', (-1,-1),(-1,-1))
128 self.auto_label_cb.SetValue(self.auto_label)
129 self.min_url = wx.ComboBox(self, wx.ID_ANY, "http://", style=wx.CB_DROPDOWN | wx.CB_SORT) 131 self.min_url = wx.ComboBox(self, wx.ID_ANY, "http://", style=wx.CB_DROPDOWN | wx.CB_SORT)
130 self.localBrowse = wx.Button(self, wx.ID_ANY, 'Browse', style=wx.BU_EXACTFIT) 132 self.localBrowse = wx.Button(self, wx.ID_ANY, 'Browse', style=wx.BU_EXACTFIT)
131 minilist = createMaskedButton( self, dir_struct["icon"]+'questionhead.gif', 'Edit miniature properties', wx.ID_ANY) 133 minilist = createMaskedButton( self, dir_struct["icon"]+'questionhead.gif', 'Edit miniature properties', wx.ID_ANY)
132 miniadd = wx.Button(self, wx.ID_OK, "Add Miniature", style=wx.BU_EXACTFIT) 134 miniadd = wx.Button(self, wx.ID_OK, "Add Miniature", style=wx.BU_EXACTFIT)
133 self.sizer.Add(self.auto_label_cb,0,wx.ALIGN_CENTER)
134 self.sizer.Add((6, 0))
135 self.sizer.Add(self.min_url, 1, wx.ALIGN_CENTER) 135 self.sizer.Add(self.min_url, 1, wx.ALIGN_CENTER)
136 self.sizer.Add((6, 0)) 136 self.sizer.Add((6, 0))
137 self.sizer.Add(miniadd, 0, wx.ALIGN_CENTER) 137 self.sizer.Add(miniadd, 0, wx.ALIGN_CENTER)
138 self.sizer.Add((6, 0)) 138 self.sizer.Add((6, 0))
139 self.sizer.Add(self.localBrowse, 0, wx.ALIGN_CENTER) 139 self.sizer.Add(self.localBrowse, 0, wx.ALIGN_CENTER)
140 self.sizer.Add((6, 0)) 140 self.sizer.Add((6, 0))
141 self.sizer.Add(minilist, 0, wx.ALIGN_CENTER) 141 self.sizer.Add(minilist, 0, wx.ALIGN_CENTER)
142 self.Bind(wx.EVT_BUTTON, self.on_min_list, minilist) 142 self.Bind(wx.EVT_BUTTON, self.on_min_list, minilist)
143 self.Bind(wx.EVT_BUTTON, self.on_miniature, miniadd) 143 self.Bind(wx.EVT_BUTTON, self.on_miniature, miniadd)
144 self.Bind(wx.EVT_BUTTON, self.on_browse, self.localBrowse) 144 self.Bind(wx.EVT_BUTTON, self.on_browse, self.localBrowse)
145 self.Bind(wx.EVT_CHECKBOX, self.on_label, self.auto_label_cb)
146 145
147 def on_browse(self, evt): 146 def on_browse(self, evt):
148 if not self.role_is_gm_or_player(): return 147 if not self.role_is_gm_or_player(): return
149 dlg = wx.FileDialog(None, "Select a Miniature to load", dir_struct["user"]+'webfiles/', 148 dlg = wx.FileDialog(None, "Select a Miniature to load", dir_struct["user"]+'webfiles/',
150 wildcard="Image files (*.bmp, *.gif, *.jpg, *.png)|*.bmp;*.gif;*.jpg;*.png", style=wx.OPEN) 149 wildcard="Image files (*.bmp, *.gif, *.jpg, *.png)|*.bmp;*.gif;*.jpg;*.png", style=wx.OPEN)
205 204
206 205
207 def build_menu(self,label = "Miniature"): 206 def build_menu(self,label = "Miniature"):
208 base_layer_handler.build_menu(self,label) 207 base_layer_handler.build_menu(self,label)
209 self.main_menu.AppendSeparator() 208 self.main_menu.AppendSeparator()
210 self.main_menu.Append(LABEL_TOOL,"&Auto label","",1) 209 self.main_menu.Append(SHOW_LABELS_TOOL, "&Show Labels", '', 1)
211 self.main_menu.Check(LABEL_TOOL,self.auto_label) 210 self.main_menu.Check(SHOW_LABELS_TOOL, self.canvas.layers['miniatures'].show_labels)
211 self.main_menu.Append(AUTO_LABEL_TOOL,"&Auto label","",1)
212 self.main_menu.Check(AUTO_LABEL_TOOL, self.auto_label)
212 self.main_menu.Append(SERIAL_TOOL,"&Number minis","",1) 213 self.main_menu.Append(SERIAL_TOOL,"&Number minis","",1)
213 self.main_menu.Check(SERIAL_TOOL, self.use_serial) 214 self.main_menu.Check(SERIAL_TOOL, self.use_serial)
214 self.main_menu.Append(MAP_REFRESH_MINI_URLS,"&Refresh miniatures") # Add the menu item 215 self.main_menu.Append(MAP_REFRESH_MINI_URLS,"&Refresh miniatures") # Add the menu item
215 self.main_menu.AppendSeparator() 216 self.main_menu.AppendSeparator()
216 self.main_menu.Append(MIN_MOVE, "Move") 217 self.main_menu.Append(MIN_MOVE, "Move")
217 self.canvas.Bind(wx.EVT_MENU, self.on_map_board_menu_item, id=MAP_REFRESH_MINI_URLS) # Set the handler 218 self.canvas.Bind(wx.EVT_MENU, self.on_map_board_menu_item, id=MAP_REFRESH_MINI_URLS) # Set the handler
218 self.canvas.Bind(wx.EVT_MENU, self.on_label, id=LABEL_TOOL) 219 self.canvas.Bind(wx.EVT_MENU, self.on_show_labels, id=SHOW_LABELS_TOOL)
220 self.canvas.Bind(wx.EVT_MENU, self.on_auto_label, id=AUTO_LABEL_TOOL)
219 self.canvas.Bind(wx.EVT_MENU, self.on_serial, id=SERIAL_TOOL) 221 self.canvas.Bind(wx.EVT_MENU, self.on_serial, id=SERIAL_TOOL)
220 # build miniature meenu 222 # build miniature meenu
221 self.min_menu = wx.Menu() 223 self.min_menu = wx.Menu()
222 # Rectangles and hexagons require slightly different menus because of 224 # Rectangles and hexagons require slightly different menus because of
223 # facing and heading possibilities. 225 # facing and heading possibilities.
353 self.moveSelectedMini(self.last_rclick_pos) 355 self.moveSelectedMini(self.last_rclick_pos)
354 self.deselectAndRefresh() 356 self.deselectAndRefresh()
355 return 357 return
356 elif id == MIN_REMOVE: self.canvas.layers['miniatures'].del_miniature(self.sel_rmin) 358 elif id == MIN_REMOVE: self.canvas.layers['miniatures'].del_miniature(self.sel_rmin)
357 elif id == MIN_TO_GAMETREE: 359 elif id == MIN_TO_GAMETREE:
360 ### Alpha ### implements ElementTree
358 min_xml = self.sel_rmin.toxml(action="new") 361 min_xml = self.sel_rmin.toxml(action="new")
359 node_begin = "<nodehandler module='map_miniature_nodehandler' class='map_miniature_handler' name='" 362 node = Element('nodehandler')
360 if self.sel_rmin.label: node_begin += self.sel_rmin.label + "'" 363 mini = fromstring(min_xml)
361 else: node_begin += "Unnamed Miniature'" 364 node.set('module', 'map_miniature_nodehandler')
362 node_begin += ">" 365 node.set('class', 'map_miniature_handler')
363 gametree = component.get('tree') 366 name = self.sel_rmin.label if self.sel_rmin.label else 'Unnamed Miniature'
364 node_xml = node_begin + min_xml + '</nodehandler>' 367 node.set('name', name)
365 #print "Sending this XML to insert_xml:" + node_xml 368 node.append(mini)
366 gametree.insert_xml(str(node_xml)) 369 gametree = component.get('tree')
370 gametree.insert_xml(tostring(node))
371 ### ElementTree is a nice decision from Core, kudos!! ###
367 elif id == MIN_SHOW_HIDE: 372 elif id == MIN_SHOW_HIDE:
368 if self.sel_rmin.hide: self.sel_rmin.hide = 0 373 if self.sel_rmin.hide: self.sel_rmin.hide = 0
369 else: self.sel_rmin.hide = 1 374 else: self.sel_rmin.hide = 1
370 elif id == MIN_LOCK_UNLOCK: 375 elif id == MIN_LOCK_UNLOCK:
371 if self.sel_rmin.locked: self.sel_rmin.locked = False 376 if self.sel_rmin.locked: self.sel_rmin.locked = False
498 min_url = self.min_url.GetValue() 503 min_url = self.min_url.GetValue()
499 # build url 504 # build url
500 if min_url == "" or min_url == "http://": return 505 if min_url == "" or min_url == "http://": return
501 if min_url[:7] != "http://" : min_url = "http://" + min_url 506 if min_url[:7] != "http://" : min_url = "http://" + min_url
502 # make label 507 # make label
508 if self.auto_label: print 'auto-label'
509 if not self.auto_label: print 'False'
503 if self.auto_label and min_url[-4:-3] == '.': 510 if self.auto_label and min_url[-4:-3] == '.':
504 start = min_url.rfind("/") + 1 511 start = min_url.rfind("/") + 1
505 min_label = min_url[start:len(min_url)-4] 512 min_label = min_url[start:len(min_url)-4]
506 if self.use_serial: 513 if self.use_serial:
507 min_label = '%s %d' % ( min_label, self.canvas.layers['miniatures'].next_serial() ) 514 min_label = '%s %d' % ( min_label, self.canvas.layers['miniatures'].next_serial() )
508 else: min_label = "" 515 else: min_label = ""
509 if self.min_url.FindString(min_url) == -1: self.min_url.Append(min_url) 516 if self.min_url.FindString(min_url) == -1: self.min_url.Append(min_url)
510 try: 517 try:
511 id = 'mini-' + self.canvas.frame.session.get_next_id() 518 id = 'mini-' + self.canvas.frame.session.get_next_id()
512 # make the new mini appear in top left of current viewable map 519 # make the new mini appear in top left of current viewable map
520 print id
513 dc = wx.ClientDC(self.canvas) 521 dc = wx.ClientDC(self.canvas)
514 self.canvas.PrepareDC(dc) 522 self.canvas.PrepareDC(dc)
515 dc.SetUserScale(self.canvas.layers['grid'].mapscale,self.canvas.layers['grid'].mapscale) 523 dc.SetUserScale(self.canvas.layers['grid'].mapscale,self.canvas.layers['grid'].mapscale)
516 x = dc.DeviceToLogicalX(0) 524 x = dc.DeviceToLogicalX(0)
517 y = dc.DeviceToLogicalY(0) 525 y = dc.DeviceToLogicalY(0)
527 self.canvas.send_map_data() 535 self.canvas.send_map_data()
528 self.canvas.Refresh(False) 536 self.canvas.Refresh(False)
529 #except Exception, e: 537 #except Exception, e:
530 #wx.MessageBox(str(e),"Miniature Error") 538 #wx.MessageBox(str(e),"Miniature Error")
531 539
532 def on_label(self,evt): 540 def on_show_labels(self, evt):
541 show_labels = not self.canvas.layers['miniatures'].show_labels
542 self.canvas.layers['miniatures'].show_labels = show_labels
543 self.canvas.Refresh()
544
545 def on_auto_label(self,evt):
533 self.auto_label = not self.auto_label 546 self.auto_label = not self.auto_label
534 self.auto_label_cb.SetValue(self.auto_label) 547 #self.auto_label_cb.SetValue(self.auto_label)
535 #self.send_map_data() 548 #self.send_map_data()
536 #self.Refresh() 549 #self.Refresh()
537 550
538 def on_min_list(self,evt): 551 def on_min_list(self,evt):
539 session = self.canvas.frame.session 552 session = self.canvas.frame.session
540 if (session.my_role() != session.ROLE_GM): 553 if (session.my_role() != session.ROLE_GM):
541 self.infoPost("You must be a GM to use this feature") 554 self.infoPost("You must be a GM to use this feature")
542 return 555 return
543 #d = min_list_panel(self.frame.GetParent(),self.canvas.layers,"Miniature list") 556 #d = min_list_panel(self.frame.GetParent(),self.canvas.layers,"Miniature list")
544 d = min_list_panel(self.canvas.frame,self.canvas.layers,"Miniature list") 557 d = min_list_panel(self.canvas.frame, self.canvas.layers, "Miniature list")
545 if d.ShowModal() == wx.ID_OK: d.Destroy() 558 if d.ShowModal() == wx.ID_OK: d.Destroy()
546 self.canvas.Refresh(False) 559 self.canvas.Refresh(False)
547 560
548 def on_serial(self, evt): 561 def on_serial(self, evt):
549 self.use_serial = not self.use_serial 562 self.use_serial = not self.use_serial
628 self.canvas.PrepareDC(dc) 641 self.canvas.PrepareDC(dc)
629 dc.SetUserScale(self.canvas.layers['grid'].mapscale,self.canvas.layers['grid'].mapscale) 642 dc.SetUserScale(self.canvas.layers['grid'].mapscale,self.canvas.layers['grid'].mapscale)
630 pos = wx.Point(dc.DeviceToLogicalX(pos.x), dc.DeviceToLogicalY(pos.y)) 643 pos = wx.Point(dc.DeviceToLogicalX(pos.x), dc.DeviceToLogicalY(pos.y))
631 mini_list = self.getMiniListOrSelectedMini(pos) 644 mini_list = self.getMiniListOrSelectedMini(pos)
632 if len(mini_list) > 0: 645 if len(mini_list) > 0:
633 tooltip = self.get_mini_tooltip(mini_list) 646 tooltip = mini_list[0].label
634 self.canvas.SetToolTipString(tooltip) 647 #self.canvas.SetToolTipString(mini_list[0].label)
635 else: self.canvas.SetToolTipString("") 648 #Once set, it never unsets, so it sucks.
649 else:
650 self.canvas.SetToolTipString('')
636 651
637 def on_motion(self,evt): 652 def on_motion(self,evt):
638 if evt.Dragging() and evt.LeftIsDown(): 653 if evt.Dragging() and evt.LeftIsDown():
639 if self.canvas.drag is None and self.drag_mini is not None: 654 if self.canvas.drag is None and self.drag_mini is not None:
640 drag_bmp = self.drag_mini.bmp 655 drag_bmp = self.drag_mini.bmp
641 if self.drag_mini.width and self.drag_mini.height: 656 if self.drag_mini.width and self.drag_mini.height:
642 tmp_image = drag_bmp.ConvertToImage() 657 tmp_image = drag_bmp.ConvertToImage()
643 tmp_image.Rescale(int(self.drag_mini.width * self.canvas.layers['grid'].mapscale),
644 int(self.drag_mini.height * self.canvas.layers['grid'].mapscale))
645 tmp_image.ConvertAlphaToMask() 658 tmp_image.ConvertAlphaToMask()
646 drag_bmp = tmp_image.ConvertToBitmap() 659 drag_bmp = tmp_image.ConvertToBitmap()
647 mask = wx.Mask(drag_bmp, wx.Colour(tmp_image.GetMaskRed(), 660 mask = wx.Mask(drag_bmp, wx.Colour(tmp_image.GetMaskRed(),
648 tmp_image.GetMaskGreen(), tmp_image.GetMaskBlue())) 661 tmp_image.GetMaskGreen(), tmp_image.GetMaskBlue()))
649 drag_bmp.SetMask(mask) 662 drag_bmp.SetMask(mask)
660 int(self.drag_offset.y * self.canvas.layers['grid'].mapscale)), self.canvas, False) 673 int(self.drag_offset.y * self.canvas.layers['grid'].mapscale)), self.canvas, False)
661 elif self.canvas.drag is not None: 674 elif self.canvas.drag is not None:
662 self.canvas.drag.Move(evt.GetPosition()) 675 self.canvas.drag.Move(evt.GetPosition())
663 self.canvas.drag.Show() 676 self.canvas.drag.Show()
664 # reset tool tip timer 677 # reset tool tip timer
665 self.canvas.SetToolTipString("") 678 self.canvas.SetToolTipString('')
666 self.tooltip_timer.Restart(self.tooltip_delay_miliseconds, evt.GetPosition()) 679 self.tooltip_timer.Restart(self.tooltip_delay_miliseconds, evt.GetPosition())
667 680
668 def on_left_up(self,evt): 681 def on_left_up(self,evt):
669 if self.canvas.drag: 682 if self.canvas.drag:
670 self.canvas.drag.Hide() 683 self.canvas.drag.Hide()