comparison orpg/gametree/nodehandlers/minilib.py @ 236:9230a33defd9 beta

Traipse Beta 'OpenRPG' {100616-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 (Closing/Closed) New Features: New to Map, can re-order Grid, Miniatures, and Whiteboard layer draw order New to Server GUI, can now clear log Updates: Update to Warhammer PC Sheet. Rollers set as macros. Should work with little maintanence. Update to Browser Server window. Display rooms with ' " & cleaner Update to Server. Handles ' " & cleaner. Fixes: Fix to InterParse that was causing an Infernal Loop with Namespace Internal Fix to XML data, removed old Minidom and switched to Element Tree Fix to Server that was causing eternal attempt to find a Server ID, in Register Rooms thread Fix to metaservers.xml file not being created Fix to Single and Double quotes in Whiteboard text Fix to Background images not showing when using the Image Server Fix to Duplicate chat names appearing Fix to Server GUI's logging output Fix to FNB.COLORFUL_TABS bug.
author sirebral
date Wed, 16 Jun 2010 03:06:20 -0500
parents a00b40ee92fc
children 3bbfd84619c0
comparison
equal deleted inserted replaced
226:b29454610f36 236:9230a33defd9
35 from orpg.dirpath import dir_struct 35 from orpg.dirpath import dir_struct
36 import string 36 import string
37 import map_miniature_nodehandler 37 import map_miniature_nodehandler
38 import orpg.mapper.map_msg 38 import orpg.mapper.map_msg
39 import orpg.minidom as minidom 39 import orpg.minidom as minidom
40 from orpg.tools.InterParse import Parse
40 # import scriptkit 41 # import scriptkit
41 42
42 # Constants 43 # Constants
43 TO_MINILIB_MAP = {'path':'url', 'label':'name', 'id':None, 'action':None} 44 TO_MINILIB_MAP = {'path':'url', 'label':'name', 'id':None, 'action':None}
44 FROM_MINILIB_MAP = {'url':'path', 'name':'label', 'unique':None} 45 FROM_MINILIB_MAP = {'url':'path', 'name':'label', 'unique':None}
45 CORE_ATTRIBUTES = ['name', 'url', 'unique', 'posy', 'posx', 'hide', 'face', 'heading', 'align', 'locked', 'width', 'height'] 46 CORE_ATTRIBUTES = ['name', 'url', 'unique', 'posy', 'posx', 'hide', 'face', 'heading', 'align', 'locked', 'width', 'height']
46 47
47 ATTRIBUTE_NAME = 'name'
48 ATTRIBUTE_URL = 'url'
49 ATTRIBUTE_UNIQUE = 'unique'
50 ATTRIBUTE_ID = 'id'
51 ATTRIBUTE_POSX = 'posx'
52 ATTRIBUTE_POSY = 'posy'
53
54 TAG_MINIATURE = 'miniature'
55
56 COMPONENT_MAP = 'map'
57 COMPONENT_SESSION = 'session'
58 # <nodehandler name='?' module='minilib' class='minilib_handler'> 48 # <nodehandler name='?' module='minilib' class='minilib_handler'>
59 # <miniature name='?' url='?' unique='?'></miniature> 49 # <miniature name='?' url='?' unique='?'></miniature>
60 # </nodehandler> 50 # </nodehandler>
61 51
62 class minilib_handler( node_handler ): 52 class minilib_handler( node_handler ):
98 widgets being used don't handle cells wider than the widgets are 88 widgets being used don't handle cells wider than the widgets are
99 expecting for a given column. 89 expecting for a given column.
100 """ 90 """
101 str = '<table border="2" >' 91 str = '<table border="2" >'
102 str += "<tr><th width='20%'>Label</th><th>Image</th><th width='65%'>URL</th><th>Unique</th></tr>" 92 str += "<tr><th width='20%'>Label</th><th>Image</th><th width='65%'>URL</th><th>Unique</th></tr>"
103 for mini in self.xml.findall(TAG_MINIATURE): 93 for mini in self.xml.findall('miniature'):
104 url = mini.get(ATTRIBUTE_URL) 94 url = mini.get('url')
105 label = mini.get(ATTRIBUTE_NAME) 95 label = mini.get('name')
106 flag = 0 96 flag = 0
107 try: flag = eval( mini.get(ATTRIBUTE_UNIQUE) ) 97 try: flag = eval( mini.get('unique') )
108 except: pass 98 except: pass
109 show = 'yes' 99 show = 'yes'
110 if flag: show = 'no' 100 if flag: show = 'no'
111 str += """<tr> 101 str += """<tr>
112 <td> %s </td> 102 <td> %s </td>
131 dict = {} 121 dict = {}
132 unique = '' 122 unique = ''
133 for attrib in obj.keys(): 123 for attrib in obj.keys():
134 key = TO_MINILIB_MAP.get( attrib, attrib ) 124 key = TO_MINILIB_MAP.get( attrib, attrib )
135 if key != None: dict[ key ] = obj.get( attrib ) 125 if key != None: dict[ key ] = obj.get( attrib )
136 dict[ ATTRIBUTE_UNIQUE ] = unique 126 dict[ 'unique' ] = unique
137 self.new_mini( dict ) 127 self.new_mini( dict )
138 else: node_handler.on_drop(self, evt) 128 else: node_handler.on_drop(self, evt)
139 129
140 130
141 def new_mini( self, data={}, add=1 ): 131 def new_mini( self, data={}, add=1 ):
142 mini = Element( TAG_MINIATURE ) 132 mini = Element( 'miniature' )
143 for key in data.keys(): mini.set( key, data[ key ] ) 133 for key in data.keys(): mini.set( key, data[ key ] )
144 for key in CORE_ATTRIBUTES: 134 for key in CORE_ATTRIBUTES:
145 if mini.get( key ) == ('' or None): mini.set( key, '0' ) 135 if mini.get( key ) == ('' or None): mini.set( key, '0' )
146 if add: 136 if add:
147 self.add_mini( mini ) 137 self.add_mini( mini )
152 self.xml.append( mini ) 142 self.xml.append( mini )
153 143
154 def add_leaf( self, mini, icon='gear' ): 144 def add_leaf( self, mini, icon='gear' ):
155 tree = self.tree 145 tree = self.tree
156 icons = tree.icons 146 icons = tree.icons
157 key = mini.get( ATTRIBUTE_NAME ) 147 key = mini.get( 'name' )
158 self.mydata.append( mini ) 148 self.mydata.append( mini )
159 149
160 def update_leaves( self ): 150 def update_leaves( self ):
161 self.mydata = [] 151 self.mydata = []
162 for n in self.xml.findall(TAG_MINIATURE): self.add_leaf( n ) 152 for n in self.xml.findall('miniature'): self.add_leaf( n )
163 153
164 def on_drag( self, evt ): 154 def on_drag( self, evt ):
165 print 'drag event caught' 155 print 'drag event caught'
166 156
167 def send_mini_to_map( self, mini, count=1, addName=True ): 157 def send_mini_to_map( self, mini, count=1, addName=True ):
168 if mini == None: return 158 if mini == None: return
169 if mini.get( ATTRIBUTE_URL ) == '' or mini.get( ATTRIBUTE_URL ) == 'http://': 159 if mini.get( 'url' ) == '' or mini.get( 'url' ) == 'http://':
170 self.chat.ParsePost( self.chat.colorize(self.chat.syscolor, '"%s" is not a valid URL, the mini "%s" will not be added to the map' % ( mini.get( ATTRIBUTE_URL ), mini.get( ATTRIBUTE_NAME ) )) ) 160 Parse.Post( self.chat.colorize(self.chat.syscolor,
161 '"%s" is not a valid URL, the mini "%s" will not be added to the map' % (
162 mini.get( 'url' ), mini.get( 'name' ) )) )
171 return 163 return
172 session = component.get( COMPONENT_SESSION ) 164 session = component.get( 'session' )
173 if (session.my_role() != session.ROLE_GM) and (session.my_role() != session.ROLE_PLAYER): 165 if (session.my_role() != session.ROLE_GM) and (session.my_role() != session.ROLE_PLAYER):
174 component.get("chat").InfoPost("You must be either a player or GM to use the miniature Layer") 166 component.get("chat").InfoPost("You must be either a player or GM to use the miniature Layer")
175 return 167 return
176 map = component.get(COMPONENT_MAP) 168 canvas = component.get('map')
177 for loop in range( count ): 169 for loop in range( count ):
178 msg = self.get_miniature_XML( mini, addName) 170 msg = self.get_miniature_XML( mini, addName)
179 msg = str("<map action='update'><miniatures>" + msg + "</miniatures></map>") 171 msg = str("<map action='update'><miniatures>" + msg + "</miniatures></map>")
180 map.new_data( msg ) 172 canvas.new_data( msg )
181 session.send( msg ) 173 session.send( msg )
182 174
183 def get_miniature_XML( self, mini_xml, addName = True ): 175 def get_miniature_XML( self, mini_xml, addName = True ):
184 msg = orpg.mapper.map_msg.mini_msg() 176 msg = orpg.mapper.map_msg.mini_msg()
185 map = component.get( COMPONENT_MAP ) 177 canvas = component.get( 'map' )
186 session = component.get( COMPONENT_SESSION ) 178 session = component.get( 'session' )
187 msg.init_prop( ATTRIBUTE_ID, session.get_next_id() ) 179 msg.init_prop( 'id', session.get_next_id() )
188 msg.init_prop('selected', '1')# this will make the mini initially selected 180 msg.init_prop('selected', '1')# this will make the mini initially selected
189 for k in mini_xml.keys(): 181 for k in mini_xml.keys():
190 # translate our attributes to map attributes 182 # translate our attributes to map attributes
191 key = FROM_MINILIB_MAP.get( k, k ) 183 key = FROM_MINILIB_MAP.get( k, k )
192 if key != None: 184 if key != None:
193 if not addName and k == 'name': pass 185 if not addName and k == 'name': pass
194 else: msg.init_prop( key, mini_xml.get( k ) ) 186 else: msg.init_prop( key, mini_xml.get( k ) )
195 unique = self.is_unique( mini_xml ) 187 unique = self.is_unique( mini_xml )
196 if addName: label = mini_xml.get( ATTRIBUTE_NAME ) 188 if addName: label = mini_xml.get( 'name' )
197 else: label = '' 189 else: label = ''
198 return msg.get_all_xml() 190 return msg.get_all_xml()
199 191
200 def is_unique( self, mini ): 192 def is_unique( self, mini ):
201 unique = mini.get( ATTRIBUTE_UNIQUE ) 193 unique = mini.get( 'unique' )
202 val = 0 194 val = 0
203 try: val = eval( unique ) 195 try: val = eval( unique )
204 except: val = len( unique ) 196 except: val = len( unique )
205 return val 197 return val
206 198
207 def sanity_check_nodes( self ): 199 def sanity_check_nodes( self ):
208 for node in self.xml.findall(TAG_MINIATURE): 200 for node in self.xml.findall('miniature'):
209 if node.get( ATTRIBUTE_POSX ) == '': node.set( ATTRIBUTE_POSX, '0' ) 201 if node.get( 'posx' ) == '': node.set( 'posx', '0' )
210 if node.get( ATTRIBUTE_POSY ) == '': node.set( ATTRIBUTE_POSY, '0' ) 202 if node.get( 'posy' ) == '': node.set( 'posy', '0' )
211 203
212 def get_mini( self, index ): 204 def get_mini( self, index ):
213 try: return self.xml.findall(TAG_MINIATURE)[index] 205 try: return self.xml.findall('miniature')[index]
214 except: return None 206 except: return None
215 207
216 class mini_handler( node_handler ): 208 class mini_handler( node_handler ):
217 def __init__( self, xml, tree_node, handler ): 209 def __init__( self, xml, tree_node, handler ):
218 node_handler.__init__( self, xml, tree_node) 210 node_handler.__init__( self, xml, tree_node)
277 269
278 def buildList( self ): 270 def buildList( self ):
279 """Returns a dictionary of label => game tree miniature DOM node mappings. 271 """Returns a dictionary of label => game tree miniature DOM node mappings.
280 """ 272 """
281 self.list = [] 273 self.list = []
282 for mini in self.handler.xml.findall(TAG_MINIATURE): self.list.append( mini.get( ATTRIBUTE_NAME ) ) 274 for mini in self.handler.xml.findall('miniature'): self.list.append( mini.get( 'name' ) )
283 return self.list 275 return self.list
284 276
285 def on_close(self, evt): 277 def on_close(self, evt):
286 self.frame.Close() 278 self.frame.Close()
287 279
405 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 397 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
406 self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.select_cell) 398 self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.select_cell)
407 self.Bind(wx.grid.EVT_GRID_LABEL_LEFT_CLICK, self.select_cell) 399 self.Bind(wx.grid.EVT_GRID_LABEL_LEFT_CLICK, self.select_cell)
408 400
409 def update_cols( self ): 401 def update_cols( self ):
410 for n in self.handler.xml.findall(TAG_MINIATURE): 402 for n in self.handler.xml.findall('miniature'):
411 for k in n.keys(): 403 for k in n.keys():
412 if k not in self.keys: self.keys.append( k ) 404 if k not in self.keys: self.keys.append( k )
413 405
414 def select_cell( self, evt ): 406 def select_cell( self, evt ):
415 """Event handler for grid cell selection changes. It stores the 407 """Event handler for grid cell selection changes. It stores the
424 416
425 def getList( self ): 417 def getList( self ):
426 """Returns the list of 'miniature' DOM elements associated with this 418 """Returns the list of 'miniature' DOM elements associated with this
427 miniature library. 419 miniature library.
428 """ 420 """
429 return self.handler.xml.findall( TAG_MINIATURE ) 421 return self.handler.xml.findall( 'miniature' )
430 422
431 def add_row( self, count = 1 ): 423 def add_row( self, count = 1 ):
432 """creates a new miniature node, and then adds it to the current 424 """creates a new miniature node, and then adds it to the current
433 miniature library, and to the grid. 425 miniature library, and to the grid.
434 """ 426 """
435 self.AppendRows( count ) 427 self.AppendRows( count )
436 node = self.handler.new_mini( { 428 node = self.handler.new_mini( {
437 ATTRIBUTE_NAME :' ', 429 'name' :' ',
438 ATTRIBUTE_URL :'http://'} )# minidom.Element( TAG_MINIATURE ) 430 'url' :'http://'} )# minidom.Element( 'miniature' )
439 self.update_all() 431 self.update_all()
440 #self.handler.xml.append( node ) 432 #self.handler.xml.append( node )
441 433
442 def del_row( self ): 434 def del_row( self ):
443 """deletes the miniature associated with the currently selected 435 """deletes the miniature associated with the currently selected
444 row. BUG BUG BUG this method should drop a child from the DOM but 436 row. BUG BUG BUG this method should drop a child from the DOM but
445 does not. 437 does not.
446 """ 438 """
447 if self.selectedRow > -1: 439 if self.selectedRow > -1:
448 pos = self.selectedRow 440 pos = self.selectedRow
449 list = self.handler.xml.findall(TAG_MINIATURE) 441 list = self.handler.xml.findall('miniature')
450 self.handler.xml.remove( list[pos] ) 442 self.handler.xml.remove( list[pos] )
451 self.DeleteRows( pos, 1 ) 443 self.DeleteRows( pos, 1 )
452 444
453 def on_cell_change( self, evt ): 445 def on_cell_change( self, evt ):
454 """Event handler for cell selection changes. selected row is used 446 """Event handler for cell selection changes. selected row is used
490 """Returns the URL for the selected row 482 """Returns the URL for the selected row
491 """ 483 """
492 return self.GetTable().GetValue( self.selectedRow, 1 ) 484 return self.GetTable().GetValue( self.selectedRow, 1 )
493 485
494 def getSelectedSerial( self ): 486 def getSelectedSerial( self ):
495 """Returns the ATTRIBUTE_UNIQUE value for the selected row 487 """Returns the 'unique' value for the selected row
496 """ 488 """
497 return self.GetTable().GetValue( self.selectedRow, 2 ) 489 return self.GetTable().GetValue( self.selectedRow, 2 )
498 490
499 def update_grid_row( self, row ): 491 def update_grid_row( self, row ):
500 """Updates the specified grid row with data from the DOM node 492 """Updates the specified grid row with data from the DOM node