Mercurial > traipse
diff orpg/mapper/whiteboard.py @ 13:211ac836b6a0 grumpy-goblin
{090731-00} Fixes problem with Name & Settings window, cleans code.
author | sirebral |
---|---|
date | Fri, 31 Jul 2009 15:22:11 -0500 |
parents | 4385a7d0efd1 |
children | 97265586402b |
line wrap: on
line diff
--- a/orpg/mapper/whiteboard.py Fri Jul 24 10:03:22 2009 -0500 +++ b/orpg/mapper/whiteboard.py Fri Jul 31 15:22:11 2009 -0500 @@ -34,16 +34,11 @@ 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 + 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 WhiteboardText: @@ -103,14 +98,10 @@ def draw(self, parent, dc, op=wx.COPY): self.log.log("Enter WhiteboardText->draw(self, parent, dc, op)", ORPG_DEBUG) self.scale = parent.canvas.layers['grid'].mapscale - if self.highlighted: - textcolor = self.highlight_color - else: - textcolor = self.textcolor - try: - dc.SetTextForeground(textcolor) - except Exception,e: - dc.SetTextForeground('#000000') + if self.highlighted: textcolor = self.highlight_color + else: textcolor = self.textcolor + try: dc.SetTextForeground(textcolor) + except Exception,e: dc.SetTextForeground('#000000') dc.SetUserScale(self.scale, self.scale) # Draw text @@ -130,28 +121,20 @@ xml_str = "<text" xml_str += " action='" + action + "'" xml_str += " id='" + str(self.id) + "'" - if self.pointsize != None: - xml_str += " pointsize='" + str(self.pointsize) + "'" - if self.style != None: - xml_str += " style='" + str(self.style) + "'" - if self.weight != None: - xml_str += " weight='" + str(self.weight) + "'" - if self.posx != None: - xml_str+= " posx='" + str(self.posx) + "'" - if not (self.posy is None): - xml_str += " posy='" + str(self.posy) + "'" - if self.text_string != None: - xml_str+= " text_string='" + self.text_string + "'" - if self.textcolor != None: - xml_str += " color='" + self.textcolor + "'" + if self.pointsize != None: xml_str += " pointsize='" + str(self.pointsize) + "'" + if self.style != None: xml_str += " style='" + str(self.style) + "'" + if self.weight != None: xml_str += " weight='" + str(self.weight) + "'" + if self.posx != None: xml_str+= " posx='" + str(self.posx) + "'" + if not (self.posy is None): xml_str += " posy='" + str(self.posy) + "'" + if self.text_string != None: xml_str+= " text_string='" + self.text_string + "'" + if self.textcolor != None: xml_str += " color='" + self.textcolor + "'" xml_str += "/>" self.log.log(xml_str, ORPG_DEBUG) self.log.log("Exit WhiteboardText->toxml(self, " + action + ")", ORPG_DEBUG) if (action == "update" and self.isUpdated) or action == "new": self.isUpdated = False return xml_str - else: - return '' + else: return '' def takedom(self, xml_dom): self.log.log("Enter WhiteboardText->takedom(self, xml_dom)", ORPG_DEBUG) @@ -179,8 +162,7 @@ self.log.log("self.pointsize=" + str(self.pointsize), ORPG_DEBUG) if xml_dom.hasAttribute("color") and xml_dom.getAttribute("color") != '': self.textcolor = xml_dom.getAttribute("color") - if self.textcolor == '#0000000': - self.textcolor = '#000000' + if self.textcolor == '#0000000': self.textcolor = '#000000' self.log.log("self.textcolor=" + self.textcolor, ORPG_DEBUG) self.log.log("Exit WhiteboardText->takedom(self, xml_dom)", ORPG_DEBUG) @@ -190,8 +172,7 @@ self.log.log("Enter WhiteboardLine", ORPG_DEBUG) self.scale = 1 self.r_h = RGBHex() - if color == '': - color = "#000000" + if color == '': color = "#000000" self.linecolor = color self.linewidth = width self.lowerright = lowerright @@ -209,7 +190,8 @@ self.highlighted = highlight self.log.log("Enter WhiteboardLine->highlight(self, highlight)", ORPG_DEBUG) - def set_line_props(self, line_string="", upperleftx=0, upperlefty=0, lowerrightx=0, lowerrighty=0, color="#000000", width=1): + def set_line_props(self, line_string="", upperleftx=0, upperlefty=0, + lowerrightx=0, lowerrighty=0, color="#000000", width=1): self.log.log("Enter WhiteboardLine->set_line_props(self, line_string, upperleftx, upperlefty, lowerrightx, lowerrighty, color, width)", ORPG_DEBUG) self.line_string = line_string self.upperleft.x = upperleftx @@ -241,15 +223,11 @@ def draw(self, parent, dc, op=wx.COPY): self.log.log("Enter WhiteboardLine->draw(self, parent, dc, op=wx.COPY)", ORPG_DEBUG) self.scale = parent.canvas.layers['grid'].mapscale - if self.highlighted: - linecolor = self.highlight_color - else: - linecolor = self.linecolor + if self.highlighted: linecolor = self.highlight_color + else: linecolor = self.linecolor pen = wx.BLACK_PEN - try: - pen.SetColour(linecolor) - except Exception,e: - pen.SetColour('#000000') + try: pen.SetColour(linecolor) + except Exception,e: pen.SetColour('#000000') pen.SetWidth( self.linewidth ) dc.SetPen( pen ) dc.SetBrush(wx.BLACK_BRUSH) @@ -262,8 +240,7 @@ points = x.split(",") x1 = int(points[0]) y1 = int(points[1]) - if x2 != -999: - dc.DrawLine(x2,y2,x1,y1) + if x2 != -999: dc.DrawLine(x2,y2,x1,y1) x2 = x1 y2 = y1 pen.SetColour(wx.Colour(0,0,0)) @@ -298,8 +275,7 @@ xml_str += "/>" self.log.log(xml_str, ORPG_DEBUG) self.log.log("Exit WhiteboardLine->toxml(self, " + action + ")", ORPG_DEBUG) - if action == "new": - return xml_str + if action == "new": return xml_str return '' def takedom(self, xml_dom): @@ -443,10 +419,8 @@ def layerDraw(self, dc): self.log.log("Enter whiteboard_layer->layerDraw(self, dc)", ORPG_DEBUG) - for m in self.lines: - m.draw(self, dc) - for m in self.texts: - m.draw(self,dc) + for m in self.lines: m.draw(self, dc) + for m in self.texts: m.draw(self,dc) self.log.log("Exit whiteboard_layer->layerDraw(self, dc)", ORPG_DEBUG) def hit_test_text(self, pos, dc): @@ -457,8 +431,7 @@ self.log.log("Exit whiteboard_layer->hit_test_text(self, pos, dc)", ORPG_DEBUG) return list_of_texts_matching for m in self.texts: - if m.hit_test(pos,dc): - list_of_texts_matching.append(m) + if m.hit_test(pos,dc): list_of_texts_matching.append(m) self.log.log("Exit whiteboard_layer->hit_test_text(self, pos, dc)", ORPG_DEBUG) return list_of_texts_matching @@ -470,8 +443,7 @@ self.log.log("Exit whiteboard_layer->hit_test_lines(self, pos, dc)", ORPG_DEBUG) return list_of_lines_matching for m in self.lines: - if m.hit_test(pos): - list_of_lines_matching.append(m) + if m.hit_test(pos): list_of_lines_matching.append(m) self.log.log("Exit whiteboard_layer->hit_test_lines(self, pos, dc)", ORPG_DEBUG) return list_of_lines_matching @@ -552,11 +524,9 @@ self.log.log("Enter whiteboard_layer->layerToXML(self, " + action + ")", ORPG_DEBUG) white_string = "" if self.lines: - for l in self.lines: - white_string += l.toxml(action) + for l in self.lines: white_string += l.toxml(action) if self.texts: - for l in self.texts: - white_string += l.toxml(action) + for l in self.texts: white_string += l.toxml(action) if len(white_string): s = "<whiteboard" s += " serial='" + str(self.serial_number) + "'" @@ -573,8 +543,7 @@ def layerTakeDOM(self, xml_dom): self.log.log("Enter whiteboard_layer->layerTakeDOM(self, xml_dom)", ORPG_DEBUG) serial_number = xml_dom.getAttribute('serial') - if serial_number != "": - self.serial_number = int(serial_number) + if serial_number != "": self.serial_number = int(serial_number) children = xml_dom._get_childNodes() for l in children: nodename = l._get_nodeName() @@ -583,18 +552,13 @@ if action == "del": if nodename == 'line': line = self.get_line_by_id(id) - if line != None: - self.lines.remove(line) - else: - self.log.log("Whiteboard error: Deletion of unknown line object attempted.", ORPG_GENERAL) + if line != None: self.lines.remove(line) + else: self.log.log("Whiteboard error: Deletion of unknown line object attempted.", ORPG_GENERAL) elif nodename == 'text': text = self.get_text_by_id(id) - if text != None: - self.texts.remove(text) - else: - self.log.log("Whiteboard error: Deletion of unknown text object attempted.", ORPG_GENERAL) - else: - self.log.log("Whiteboard error: Deletion of unknown whiteboard object attempted.", ORPG_GENERAL) + if text != None: self.texts.remove(text) + else: self.log.log("Whiteboard error: Deletion of unknown text object attempted.", ORPG_GENERAL) + else: self.log.log("Whiteboard error: Deletion of unknown whiteboard object attempted.", ORPG_GENERAL) elif action == "new": if nodename == "line": try: @@ -606,8 +570,7 @@ upperleft = wx.Point(int(upperleftx),int(upperlefty)) lowerright = wx.Point(int(lowerrightx),int(lowerrighty)) color = l.getAttribute('color') - if color == '#0000000': - color = '#000000' + if color == '#0000000': color = '#000000' id = l.getAttribute('id') width = int(l.getAttribute('width')) except: @@ -624,8 +587,7 @@ pointsize = l.getAttribute('pointsize') weight = l.getAttribute('weight') color = l.getAttribute('color') - if color == '#0000000': - color = '#000000' + if color == '#0000000': color = '#000000' id = l.getAttribute('id') posx = l.getAttribute('posx') posy = l.getAttribute('posy') @@ -641,24 +603,20 @@ else: if nodename == "line": line = self.get_line_by_id(id) - if line: - line.takedom(l) - else: - self.log.log("Whiteboard error: Update of unknown line attempted.", ORPG_GENERAL) + if line: line.takedom(l) + else: self.log.log("Whiteboard error: Update of unknown line attempted.", ORPG_GENERAL) if nodename == "text": text = self.get_text_by_id(id) - if text: - text.takedom(l) - else: - self.log.log("Whiteboard error: Update of unknown text attempted.", ORPG_GENERAL) + if text: text.takedom(l) + else: self.log.log("Whiteboard error: Update of unknown text attempted.", ORPG_GENERAL) self.log.log("Enter whiteboard_layer->layerTakeDOM(self, xml_dom)", ORPG_DEBUG) #self.canvas.send_map_data() def add_temp_line(self, line_string): - line = WhiteboardLine(0, line_string, wx.Point(0,0), wx.Point(0,0), color=self.color, width=self.width, log=self.log) + line = WhiteboardLine(0, line_string, wx.Point(0,0), wx.Point(0,0), + color=self.color, width=self.width, log=self.log) self.lines.append(line) return line def del_temp_line(self, line): - if line: - self.lines.remove(line) + if line: self.lines.remove(line)