Mercurial > traipse_dev
diff orpg/gametree/nodehandlers/minilib.py @ 227:81d0bfd5e800 alpha
Traipse Alpha 'OpenRPG' {100612-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 (Preparing to close updates)
New Features:
New to Map, can re-order Grid, Miniatures, and Whiteboard layer draw order
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
author | sirebral |
---|---|
date | Sat, 12 Jun 2010 03:50:37 -0500 |
parents | bf799efe7a8a |
children |
line wrap: on
line diff
--- a/orpg/gametree/nodehandlers/minilib.py Fri Jan 15 22:45:51 2010 -0600 +++ b/orpg/gametree/nodehandlers/minilib.py Sat Jun 12 03:50:37 2010 -0500 @@ -21,12 +21,12 @@ # Author: Ted Berg # Maintainer: # Version: -# $Id: minilib.py,v 1.28 2007/04/22 22:00:18 digitalxero Exp $ +# $Id: minilib.py,v Traipse 'Ornery-Orc' prof.ebral Exp $ # # Description: nodehandler for a collection of miniatures. # -__version__ = "$Id: minilib.py,v 1.28 2007/04/22 22:00:18 digitalxero Exp $" +__version__ = "$Id: minilib.py,v Traipse 'Ornery-Orc' prof.ebral Exp $" """Nodehandler for collections of miniatures. User can add, delete, edit miniatures as sending them to the map singly or in batches. @@ -37,6 +37,7 @@ import map_miniature_nodehandler import orpg.mapper.map_msg import orpg.minidom as minidom +from orpg.tools.InterParse import Parse # import scriptkit # Constants @@ -44,17 +45,6 @@ FROM_MINILIB_MAP = {'url':'path', 'name':'label', 'unique':None} CORE_ATTRIBUTES = ['name', 'url', 'unique', 'posy', 'posx', 'hide', 'face', 'heading', 'align', 'locked', 'width', 'height'] -ATTRIBUTE_NAME = 'name' -ATTRIBUTE_URL = 'url' -ATTRIBUTE_UNIQUE = 'unique' -ATTRIBUTE_ID = 'id' -ATTRIBUTE_POSX = 'posx' -ATTRIBUTE_POSY = 'posy' - -TAG_MINIATURE = 'miniature' - -COMPONENT_MAP = 'map' -COMPONENT_SESSION = 'session' # <nodehandler name='?' module='minilib' class='minilib_handler'> # <miniature name='?' url='?' unique='?'></miniature> # </nodehandler> @@ -100,11 +90,11 @@ """ str = '<table border="2" >' str += "<tr><th width='20%'>Label</th><th>Image</th><th width='65%'>URL</th><th>Unique</th></tr>" - for mini in self.xml.findall(TAG_MINIATURE): - url = mini.get(ATTRIBUTE_URL) - label = mini.get(ATTRIBUTE_NAME) + for mini in self.xml.findall('miniature'): + url = mini.get('url') + label = mini.get('name') flag = 0 - try: flag = eval( mini.get(ATTRIBUTE_UNIQUE) ) + try: flag = eval( mini.get('unique') ) except: pass show = 'yes' if flag: show = 'no' @@ -133,16 +123,16 @@ for attrib in obj.keys(): key = TO_MINILIB_MAP.get( attrib, attrib ) if key != None: dict[ key ] = obj.get( attrib ) - dict[ ATTRIBUTE_UNIQUE ] = unique + dict[ 'unique' ] = unique self.new_mini( dict ) else: node_handler.on_drop(self, evt) def new_mini( self, data={}, add=1 ): - mini = Element( TAG_MINIATURE ) + mini = Element( 'miniature' ) for key in data.keys(): mini.set( key, data[ key ] ) for key in CORE_ATTRIBUTES: - if mini.get( key ) == '': mini.set( key, '0' ) + if mini.get( key ) == ('' or None): mini.set( key, '0' ) if add: self.add_mini( mini ) self.add_leaf( mini ) @@ -154,37 +144,39 @@ def add_leaf( self, mini, icon='gear' ): tree = self.tree icons = tree.icons - key = mini.get( ATTRIBUTE_NAME ) + key = mini.get( 'name' ) self.mydata.append( mini ) def update_leaves( self ): self.mydata = [] - for n in self.xml.findall(TAG_MINIATURE): self.add_leaf( n ) + for n in self.xml.findall('miniature'): self.add_leaf( n ) def on_drag( self, evt ): print 'drag event caught' def send_mini_to_map( self, mini, count=1, addName=True ): if mini == None: return - if mini.get( ATTRIBUTE_URL ) == '' or mini.get( ATTRIBUTE_URL ) == 'http://': - 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 ) )) ) + if mini.get( 'url' ) == '' or mini.get( 'url' ) == 'http://': + Parse.Post( self.chat.colorize(self.chat.syscolor, + '"%s" is not a valid URL, the mini "%s" will not be added to the map' % ( + mini.get( 'url' ), mini.get( 'name' ) )) ) return - session = component.get( COMPONENT_SESSION ) + session = component.get( 'session' ) if (session.my_role() != session.ROLE_GM) and (session.my_role() != session.ROLE_PLAYER): component.get("chat").InfoPost("You must be either a player or GM to use the miniature Layer") return - map = component.get(COMPONENT_MAP) + canvas = component.get('map') for loop in range( count ): msg = self.get_miniature_XML( mini, addName) msg = str("<map action='update'><miniatures>" + msg + "</miniatures></map>") - map.new_data( msg ) + canvas.new_data( msg ) session.send( msg ) def get_miniature_XML( self, mini_xml, addName = True ): msg = orpg.mapper.map_msg.mini_msg() - map = component.get( COMPONENT_MAP ) - session = component.get( COMPONENT_SESSION ) - msg.init_prop( ATTRIBUTE_ID, session.get_next_id() ) + canvas = component.get( 'map' ) + session = component.get( 'session' ) + msg.init_prop( 'id', session.get_next_id() ) msg.init_prop('selected', '1')# this will make the mini initially selected for k in mini_xml.keys(): # translate our attributes to map attributes @@ -193,24 +185,24 @@ if not addName and k == 'name': pass else: msg.init_prop( key, mini_xml.get( k ) ) unique = self.is_unique( mini_xml ) - if addName: label = mini_xml.get( ATTRIBUTE_NAME ) + if addName: label = mini_xml.get( 'name' ) else: label = '' return msg.get_all_xml() def is_unique( self, mini ): - unique = mini.get( ATTRIBUTE_UNIQUE ) + unique = mini.get( 'unique' ) val = 0 try: val = eval( unique ) except: val = len( unique ) return val def sanity_check_nodes( self ): - for node in self.xml.findall(TAG_MINIATURE): - if node.get( ATTRIBUTE_POSX ) == '': node.set( ATTRIBUTE_POSX, '0' ) - if node.get( ATTRIBUTE_POSY ) == '': node.set( ATTRIBUTE_POSY, '0' ) + for node in self.xml.findall('miniature'): + if node.get( 'posx' ) == '': node.set( 'posx', '0' ) + if node.get( 'posy' ) == '': node.set( 'posy', '0' ) def get_mini( self, index ): - try: return self.xml.findall(TAG_MINIATURE)[index] + try: return self.xml.findall('miniature')[index] except: return None class mini_handler( node_handler ): @@ -279,7 +271,7 @@ """Returns a dictionary of label => game tree miniature DOM node mappings. """ self.list = [] - for mini in self.handler.xml.findall(TAG_MINIATURE): self.list.append( mini.get( ATTRIBUTE_NAME ) ) + for mini in self.handler.xml.findall('miniature'): self.list.append( mini.get( 'name' ) ) return self.list def on_close(self, evt): @@ -314,6 +306,11 @@ self.frame = frame self.sizer = wx.BoxSizer( wx.VERTICAL ) + + self.text = wx.TextCtrl(self, 3, handler.xml.get('name')) + self.sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) + self.sizer.Add(self.text, 0, wx.EXPAND) + self.grid = minilib_grid( self, handler ) bbox = wx.BoxSizer( wx.HORIZONTAL ) @@ -333,6 +330,7 @@ self.SetAutoLayout(True) self.Fit() + self.Bind(wx.EVT_TEXT, self.on_text, id=3) self.Bind(wx.EVT_BUTTON, self.add_mini, newMiniBtn) self.Bind(wx.EVT_BUTTON, self.del_mini, delMiniBtn) self.Bind(wx.EVT_BUTTON, self.send_to_map, addMiniBtn) @@ -354,7 +352,7 @@ """Event handler for the 'Add 1' button. Sends the miniature defined by the currently selected row to the map, once. """ - index = self.grid.GetGridCursorRow() + index = self.grid.GetSelectedRows()[0] if len(self.grid.GetSelectedRows()) > 0 else 0 self.handler.send_mini_to_map( self.handler.get_mini( index ) ) def send_group_to_map( self, evt=None ): @@ -370,10 +368,16 @@ try: value = eval( dlg.GetValue() ) except: value = 0 print 'getting selected index for batch send' - index = self.grid.GetGridCursorRow() + index = self.grid.GetSelectedRows()[0] if len(self.grid.GetSelectedRows()) > 0 else 0 print 'sending batch to map' self.handler.send_mini_to_map( self.handler.get_mini( index ), value ) + def on_text(self, evt): + txt = self.text.GetValue() + if txt != "": + self.handler.xml.set('name',txt) + self.handler.rename(txt) + class minilib_grid(wx.grid.Grid): """A wxGrid subclass designed for editing game tree miniature library nodes. @@ -392,9 +396,10 @@ self.AutoSizeColumns() self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.select_cell) + self.Bind(wx.grid.EVT_GRID_LABEL_LEFT_CLICK, self.select_cell) def update_cols( self ): - for n in self.handler.xml.findall(TAG_MINIATURE): + for n in self.handler.xml.findall('miniature'): for k in n.keys(): if k not in self.keys: self.keys.append( k ) @@ -413,7 +418,7 @@ """Returns the list of 'miniature' DOM elements associated with this miniature library. """ - return self.handler.xml.findall( TAG_MINIATURE ) + return self.handler.xml.findall( 'miniature' ) def add_row( self, count = 1 ): """creates a new miniature node, and then adds it to the current @@ -421,8 +426,8 @@ """ self.AppendRows( count ) node = self.handler.new_mini( { - ATTRIBUTE_NAME :' ', - ATTRIBUTE_URL :'http://'} )# minidom.Element( TAG_MINIATURE ) + 'name' :' ', + 'url' :'http://'} )# minidom.Element( 'miniature' ) self.update_all() #self.handler.xml.append( node ) @@ -433,11 +438,9 @@ """ if self.selectedRow > -1: pos = self.selectedRow - list = self.handler.xml.findall(TAG_MINIATURE) + list = self.handler.xml.findall('miniature') self.handler.xml.remove( list[pos] ) self.DeleteRows( pos, 1 ) - list = self.getList() - del list[ pos ] def on_cell_change( self, evt ): """Event handler for cell selection changes. selected row is used @@ -481,7 +484,7 @@ return self.GetTable().GetValue( self.selectedRow, 1 ) def getSelectedSerial( self ): - """Returns the ATTRIBUTE_UNIQUE value for the selected row + """Returns the 'unique' value for the selected row """ return self.GetTable().GetValue( self.selectedRow, 2 )