annotate orpg/gametree/nodehandlers/map_miniature_nodehandler.py @ 33:6f460a73989e ornery-orc

Traipse 'OpenRPG' {100503-02} 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 (Patch-2) New Features: New Namespace method with two new syntaxes New Namespace Internal is context sensitive, always! New Namespace External is 'as narrow as you make it' New Namespace FutureCheck helps ensure you don't receive an incorrect node New Namespace 2.0 documentation in the User Manual New Namespace plugin, Allows Traipse users to use the Standard syntax !@ :: @! New Mini Library with minis from Devin Knight New PluginDB access for URL2Link plugin New to Forms, they now show their content in Design Mode New to Update Manager, checks Repo for updates on software start New to Mini Lib node, change title in design mode New to Game Tree, never lose a node, appends a number to the end of corrupted trees New to Server GUI, Traipse Suite's Debug Console New Warhammer PC Sheet Updates: Update to White Board layer, uses a pencil image for color button Update to Grid Layer, uses a grid image for color button Update to Chat Window, size of drop down menus Update to default lobby message Update to template Text node Update to 4e PC Sheet node Update to how display names are acquired Update to Server, added some 'Pious' technology Update to features node Fixes: Fix to Server GUI startup errors Fix to Server GUI Rooms tab updating Fix to Chat and Settings if non existant die roller is picked Fix to Dieroller and .open() used with .vs(). Successes are correctly calculated Fix to Alias Lib's Export to Tree, Open, Save features Fix to alias node, now works properly Fix to Splitter node, minor GUI cleanup Fix to Backgrounds not loading through remote loader Fix to Node name errors Fix to rolling dice in chat Whispers Fix to Splitters Sizing issues Fix to URL2Link plugin, modified regex compilation should remove memory leak Fix to mapy.py, a roll back due to zoomed grid issues Fix to whiteboard_handler, Circles work by you clicking the center of the circle Fix to Servers parse_incoming_dom which was outdated and did not respect XML Fix to a broken link in the server welcome message Fix to InterParse and logger requiring traceback Fix to Update Manager Status Bar Fix to failed image and erroneous pop up Fix to Mini Lib node that was preventing use Fix to plugins that parce dice but did not call InterParse Fix to nodes for name changing by double click Fix to Game Tree, node ordering on drag and drop corrected Fix to Game Tree, corrupted error message was not showing Fix to Update Manager, checks for internet connection Fix to Update Manager, Auto Update corrections Fix to Server GUI's broadcast, room, player messaging Daily-01: Figured out, this time, why the version file is copied. because of the linux .py~ files. Daily-02: Incomplete feature node updates, sorry. Should be a complete transition after this. Files in the update: Currently selected branch: ornery-orc Author: sirebral Files Modified (in update): data/tips.txt images/draw.png images/grid.png orpg/chat/chatwnd.py orpg/chat/commands.py orpg/dieroller/base.py orpg/dieroller/rollers/std.py orpg/gametree/gametree.py orpg/gametree/nodehandlers/chatmacro.py orpg/gametree/nodehandlers/containers.py orpg/gametree/nodehandlers/core.py~ orpg/gametree/nodehandlers/forms.py orpg/gametree/nodehandlers/minilib.py orpg/gametree/nodehandlers/minilib.py~ orpg/gametree/nodehandlers/rpg_grid.py orpg/main.py orpg/mapper/background.py orpg/mapper/grid_handler.py orpg/mapper/map.py orpg/mapper/whiteboard_handler.py orpg/networking/mplay_server.py orpg/networking/mplay_server_gui.py orpg/orpg_version.py orpg/pluginhandler.py orpg/templates/default_LobbyMessage.html orpg/templates/feature.xml orpg/templates/nodes/4e_char_sheet.xml orpg/templates/nodes/Warhammerv2CS2-Traipse.xml orpg/templates/nodes/split.xml orpg/templates/nodes/textctrl.xml orpg/tools/InterParse.py orpg/tools/aliaslib.py orpg/tools/orpg_log.py orpg/tools/orpg_settings.py plugins/xxhiddendice.py plugins/xxsimpleinit.py plugins/xxstdnamespace.py plugins/xxurl2link.py readme.txt rollback.py start_developer.py start_noupdate.py upmana/updatemana.py
author sirebral
date Mon, 03 May 2010 03:47:00 -0500
parents ff154cf3350c
children d02e9197c066
rev   line source
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
1 # Copyright (C) 2000-2001 The OpenRPG Project
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
2 #
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
3 # openrpg-dev@lists.sourceforge.net
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
4 #
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
5 # This program is free software; you can redistribute it and/or modify
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
6 # it under the terms of the GNU General Public License as published by
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
7 # the Free Software Foundation; either version 2 of the License, or
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
8 # (at your option) any later version.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
9 #
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
10 # This program is distributed in the hope that it will be useful,
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
13 # GNU General Public License for more details.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
14 #
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
15 # You should have received a copy of the GNU General Public License
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
16 # along with this program; if not, write to the Free Software
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
18 # --
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
19 #
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
20 # File: map_miniature_nodehandler.py
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
21 # Author: Andrew Bennett
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
22 # Maintainer:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
23 # Version:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
24 # $Id: map_miniature_nodehandler.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
25 #
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
26 # Description: nodehandler for miniature images
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
27 #
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
29 #from nodehandlers.core import *
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
30 from core import *
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
31 from orpg.gametree import *
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
32 from orpg.mapper.miniatures_msg import mini_msg
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
33 from orpg.mapper.images import ImageHandler
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
34 import urllib
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
35
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
36 class map_miniature_handler(node_handler):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
37
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
38 """ A node handler for miniatures
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
39 <nodehandler name='Elf-1' module='map_miniature_nodehandler' class='map_miniature_handler' >
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
40 <miniature id='' label='Elf-1' posx='' posy='' path='' ... />
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
41 </nodehandler >
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
42 """
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
43
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
44 def __init__(self,xml,tree_node):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
45 node_handler.__init__(self,xml,tree_node)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
46 self.mapper = component.get("map")
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
47 self.session = component.get("session")
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
48 self.miniature_xml = self.xml.find("miniature")
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
49
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
50 def get_scaled_bitmap(self,x,y):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
51 my_mini_msg = mini_msg()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
52 my_mini_msg.init_from_dom(self.miniature_xml)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
53 bmp = None
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
54 path = my_mini_msg.get_prop("path")
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
55
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
56 if path:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
57 path = urllib.unquote(path)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
58 if ImageHandler.Cache.has_key(path): bmp = ImageHandler.Cache[path]
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
59 else: bmp = ImageHandler.directLoad(path)# Old Code TaS.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
60
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
61 if bmp:
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
62 img = wx.ImageFromMime(ImageHandler.Cache[path][1], ImageHandler.Cache[path][2])
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
63 #img = wx.ImageFromBitmap(bmp)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
64 scaled_img = img.Scale(x,y)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
65 scaled_bmp = scaled_img.ConvertToBitmap()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
66 scratch = scaled_img.ConvertToBitmap()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
67 memDC = wx.MemoryDC()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
68 memDC.BeginDrawing()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
69 memDC.SelectObject(scaled_bmp)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
70 memDC.SetBrush(wx.WHITE_BRUSH)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
71 memDC.SetPen(wx.WHITE_PEN)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
72 memDC.DrawRectangle(0,0,x,y)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
73 memDC.SetPen(wx.NullPen)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
74 memDC.SetBrush(wx.NullBrush)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
75 memDC.DrawBitmap(scratch,0,0,1)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
76 memDC.SelectObject(wx.NullBitmap)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
77 memDC.EndDrawing()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
78 del memDC
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
79 return scaled_bmp
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
80
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
81 def map_aware(self):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
82 return 1
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
83
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
84 def get_miniature_XML(self):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
85 my_mini_msg = mini_msg()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
86 my_mini_msg.init_from_dom(self.miniature_xml)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
87 my_mini_msg.init_prop("id",self.session.get_next_id())
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
88 label = self.xml.get("name")
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
89 my_mini_msg.init_prop("label",label)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
90 new_xml = my_mini_msg.get_all_xml()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
91 return new_xml
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
92
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
93 def get_to_map_XML(self):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
94 new_xml = self.get_miniature_XML()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
95 new_xml = str("<map action='update'><miniatures>" + new_xml + "</miniatures></map>")
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
96 return new_xml
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
97
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
98 def on_send_to_map(self,evt):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
99 if isinstance(evt, wx.MouseEvent) and evt.LeftUp():# as opposed to a menu event
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
100 dc = wx.ClientDC(self.mapper.canvas)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
101 self.mapper.canvas.PrepareDC(dc)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
102 grid = self.mapper.canvas.layers['grid']
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
103 dc.SetUserScale(grid.mapscale, grid.mapscale)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
104 pos = evt.GetLogicalPosition(dc)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
105 try:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
106 align = int(self.xml.get("align"))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
107 width = int(self.xml.get("width"))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
108 height = int(self.xml.get("height"))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
109 pos = grid.get_snapped_to_pos(pos, align, width, height)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
110 except: pass
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
111 self.miniature_xml.set("posx", str(pos.x))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
112 self.miniature_xml.set("posy", str(pos.y))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
113 new_xml = self.get_to_map_XML()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
114 if (self.session.my_role() != self.session.ROLE_GM) and (self.session.my_role() != self.session.ROLE_PLAYER):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
115 component.get("chat").InfoPost("You must be either a player or GM to use the miniature Layer")
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
116 return
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
117 if new_xml:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
118 self.mapper.new_data(new_xml)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
119 self.session.send(new_xml)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
120 else: print "problem converting old mini xml to new mini xml"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
121
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
122 def about(self):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
123 return "Miniature node by Andrew Bennett"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
124
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
125 def tohtml(self):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
126 html_str = "<table><tr><td>"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
127 html_str += "<center><img src='" + self.xml.get("path") + "'>"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
128 html_str += "</center></td></tr>\n"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
129 html_str += "<tr><td><center>" + self.xml.get("name") + "</center></td></tr></table>"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
130 return html_str