[Winopenrpg-developer] openrpg1/orpg/mapper __init__.py,NONE,1.1 background.py,NONE,1.1 background_h
Status: Inactive
Brought to you by:
digitalxero
Update of /cvsroot/winopenrpg/openrpg1/orpg/mapper In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30930/orpg/mapper Added Files: __init__.py background.py background_handler.py background_msg.py base.py base_handler.py base_msg.py fog.py fog_handler.py fog_msg.py grid.py grid_handler.py grid_msg.py images.py isometric.py map.py map_handler.py map_msg.py map_prop_dialog.py map_utils.py map_version.py min_dialogs.py miniatures.py miniatures_handler.py miniatures_msg.py region.py whiteboard.py whiteboard_handler.py whiteboard_msg.py Log Message: Initial commit of OpenRPG++ python --- NEW FILE: whiteboard_msg.py --- # Copyright (C) 2000-2001 The OpenRPG Project # # ope...@li... # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # -- # # File: mapper/whiteboard_msg.py # Author: Chris Davis # Maintainer: # Version: # $Id: whiteboard_msg.py,v 1.1 2006/01/26 17:33:16 digitalxero Exp $ # # Description: This file contains some of the basic definitions for the chat # utilities in the orpg project. # __version__ = "$Id: whiteboard_msg.py,v 1.1 2006/01/26 17:33:16 digitalxero Exp $" from base_msg import * class item_msg(map_element_msg_base): def __init__(self,reentrant_lock_object = None, tagname = "line"): self.tagname = tagname # set this to be for items. Tagname gets used in some base class functions. map_element_msg_base.__init__(self,reentrant_lock_object) # call base class # convenience method to use if only this item is modified # outputs a <map/> element containing only the changes to this item def standalone_update_text(self,update_id_string): buffer = "<map id='" + update_id_string + "'>" buffer += "<whiteboard>" buffer += self.get_changed_xml() buffer += "</whiteboad></map>" return buffer # convenience method to use if only this item is modified # outputs a <map/> element that deletes this item def standalone_delete_text(self,update_id_string): buffer = None if self._props.has_key("id"): buffer = "<map id='" + update_id_string + "'>" buffer += "<whiteboard>" buffer += "<"+self.tagname+" action='del' id='" + self._props("id") + "'/>" buffer += "</whiteboard></map>" return buffer # convenience method to use if only this item is modified # outputs a <map/> element to add this item def standalone_add_text(self,update_id_string): buffer = "<map id='" + update_id_string + "'>" buffer += "<whiteboard>" buffer += self.get_all_xml() buffer += "</whiteboard></map>" return buffer def get_all_xml(self,action="new",output_action=1): return map_element_msg_base.get_all_xml(self,action,output_action) def get_changed_xml(self,action="update",output_action=1): return map_element_msg_base.get_changed_xml(self,action,output_action) class whiteboard_msg(map_element_msg_base): def __init__(self,reentrant_lock_object = None): self.tagname = "whiteboard" map_element_msg_base.__init__(self,reentrant_lock_object) def init_from_dom(self,xml_dom): self.p_lock.acquire() if xml_dom.tagName == self.tagname: if xml_dom.getAttributeKeys(): for k in xml_dom.getAttributeKeys(): self.init_prop(k,xml_dom.getAttribute(k)) for c in xml_dom._get_childNodes(): item = item_msg(self.p_lock,c._get_nodeName()) try: item.init_from_dom(c) except Exception, e: print e continue id = item.get_prop("id") action = item.get_prop("action") if action == "new": self.children[id] = item elif action == "del": if self.children.has_key(id): self.children[id] = None del self.children[id] elif action == "update": if self.children.has_key(id): self.children[id].init_props(item.get_all_props()) else: self.p_lock.release() raise Exception, "Error attempting to initialize a " + self.tagname + " from a non-<" + self.tagname + "/> element in whiteboard" self.p_lock.release() def set_from_dom(self,xml_dom): self.p_lock.acquire() if xml_dom.tagName == self.tagname: if xml_dom.getAttributeKeys(): for k in xml_dom.getAttributeKeys(): self.set_prop(k,xml_dom.getAttribute(k)) for c in xml_dom._get_childNodes(): item = item_msg(self.p_lock, c._get_nodeName()) try: print "setting from dom" item.set_from_dom(c) except Exception, e: print e continue id = item.get_prop("id") action = item.get_prop("action") if action == "new": self.children[id] = item elif action == "del": if self.children.has_key(id): self.children[id] = None del self.children[id] elif action == "update": if self.children.has_key(id): self.children[id].set_props(item.get_all_props()) else: self.p_lock.release() raise Exception, "Error attempting to set a " + self.tagname + " from a non-<" + self.tagname + "/> element" self.p_lock.release() --- NEW FILE: grid_handler.py --- # # ope...@li... # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # -- # # File: orpg/mapper/grid_handler.py # Author: OpenRPG Team # Maintainer: # Version: # $Id: grid_handler.py,v 1.1 2006/01/26 17:33:16 digitalxero Exp $ # # Description: grid layer handler # __version__ = "$Id: grid_handler.py,v 1.1 2006/01/26 17:33:16 digitalxero Exp $" from grid import * from base_handler import * CTRL_GRID_LINE = wxNewId() CTRL_GRID_MODE = wxNewId() CTRL_GRID_COLOR = wxNewId() CTRL_GRID_SNAP = wxNewId() CTRL_GRID_SIZE = wxNewId() CTRL_GRID_RATIO = wxNewId() CTRL_GRID_APPLY = wxNewId() class grid_handler(base_layer_handler): def __init__(self, parent, id, canvas): base_layer_handler.__init__(self, parent, id, canvas) def build_ctrls(self): base_layer_handler.build_ctrls(self) self.line_type = wxChoice(self, CTRL_GRID_LINE, choices = ["No Lines", "Dotted Lines", "Solid Lines" ]) #EVT_CHOICE(self, CTRL_GRID_LINE, self.on_line_type) self.grid_mode = wxChoice(self, CTRL_GRID_MODE, choices = ["Rectangular", "Hexagonal","Isometric"]) self.grid_snap = wxCheckBox(self, CTRL_GRID_SNAP, " Snap") self.grid_size = orpgTextCtrl(self, CTRL_GRID_SIZE, size=(32,-1) ) self.grid_ratio = orpgTextCtrl(self, CTRL_GRID_RATIO, size=(32,-1) ) self.color_button = wxButton(self, CTRL_GRID_COLOR, "Color", style=wxBU_EXACTFIT) self.apply_button = wxButton(self, CTRL_GRID_APPLY, "Apply", style=wxBU_EXACTFIT) self.color_button.SetBackgroundColour(wxBLACK) self.color_button.SetForegroundColour(wxWHITE) #EVT_CHOICE(self, CTRL_GRID_MODE, self.on_mode) self.sizer.Prepend(wxSize(20,25),1) self.sizer.Prepend(self.apply_button, 0, wxEXPAND) self.sizer.Prepend(wxSize(10,25)) self.sizer.Prepend(self.color_button, 0, wxEXPAND) self.sizer.Prepend(wxSize(10,25)) self.sizer.Prepend(self.grid_snap, 0, wxEXPAND) self.sizer.Prepend(wxSize(3,25)) self.sizer.Prepend(self.grid_mode, 0, wxEXPAND) self.sizer.Prepend(wxSize(3,25)) self.sizer.Prepend(self.line_type, 0, wxEXPAND) self.sizer.Prepend(wxSize(3,25)) self.sizer.Prepend(self.grid_ratio, 0, wxEXPAND) self.sizer.Prepend(wxStaticText(self, -1, "Ratio: "),0,wxALIGN_CENTER) self.sizer.Prepend(wxSize(3,25)) self.sizer.Prepend(self.grid_size, 0, wxEXPAND) self.sizer.Prepend(wxStaticText(self, -1, "Size: "),0,wxALIGN_CENTER) EVT_BUTTON(self, CTRL_GRID_COLOR, self.on_bg_color) EVT_BUTTON(self, CTRL_GRID_APPLY, self.on_apply) self.update_info() def update_info(self): layer = self.canvas.layers['grid'] self.grid_size.SetValue(str(layer.get_unit_size())) self.grid_ratio.SetValue(str(layer.get_iso_ratio())) self.grid_mode.SetSelection(layer.get_mode()) self.line_type.SetSelection(layer.get_line_type()) self.color_button.SetBackgroundColour(layer.get_color()) self.grid_snap.SetValue(layer.is_snap()) def build_menu(self,label = "Grid"): base_layer_handler.build_menu(self,label) def on_bg_color(self,evt): data = wxColourData() data.SetChooseFull(true) dlg = wxColourDialog(self.canvas, data) if dlg.ShowModal() == wxID_OK: data = dlg.GetColourData() color = data.GetColour() self.color_button.SetBackgroundColour(color) dlg.Destroy() def on_apply(self, evt): session=self.canvas.frame.session if (session.my_role() <> session.ROLE_GM): self.top_frame.myopenrpg.get_component("chat").InfoPost("You must be a GM to use this feature") return self.canvas.layers['grid'].set_grid(int(self.grid_size.GetValue()),self.grid_snap.GetValue(), self.color_button.GetBackgroundColour(),self.grid_mode.GetSelection(),self.line_type.GetSelection(),float(self.grid_ratio.GetValue())) self.update_info() self.canvas.send_map_data() self.canvas.Refresh() --- NEW FILE: map_msg.py --- # Copyright (C) 2000-2001 The OpenRPG Project # # ope...@li... # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # -- # # File: mapper/map_msg.py # Author: OpenRPG # Maintainer: # Version: # $Id: map_msg.py,v 1.1 2006/01/26 17:33:16 digitalxero Exp $ # # Description: # __version__ = "$Id: map_msg.py,v 1.1 2006/01/26 17:33:16 digitalxero Exp $" #from base import * from base_msg import * from background_msg import * from grid_msg import * from miniatures_msg import * from whiteboard_msg import * from fog_msg import * """ <map name=? id=? > <bg type=? file=? color=? /> <grid size=? snap=? /> <miniatures serial=? > <miniature path=? posx=? posy=? heading=? face=? owner=? label=? locked=? width=? height=? /> </miniatures> </map> """ class map_msg(map_element_msg_base): def __init__(self,reentrant_lock_object = None): self.tagname = "map" map_element_msg_base.__init__(self,reentrant_lock_object) def init_from_dom(self,xml_dom): self.p_lock.acquire() if xml_dom.tagName == self.tagname: # If this is a map message, look for the "action=new" # Notice we only do this when the root is a map tag if self.tagname == "map": if xml_dom.getAttributeKeys(): for k in xml_dom.getAttributeKeys(): if k == "action" and xml_dom.getAttribute( k ) == "new": #print "******* Resetting all map attributes for a new map load..." self.clear() #print "******* Old map has been cleared...loading new map..." # Process all of the properties in each tag if xml_dom.getAttributeKeys(): for k in xml_dom.getAttributeKeys(): self.init_prop(k,xml_dom.getAttribute(k)) for c in xml_dom._get_childNodes(): name = c._get_nodeName() if not self.children.has_key(name): if name == "miniatures": self.children[name] = minis_msg(self.p_lock) elif name == "grid": self.children[name] = grid_msg(self.p_lock) elif name == "bg": self.children[name] = bg_msg(self.p_lock) elif name == "whiteboard": self.children[name] = whiteboard_msg(self.p_lock) elif name == "fog": self.children[name] = fog_msg(self.p_lock) else: print "Unrecognized tag " + name + " found in map_msg.init_from_dom - skipping" continue try: self.children[name].init_from_dom(c) except Exception, e: print "map_msg.init_from_dom() exception: ", e continue else: self.p_lock.release() raise Exception, "Error attempting to initialize a " + self.tagname + " from a non-<" + self.tagname + "/> element" self.p_lock.release() def set_from_dom(self,xml_dom): self.p_lock.acquire() if xml_dom.tagName == self.tagname: # If this is a map message, look for the "action=new" # Notice we only do this when the root is a map tag if self.tagname == "map": if xml_dom.getAttributeKeys(): for k in xml_dom.getAttributeKeys(): if k == "action" and xml_dom.getAttribute( k ) == "new": #print "******* Resetting all map attributes for a new map load..." self.clear() #print "******* Old map has been cleared...loading new map..." # Process all of the properties in each tag if xml_dom.getAttributeKeys(): for k in xml_dom.getAttributeKeys(): self.set_prop(k,xml_dom.getAttribute(k)) for c in xml_dom._get_childNodes(): name = c._get_nodeName() if not self.children.has_key(name): if name == "miniatures": self.children[name] = minis_msg(self.p_lock) elif name == "grid": self.children[name] = grid_msg(self.p_lock) elif name == "bg": self.children[name] = bg_msg(self.p_lock) elif name == "whiteboard": self.children[name] = whiteboard_msg(self.p_lock) print "set_from dom msg", self.children[name] elif name == "fog": self.children[name] = fog_msg(self.p_lock) else: print "Unrecognized tag " + name + " found in map_msg.init_from_dom - skipping" continue try: self.children[name].set_from_dom(c) except Exception, e: print "map_msg.set_from_dom() exception: " , e continue else: self.p_lock.release() raise Exception, "Error attempting to set a " + self.tagname + " from a non-<" + self.tagname + "/> element in map" self.p_lock.release() def get_all_xml(self,action="new",output_action=1): return map_element_msg_base.get_all_xml(self,action,output_action) def get_changed_xml(self,action="update",output_action=1): return map_element_msg_base.get_changed_xml(self,action,output_action) --- NEW FILE: miniatures.py --- # Copyright (C) 2000-2001 The OpenRPG Project # # ope...@li... # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # -- # # File: mapper/miniatures.py # Author: Chris Davis # Maintainer: # Version: # $Id: miniatures.py,v 1.1 2006/01/26 17:33:16 digitalxero Exp $ # # Description: This file contains some of the basic definitions for the chat # utilities in the orpg project. # __version__ = "$Id: miniatures.py,v 1.1 2006/01/26 17:33:16 digitalxero Exp $" from base import * #from images import * import images MIN_STICKY_BACK = -0XFFFFFF MIN_STICKY_FRONT = 0xFFFFFF ##---------------------------------------- ## miniature object ##---------------------------------------- FACE_NONE = 0 FACE_NORTH = 1 FACE_NORTHEAST = 2 FACE_EAST = 3 FACE_SOUTHEAST = 4 FACE_SOUTH = 5 FACE_SOUTHWEST = 6 FACE_WEST = 7 FACE_NORTHWEST = 8 SNAPTO_ALIGN_CENTER = 0 SNAPTO_ALIGN_TL = 1 def cmp_zorder(first,second): f = first.zorder s = second.zorder if f == None: f = 0 if s == None: s = 0 if f == s: value = 0 elif f < s: value = -1 else: value = 1 return value class bmp_miniature(protectable_attributes): def __init__(self, id,path, bmp, pos=cmpPoint(0,0), heading=FACE_NONE, face=FACE_NONE, label="", locked=false, hide=false, snap_to_align=SNAPTO_ALIGN_CENTER,zorder = 0, width=0, height=0): protectable_attributes.__init__(self) self._protected_attr = ["heading", "face", "label", "path", "pos", "locked", "snap_to_align", "hide", "id", "zorder", "width", "height"] self.heading = heading self.face = face self.label = label self.path = path self.bmp = bmp self.pos = pos self.selected = false self.locked = locked self.snap_to_align = snap_to_align self.hide = hide self.id = id self.zorder = zorder self.left = 0 if not width: self.width = 0 else: self.width = width if not height: self.height = 0 else: self.height = height self.right = bmp.GetWidth() self.top = 0 self.bottom = bmp.GetHeight() #self._clean_all_attr() def __del__(self): #images.delete_img(self.bmp) del self.bmp self.bmp = None def set_bmp(self,bmp): self.bmp = bmp def set_min_props(self, heading=FACE_NONE, face=FACE_NONE, label="", locked=false, hide=false, width=0, height=0): self.heading = heading self.face = face self.label = label self.locked = locked self.hide = hide self.width = width self.height = height def hit_test(self, pt): rect = self.get_rect() result = None # fixes problem between wxPython version 2.4.0.7 and higher # and wxPython version 2.4.0.2 and lower --Snowdog try: #2.4.0.7 and up check result = rect.InsideXY(pt.x, pt.y) except: #2.4.0.2 and lower check result = rect.Inside(pt.x, pt.y) return result def get_rect(self): return wxRect(self.pos.x, self.pos.y, self.bmp.GetWidth(), self.bmp.GetHeight()) def draw(self, dc, op = wxCOPY): if self.bmp != None and self.bmp.Ok(): # check if hidden if self.hide: return true dc.DrawBitmap(self.bmp,self.pos.x,self.pos.y,true) # Blit the miniature bmp # memDC = wxMemoryDC() # memDC.SelectObject(self.bmp) # dc.Blit(self.pos.x, self.pos.y, # self.bmp.GetWidth(), self.bmp.GetHeight(), # memDC, 0, 0, op, true) # memDC.SelectObject(wxNullBitmap) # del memDC # set the width and height of the image if self.width and self.height: tmp_image = wxImageFromBitmap(self.bmp) tmp_image.Rescale(int(self.width), int(self.height)) self.bmp = wxBitmapFromImage(tmp_image) self.left = 0 self.right = self.bmp.GetWidth() self.top = 0 self.bottom = self.bmp.GetHeight() # Draw the facing marker if needed if self.face: x_mid = self.pos.x + (self.bmp.GetWidth()/2) x_right = self.pos.x + self.bmp.GetWidth() y_mid = self.pos.y + (self.bmp.GetHeight()/2) y_bottom = self.pos.y + self.bmp.GetHeight() dc.SetPen( wxWHITE_PEN ) dc.SetBrush( wxRED_BRUSH ) triangle = [] # Figure out which direction to draw the marker!! if self.face == FACE_WEST: triangle.append(cmpPoint(self.pos.x,self.pos.y)) triangle.append(cmpPoint(self.pos.x - 5, y_mid)) triangle.append(cmpPoint(self.pos.x, y_bottom)) elif self.face == FACE_EAST: triangle.append(cmpPoint(x_right, self.pos.y)) triangle.append(cmpPoint(x_right + 5, y_mid)) triangle.append(cmpPoint(x_right, y_bottom)) elif self.face == FACE_SOUTH: triangle.append(cmpPoint(self.pos.x, y_bottom)) triangle.append(cmpPoint(x_mid, y_bottom + 5)) triangle.append(cmpPoint(x_right, y_bottom)) elif self.face == FACE_NORTH: triangle.append(cmpPoint(self.pos.x, self.pos.y)) triangle.append(cmpPoint(x_mid, self.pos.y - 5)) triangle.append(cmpPoint(x_right, self.pos.y)) elif self.face == FACE_NORTHEAST: triangle.append(cmpPoint(x_mid, self.pos.y)) triangle.append(cmpPoint(x_right + 5, self.pos.y - 5)) triangle.append(cmpPoint(x_right, y_mid)) triangle.append(cmpPoint(x_right, self.pos.y)) elif self.face == FACE_SOUTHEAST: triangle.append(cmpPoint(x_right, y_mid)) triangle.append(cmpPoint(x_right + 5, y_bottom + 5)) triangle.append(cmpPoint(x_mid, y_bottom)) triangle.append(cmpPoint(x_right, y_bottom)) elif self.face == FACE_SOUTHWEST: triangle.append(cmpPoint(x_mid, y_bottom)) triangle.append(cmpPoint(self.pos.x - 5, y_bottom + 5)) triangle.append(cmpPoint(self.pos.x, y_mid)) triangle.append(cmpPoint(self.pos.x, y_bottom)) elif self.face == FACE_NORTHWEST: triangle.append(cmpPoint(self.pos.x, y_mid)) triangle.append(cmpPoint(self.pos.x - 5, self.pos.y - 5)) triangle.append(cmpPoint(x_mid, self.pos.y)) triangle.append(cmpPoint(self.pos.x, self.pos.y)) dc.DrawPolygon(triangle) dc.SetBrush(wxNullBrush) dc.SetPen(wxNullPen) # Draw the heading if needed if self.heading: x_adjust = 0 y_adjust = 4 x_half = self.bmp.GetWidth()/2 y_half = self.bmp.GetHeight()/2 x_quarter = self.bmp.GetWidth()/4 y_quarter = self.bmp.GetHeight()/4 x_3quarter = x_quarter*3 y_3quarter = y_quarter*3 x_full = self.bmp.GetWidth() y_full = self.bmp.GetHeight() x_center = self.pos.x + x_half y_center = self.pos.y + y_half # Remember, the pen/brush must be a different color than the # facing marker!!!! We'll use black/cyan for starters. # Also notice that we will draw the heading on top of the # larger facing marker. dc.SetPen( wxBLACK_PEN ) dc.SetBrush( wxCYAN_BRUSH ) ## wxBrush = dc.GetBrush() ## wxBrush.SetStyle( wxCROSSDIAG_HATCH ) ## dc.SetBrush( wxBrush ) triangle = [] # Figure out which direction to draw the marker!! if self.heading == FACE_NORTH: triangle.append(cmpPoint(x_center - x_quarter, y_center - y_half )) triangle.append(cmpPoint(x_center, y_center - y_3quarter )) triangle.append(cmpPoint(x_center + x_quarter, y_center - y_half )) elif self.heading == FACE_SOUTH: triangle.append(cmpPoint(x_center - x_quarter, y_center + y_half )) triangle.append(cmpPoint(x_center, y_center + y_3quarter )) triangle.append(cmpPoint(x_center + x_quarter, y_center + y_half )) elif self.heading == FACE_NORTHEAST: triangle.append(cmpPoint(x_center + x_quarter, y_center - y_half )) triangle.append(cmpPoint(x_center + x_3quarter, y_center - y_3quarter )) triangle.append(cmpPoint(x_center + x_half, y_center - y_quarter )) elif self.heading == FACE_EAST: triangle.append(cmpPoint(x_center + x_half, y_center - y_quarter )) triangle.append(cmpPoint(x_center + x_3quarter, y_center )) triangle.append(cmpPoint(x_center + x_half, y_center + y_quarter )) elif self.heading == FACE_SOUTHEAST: triangle.append(cmpPoint(x_center + x_half, y_center + y_quarter )) triangle.append(cmpPoint(x_center + x_3quarter, y_center + y_3quarter )) triangle.append(cmpPoint(x_center + x_quarter, y_center + y_half )) elif self.heading == FACE_SOUTHWEST: triangle.append(cmpPoint(x_center - x_quarter, y_center + y_half )) triangle.append(cmpPoint(x_center - x_3quarter, y_center + y_3quarter )) triangle.append(cmpPoint(x_center - x_half, y_center + y_quarter )) elif self.heading == FACE_WEST: triangle.append(cmpPoint(x_center - x_half, y_center + y_quarter )) triangle.append(cmpPoint(x_center - x_3quarter, y_center )) triangle.append(cmpPoint(x_center - x_half, y_center - y_quarter )) elif self.heading == FACE_NORTHWEST: triangle.append(cmpPoint(x_center - x_half, y_center - y_quarter )) triangle.append(cmpPoint(x_center - x_3quarter, y_center - y_3quarter )) triangle.append(cmpPoint(x_center - x_quarter, y_center - y_half )) dc.DrawPolygon(triangle) dc.SetBrush(wxNullBrush) dc.SetPen(wxNullPen) #selected outline if self.selected: dc.SetPen(wxRED_PEN) dc.SetBrush(wxTRANSPARENT_BRUSH) dc.DrawRectangle(self.pos.x, self.pos.y, self.bmp.GetWidth(), self.bmp.GetHeight()) dc.SetBrush(wxNullBrush) dc.SetPen(wxNullPen) # draw label if len(self.label): dc.SetTextForeground(wxRED) (textWidth,textHeight) = dc.GetTextExtent(self.label) x = self.pos.x +((self.bmp.GetWidth() - textWidth) /2) - 1 y = self.pos.y + self.bmp.GetHeight() + 6 dc.SetPen(wxWHITE_PEN) dc.SetBrush(wxWHITE_BRUSH) dc.DrawRectangle(x,y,textWidth+2,textHeight+2) if (textWidth+2>self.right): self.right+=int((textWidth+2-self.right)/2)+1 self.left-=int((textWidth+2-self.right)/2)+1 self.bottom=y+textHeight+2-self.pos.y dc.SetPen(wxNullPen) dc.SetBrush(wxNullBrush) dc.DrawText(self.label,x+1,y+1) self.top-=5 self.bottom+=5 self.left-=5 self.right+=5 return true else: return false def toxml(self, action = "update",preserve_changed=0): xml_str = "" if preserve_changed: original_changed = self._changed_attr() if action == "del": xml_str = "<miniature action='del' id='" + self.id + "'/>" return xml_str if action == "new": self._dirty_all_attr() changed = self._changed_attr() if changed: # if there are any changes, make sure id is one of them if not changed.has_key("id"): self._dirty_attr("id") changed = self._changed_attr() xml_str = "<miniature" xml_str += " action='" + action + "'" for a in changed.keys(): if a == "pos": if not(self.pos is None): xml_str += " posx='" + str(self.pos.x) + "'" xml_str += " posy='" + str(self.pos.y) + "'" elif a == "heading": if not (self.heading is None): xml_str += " heading='" + str(self.heading) + "'" elif a == "face": if not (self.face is None): xml_str += " face='" + str(self.face) + "'" elif a == "path": if not (self.path is None): xml_str += " path='" + self.path + "'" elif a == "locked": if not (self.locked is None): xml_str+= " locked='" + str(self.locked) + "'" elif a == "hide": if not (self.hide is None): xml_str+= " hide='" + str(self.hide) + "'" elif a == "label": if not (self.label is None): xml_str+= " label='" + self.label + "'" elif a == "snap_to_align": if not (self.snap_to_align is None): xml_str+= " align='" + str(self.snap_to_align) + "'" elif a == "id": if not (self.id is None): xml_str+= " id='" + self.id + "'" elif a == "zorder": if not(self.id is None): xml_str+= " zorder='" + str(self.zorder) + "'" elif a == "width": if not(self.width is None): xml_str+= " width='" + str(self.width) + "'" elif a == "height": if not(self.height is None): xml_str+= " height='" + str(self.height) + "'" xml_str += "/>" self._clean_all_attr() if preserve_changed: for a in original_changed.keys(): self._dirty_attr(a) return xml_str def takedom(self,xml_dom): posx = xml_dom.getAttribute("posx") if posx <> "": self.pos.x = int(posx) self._clean_attr("pos") posy = xml_dom.getAttribute("posy") if posy <> "": self.pos.y = int(posy) self._clean_attr("pos") heading = xml_dom.getAttribute("heading") if heading <> "": self.heading = int(heading) self._clean_attr("heading") face = xml_dom.getAttribute("face") if face <> "": self.face = int(face) self._clean_attr("face") path = xml_dom.getAttribute("path") if path <> "": self.path = path ## self.bmp = wxBitmap("icons/fetching.png",wxBITMAP_TYPE_PNG) ## load_img(path,"miniature",self.id) # change the bitmap image # Sorry if I hosed this up...just didn't look right self.set_bmp(images.load_img(path,"miniature",self.id)) # change the bitmap image self._clean_attr("path") locked = xml_dom.getAttribute("locked") if locked <> "": self.locked = int(locked) self._clean_attr("locked") hide = xml_dom.getAttribute("hide") if hide <> "": self.hide = int(hide) self._clean_attr("hide") label = xml_dom.getAttribute("label") if label <> "": self.label = label self._clean_attr("label") zorder = xml_dom.getAttribute("zorder") if zorder <> "": self.zorder = int(zorder) self._clean_attr("zorder") snap_to_align = xml_dom.getAttribute("align") if snap_to_align <> "": self.snap_to_align = int(snap_to_align) self._clean_attr("snap_to_align") id = xml_dom.getAttribute("id") if id <> "": self.id = id self._clean_attr("id") width = xml_dom.getAttribute("width") if width <> "": self.width = int(width) self._clean_attr("width") height = xml_dom.getAttribute("height") if height <> "": self.height = int(height) self._clean_attr("height") ##----------------------------- ## miniature layer ##----------------------------- class miniature_layer(layer_base): def __init__(self, canvas): layer_base.__init__(self) self._protected_attr = ["serial_number"] self.canvas = canvas self.id = -1 self.miniatures = [] self.serial_number = 0 self._clean_all_attr() def next_serial( self ): self.serial_number += 1 return self.serial_number def get_next_highest_z(self): z = len(self.miniatures)+1 return z def cleanly_collapse_zorder(self): # lock the zorder stuff sorted_miniatures = self.miniatures[:] sorted_miniatures.sort(cmp_zorder) i = 0 for mini in sorted_miniatures: mini.zorder = i i = i + 1 mini._clean_attr("zorder") # unlock the zorder stuff def collapse_zorder(self): # lock the zorder stuff sorted_miniatures = self.miniatures[:] sorted_miniatures.sort(cmp_zorder) i = 0 for mini in sorted_miniatures: if (mini.zorder != MIN_STICKY_BACK) and (mini.zorder != MIN_STICKY_FRONT): ## print "zorder is " + str(mini.zorder) + " and is being set to " + str(i) mini.zorder = i else: print "sticky item found having value of " + str( mini.zorder) i = i + 1 # unlock the zorder stuff def rollback_serial( self ): self.serial_number -= 1 def add_miniature(self,id,path,pos=cmpPoint(0,0),label="",heading=FACE_NONE,face=FACE_NONE,width=0, height=0): print "Before mini creation:" + str(self.get_next_highest_z()) bmp = images.load_img(path,"miniature",id) if bmp: mini = bmp_miniature(id,path,bmp,pos,heading,face,label, zorder = self.get_next_highest_z(),width = width,height = height) print "After mini creation:" + str(self.get_next_highest_z()) self.miniatures.append(mini) print "After mini addition:" + str(self.get_next_highest_z()) mini._dirty_all_attr() xml_str = "<map><miniatures>" xml_str += mini.toxml("new") xml_str += "</miniatures></map>" self.canvas.frame.session.send(xml_str) else: print "Invalid image " + path + " has been ignored!" def get_miniature_by_id(self,id): for mini in self.miniatures: if mini.id == id: return mini return None def del_miniature(self,min): xml_str = "<map><miniatures>" xml_str += min.toxml("del") xml_str += "</miniatures></map>" self.canvas.frame.session.send(xml_str) self.miniatures.remove(min) del min self.collapse_zorder() def del_all_miniatures(self): while len(self.miniatures): min = self.miniatures.pop() del min self.collapse_zorder() def draw(self,dc,topleft,size): #min = self.miniatures.keys() sorted_miniatures = self.miniatures[:] sorted_miniatures.sort(cmp_zorder) for m in sorted_miniatures: if (m.pos.x>topleft[0]-m.right and m.pos.y>topleft[1]-m.bottom and m.pos.x<topleft[0]+size[0]-m.left and m.pos.y<topleft[1]+size[1]-m.top): m.draw(dc) def find_miniature(self, pt,only_locked=false): min_list = [] for m in self.miniatures: if m.hit_test(pt): if only_locked and not m.locked: min_list.append(m) elif not only_locked: min_list.append(m) else: continue if len(min_list) > 0: return min_list else: return None def toxml(self,action="update"): """ format """ attributes = "" if action == "new": self._dirty_all_attr() changed = self._changed_attr() if changed: for a in changed.keys(): if a == "serial_number": attributes += " serial='" + str(self.serial_number) + "'" self._clean_attr("serial_number") minis_string = "" if self.miniatures: for m in self.miniatures: minis_string += m.toxml(action) if minis_string or changed: s = "<miniatures" s += attributes if minis_string: s += ">" s += minis_string s += "</miniatures>" else: s+="/>" return s else: return "" def takedom(self,xml_dom): serial_number = xml_dom.getAttribute('serial') if serial_number <> "": self.serial_number = int(serial_number) self._clean_attr("serial_number") children = xml_dom._get_childNodes() for c in children: action = c.getAttribute("action") id = c.getAttribute('id') if action == "del": mini = self.get_miniature_by_id(id) if mini: self.miniatures.remove(mini) del mini else: wxMessageBox("Deletion of unknown mini attempted","Map Synchronization Error") elif action == "new": pos = cmpPoint(int(c.getAttribute('posx')),int(c.getAttribute('posy'))) path = c.getAttribute('path') label = c.getAttribute('label') try: height = int(c.getAttribute('height')) width = int(c.getAttribute('width')) locked = int(c.getAttribute('locked')) hide = int(c.getAttribute('hide')) heading = int(c.getAttribute('heading')) face = int(c.getAttribute('face')) snap_to_align = int(c.getAttribute('align')) except: height = width = locked = hide = heading = face = snap_to_align = zorder = 0 # The following section is necessary because the zorder might not be sent # e.g. 0.9.4 clients # Assume everything is okay zorder_bad = 0 # If there's a problem getting a zorder (like it's not there) # set the flag try: zorder = int(c.getAttribute('zorder')) except: zorder_bad = 1 zorder = 0 min = bmp_miniature(id, path, images.load_img(path,"miniature",id),pos, heading, face, label, locked, hide, snap_to_align, zorder, width, height) self.miniatures.append(min) # collapse the zorder. If the client behaved well, then nothing should change. # Otherwise, this will ensure that there's some kind of z-order self.collapse_zorder() # Do the normal clean of this minis attributes min._clean_all_attr() # But dirty zorder if there was a problem with it. A new zorder should now # be in effect if zorder_bad: min._dirty_attr('zorder') else: mini = self.get_miniature_by_id(id) if mini: mini.takedom(c) else: wxMessageBox("Update of unknown mini attempted","Map Synchronization Error") #self.canvas.send_map_data() --- NEW FILE: __init__.py --- __all__ = [ 'background_handler', 'fog_msg', 'map_msg', 'background_msg', 'map_prop_dialog', 'background', 'map', 'base_handler', 'map_version', 'base_msg', 'min_dialogs', 'base', 'miniatures_handler', 'grid_handler', 'miniatures_msg', 'grid_msg', 'miniatures', 'grid', 'whiteboard_handler', 'images', 'whiteboard_msg', 'whiteboard', 'map_handler' ] --- NEW FILE: fog_msg.py --- # Copyright (C) 2000-2001 The OpenRPG Project # # ope...@li... # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # -- # # File: mapper/fog_msg.py # Author: Mark Tarrabain # Maintainer: # Version: # $Id: fog_msg.py,v 1.1 2006/01/26 17:33:16 digitalxero Exp $ # __version__ = "$Id: fog_msg.py,v 1.1 2006/01/26 17:33:16 digitalxero Exp $" from base_msg import * from region import * from orpg.minidom import Element import string class fog_msg(map_element_msg_base): def __init__(self,reentrant_lock_object = None): self.tagname = "fog" map_element_msg_base.__init__(self,reentrant_lock_object) self.use_fog = 0 self.fogregion=IRegion() self.fogregion.Clear() def get_line(self,outline,action,output_act): # xml_str = "" # xml_str += "<poly" # if (output_act): # xml_str += " action='" + action + "'" # xml_str += " outline='" + outline + "'" # xml_str += "/>" # return xml_str elem = Element( "poly" ) if ( output_act ): elem.setAttribute( "action", action ) if ( outline == 'all' ) or ( outline == 'none' ): elem.setAttribute( "outline", outline ) else: elem.setAttribute( "outline", "points" ) for pair in string.split( outline, ";" ): p = string.split( pair, "," ) point = Element( "point" ) point.setAttribute( "x", p[ 0 ] ) point.setAttribute( "y", p[ 1 ] ) elem.appendChild( point ) str = elem.toxml() elem.unlink() return str # convenience method to use if only this line is modified # outputs a <map/> element containing only the changes to this line def standalone_update_text(self,update_id_string): buffer = "<map id='" + update_id_string + "'>" buffer += "<fog>" buffer += self.get_changed_xml() buffer += "</fog></map>" return buffer def get_all_xml(self,action="new",output_action=1): return self.toxml(action,output_action) def get_changed_xml(self,action="update",output_action=1): return self.toxml(action,output_action) def toxml(self,action,output_action): #print "fog_msg.toxml called" #print "use_fog :",self.use_fog #print "output_action :",output_action #print "action :",action if not (self.use_fog): return "" fog_string = "" if self.fogregion.IsEmpty(): fog_string=self.get_line("all","del",output_action) for ri in self.fogregion.GetRectList(): x1=ri.GetX() x2=x1+ri.GetW()-1 y1=ri.GetY() y2=y1+ri.GetH()-1 fog_string += self.get_line(str(x1)+","+str(y1)+";"+ str(x2)+","+str(y1)+";"+ str(x2)+","+str(y2)+";"+ str(x1)+","+str(y2),action,output_action) s = "<fog" if fog_string: s += ">" s += fog_string s += "</fog>" else: s+="/>" return s def interpret_dom(self,xml_dom): self.use_fog=1 #print 'fog_msg.interpret_dom called' children = xml_dom._get_childNodes() #print "children",children for l in children: action = l.getAttribute("action") outline = l.getAttribute("outline") #print "action/outline",action, outline if (outline=="all"): polyline=[] self.fogregion.Clear() elif (outline=="none"): polyline=[] self.use_fog=0 self.fogregion.Clear() else: polyline=[] list = l._get_childNodes() for node in list: polyline.append( IPoint().make( int(node.getAttribute("x")), int(node.getAttribute("y")) ) ) # pointarray = outline.split(";") # for m in range(len(pointarray)): # pt=pointarray[m].split(",") # polyline.append(IPoint().make(int(pt[0]),int(pt[1]))) #print "length of polyline", len(polyline) if (len(polyline)>2): if action=="del": self.fogregion.FromPolygon(polyline,0) else: self.fogregion.FromPolygon(polyline,1) def init_from_dom(self,xml_dom): #print "xml_dom",xml_dom self.interpret_dom(xml_dom) --- NEW FILE: whiteboard_handler.py --- # Copyright (C) 2000-2001 The OpenRPG Project # # ope...@li... # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # -- # # File: mapper/whiteboard_hander.py # Author: OpenRPG Team # Maintainer: # Version: # $Id: whiteboard_handler.py,v 1.1 2006/01/26 17:33:16 digitalxero Exp $ # # Description: Whiteboard layer handler # __version__ = "$Id: whiteboard_handler.py,v 1.1 2006/01/26 17:33:16 digitalxero Exp $" from base_handler import * DELETE_ALL_LINES= wxNewId() LINE_REMOVE = wxNewId() LINE_TITLE_HACK = wxNewId() LINE_COLOR = wxNewId() LINE_WIDTH = wxNewId() SELECT_ITEM = wxNewId() # Text properties menu variables TEXT_REMOVE = wxNewId() TEXT_TITLE_HACK = wxNewId() TEXT_POINT_SIZE = wxNewId() TEXT_WEIGHT = wxNewId() TEXT_STYLE = wxNewId() TEXT_STRING = wxNewId() TEXT_COLOR = wxNewId() TEXT_STYLES = [wxNORMAL, wxITALIC] TEXT_WEIGHTS = [wxNORMAL, wxBOLD] TEXT_OKAY = wxNewId() TEXT_PROPERTIES = wxNewId() #drawing modes (added by Snowdog 05-09-2003) DRAW_MODE = wxNewId() DRAW_FREEFORM = 1 DRAW_POLYLINE = 2 DRAW_TEXT = 3 POLYLINE_END_TOLERANCE = 5 LIVE_REFRESH = wxNewId() LIVE_POLYLINE_DEFAULT = 1 class whiteboard_handler(base_layer_handler): def __init__(self, parent, id, canvas): self.drawing_mode = DRAW_FREEFORM self.line_string = "0,0;" self.drawing = false self.upperleft = wxPoint(0,0) self.lowerright = wxPoint(0,0) #polyline drawing vars self.polypoints = 0 self.lastpoint = None self.selected = None #text drawing vars self.style = str(wxNORMAL) self.weight = str(wxNORMAL) self.pointsize = str(12) self.text_selected_item = None #self.r_h = RGBHex() base_layer_handler.__init__(self, parent, id, canvas) self.build_text_properties_menu() self.wb = self.canvas.layers['whiteboard'] def build_ctrls(self): base_layer_handler.build_ctrls(self) self.color_button = wxButton(self, LINE_COLOR, "Pen Color", style=wxBU_EXACTFIT) self.drawmode_ctrl = wxChoice(self, DRAW_MODE, choices = ["Freeform", "Polyline","Text"]) self.drawmode_ctrl.SetSelection(0) #always start showing "Freeform" self.live_refresh = wxCheckBox(self, LIVE_REFRESH, " Live Refresh") self.live_refresh.SetValue(LIVE_POLYLINE_DEFAULT) self.color_button.SetBackgroundColour(wxBLACK) self.color_button.SetForegroundColour(wxWHITE) dwidthList=['1','2','3','4','5','6','7','8','9','10'] self.widthList=wxChoice(self,LINE_WIDTH,size=wxSize(40, 20),choices=dwidthList, name="choice") self.widthList.SetSelection(0) #always start showing "1" self.sizer.Prepend(wxSize(20,25),1) self.sizer.Prepend(self.color_button, 0, wxEXPAND) self.sizer.Prepend(wxSize(20,25)) self.sizer.Prepend(self.live_refresh, 0, wxEXPAND) self.sizer.Prepend(wxSize(10,25)) self.sizer.Prepend(self.drawmode_ctrl, 0, wxEXPAND) self.sizer.Prepend(wxStaticText(self, -1, "Drawing Mode: "),0,wxALIGN_CENTER) self.sizer.Prepend(wxSize(10,25)) self.sizer.Prepend(self.widthList, 0, wxEXPAND) self.sizer.Prepend(wxStaticText(self, -1, "Line Width: "),0,wxALIGN_CENTER) EVT_MOTION(self, self.on_motion) EVT_CHOICE(self, DRAW_MODE, self.check_draw_mode) EVT_BUTTON(self, LINE_COLOR, self.on_pen_color) EVT_CHOICE(self, LINE_WIDTH, self.on_pen_width) def build_text_properties_menu(self, label="Text Properties"): self.text_properties_dialog = wxDialog(self, -1, "Text Properties", name = "Text Properties") self.text_props_sizer = wxBoxSizer(wxVERTICAL) okay_boxer = wxBoxSizer(wxHORIZONTAL) okay_button = wxButton(self.text_properties_dialog, TEXT_OKAY, "APPLY") cancel_button = wxButton(self.text_properties_dialog, wxID_CANCEL,"CANCEL") okay_boxer.Add(okay_button, 1, wxALIGN_LEFT) okay_boxer.Add(wxSize(10,10)) okay_boxer.Add(cancel_button, 1, wxALIGN_RIGHT) self.txt_boxer = wxBoxSizer(wxHORIZONTAL) self.txt_static = wxStaticText(self.text_properties_dialog, -1, "Text: ") self.text_control = wxTextCtrl(self.text_properties_dialog, TEXT_STRING, "", name = "Text: ") self.txt_boxer.Add(self.txt_static,0,wxEXPAND) self.txt_boxer.Add(wxSize(10,10)) self.txt_boxer.Add(self.text_control,1,wxEXPAND) self.point_boxer = wxBoxSizer(wxHORIZONTAL) # self.point_static = wxStaticText(self.text_properties_dialog, -1, "Text Size: ") # self.point_control = wxSpinCtrl(self.text_properties_dialog,TEXT_POINT_SIZE, value = "12",min = 1, initial = 12, name = "Font Size: ") # self.point_boxer.Add(self.point_static,1,wxEXPAND) # self.point_boxer.Add(wxSize(10,10)) # self.point_boxer.Add(self.point_control,0,wxEXPAND) self.text_color_control = wxButton(self.text_properties_dialog, TEXT_COLOR, "TEXT COLOR",style=wxBU_EXACTFIT) # self.weight_control = wxRadioBox(self.text_properties_dialog, TEXT_WEIGHT, "Weight",choices = ["Normal","Bold"]) # self.style_control = wxRadioBox(self.text_properties_dialog, TEXT_STYLE, "Style",choices = ["Normal", "Italic"]) self.text_props_sizer.Add(self.txt_boxer,0,wxEXPAND) self.text_props_sizer.Add(self.point_boxer,0, wxEXPAND) # self.text_props_sizer.Add(self.weight_control,0, wxEXPAND) # self.text_props_sizer.Add(self.style_control,0, wxEXPAND) self.text_props_sizer.Add(self.text_color_control, 0, wxEXPAND) self.text_props_sizer.Add(wxSize(10,10)) self.text_props_sizer.Add(okay_boxer,0, wxEXPAND) self.text_props_sizer.Fit(self) self.text_properties_dialog.SetSizer(self.text_props_sizer) self.text_properties_dialog.Fit() EVT_BUTTON(self.text_properties_dialog,TEXT_COLOR, self.on_text_color) EVT_BUTTON(self.text_properties_dialog,TEXT_OKAY,self.on_text_properties) # EVT_MENU(self.canvas,TEXT_POINT_SIZE,self.on_text_properties) # EVT_MENU(self.canvas,TEXT_WEIGHT,self.on_text_properties) # EVT_MENU(self.canvas,TEXT_STYLE,self.on_text_properties) # self.text_properties_dialog.Destroy() pass def build_menu(self,label = "Whiteboard"): base_layer_handler.build_menu(self,label) self.main_menu.AppendSeparator() self.main_menu.Append(LINE_COLOR,"&Change Pen Color") self.main_menu.Append(DELETE_ALL_LINES,"Delete &All Lines") EVT_MENU(self.canvas,LINE_COLOR,self.on_pen_color) EVT_MENU(self.canvas,DELETE_ALL_LINES,self.delete_all_lines) self.line_menu = wxMenu() if wxPlatform == '__WXMSW__': self.line_menu.SetTitle(label) else: self.line_menu.Append(LINE_TITLE_HACK,label) self.line_menu.AppendSeparator() self.line_menu.Append(LINE_REMOVE,"&Remove") EVT_MENU(self.canvas, LINE_REMOVE, self.on_line_menu_item) self.text_menu = wxMenu() if wxPlatform == '__WXMSW__': self.text_menu.SetTitle(label) else: self.text_menu.Append(TEXT_TITLE_HACK,label) self.text_menu.AppendSeparator() self.text_menu.Append(TEXT_PROPERTIES,"&Properties") self.text_menu.Append(TEXT_REMOVE,"&Remove") EVT_MENU(self.canvas, TEXT_PROPERTIES, self.text_menu_properties) EVT_MENU(self.canvas, TEXT_REMOVE, self.on_text_menu_item) def do_line_menu(self,pos): self.canvas.PopupMenu(self.line_menu, pos) def item_selected(self,evt): item = evt.GetId() self.item_selection = self.selection_list[item] def on_text_properties(self,evt): text_string = self.text_control.GetValue() style = wxNORMAL weight = wxNORMAL point = 12 c = self.text_color_control.GetForegroundColour() color = self.canvas.layers['whiteboard'].r_h.hexstring(c.Red(), c.Green(), c.Blue()) # self.text_selected_item.set_text_props(text_string, style, point, weight,color) self.text_to_xml() self.text_properties_dialog.Show(FALSE) self.text_selected_item.selected = false self.text_selected_item = None def on_text_color(self,evt): dlg = wxColourDialog(self) if dlg.ShowModal() == wxID_OK: c = dlg.GetColourData() self.text_color_control.SetForegroundColour(c.GetColour()) dlg.Destroy() def text_to_xml(self): xml_str = "<map><whiteboard>" xml_str += self.text_selected_item.toxml('update') xml_str += "</whiteboard></map>" self.canvas.frame.session.send(xml_str) self.canvas.Refresh(false) def get_text_properties(self, pos, item): self.text_color_control.SetForegroundColour(self.text_selected_item.textcolor) self.text_control.SetValue(self.text_selected_item.text_string) # self.point_control.SetValue(int(self.text_selected_item.pointsize)) self.text_properties_dialog.Center() self.text_properties_dialog.Show(TRUE) def do_text_menu(self,pos): self.canvas.PopupMenu(self.text_menu, pos) return def text_menu_properties(self, text_list): self.selection_list = text_list self.text_select_menu = None self.text_select_menu = wxMenu() self.text_select_menu.SetTitle("Which item?") menu_list = [] loop_count = 0 try: for m in text_list: menu_list.append(loop_count) self.text_select_menu.Append(menu_list[loop_count],m.text_string) EVT_MENU(self.canvas, menu_list[loop_count] , self.item_selected) loop_count += 1 item = self.canvas.PopupMenu(self.text_select_menu,pos) return self.item_selection except Exception, e: print "Error found in do_text_menu!",e def on_right_down(self,evt): line = 0 scale = self.canvas.layers['grid'].mapscale dc = wxClientDC(self.canvas) self.canvas.PrepareDC(dc) dc.SetUserScale(scale,scale) pos = evt.GetLogicalPosition(dc) if self.drawing_mode == DRAW_TEXT: self.on_text_right_down(evt,dc) elif (self.drawing_mode == DRAW_FREEFORM) or (self.drawing_mode == DRAW_POLYLINE): line_list = self.canvas.layers['whiteboard'].find_line(pos) if line_list: self.sel_rline = self.canvas.layers['whiteboard'].get_line_by_id(line_list.id) if self.sel_rline: s... [truncated message content] |