comparison orpg/gametree/nodehandlers/minilib.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 f38df4bf9715
children 06f10429eedc
comparison
equal deleted inserted replaced
117:0f18d16f3fe7 118:217fb049bd00
66 <nodehandler name='?' module='minilib' class='minilib_handler'> 66 <nodehandler name='?' module='minilib' class='minilib_handler'>
67 <miniature name='?' url='?' unique='?'></miniature> 67 <miniature name='?' url='?' unique='?'></miniature>
68 </nodehandler> 68 </nodehandler>
69 </pre> 69 </pre>
70 """ 70 """
71 def __init__(self, xml_dom, tree_node): 71 def __init__(self, xml, tree_node):
72 """Instantiates the class, and sets all vars to their default state 72 """Instantiates the class, and sets all vars to their default state
73 """ 73 """
74 node_handler.__init__(self, xml_dom, tree_node) 74 node_handler.__init__(self, xml, tree_node)
75
76 self.myeditor = None 75 self.myeditor = None
77 self.mywindow = None 76 self.mywindow = None
78 self.tree_node = tree_node 77 self.tree_node = tree_node
79 # self.xml_dom = xml_dom
80 self.update_leaves() 78 self.update_leaves()
81 self.sanity_check_nodes() 79 self.sanity_check_nodes()
82 80
83 def get_design_panel( self, parent ): 81 def get_design_panel( self, parent ):
84 """returns an instance of the miniature library edit control ( see 82 """returns an instance of the miniature library edit control ( see
99 The table columnwidths are currently being forced, as the wxHTML 97 The table columnwidths are currently being forced, as the wxHTML
100 widgets being used don't handle cells wider than the widgets are 98 widgets being used don't handle cells wider than the widgets are
101 expecting for a given column. 99 expecting for a given column.
102 """ 100 """
103 str = '<table border="2" >' 101 str = '<table border="2" >'
104 list = self.master_dom.getElementsByTagName(TAG_MINIATURE) 102 str += "<tr><th width='20%'>Label</th><th>Image</th><th width='65%'>URL</th><th>Unique</th></tr>"
105 str += "<tr><th width='20%'>Label</th><th>Image</th><th width='65%'>URL</th><th>Unique</th></t>" 103 for mini in self.xml.findall(TAG_MINIATURE):
106 for mini in list: 104 url = mini.get(ATTRIBUTE_URL)
107 url = mini.getAttribute(ATTRIBUTE_URL) 105 label = mini.get(ATTRIBUTE_NAME)
108 label = mini.getAttribute(ATTRIBUTE_NAME)
109 flag = 0 106 flag = 0
110 try: 107 try:
111 flag = eval( mini.getAttribute(ATTRIBUTE_UNIQUE) ) 108 flag = eval( mini.get(ATTRIBUTE_UNIQUE) )
112 except: 109 except:
113 pass 110 pass
114
115 show = 'yes' 111 show = 'yes'
116 if flag: 112 if flag:
117 show = 'no' 113 show = 'no'
118 114
119 str += """<tr> 115 str += """<tr>
122 <td> %s </td> 118 <td> %s </td>
123 <td> %s </td> 119 <td> %s </td>
124 </tr>""" % ( label, url, url, show ) 120 </tr>""" % ( label, url, url, show )
125 121
126 str += "</table>" 122 str += "</table>"
127 print str
128 return str 123 return str
129 124
130 def html_view( self ): 125 def html_view( self ):
131 """see to_html 126 """see to_html
132 """ 127 """
134 129
135 def on_drop(self, evt): 130 def on_drop(self, evt):
136 drag_obj = self.tree.drag_obj 131 drag_obj = self.tree.drag_obj
137 if drag_obj == self or self.tree.is_parent_node( self.mytree_node, drag_obj.mytree_node ): 132 if drag_obj == self or self.tree.is_parent_node( self.mytree_node, drag_obj.mytree_node ):
138 return 133 return
139 if isinstance( drag_obj, minilib_handler ): 134 elif isinstance( drag_obj, map_miniature_nodehandler.map_miniature_handler ):
140 item = self.tree.GetSelection() 135 drop_xml = self.tree.drag_obj.xml#.delete()
141 name = self.tree.GetItemText( item ) 136 obj = drop_xml[0]
142 if isinstance( drag_obj, map_miniature_nodehandler.map_miniature_handler ):
143 xml_dom = self.tree.drag_obj.master_dom#.delete()
144 obj = xml_dom.firstChild
145 print obj.getAttributeKeys()
146 dict = {} 137 dict = {}
147 unique = '' 138 unique = ''
148 for attrib in obj.getAttributeKeys(): 139 for attrib in obj.keys():
149 key = TO_MINILIB_MAP.get( attrib, attrib ) 140 key = TO_MINILIB_MAP.get( attrib, attrib )
150 if key != None: 141 if key != None:
151 dict[ key ] = obj.getAttribute( attrib ) 142 dict[ key ] = obj.get( attrib )
152 dict[ ATTRIBUTE_UNIQUE ] = unique 143 dict[ ATTRIBUTE_UNIQUE ] = unique
153 self.new_mini( dict ) 144 self.new_mini( dict )
145 else:
146 node_handler.on_drop(self, evt)
154 147
155 148
156 def new_mini( self, data={}, add=1 ): 149 def new_mini( self, data={}, add=1 ):
157 mini = minidom.Element( TAG_MINIATURE ) 150 mini = Element( TAG_MINIATURE )
158 for key in data.keys(): 151 for key in data.keys():
159 mini.setAttribute( key, data[ key ] ) 152 mini.set( key, data[ key ] )
160 for key in CORE_ATTRIBUTES: 153 for key in CORE_ATTRIBUTES:
161 if mini.getAttribute( key ) == '': 154 if mini.get( key ) == '':
162 mini.setAttribute( key, '0' ) 155 mini.set( key, '0' )
163 if add: 156 if add:
164 self.add_mini( mini ) 157 self.add_mini( mini )
165 self.add_leaf( mini ) 158 self.add_leaf( mini )
166 return mini 159 return mini
167 160
168 def add_mini( self, mini ): 161 def add_mini( self, mini ):
169 self.master_dom.appendChild( mini ) 162 self.xml.append( mini )
170 163
171 def add_leaf( self, mini, icon='gear' ): 164 def add_leaf( self, mini, icon='gear' ):
172 tree = self.tree 165 tree = self.tree
173 icons = tree.icons 166 icons = tree.icons
174 key = mini.getAttribute( ATTRIBUTE_NAME ) 167 key = mini.get( ATTRIBUTE_NAME )
175 self.mydata.append( mini ) 168 self.mydata.append( mini )
176 169
177 def update_leaves( self ): 170 def update_leaves( self ):
178 self.mydata = [] 171 self.mydata = []
179 nl = self.master_dom.getElementsByTagName( TAG_MINIATURE ) 172 for n in self.xml.findall(TAG_MINIATURE):
180 for n in nl:
181 self.add_leaf( n ) 173 self.add_leaf( n )
182
183 174
184 def on_drag( self, evt ): 175 def on_drag( self, evt ):
185 print 'drag event caught' 176 print 'drag event caught'
186 177
187 def send_mini_to_map( self, mini, count=1, addName=True ): 178 def send_mini_to_map( self, mini, count=1, addName=True ):
188 if mini == None: 179 if mini == None:
189 return 180 return
190 if mini.getAttribute( ATTRIBUTE_URL ) == '' or mini.getAttribute( ATTRIBUTE_URL ) == 'http://': 181 if mini.get( ATTRIBUTE_URL ) == '' or mini.get( ATTRIBUTE_URL ) == 'http://':
191 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.getAttribute( ATTRIBUTE_URL ), mini.getAttribute( ATTRIBUTE_NAME ) )) ) 182 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 ) )) )
192 return 183 return
193 session = component.get( COMPONENT_SESSION ) 184 session = component.get( COMPONENT_SESSION )
194 if (session.my_role() != session.ROLE_GM) and (session.my_role() != session.ROLE_PLAYER): 185 if (session.my_role() != session.ROLE_GM) and (session.my_role() != session.ROLE_PLAYER):
195 component.get("chat").InfoPost("You must be either a player or GM to use the miniature Layer") 186 component.get("chat").InfoPost("You must be either a player or GM to use the miniature Layer")
196 return 187 return
199 msg = self.get_miniature_XML( mini, addName) 190 msg = self.get_miniature_XML( mini, addName)
200 msg = str("<map action='update'><miniatures>" + msg + "</miniatures></map>") 191 msg = str("<map action='update'><miniatures>" + msg + "</miniatures></map>")
201 map.new_data( msg ) 192 map.new_data( msg )
202 session.send( msg ) 193 session.send( msg )
203 194
204 def get_miniature_XML( self, mini, addName = True ): 195 def get_miniature_XML( self, mini_xml, addName = True ):
205 msg = orpg.mapper.map_msg.mini_msg() 196 msg = orpg.mapper.map_msg.mini_msg()
206 map = component.get( COMPONENT_MAP ) 197 map = component.get( COMPONENT_MAP )
207 session = component.get( COMPONENT_SESSION ) 198 session = component.get( COMPONENT_SESSION )
208 msg.init_prop( ATTRIBUTE_ID, session.get_next_id() ) 199 msg.init_prop( ATTRIBUTE_ID, session.get_next_id() )
209 for k in mini.getAttributeKeys(): 200 msg.init_prop('selected', '1')# this will make the mini initially selected
201 for k in mini_xml.keys():
210 # translate our attributes to map attributes 202 # translate our attributes to map attributes
211 key = FROM_MINILIB_MAP.get( k, k ) 203 key = FROM_MINILIB_MAP.get( k, k )
212 if key != None: 204 if key != None:
213 if not addName and k == 'name': 205 if not addName and k == 'name':
214 pass 206 pass
215 else: 207 else:
216 msg.init_prop( key, mini.getAttribute( k ) ) 208 msg.init_prop( key, mini_xml.get( k ) )
217 unique = self.is_unique( mini ) 209 unique = self.is_unique( mini_xml )
218 if addName: 210 if addName:
219 label = mini.getAttribute( ATTRIBUTE_NAME ) 211 label = mini_xml.get( ATTRIBUTE_NAME )
220 else: 212 else:
221 label = '' 213 label = ''
222 return msg.get_all_xml() 214 return msg.get_all_xml()
223 215
224 def is_unique( self, mini ): 216 def is_unique( self, mini ):
225 unique = mini.getAttribute( ATTRIBUTE_UNIQUE ) 217 unique = mini.get( ATTRIBUTE_UNIQUE )
226 val = 0 218 val = 0
227 try: 219 try: val = eval( unique )
228 val = eval( unique ) 220 except: val = len( unique )
229 except:
230 val = len( unique )
231 return val 221 return val
232 222
233 def sanity_check_nodes( self ): 223 def sanity_check_nodes( self ):
234 nl = self.master_dom.getElementsByTagName( TAG_MINIATURE ) 224 for node in self.xml.findall(TAG_MINIATURE):
235 for node in nl: 225 if node.get( ATTRIBUTE_POSX ) == '': node.set( ATTRIBUTE_POSX, '0' )
236 if node.getAttribute( ATTRIBUTE_POSX ) == '': 226 if node.get( ATTRIBUTE_POSY ) == '': node.set( ATTRIBUTE_POSY, '0' )
237 node.setAttribute( ATTRIBUTE_POSX, '0' )
238 if node.getAttribute( ATTRIBUTE_POSY ) == '':
239 node.setAttribute( ATTRIBUTE_POSY, '0' )
240 227
241 def get_mini( self, index ): 228 def get_mini( self, index ):
242 try: 229 try: return self.xml.findall(TAG_MINIATURE)[index]
243 nl = self.master_dom.getElementsByTagName( TAG_MINIATURE ) 230 except: return None
244 return nl[ index ]
245 except:
246 return None
247 231
248 class mini_handler( node_handler ): 232 class mini_handler( node_handler ):
249 def __init__( self, xml_dom, tree_node, handler ): 233 def __init__( self, xml, tree_node, handler ):
250 node_handler.__init__( self, xml_dom, tree_node) 234 node_handler.__init__( self, xml, tree_node)
251 self.handler = handler 235 self.handler = handler
252 236
253 def on_ldclick( self, evt ): 237 def on_ldclick( self, evt ):
254 self.handler.send_mini_to_map( self.master_dom ) 238 self.handler.send_mini_to_map( self.xml )
255 239
256 def on_drop( self, evt ): 240 def on_drop( self, evt ):
257 pass 241 pass
258 242
259 def on_lclick( self, evt ): 243 def on_lclick( self, evt ):
311 self.Fit() 295 self.Fit()
312 296
313 def buildList( self ): 297 def buildList( self ):
314 """Returns a dictionary of label => game tree miniature DOM node mappings. 298 """Returns a dictionary of label => game tree miniature DOM node mappings.
315 """ 299 """
316 list = self.handler.master_dom.getElementsByTagName(TAG_MINIATURE)
317 self.list = [] 300 self.list = []
318 for mini in list: 301 for mini in self.handler.xml.findall(TAG_MINIATURE):
319 self.list.append( mini.getAttribute( ATTRIBUTE_NAME ) ) 302 self.list.append( mini.get( ATTRIBUTE_NAME ) )
320 return self.list 303 return self.list
321 # self.list = {}
322 # for mini in list:
323 # name = mini.getAttribute( ATTRIBUTE_NAME )
324 # if name == '':
325 # name = self.map.canvas.get_label_from_url( mini.getAttribute( ATTRIBUTE_URL ) )
326 # self.list[ name ] = mini
327 304
328 def on_close(self, evt): 305 def on_close(self, evt):
329 self.frame.Close() 306 self.frame.Close()
330 307
331 def on_ok( self, evt ): 308 def on_ok( self, evt ):
452 self.AutoSizeColumns() 429 self.AutoSizeColumns()
453 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) 430 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
454 self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.select_cell) 431 self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.select_cell)
455 432
456 def update_cols( self ): 433 def update_cols( self ):
457 nl = self.handler.master_dom.getElementsByTagName( TAG_MINIATURE ) 434 for n in self.handler.xml.findall(TAG_MINIATURE):
458 for n in nl: 435 for k in n.keys():
459 for k in n.getAttributeKeys():
460 if k not in self.keys: 436 if k not in self.keys:
461 self.keys.append( k ) 437 self.keys.append( k )
462 438
463 def select_cell( self, evt ): 439 def select_cell( self, evt ):
464 """Event handler for grid cell selection changes. It stores the 440 """Event handler for grid cell selection changes. It stores the
473 449
474 def getList( self ): 450 def getList( self ):
475 """Returns the list of 'miniature' DOM elements associated with this 451 """Returns the list of 'miniature' DOM elements associated with this
476 miniature library. 452 miniature library.
477 """ 453 """
478 return self.handler.master_dom.getElementsByTagName( TAG_MINIATURE ) 454 return self.handler.xml.findall( TAG_MINIATURE )
479 455
480 def add_row( self, count = 1 ): 456 def add_row( self, count = 1 ):
481 """creates a new miniature node, and then adds it to the current 457 """creates a new miniature node, and then adds it to the current
482 miniature library, and to the grid. 458 miniature library, and to the grid.
483 """ 459 """
484 self.AppendRows( count ) 460 self.AppendRows( count )
485 node = self.handler.new_mini( { 461 node = self.handler.new_mini( {
486 ATTRIBUTE_NAME :' ', 462 ATTRIBUTE_NAME :' ',
487 ATTRIBUTE_URL :'http://'} )# minidom.Element( TAG_MINIATURE ) 463 ATTRIBUTE_URL :'http://'} )# minidom.Element( TAG_MINIATURE )
488 self.update_all() 464 self.update_all()
489 #self.handler.master_dom.appendChild( node ) 465 #self.handler.xml.append( node )
490 466
491 def del_row( self ): 467 def del_row( self ):
492 """deletes the miniature associated with the currently selected 468 """deletes the miniature associated with the currently selected
493 row. BUG BUG BUG this method should drop a child from the DOM but 469 row. BUG BUG BUG this method should drop a child from the DOM but
494 does not. 470 does not.
495 """ 471 """
496 if self.selectedRow > -1: 472 if self.selectedRow > -1:
497 pos = self.selectedRow 473 pos = self.selectedRow
498 list = self.handler.master_dom.getElementsByTagName(TAG_MINIATURE) 474 list = self.handler.xml.findall(TAG_MINIATURE)
499 self.handler.master_dom.removeChild( list[pos] ) 475 self.handler.xml.remove( list[pos] )
500 self.DeleteRows( pos, 1 ) 476 self.DeleteRows( pos, 1 )
501 list = self.getList() 477 list = self.getList()
502 del list[ pos ] 478 del list[ pos ]
503 479
504 def on_cell_change( self, evt ): 480 def on_cell_change( self, evt ):
513 rows, and then updates all data displayed by the grid 489 rows, and then updates all data displayed by the grid
514 """ 490 """
515 list = self.getList() 491 list = self.getList()
516 count = 0 492 count = 0
517 for n in list: 493 for n in list:
518 for k in n.getAttributeKeys(): 494 for k in n.keys():
519 if k not in self.keys: 495 if k not in self.keys:
520 self.keys.append( k ) 496 self.keys.append( k )
521 count = len( self.keys ) 497 count = len( self.keys )
522 if self.GetNumberCols() < count: 498 if self.GetNumberCols() < count:
523 self.AppendCols( count - self.GetNumberCols() ) 499 self.AppendCols( count - self.GetNumberCols() )
553 """Updates the specified grid row with data from the DOM node 529 """Updates the specified grid row with data from the DOM node
554 specified by 'row' 530 specified by 'row'
555 """ 531 """
556 list = self.getList() 532 list = self.getList()
557 item = list[ row ] 533 item = list[ row ]
558 # self.GetTable().SetValue( row, 0, item.getAttribute(ATTRIBUTE_NAME) )
559 # self.GetTable().SetValue( row, 1, item.getAttribute(ATTRIBUTE_URL) )
560 # self.GetTable().SetValue( row, 2, item.getAttribute(ATTRIBUTE_UNIQUE) )
561 for key in self.keys: 534 for key in self.keys:
562 self.GetTable().SetValue( row, self.keys.index( key ), item.getAttribute( key ) ) 535 self.GetTable().SetValue( row, self.keys.index( key ), item.get( key ) )
563 536
564 def update_data_row( self, row ): 537 def update_data_row( self, row ):
565 """Updates the DOM nodw 'row' with grid data from 'row' 538 """Updates the DOM nodw 'row' with grid data from 'row'
566 """ 539 """
567 list = self.getList() 540 list = self.getList()
568 item = list[ row ] 541 item = list[ row ]
569 for key in self.keys: 542 for key in self.keys:
570 item.setAttribute( key, string.strip( self.GetTable().GetValue( row, self.keys.index( key ) ) ) ) 543 item.set( key, string.strip( self.GetTable().GetValue( row, self.keys.index( key ) ) ) )
571 # item.setAttribute( ATTRIBUTE_NAME, string.strip( self.GetTable().GetValue( row, 0 ) ) )
572 # item.setAttribute( ATTRIBUTE_URL, string.strip( self.GetTable().GetValue( row, 1 ) ) )
573 # item.setAttribute( ATTRIBUTE_UNIQUE, string.strip( self.GetTable().GetValue( row, 2 ) ) )
574 # self.GetTable().SetValue( row, 0, item.getAttribute(ATTRIBUTE_NAME) )
575 # self.GetTable().SetValue( row, 1, item.getAttribute(ATTRIBUTE_URL) )
576 # self.GetTable().SetValue( row, 2, item.getAttribute(ATTRIBUTE_UNIQUE) )