comparison orpg/mapper/miniatures_handler.py @ 20:072ffc1d466f traipse_dev

2nd attempt. Still untested.
author sirebral
date Sat, 25 Jul 2009 19:23:25 -0500
parents 78407d627cba
children 5aff3ef1ae46
comparison
equal deleted inserted replaced
19:78407d627cba 20:072ffc1d466f
141 self.Bind(wx.EVT_BUTTON, self.on_miniature, miniadd) 141 self.Bind(wx.EVT_BUTTON, self.on_miniature, miniadd)
142 self.Bind(wx.EVT_BUTTON, self.on_browse, self.localBrowse) 142 self.Bind(wx.EVT_BUTTON, self.on_browse, self.localBrowse)
143 self.Bind(wx.EVT_CHECKBOX, self.on_label, self.auto_label_cb) 143 self.Bind(wx.EVT_CHECKBOX, self.on_label, self.auto_label_cb)
144 144
145 def on_browse(self, evt): 145 def on_browse(self, evt):
146 if not self.role_is_gm_or_player(): 146 if not self.role_is_gm_or_player(): return
147 return 147 dlg = wx.FileDialog(None, "Select a Miniature to load", orpg.dirpath.dir_struct["user"]+'webfiles/',
148 dlg = wx.FileDialog(None, "Select a Miniature to load", orpg.dirpath.dir_struct["user"]+'webfiles/', wildcard="Image files (*.bmp, *.gif, *.jpg, *.png)|*.bmp;*.gif;*.jpg;*.png", style=wx.OPEN) 148 wildcard="Image files (*.bmp, *.gif, *.jpg, *.png)|*.bmp;*.gif;*.jpg;*.png", style=wx.OPEN)
149 if not dlg.ShowModal() == wx.ID_OK: 149 if not dlg.ShowModal() == wx.ID_OK:
150 dlg.Destroy() 150 dlg.Destroy()
151 return 151 return
152 file = open(dlg.GetPath(), "rb") 152 file = open(dlg.GetPath(), "rb")
153 imgdata = file.read() 153 imgdata = file.read()
162 dc.SetUserScale(self.canvas.layers['grid'].mapscale,self.canvas.layers['grid'].mapscale) 162 dc.SetUserScale(self.canvas.layers['grid'].mapscale,self.canvas.layers['grid'].mapscale)
163 x = dc.DeviceToLogicalX(0) 163 x = dc.DeviceToLogicalX(0)
164 y = dc.DeviceToLogicalY(0) 164 y = dc.DeviceToLogicalY(0)
165 thread.start_new_thread(self.canvas.layers['miniatures'].upload, (postdata, dlg.GetPath()), {'pos':cmpPoint(x,y)}) 165 thread.start_new_thread(self.canvas.layers['miniatures'].upload, (postdata, dlg.GetPath()), {'pos':cmpPoint(x,y)})
166 else: 166 else:
167 try: 167 try: min_url = open_rpg.get_component("cherrypy") + filename
168 min_url = open_rpg.get_component("cherrypy") + filename 168 except: return
169 except:
170 return
171 min_url = dlg.GetDirectory().replace(orpg.dirpath.dir_struct["user"]+'webfiles' + os.sep, 169 min_url = dlg.GetDirectory().replace(orpg.dirpath.dir_struct["user"]+'webfiles' + os.sep,
172 open_rpg.get_component("cherrypy")) + '/' + filename 170 open_rpg.get_component("cherrypy")) + '/' + filename
173 # build url 171 # build url
174 if min_url == "" or min_url == "http://": 172 if min_url == "" or min_url == "http://": return
175 return 173 if min_url[:7] != "http://": min_url = "http://" + min_url
176 if min_url[:7] != "http://" :
177 min_url = "http://" + min_url
178 # make label 174 # make label
179 if self.auto_label and min_url[-4:-3] == '.': 175 if self.auto_label and min_url[-4:-3] == '.':
180 start = min_url.rfind("/") + 1 176 start = min_url.rfind("/") + 1
181 min_label = min_url[start:len(min_url)-4] 177 min_label = min_url[start:len(min_url)-4]
182 if self.use_serial: 178 if self.use_serial: min_label = '%s %d' % ( min_label, self.canvas.layers['miniatures'].next_serial() )
183 min_label = '%s %d' % ( min_label, self.canvas.layers['miniatures'].next_serial() ) 179 else: min_label = ""
184 else: 180 if self.min_url.FindString(min_url) == -1: self.min_url.Append(min_url)
185 min_label = ""
186 if self.min_url.FindString(min_url) == -1:
187 self.min_url.Append(min_url)
188 try: 181 try:
189 id = 'mini-' + self.canvas.frame.session.get_next_id() 182 id = 'mini-' + self.canvas.frame.session.get_next_id()
190 # make the new mini appear in top left of current viewable map 183 # make the new mini appear in top left of current viewable map
191 dc = wx.ClientDC(self.canvas) 184 dc = wx.ClientDC(self.canvas)
192 self.canvas.PrepareDC(dc) 185 self.canvas.PrepareDC(dc)
245 heading_menu.Append(MIN_HEADING_NORTHWEST,"Northwest") 238 heading_menu.Append(MIN_HEADING_NORTHWEST,"Northwest")
246 align_menu = wx.Menu() 239 align_menu = wx.Menu()
247 align_menu.Append(MIN_ALIGN_GRID_CENTER,"&Center") 240 align_menu.Append(MIN_ALIGN_GRID_CENTER,"&Center")
248 align_menu.Append(MIN_ALIGN_GRID_TL,"&Top-Left") 241 align_menu.Append(MIN_ALIGN_GRID_TL,"&Top-Left")
249 # This is a hack to simulate a menu title, due to problem in Linux 242 # This is a hack to simulate a menu title, due to problem in Linux
250 if wx.Platform == '__WXMSW__': 243 if wx.Platform == '__WXMSW__': self.min_menu.SetTitle(label)
251 self.min_menu.SetTitle(label)
252 else: 244 else:
253 self.min_menu.Append(MIN_TITLE_HACK,label) 245 self.min_menu.Append(MIN_TITLE_HACK,label)
254 self.min_menu.AppendSeparator() 246 self.min_menu.AppendSeparator()
255 self.min_menu.Append(MIN_SHOW_HIDE,"Show / Hide") 247 self.min_menu.Append(MIN_SHOW_HIDE,"Show / Hide")
256 self.min_menu.Append(MIN_LOCK_UNLOCK, "Lock / Unlock") 248 self.min_menu.Append(MIN_LOCK_UNLOCK, "Lock / Unlock")
310 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=MIN_LOCK_FRONT) 302 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=MIN_LOCK_FRONT)
311 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=MIN_FRONTBACK_UNLOCK) 303 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=MIN_FRONTBACK_UNLOCK)
312 ######### add plugin added menu items ######### 304 ######### add plugin added menu items #########
313 if len(self.mini_rclick_menu_extra_items)>0: 305 if len(self.mini_rclick_menu_extra_items)>0:
314 self.min_menu.AppendSeparator() 306 self.min_menu.AppendSeparator()
315 for item in self.mini_rclick_menu_extra_items.items(): 307 for item in self.mini_rclick_menu_extra_items.items(): self.min_menu.Append(item[1], item[0])
316 self.min_menu.Append(item[1], item[0])
317 if len(self.background_rclick_menu_extra_items)>0: 308 if len(self.background_rclick_menu_extra_items)>0:
318 self.main_menu.AppendSeparator() 309 self.main_menu.AppendSeparator()
319 for item in self.background_rclick_menu_extra_items.items(): 310 for item in self.background_rclick_menu_extra_items.items():
320 self.main_menu.Append(item[1], item[0]) 311 self.main_menu.Append(item[1], item[0])
321 312
329 self.min_select_menu.SetTitle("Select Miniature") 320 self.min_select_menu.SetTitle("Select Miniature")
330 loop_count = 1 321 loop_count = 1
331 try: 322 try:
332 for m in min_list: 323 for m in min_list:
333 # Either use the miniatures label for the selection list 324 # Either use the miniatures label for the selection list
334 if m.label: 325 if m.label: self.min_select_menu.Append(loop_count, m.label)
335 self.min_select_menu.Append(loop_count, m.label)
336 # Or use part of the images filename as an identifier 326 # Or use part of the images filename as an identifier
337 else: 327 else:
338 string_split = string.split(m.path,"/",) 328 string_split = string.split(m.path,"/",)
339 last_string = string_split[len(string_split)-1] 329 last_string = string_split[len(string_split)-1]
340 self.min_select_menu.Append(loop_count, 'Unlabeled - ' + last_string[:len(last_string)-4]) 330 self.min_select_menu.Append(loop_count, 'Unlabeled - ' + last_string[:len(last_string)-4])
341 self.canvas.Bind(wx.EVT_MENU, self.min_selected, id=loop_count) 331 self.canvas.Bind(wx.EVT_MENU, self.min_selected, id=loop_count)
342 loop_count += 1 332 loop_count += 1
343 self.canvas.PopupMenu(self.min_select_menu,pos) 333 self.canvas.PopupMenu(self.min_select_menu,pos)
344 except: 334 except: pass
345 pass
346 335
347 def min_selected(self,evt): 336 def min_selected(self,evt):
348 # this is the callback function for the menu that is used to choose 337 # this is the callback function for the menu that is used to choose
349 # between minis when you right click, left click or left double click 338 # between minis when you right click, left click or left double click
350 # on a stack of two or more 339 # on a stack of two or more
357 if id == MIN_MOVE: 346 if id == MIN_MOVE:
358 if self.sel_min: 347 if self.sel_min:
359 self.moveSelectedMini(self.last_rclick_pos) 348 self.moveSelectedMini(self.last_rclick_pos)
360 self.deselectAndRefresh() 349 self.deselectAndRefresh()
361 return 350 return
362 elif id == MIN_REMOVE: 351 elif id == MIN_REMOVE: self.canvas.layers['miniatures'].del_miniature(self.sel_rmin)
363 self.canvas.layers['miniatures'].del_miniature(self.sel_rmin)
364 elif id == MIN_TO_GAMETREE: 352 elif id == MIN_TO_GAMETREE:
365 min_xml = self.sel_rmin.toxml(action="new") 353 min_xml = self.sel_rmin.toxml(action="new")
366 node_begin = "<nodehandler module='map_miniature_nodehandler' class='map_miniature_handler' name='" 354 node_begin = "<nodehandler module='map_miniature_nodehandler' class='map_miniature_handler' name='"
367 if self.sel_rmin.label: 355 if self.sel_rmin.label: node_begin += self.sel_rmin.label + "'"
368 node_begin += self.sel_rmin.label + "'" 356 else: node_begin += "Unnamed Miniature'"
369 else:
370 node_begin += "Unnamed Miniature'"
371 node_begin += ">" 357 node_begin += ">"
372 gametree = open_rpg.get_component('tree') 358 gametree = open_rpg.get_component('tree')
373 node_xml = node_begin + min_xml + '</nodehandler>' 359 node_xml = node_begin + min_xml + '</nodehandler>'
374 #print "Sending this XML to insert_xml:" + node_xml 360 #print "Sending this XML to insert_xml:" + node_xml
375 gametree.insert_xml(node_xml) 361 gametree.insert_xml(node_xml)
376 elif id == MIN_SHOW_HIDE: 362 elif id == MIN_SHOW_HIDE:
377 if self.sel_rmin.hide: 363 if self.sel_rmin.hide: self.sel_rmin.hide = 0
378 self.sel_rmin.hide = 0 364 else: self.sel_rmin.hide = 1
379 else:
380 self.sel_rmin.hide = 1
381 elif id == MIN_LOCK_UNLOCK: 365 elif id == MIN_LOCK_UNLOCK:
382 if self.sel_rmin.locked: 366 if self.sel_rmin.locked: self.sel_rmin.locked = False
383 self.sel_rmin.locked = False 367 else: self.sel_rmin.locked = True
384 else:
385 self.sel_rmin.locked = True
386 if self.sel_rmin == self.sel_min: 368 if self.sel_rmin == self.sel_min:
387 # when we lock / unlock the selected mini make sure it isn't still selected 369 # when we lock / unlock the selected mini make sure it isn't still selected
388 # or it might easily get moved by accident and be hard to move back 370 # or it might easily get moved by accident and be hard to move back
389 self.sel_min.selected = False 371 self.sel_min.selected = False
390 self.sel_min.isUpdated = True 372 self.sel_min.isUpdated = True
393 MIN_HEADING_NORTHWEST: FACE_NORTHWEST, MIN_HEADING_NORTHEAST: FACE_NORTHEAST, 375 MIN_HEADING_NORTHWEST: FACE_NORTHWEST, MIN_HEADING_NORTHEAST: FACE_NORTHEAST,
394 MIN_HEADING_EAST: FACE_EAST, MIN_HEADING_SOUTHEAST: FACE_SOUTHEAST, MIN_HEADING_SOUTHWEST: FACE_SOUTHWEST, 376 MIN_HEADING_EAST: FACE_EAST, MIN_HEADING_SOUTHEAST: FACE_SOUTHEAST, MIN_HEADING_SOUTHWEST: FACE_SOUTHWEST,
395 MIN_HEADING_SOUTH: FACE_SOUTH, MIN_HEADING_WEST: FACE_WEST} 377 MIN_HEADING_SOUTH: FACE_SOUTH, MIN_HEADING_WEST: FACE_WEST}
396 if recycle_bin.has_key(id): 378 if recycle_bin.has_key(id):
397 self.sel_rmin.heading = recycle_bin[id] 379 self.sel_rmin.heading = recycle_bin[id]
398 recycle_bin = {} 380 del recycle_bin
399 recycle_bin = {MIN_FACING_NONE: FACE_NONE, MIN_FACING_NORTH: FACE_NORTH, 381 recycle_bin = {MIN_FACING_NONE: FACE_NONE, MIN_FACING_NORTH: FACE_NORTH,
400 MIN_FACING_NORTHWEST: FACE_NORTHWEST, MIN_FACING_NORTHEAST: FACE_NORTHEAST, 382 MIN_FACING_NORTHWEST: FACE_NORTHWEST, MIN_FACING_NORTHEAST: FACE_NORTHEAST,
401 MIN_FACING_EAST: FACE_EAST, MIN_FACING_SOUTHEAST: FACE_SOUTHEAST, MIN_FACING_SOUTHWEST: FACE_SOUTHWEST, 383 MIN_FACING_EAST: FACE_EAST, MIN_FACING_SOUTHEAST: FACE_SOUTHEAST, MIN_FACING_SOUTHWEST: FACE_SOUTHWEST,
402 MIN_FACING_SOUTH: FACE_SOUTH, MIN_FACING_WEST: FACE_WEST} 384 MIN_FACING_SOUTH: FACE_SOUTH, MIN_FACING_WEST: FACE_WEST}
403 if recycle_bin.has_key(id): 385 if recycle_bin.has_key(id):
404 self.sel_rmin.face = recycle_bin[id] 386 self.sel_rmin.face = recycle_bin[id]
405 recycle_bin = {} 387 del recycle_bin
406 elif id == MIN_ALIGN_GRID_CENTER: 388 elif id == MIN_ALIGN_GRID_CENTER: self.sel_rmin.snap_to_align = SNAPTO_ALIGN_CENTER
407 self.sel_rmin.snap_to_align = SNAPTO_ALIGN_CENTER 389 elif id == MIN_ALIGN_GRID_TL: self.sel_rmin.snap_to_align = SNAPTO_ALIGN_TL
408 elif id == MIN_ALIGN_GRID_TL:
409 self.sel_rmin.snap_to_align = SNAPTO_ALIGN_TL
410 elif id == MIN_PROP_DLG: 390 elif id == MIN_PROP_DLG:
411 old_lock_value = self.sel_rmin.locked 391 old_lock_value = self.sel_rmin.locked
412 dlg = min_edit_dialog(self.canvas.frame.GetParent(),self.sel_rmin) 392 dlg = min_edit_dialog(self.canvas.frame.GetParent(),self.sel_rmin)
413 if dlg.ShowModal() == wx.ID_OK: 393 if dlg.ShowModal() == wx.ID_OK:
414 if self.sel_rmin == self.sel_min and self.sel_rmin.locked != old_lock_value: 394 if self.sel_rmin == self.sel_min and self.sel_rmin.locked != old_lock_value:
492 # Note: only one update (with the final values) will be sent 472 # Note: only one update (with the final values) will be sent
493 self.canvas.layers['miniatures'].collapse_zorder() 473 self.canvas.layers['miniatures'].collapse_zorder()
494 474
495 elif id == MIN_FRONTBACK_UNLOCK: 475 elif id == MIN_FRONTBACK_UNLOCK:
496 #print "Unlocked/ unstickified..." 476 #print "Unlocked/ unstickified..."
497 if self.sel_rmin.zorder == MIN_STICKY_BACK: 477 if self.sel_rmin.zorder == MIN_STICKY_BACK: self.sel_rmin.zorder = MIN_STICKY_BACK + 1
498 self.sel_rmin.zorder = MIN_STICKY_BACK + 1 478 elif self.sel_rmin.zorder == MIN_STICKY_FRONT: self.sel_rmin.zorder = MIN_STICKY_FRONT - 1
499 elif self.sel_rmin.zorder == MIN_STICKY_FRONT: 479 elif id == MIN_LOCK_BACK: self.sel_rmin.zorder = MIN_STICKY_BACK
500 self.sel_rmin.zorder = MIN_STICKY_FRONT - 1 480 elif id == MIN_LOCK_FRONT: self.sel_rmin.zorder = MIN_STICKY_FRONT
501 elif id == MIN_LOCK_BACK:
502 #print "lock back"
503 self.sel_rmin.zorder = MIN_STICKY_BACK
504 elif id == MIN_LOCK_FRONT:
505 #print "lock front"
506 self.sel_rmin.zorder = MIN_STICKY_FRONT
507 # Pretty much, we always want to refresh when we go through here 481 # Pretty much, we always want to refresh when we go through here
508 # This helps us remove the redundant self.Refresh() on EVERY menu event 482 # This helps us remove the redundant self.Refresh() on EVERY menu event
509 # that we process above. 483 # that we process above.
510 self.sel_rmin.isUpdated = True 484 self.sel_rmin.isUpdated = True
511 self.canvas.Refresh(False) 485 self.canvas.Refresh(False)
516 if (session.my_role() != session.ROLE_GM) and (session.my_role() != session.ROLE_PLAYER) and (session.use_roles()): 490 if (session.my_role() != session.ROLE_GM) and (session.my_role() != session.ROLE_PLAYER) and (session.use_roles()):
517 self.infoPost("You must be either a player or GM to use the miniature Layer") 491 self.infoPost("You must be either a player or GM to use the miniature Layer")
518 return 492 return
519 min_url = self.min_url.GetValue() 493 min_url = self.min_url.GetValue()
520 # build url 494 # build url
521 if min_url == "" or min_url == "http://": 495 if min_url == "" or min_url == "http://": return
522 return 496 if min_url[:7] != "http://" : min_url = "http://" + min_url
523 if min_url[:7] != "http://" :
524 min_url = "http://" + min_url
525 # make label 497 # make label
526 if self.auto_label and min_url[-4:-3] == '.': 498 if self.auto_label and min_url[-4:-3] == '.':
527 start = min_url.rfind("/") + 1 499 start = min_url.rfind("/") + 1
528 min_label = min_url[start:len(min_url)-4] 500 min_label = min_url[start:len(min_url)-4]
529 if self.use_serial: 501 if self.use_serial:
530 min_label = '%s %d' % ( min_label, self.canvas.layers['miniatures'].next_serial() ) 502 min_label = '%s %d' % ( min_label, self.canvas.layers['miniatures'].next_serial() )
531 else: 503 else: min_label = ""
532 min_label = "" 504 if self.min_url.FindString(min_url) == -1: self.min_url.Append(min_url)
533 if self.min_url.FindString(min_url) == -1:
534 self.min_url.Append(min_url)
535 try: 505 try:
536 id = 'mini-' + self.canvas.frame.session.get_next_id() 506 id = 'mini-' + self.canvas.frame.session.get_next_id()
537 # make the new mini appear in top left of current viewable map 507 # make the new mini appear in top left of current viewable map
538 dc = wx.ClientDC(self.canvas) 508 dc = wx.ClientDC(self.canvas)
539 self.canvas.PrepareDC(dc) 509 self.canvas.PrepareDC(dc)
565 if (session.my_role() != session.ROLE_GM): 535 if (session.my_role() != session.ROLE_GM):
566 self.infoPost("You must be a GM to use this feature") 536 self.infoPost("You must be a GM to use this feature")
567 return 537 return
568 #d = min_list_panel(self.frame.GetParent(),self.canvas.layers,"Miniature list") 538 #d = min_list_panel(self.frame.GetParent(),self.canvas.layers,"Miniature list")
569 d = min_list_panel(self.canvas.frame,self.canvas.layers,"Miniature list") 539 d = min_list_panel(self.canvas.frame,self.canvas.layers,"Miniature list")
570 if d.ShowModal() == wx.ID_OK: 540 if d.ShowModal() == wx.ID_OK: d.Destroy()
571 d.Destroy()
572 self.canvas.Refresh(False) 541 self.canvas.Refresh(False)
573 542
574 def on_serial(self, evt): 543 def on_serial(self, evt):
575 self.use_serial = not self.use_serial 544 self.use_serial = not self.use_serial
576 545
583 552
584 #################################################################### 553 ####################################################################
585 ## old functions, changed an awful lot 554 ## old functions, changed an awful lot
586 555
587 def on_left_down(self, evt): 556 def on_left_down(self, evt):
588 if not self.role_is_gm_or_player() or self.alreadyDealingWithMenu(): 557 if not self.role_is_gm_or_player() or self.alreadyDealingWithMenu(): return
589 return
590 mini = self.find_mini(evt, evt.CmdDown() and self.role_is_gm()) 558 mini = self.find_mini(evt, evt.CmdDown() and self.role_is_gm())
591 if mini: 559 if mini:
592 deselecting_selected_mini = (mini == self.sel_min) #clicked on the selected mini 560 deselecting_selected_mini = (mini == self.sel_min) #clicked on the selected mini
593 self.deselectAndRefresh() 561 self.deselectAndRefresh()
594 self.drag_mini = mini 562 self.drag_mini = mini
595 if deselecting_selected_mini: 563 if deselecting_selected_mini: return
596 return
597 self.sel_min = mini 564 self.sel_min = mini
598 self.sel_min.selected = True 565 self.sel_min.selected = True
599 self.canvas.Refresh() 566 self.canvas.Refresh()
600 else: 567 else:
601 self.drag_mini = None 568 self.drag_mini = None
602 pos = self.getLogicalPosition(evt) 569 pos = self.getLogicalPosition(evt)
603 self.moveSelectedMini(pos) 570 self.moveSelectedMini(pos)
604 self.deselectAndRefresh() 571 self.deselectAndRefresh()
605 572
606 def on_right_down(self, evt): 573 def on_right_down(self, evt):
607 if not self.role_is_gm_or_player() or self.alreadyDealingWithMenu(): 574 if not self.role_is_gm_or_player() or self.alreadyDealingWithMenu(): return
608 return
609 self.last_rclick_pos = self.getLogicalPosition(evt) 575 self.last_rclick_pos = self.getLogicalPosition(evt)
610 mini = self.find_mini(evt, evt.CmdDown() and self.role_is_gm()) 576 mini = self.find_mini(evt, evt.CmdDown() and self.role_is_gm())
611 if mini: 577 if mini:
612 self.sel_rmin = mini 578 self.sel_rmin = mini
613 if self.sel_min: 579 if self.sel_min: self.min_menu.Enable(MIN_MOVE, True)
614 self.min_menu.Enable(MIN_MOVE, True) 580 else: self.min_menu.Enable(MIN_MOVE, False)
615 else:
616 self.min_menu.Enable(MIN_MOVE, False)
617 self.prepare_mini_rclick_menu(evt) 581 self.prepare_mini_rclick_menu(evt)
618 self.do_min_menu(evt.GetPosition()) 582 self.do_min_menu(evt.GetPosition())
619 else:# pass it on 583 else:# pass it on
620 if self.sel_min: 584 if self.sel_min: self.main_menu.Enable(MIN_MOVE, True)
621 self.main_menu.Enable(MIN_MOVE, True) 585 else: self.main_menu.Enable(MIN_MOVE, False)
622 else:
623 self.main_menu.Enable(MIN_MOVE, False)
624 self.prepare_background_rclick_menu(evt) 586 self.prepare_background_rclick_menu(evt)
625 base_layer_handler.on_right_down(self, evt) 587 base_layer_handler.on_right_down(self, evt)
626 588
627 #################################################################### 589 ####################################################################
628 ## new functions 590 ## new functions
630 def on_drop_files(self, x, y, filepaths): 592 def on_drop_files(self, x, y, filepaths):
631 # currently we ignore multiple files 593 # currently we ignore multiple files
632 filepath = filepaths[0] 594 filepath = filepaths[0]
633 start1 = filepath.rfind("\\") + 1 # check for both slashes in path to be on the safe side 595 start1 = filepath.rfind("\\") + 1 # check for both slashes in path to be on the safe side
634 start2 = filepath.rfind("/") + 1 596 start2 = filepath.rfind("/") + 1
635 if start1 < start2: 597 if start1 < start2: start1 = start2
636 start1 = start2
637 filename = filepath[start1:] 598 filename = filepath[start1:]
638 pos = filename.rfind('.') 599 pos = filename.rfind('.')
639 ext = filename[pos:].lower() 600 ext = filename[pos:].lower()
640 #ext = filename[-4:].lower() 601 #ext = filename[-4:].lower()
641 if(ext != ".bmp" and ext != ".gif" and ext != ".jpg" and ext != ".jpeg" and ext != ".png"): 602 if(ext != ".bmp" and ext != ".gif" and ext != ".jpg" and ext != ".jpeg" and ext != ".png"):
661 pos = wx.Point(dc.DeviceToLogicalX(pos.x), dc.DeviceToLogicalY(pos.y)) 622 pos = wx.Point(dc.DeviceToLogicalX(pos.x), dc.DeviceToLogicalY(pos.y))
662 mini_list = self.getMiniListOrSelectedMini(pos) 623 mini_list = self.getMiniListOrSelectedMini(pos)
663 if len(mini_list) > 0: 624 if len(mini_list) > 0:
664 tooltip = self.get_mini_tooltip(mini_list) 625 tooltip = self.get_mini_tooltip(mini_list)
665 self.canvas.SetToolTipString(tooltip) 626 self.canvas.SetToolTipString(tooltip)
666 else: 627 else: self.canvas.SetToolTipString("")
667 self.canvas.SetToolTipString("")
668 628
669 def on_motion(self,evt): 629 def on_motion(self,evt):
670 if evt.Dragging() and evt.LeftIsDown(): 630 if evt.Dragging() and evt.LeftIsDown():
671 if self.canvas.drag is None and self.drag_mini is not None: 631 if self.canvas.drag is None and self.drag_mini is not None:
672 drag_bmp = self.drag_mini.bmp 632 drag_bmp = self.drag_mini.bmp
707 if self.canvas.layers['grid'].snap: 667 if self.canvas.layers['grid'].snap:
708 nudge = int(self.canvas.layers['grid'].unit_size/2) 668 nudge = int(self.canvas.layers['grid'].unit_size/2)
709 if self.canvas.layers['grid'].mode != GRID_ISOMETRIC: 669 if self.canvas.layers['grid'].mode != GRID_ISOMETRIC:
710 if self.drag_mini.snap_to_align == SNAPTO_ALIGN_CENTER: 670 if self.drag_mini.snap_to_align == SNAPTO_ALIGN_CENTER:
711 pos = pos + (int(self.drag_mini.bmp.GetWidth()/2),int(self.drag_mini.bmp.GetHeight()/2)) 671 pos = pos + (int(self.drag_mini.bmp.GetWidth()/2),int(self.drag_mini.bmp.GetHeight()/2))
712 else: 672 else: pos = pos + (nudge, nudge)
713 pos = pos + (nudge, nudge)
714 else:# GRID_ISOMETRIC 673 else:# GRID_ISOMETRIC
715 if self.drag_mini.snap_to_align == SNAPTO_ALIGN_CENTER: 674 if self.drag_mini.snap_to_align == SNAPTO_ALIGN_CENTER:
716 pos = pos + (int(self.drag_mini.bmp.GetWidth()/2), self.drag_mini.bmp.GetHeight()) 675 pos = pos + (int(self.drag_mini.bmp.GetWidth()/2), self.drag_mini.bmp.GetHeight())
717 else: 676 else: pass # no nudge for the isomorphic / top-left
718 pass # no nudge for the isomorphic / top-left
719 self.sel_min = self.drag_mini 677 self.sel_min = self.drag_mini
720 # check to see if the mouse is inside the window still 678 # check to see if the mouse is inside the window still
721 w = self.canvas.GetClientSizeTuple() # this is the window size, minus any scrollbars 679 w = self.canvas.GetClientSizeTuple() # this is the window size, minus any scrollbars
722 p = evt.GetPosition() # compare the window size, w with the non-logical position 680 p = evt.GetPosition() # compare the window size, w with the non-logical position
723 c = self.canvas.size # this is the grid size, compare with the logical position, pos 681 c = self.canvas.size # this is the grid size, compare with the logical position, pos
731 self.canvas.send_map_data() 689 self.canvas.send_map_data()
732 self.sel_min = None 690 self.sel_min = None
733 self.drag_mini = None 691 self.drag_mini = None
734 692
735 def on_left_dclick(self,evt): 693 def on_left_dclick(self,evt):
736 if not self.role_is_gm_or_player() or self.alreadyDealingWithMenu(): 694 if not self.role_is_gm_or_player() or self.alreadyDealingWithMenu(): return
737 return
738 mini = self.find_mini(evt, evt.CmdDown() and self.role_is_gm()) 695 mini = self.find_mini(evt, evt.CmdDown() and self.role_is_gm())
739 if mini: 696 if mini: self.on_mini_dclick(evt, mini)
740 self.on_mini_dclick(evt, mini) 697 else: base_layer_handler.on_left_dclick(self, evt)
741 else:# pass it on
742 base_layer_handler.on_left_dclick(self, evt)
743 698
744 699
745 #################################################################### 700 ####################################################################
746 ## hook functions (although with python you can override any of the functions) 701 ## hook functions (although with python you can override any of the functions)
747 702
767 def set_mini_rclick_menu_item(self, label, callback_function): 722 def set_mini_rclick_menu_item(self, label, callback_function):
768 # remember you might want to call these at the end of your callback function: 723 # remember you might want to call these at the end of your callback function:
769 # mini_handler.sel_rmin.isUpdated = True 724 # mini_handler.sel_rmin.isUpdated = True
770 # canvas.Refresh(False) 725 # canvas.Refresh(False)
771 # canvas.send_map_data() 726 # canvas.send_map_data()
772 if callback_function == None: 727 if callback_function == None: del self.mini_rclick_menu_extra_items[label]
773 del self.mini_rclick_menu_extra_items[label]
774 else: 728 else:
775 if not self.mini_rclick_menu_extra_items.has_key(label): 729 if not self.mini_rclick_menu_extra_items.has_key(label):
776 self.mini_rclick_menu_extra_items[label]=wx.NewId() 730 self.mini_rclick_menu_extra_items[label]=wx.NewId()
777 menu_id = self.mini_rclick_menu_extra_items[label] 731 menu_id = self.mini_rclick_menu_extra_items[label]
778 self.canvas.Bind(wx.EVT_MENU, callback_function, id=menu_id) 732 self.canvas.Bind(wx.EVT_MENU, callback_function, id=menu_id)
779 self.build_menu() 733 self.build_menu()
780 734
781 def set_background_rclick_menu_item(self, label, callback_function): 735 def set_background_rclick_menu_item(self, label, callback_function):
782 if callback_function == None: 736 if callback_function == None: del self.background_rclick_menu_extra_items[label]
783 del self.background_rclick_menu_extra_items[label]
784 else: 737 else:
785 if not self.background_rclick_menu_extra_items.has_key(label): 738 if not self.background_rclick_menu_extra_items.has_key(label):
786 self.background_rclick_menu_extra_items[label]=wx.NewId() 739 self.background_rclick_menu_extra_items[label]=wx.NewId()
787 menu_id = self.background_rclick_menu_extra_items[label] 740 menu_id = self.background_rclick_menu_extra_items[label]
788 self.canvas.Bind(wx.EVT_MENU, callback_function, id=menu_id) 741 self.canvas.Bind(wx.EVT_MENU, callback_function, id=menu_id)
802 return False 755 return False
803 return True 756 return True
804 757
805 def role_is_gm(self): 758 def role_is_gm(self):
806 session = self.canvas.frame.session 759 session = self.canvas.frame.session
807 if (session.my_role() <> session.ROLE_GM) and (session.use_roles()): 760 if (session.my_role() <> session.ROLE_GM) and (session.use_roles()): return False
808 return False
809 return True 761 return True
810 762
811 def alreadyDealingWithMenu(self): 763 def alreadyDealingWithMenu(self):
812 return self.lastMenuChoice is not None 764 return self.lastMenuChoice is not None
813 765
829 # and don't give a choice of it and any other minis stacked with it 781 # and don't give a choice of it and any other minis stacked with it
830 mini_list = [] 782 mini_list = []
831 mini_list.append(self.sel_min) 783 mini_list.append(self.sel_min)
832 return mini_list 784 return mini_list
833 mini_list = self.canvas.layers['miniatures'].find_miniature(pos, (not include_locked)) 785 mini_list = self.canvas.layers['miniatures'].find_miniature(pos, (not include_locked))
834 if mini_list: 786 if mini_list: return mini_list
835 return mini_list
836 mini_list = [] 787 mini_list = []
837 return mini_list 788 return mini_list
838 789
839 def deselectAndRefresh(self): 790 def deselectAndRefresh(self):
840 if self.sel_min: 791 if self.sel_min:
843 self.canvas.Refresh(False) 794 self.canvas.Refresh(False)
844 self.canvas.send_map_data() 795 self.canvas.send_map_data()
845 self.sel_min = None 796 self.sel_min = None
846 797
847 def moveSelectedMini(self, pos): 798 def moveSelectedMini(self, pos):
848 if self.sel_min: 799 if self.sel_min: self.moveMini(pos, self.sel_min)
849 self.moveMini(pos, self.sel_min)
850 800
851 def moveMini(self, pos, mini): 801 def moveMini(self, pos, mini):
852 grid = self.canvas.layers['grid'] 802 grid = self.canvas.layers['grid']
853 mini.pos = grid.get_snapped_to_pos(pos, mini.snap_to_align, mini.bmp.GetWidth(), mini.bmp.GetHeight()) 803 mini.pos = grid.get_snapped_to_pos(pos, mini.snap_to_align, mini.bmp.GetWidth(), mini.bmp.GetHeight())
854 804
855 def find_mini(self, evt, include_locked): 805 def find_mini(self, evt, include_locked):
856 if not self.role_is_gm_or_player() or self.alreadyDealingWithMenu(): 806 if not self.role_is_gm_or_player() or self.alreadyDealingWithMenu(): return
857 return
858 pos = self.getLogicalPosition(evt) 807 pos = self.getLogicalPosition(evt)
859 mini_list = self.getMiniListOrSelectedMini(pos, include_locked) 808 mini_list = self.getMiniListOrSelectedMini(pos, include_locked)
860 mini = None 809 mini = None
861 if len(mini_list) > 1: 810 if len(mini_list) > 1:
862 try: 811 try: self.do_min_select_menu(mini_list, evt.GetPosition())
863 self.do_min_select_menu(mini_list, evt.GetPosition()) 812 except: pass
864 except:
865 pass
866 choice = self.getLastMenuChoice() 813 choice = self.getLastMenuChoice()
867 if choice == None: 814 if choice == None: return None # left menu without making a choice, eg by clicking outside menu
868 return None # left menu without making a choice, eg by clicking outside menu
869 mini = mini_list[choice] 815 mini = mini_list[choice]
870 elif len(mini_list) == 1: 816 elif len(mini_list) == 1: mini = mini_list[0]
871 mini = mini_list[0]
872 return mini 817 return mini
873 818