[GRASS-SVN] r48249 -
grass/branches/develbranch_6/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Sep 12 09:42:24 EDT 2011
Author: annakrat
Date: 2011-09-12 06:42:24 -0700 (Mon, 12 Sep 2011)
New Revision: 48249
Modified:
grass/branches/develbranch_6/gui/wxpython/gui_modules/psmap.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/psmap_dialogs.py
Log:
wx.psmap: fix several bugs in color and font management (merge from trunk)
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/psmap.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/psmap.py 2011-09-12 12:19:12 UTC (rev 48248)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/psmap.py 2011-09-12 13:42:24 UTC (rev 48249)
@@ -673,13 +673,66 @@
return wx.Rect(x,y, *textExtent)
else:
return wx.Rect(X, Y, abs(W), abs(H)).Inflate(h,h)
+
+ def makePSFont(self, textDict):
+ """!creates a wx.Font object from selected postscript font. To be
+ used for estimating bounding rectangle of text"""
+ fontsize = textDict['fontsize'] * self.canvas.currScale
+ fontface = textDict['font'].split('-')[0]
+ try:
+ fontstyle = textDict['font'].split('-')[1]
+ except IndexError:
+ fontstyle = ''
+
+ if fontface == "Times":
+ family = wx.FONTFAMILY_ROMAN
+ face = "times"
+ elif fontface == "Helvetica":
+ family = wx.FONTFAMILY_SWISS
+ face = 'helvetica'
+ elif fontface == "Courier":
+ family = wx.FONTFAMILY_TELETYPE
+ face = 'courier'
+ else:
+ family = wx.FONTFAMILY_DEFAULT
+ face = ''
+
+ style = wx.FONTSTYLE_NORMAL
+ weight = wx.FONTWEIGHT_NORMAL
+
+ if 'Oblique' in fontstyle:
+ style = wx.FONTSTYLE_SLANT
+
+ if 'Italic' in fontstyle:
+ style = wx.FONTSTYLE_ITALIC
+
+ if 'Bold' in fontstyle:
+ weight = wx.FONTWEIGHT_BOLD
+
+ try:
+ fn = wx.Font(pointSize = fontsize, family = family, style = style,
+ weight = weight, face = face)
+ except:
+ fn = wx.Font(pointSize = fontsize, family = wx.FONTFAMILY_DEFAULT,
+ style = wx.FONTSTYLE_NORMAL, weight = wx.FONTWEIGHT_NORMAL)
+
+ return fn
+
+
def getTextExtent(self, textDict):
- fontsize = str(textDict['fontsize'] * self.canvas.currScale)
+ """!Estimates bounding rectangle of text"""
#fontsize = str(fontsize if fontsize >= 4 else 4)
dc = wx.PaintDC(self) # dc created because of method GetTextExtent, which pseudoDC lacks
- dc.SetFont(wx.FontFromNativeInfoString(textDict['font'] + " " + fontsize))
- return dc.GetTextExtent(textDict['text'])
+
+ fn = self.makePSFont(textDict)
+
+ try:
+ dc.SetFont(fn)
+ w,h,lh = dc.GetMultiLineTextExtent(textDict['text'])
+ return (w,h)
+ except:
+ return (0,0)
def getInitMap(self):
"""!Create default map frame when no map is selected, needed for coordinates in map units"""
@@ -717,8 +770,7 @@
self.getInitMap()
self.canvas.RecalculateEN()
else:
- self.deleteObject(self.canvas.dragId)
-
+ self.deleteObject(self.canvas.dragId)
def deleteObject(self, id):
"""!Deletes object, his id and redraws"""
@@ -732,12 +784,6 @@
# delete from instructions
del self.instruction[id]
-
-
-
-
-
-
def DialogDataChanged(self, id):
ids = id
if type(id) == int:
@@ -751,7 +797,6 @@
pdc = self.canvas.pdcObj, drawid = id, pdctype = 'rectText', bb = drawRectangle)
self.canvas.RedrawSelectBox(id)
-
if itype == 'text':
if self.instruction[id]['rotate']:
@@ -759,7 +804,6 @@
else:
rot = 0
-
extent = self.getTextExtent(textDict = self.instruction[id].GetInstruction())
rect = wx.Rect2D(self.instruction[id]['where'][0], self.instruction[id]['where'][1], 0, 0)
self.instruction[id]['coords'] = list(self.canvas.CanvasPaperCoordinates(rect = rect, canvasToPaper = False)[:2])
@@ -1434,8 +1478,6 @@
imageRect.OffsetXY(-view[0], -view[1])
imageRect = self.ScaleRect(rect = imageRect, scale = zoomFactor)
self.DrawImage(imageRect)
-
-
def ZoomAll(self):
"""! Zoom to full extent"""
@@ -1468,7 +1510,8 @@
dc.SetFont(font)
pdc.SetFont(font)
text = '\n'.join(self.itemLabels[self.instruction[drawid].type])
- textExtent = dc.GetTextExtent(text)
+ w,h,lh = dc.GetMultiLineTextExtent(text)
+ textExtent = (w,h)
textRect = wx.Rect(0, 0, *textExtent).CenterIn(bb)
r = map(int, bb)
while not wx.Rect(*r).ContainsRect(textRect) and size >= 8:
@@ -1480,7 +1523,6 @@
textRect = wx.Rect(0, 0, *textExtent).CenterIn(bb)
pdc.SetTextForeground(wx.Color(100,100,100,200))
pdc.SetBackgroundMode(wx.TRANSPARENT)
-
pdc.DrawText(text = text, x = textRect.x, y = textRect.y)
pdc.SetIdBounds(drawid, bb)
@@ -1494,29 +1536,37 @@
rot = float(textDict['rotate'])
else:
rot = 0
-
- fontsize = str(textDict['fontsize'] * self.currScale)
+
+ fontsize = textDict['fontsize'] * self.currScale
if textDict['background'] != 'none':
background = textDict['background']
else:
background = None
-
pdc.RemoveId(drawId)
pdc.SetId(drawId)
pdc.BeginDrawing()
- # doesn't work
+
+ # border is not redrawn when zoom changes, why?
+## if textDict['border'] != 'none' and not rot:
+## units = UnitConversion(self)
+## borderWidth = units.convert(value = textDict['width'],
+## fromUnit = 'point', toUnit = 'pixel' ) * self.currScale
+## pdc.SetPen(wx.Pen(colour = convertRGB(textDict['border']), width = borderWidth))
+## pdc.DrawRectangle(*bounds)
+
if background:
- pdc.SetBackground(wx.Brush(convertRGB(background)))
+ pdc.SetTextBackground(convertRGB(background))
pdc.SetBackgroundMode(wx.SOLID)
else:
- pdc.SetBackground(wx.TRANSPARENT_BRUSH)
pdc.SetBackgroundMode(wx.TRANSPARENT)
- pdc.SetFont(wx.FontFromNativeInfoString(textDict['font'] + " " + fontsize))
+ fn = self.parent.makePSFont(textDict)
+
+ pdc.SetFont(fn)
pdc.SetTextForeground(convertRGB(textDict['color']))
pdc.DrawRotatedText(textDict['text'], coords[0], coords[1], rot)
-
+
pdc.SetIdBounds(drawId, wx.Rect(*bounds))
self.Refresh()
pdc.EndDrawing()
@@ -1639,7 +1689,6 @@
self._buffer = wx.EmptyBitmap(width, height)
# re-render image on idle
self.resize = True
-
def ScaleRect(self, rect, scale):
"""! Scale rectangle"""
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/psmap_dialogs.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/psmap_dialogs.py 2011-09-12 12:19:12 UTC (rev 48248)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/psmap_dialogs.py 2011-09-12 13:42:24 UTC (rev 48249)
@@ -840,8 +840,7 @@
self.type = 'mapinfo'
# default values
self.defaultInstruction = dict(unit = 'inch', where = (0, 0),
- font = 'Helvetica', fontsize = 10, color = 'black', background = 'none',
- #font = 'Sans', fontsize = 10, color = '0:0:0', background = 'none',
+ font = 'Helvetica', fontsize = 10, color = '0:0:0', background = 'none',
border = 'none', rect = None)
# current values
self.instruction = dict(self.defaultInstruction)
@@ -903,21 +902,40 @@
def __str__(self):
text = self.instruction['text'].replace('\n','\\n')
instr = "text %s %s" % (self.instruction['east'], self.instruction['north'])
- instr += " %s\n" % text
- instr += string.Template(" font $font\n fontsize $fontsize\n color $color\n").substitute(self.instruction)
- instr += string.Template(" hcolor $hcolor\n").substitute(self.instruction)
+ try:
+ instr += " %s\n" % text.encode('latin_1')
+ except UnicodeEncodeError, err:
+ try:
+ pos = str(err).split('position')[1].split(':')[0].strip()
+ except IndexError:
+ pos = ''
+ if pos:
+ message = _("Characters on position %s are not supported "
+ "by ISO-8859-1 (Latin 1) encoding "
+ "which is required by module ps.map.") % pos
+ else:
+ message = _("Not all characters are supported "
+ "by ISO-8859-1 (Latin 1) encoding "
+ "which is required by module ps.map.")
+ GMessage(message = message)
+ return ''
+ instr += (string.Template(" font $font\n fontsize $fontsize\n color $color\n").
+ substitute(self.instruction).
+ encode('latin_1'))
+ instr += string.Template(" hcolor $hcolor\n").substitute(self.instruction).encode('latin_1')
if self.instruction['hcolor'] != 'none':
- instr += string.Template(" hwidth $hwidth\n").substitute(self.instruction)
- instr += string.Template(" border $border\n").substitute(self.instruction)
+ instr += string.Template(" hwidth $hwidth\n").substitute(self.instruction).encode('latin_1')
+ instr += string.Template(" border $border\n").substitute(self.instruction).encode('latin_1')
if self.instruction['border'] != 'none':
- instr += string.Template(" width $width\n").substitute(self.instruction)
- instr += string.Template(" background $background\n").substitute(self.instruction)
+ instr += string.Template(" width $width\n").substitute(self.instruction).encode('latin_1')
+ instr += string.Template(" background $background\n").substitute(self.instruction).encode('latin_1')
if self.instruction["ref"] != '0':
- instr += string.Template(" ref $ref\n").substitute(self.instruction)
+ instr += string.Template(" ref $ref\n").substitute(self.instruction).encode('latin_1')
if self.instruction["rotate"]:
- instr += string.Template(" rotate $rotate\n").substitute(self.instruction)
+ instr += string.Template(" rotate $rotate\n").substitute(self.instruction).encode('latin_1')
if float(self.instruction["xoffset"]) or float(self.instruction["yoffset"]):
- instr += string.Template(" xoffset $xoffset\n yoffset $yoffset\n").substitute(self.instruction)
+ instr += (string.Template(" xoffset $xoffset\n yoffset $yoffset\n").
+ substitute(self.instruction).encode('latin_1'))
instr += " end"
return instr
@@ -2644,7 +2662,7 @@
self.btnDel = wx.Button(self, id = wx.ID_ANY, label = _("Delete"))
self.btnProp = wx.Button(self, id = wx.ID_ANY, label = _("Properties..."))
- self.updateListBox(selected = 0)
+ self.updateListBox(selected=0)
gridBagSizer.Add(text, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
@@ -2819,7 +2837,6 @@
vector.SetInstruction({'list': deepcopy(self.vectorList)})
-
# save new vectors
for item in self.vectorList:
id = item[2]
@@ -2837,6 +2854,7 @@
if 'map' in self.parent.parent.openDialogs:
self.parent.parent.openDialogs['map'].updateDialog()
+
return True
class RasterDialog(PsmapDialog):
@@ -3104,7 +3122,7 @@
if self.vPropertiesDict['color'] != 'none':
self.colorPicker.SetColour(convertRGB(self.vPropertiesDict['color']))
else:
- self.colorPicker.SetColour('black')
+ self.colorPicker.SetColour(convertRGB('black'))
@@ -3139,7 +3157,7 @@
if self.vPropertiesDict['fcolor'] != 'none':
self.fillColorPicker.SetColour(convertRGB(self.vPropertiesDict['fcolor']))
else:
- self.fillColorPicker.SetColour('red')
+ self.fillColorPicker.SetColour(convertRGB('red'))
@@ -4126,10 +4144,7 @@
fontSizer.Add(item = flexSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
border.Add(item = fontSizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
-
-
-
# some enable/disable methods
def OnIsLegend(self, event):
@@ -4214,9 +4229,8 @@
self.rSizeGBSizer.Add(self.panelRaster.heightOrColumnsCtrl, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
self.panelRaster.Layout()
- self.panelRaster.Fit()
+ self.panelRaster.Fit()
-
def OnRange(self, event):
if not self.range.GetValue():
self.min.Disable()
@@ -4330,13 +4344,7 @@
# font
self.rLegendDict['font'] = self.panelRaster.font['fontCtrl'].GetStringSelection()
self.rLegendDict['fontsize'] = self.panelRaster.font['fontSizeCtrl'].GetValue()
-## font = self.panelRaster.font['fontCtrl'].GetSelectedFont()
-## self.rLegendDict['font'] = font.GetFaceName()
-## self.rLegendDict['fontsize'] = font.GetPointSize()
color = self.panelRaster.font['colorCtrl'].GetColour()
-## if color.GetAsString(wx.C2S_NAME) in PSMAP_COLORS:
-## self.rLegendDict['color'] = color.GetAsString(wx.C2S_NAME)
-## else:
self.rLegendDict['color'] = convertRGB(color)
# position
@@ -4450,8 +4458,6 @@
# font
self.vLegendDict['font'] = self.panelVector.font['fontCtrl'].GetStringSelection()
self.vLegendDict['fontsize'] = self.panelVector.font['fontSizeCtrl'].GetValue()
-## self.vLegendDict['font'] = font.GetFaceName()
-## self.vLegendDict['fontsize'] = font.GetPointSize()
dc = wx.PaintDC(self)
font = dc.GetFont()
dc.SetFont(wx.Font(pointSize = self.vLegendDict['fontsize'], family = font.GetFamily(),
@@ -4480,16 +4486,11 @@
#border
if self.borderCheck.GetValue():
color = self.borderColorCtrl.GetColour()
-## if color.GetAsString(wx.C2S_NAME) in PSMAP_COLORS:
-## self.vLegendDict['border'] = color.GetAsString(wx.C2S_NAME)
-## else:
self.vLegendDict['border'] = convertRGB(color)
else:
self.vLegendDict['border'] = 'none'
-
-
-
+
if not self.id[1] in self.instruction:
vectorLegend = VectorLegend(self.id[1])
self.instruction.AddInstruction(vectorLegend)
@@ -4571,7 +4572,6 @@
else:
self.id = wx.NewId()
self.mapinfo = Mapinfo(self.id)
-
self.mapinfoDict = self.mapinfo.GetInstruction()
page = self.instruction.FindInstructionByType('page').GetInstruction()
self.mapinfoDict['where'] = page['Left'], page['Top']
@@ -4582,14 +4582,11 @@
self.OnIsBackground(None)
self.OnIsBorder(None)
-
-
def _mapinfoPanel(self):
panel = wx.Panel(parent = self, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
#panel.SetupScrolling(scroll_x = False, scroll_y = True)
border = wx.BoxSizer(wx.VERTICAL)
-
-
+
# position
box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Position"))
@@ -4618,11 +4615,6 @@
self.AddFont(parent = panel, dialogDict = self.mapinfoDict)#creates font color too, used below
-## gridBagSizer.Add(panel.font['fontLabel'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
-## gridBagSizer.Add(panel.font['fontCtrl'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
-## gridBagSizer.Add(panel.font['colorLabel'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
-## gridBagSizer.Add(panel.font['colorCtrl'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
-
gridBagSizer.Add(panel.font['fontLabel'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
gridBagSizer.Add(panel.font['fontCtrl'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
gridBagSizer.Add(panel.font['fontSizeLabel'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
@@ -4645,29 +4637,24 @@
self.colors['borderColor'] = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
self.colors['backgroundColor'] = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
+ if self.mapinfoDict['border'] == None:
+ self.mapinfoDict['border'] = 'none'
if self.mapinfoDict['border'] != 'none':
self.colors['borderCtrl'].SetValue(True)
+ self.colors['borderColor'].SetColour(convertRGB(self.mapinfoDict['border']))
else:
self.colors['borderCtrl'].SetValue(False)
-
+ self.colors['borderColor'].SetColour(convertRGB('black'))
+
+ if self.mapinfoDict['background'] == None:
+ self.mapinfoDict['background'] == 'none'
if self.mapinfoDict['background'] != 'none':
self.colors['backgroundCtrl'].SetValue(True)
- else:
- self.colors['backgroundCtrl'].SetValue(False)
-
- if self.mapinfoDict['border'] != 'none':
- self.colors['borderColor'].SetColour(convertRGB(self.mapinfoDict['border']))
-
- else:
- self.colors['borderColor'].SetColour('black')
-
- if self.mapinfoDict['background'] != 'none':
self.colors['backgroundColor'].SetColour(convertRGB(self.mapinfoDict['background']))
else:
- self.colors['backgroundColor'].SetColour('black')
-
-
-
+ self.colors['backgroundCtrl'].SetValue(False)
+ self.colors['backgroundColor'].SetColour(convertRGB('white'))
+
flexSizer.Add(self.colors['borderCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
flexSizer.Add(self.colors['borderColor'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
flexSizer.Add(self.colors['backgroundCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
@@ -4678,7 +4665,6 @@
panel.SetSizer(border)
-
self.Bind(wx.EVT_CHECKBOX, self.OnIsBorder, self.colors['borderCtrl'])
self.Bind(wx.EVT_CHECKBOX, self.OnIsBackground, self.colors['backgroundCtrl'])
@@ -4687,12 +4673,14 @@
def OnIsBackground(self, event):
if self.colors['backgroundCtrl'].GetValue():
self.colors['backgroundColor'].Enable()
+ self.update()
else:
self.colors['backgroundColor'].Disable()
def OnIsBorder(self, event):
if self.colors['borderCtrl'].GetValue():
self.colors['borderColor'].Enable()
+ self.update()
else:
self.colors['borderColor'].Disable()
@@ -4702,6 +4690,7 @@
#units
currUnit = self.panel.units['unitsCtrl'].GetStringSelection()
self.mapinfoDict['unit'] = currUnit
+
# position
if self.panel.position['xCtrl'].GetValue():
x = self.panel.position['xCtrl'].GetValue()
@@ -4716,33 +4705,23 @@
x = self.unitConv.convert(value = float(self.panel.position['xCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
y = self.unitConv.convert(value = float(self.panel.position['yCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
self.mapinfoDict['where'] = (x, y)
+
# font
self.mapinfoDict['font'] = self.panel.font['fontCtrl'].GetStringSelection()
self.mapinfoDict['fontsize'] = self.panel.font['fontSizeCtrl'].GetValue()
-## font = self.panel.font['fontCtrl'].GetSelectedFont()
-## self.mapinfoDict['font'] = font.GetFaceName()
-## self.mapinfoDict['fontsize'] = font.GetPointSize()
+
#colors
color = self.panel.font['colorCtrl'].GetColour()
-## if color.GetAsString(wx.C2S_NAME) in PSMAP_COLORS:
-## self.mapinfoDict['color'] = color.GetAsString(wx.C2S_NAME)
-## else:
self.mapinfoDict['color'] = convertRGB(color)
if self.colors['backgroundCtrl'].GetValue():
background = self.colors['backgroundColor'].GetColour()
-## if background.GetAsString(wx.C2S_NAME) in PSMAP_COLORS:
-## self.mapinfoDict['background'] = background.GetAsString(wx.C2S_NAME)
-## else:
self.mapinfoDict['background'] = convertRGB(background)
else:
self.mapinfoDict['background'] = 'none'
if self.colors['borderCtrl'].GetValue():
border = self.colors['borderColor'].GetColour()
-## if border.GetAsString(wx.C2S_NAME) in PSMAP_COLORS:
-## self.mapinfoDict['border'] = border.GetAsString(wx.C2S_NAME)
-## else:
self.mapinfoDict['border'] = convertRGB(border)
else:
self.mapinfoDict['border'] = 'none'
@@ -4750,15 +4729,17 @@
# estimation of size
self.mapinfoDict['rect'] = self.mapinfo.EstimateRect(self.mapinfoDict)
-
if self.id not in self.instruction:
mapinfo = Mapinfo(self.id)
self.instruction.AddInstruction(mapinfo)
+
self.instruction[self.id].SetInstruction(self.mapinfoDict)
if self.id not in self.parent.objectId:
self.parent.objectId.append(self.id)
+ self.updateDialog()
+
return True
def updateDialog(self):
@@ -4769,9 +4750,7 @@
y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
self.panel.position['xCtrl'].SetValue("%5.3f" % x)
self.panel.position['yCtrl'].SetValue("%5.3f" % y)
-
-
-
+
class ScalebarDialog(PsmapDialog):
"""!Dialog for scale bar"""
def __init__(self, parent, id, settings):
@@ -4787,8 +4766,6 @@
page = self.instruction.FindInstructionByType('page').GetInstruction()
self.scalebarDict['where'] = page['Left'], page['Top']
-
-
self.panel = self._scalebarPanel()
self._layout(self.panel)
@@ -5093,7 +5070,6 @@
sizer.Add(self.textCtrl, proportion = 1, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
-
#font
box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
@@ -5132,38 +5108,37 @@
self.effect['borderColor'] = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
self.effect['borderWidth'] = wx.SpinCtrl(panel, id = wx.ID_ANY, size = self.spinCtrlSize, min = 1, max = 25, initial = 1)
self.effect['borderWidthLabel'] = wx.StaticText(panel, id = wx.ID_ANY, label = _("Width (pts):"))
+
#set values
+ if self.textDict['background'] == None:
+ self.textDict['background'] = 'none'
if self.textDict['background'] != 'none':
self.effect['backgroundCtrl'].SetValue(True)
+ self.effect['backgroundColor'].SetColour(convertRGB(self.textDict['background']))
else:
self.effect['backgroundCtrl'].SetValue(False)
+ self.effect['backgroundColor'].SetColour(convertRGB('white'))
- if self.textDict['background'] != 'none':
- self.effect['backgroundColor'].SetColour(convertRGB(self.textDict['background']))
- else:
- self.effect['backgroundColor'].SetColour('white')
-
+ if self.textDict['hcolor'] == None:
+ self.textDict['hcolor'] = 'none'
if self.textDict['hcolor'] != 'none':
self.effect['highlightCtrl'].SetValue(True)
- else:
- self.effect['highlightCtrl'].SetValue(False)
-
- if self.textDict['hcolor'] != 'none':
self.effect['highlightColor'].SetColour(convertRGB(self.textDict['hcolor']))
else:
+ self.effect['highlightCtrl'].SetValue(False)
self.effect['highlightColor'].SetColour(convertRGB('grey'))
self.effect['highlightWidth'].SetValue(float(self.textDict['hwidth']))
+
+ if self.textDict['border'] == None:
+ self.textDict['border'] = 'none'
if self.textDict['border'] != 'none':
self.effect['borderCtrl'].SetValue(True)
+ self.effect['borderColor'].SetColour(convertRGB(self.textDict['border']))
else:
self.effect['borderCtrl'].SetValue(False)
+ self.effect['borderColor'].SetColour(convertRGB('black'))
- if self.textDict['border'] != 'none':
- self.effect['borderColor'].SetColour(convertRGB(self.textDict['border']))
- else:
- self.effect['borderColor'].SetColour('black')
-
self.effect['borderWidth'].SetValue(float(self.textDict['width']))
gridBagSizer.Add(self.effect['backgroundCtrl'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
@@ -5187,6 +5162,7 @@
panel.SetSizer(border)
panel.Fit()
+
return panel
def _positionPanel(self, notebook):
@@ -5230,11 +5206,9 @@
self.gridBagSizerP.Add(panel.position['yCtrl'], pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
self.gridBagSizerP.Add(panel.position['comment'], pos = (3,0), span = (1,2), flag = wx.ALIGN_BOTTOM, border = 0)
-
sizerP.Add(self.gridBagSizerP, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
gridBagSizer.Add(sizerP, pos = (2,0),span = (1,1), flag = wx.ALIGN_CENTER_HORIZONTAL|wx.EXPAND, border = 0)
-
# second box - map coordinates
box2 = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = "")
sizerM = wx.StaticBoxSizer(box2, wx.VERTICAL)
@@ -5250,7 +5224,6 @@
self.eastingCtrl.SetValue(str(east))
self.northingCtrl.SetValue(str(north))
-
self.gridBagSizerM.Add(self.eastingLabel, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
self.gridBagSizerM.Add(self.northingLabel, pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
self.gridBagSizerM.Add(self.eastingCtrl, pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
@@ -5295,8 +5268,7 @@
self.radio[-1].SetValue(False)
flexSizer.Add(self.radio[-1], proportion = 0, flag = wx.ALIGN_CENTER, border = 0)
self.FindWindowByName(self.textDict['ref']).SetValue(True)
-
-
+
sizerR.Add(flexSizer, proportion = 1, flag = wx.EXPAND, border = 0)
gridBagSizer.Add(sizerR, pos = (3,1), flag = wx.ALIGN_LEFT|wx.EXPAND, border = 0)
@@ -5349,9 +5321,11 @@
widget.GetWindow().Enable()
for widget in self.gridBagSizerP.GetChildren():
widget.GetWindow().Disable()
+
def OnBackground(self, event):
if self.effect['backgroundCtrl'].GetValue():
self.effect['backgroundColor'].Enable()
+ self.update()
else:
self.effect['backgroundColor'].Disable()
@@ -5360,6 +5334,7 @@
self.effect['highlightColor'].Enable()
self.effect['highlightWidth'].Enable()
self.effect['highlightWidthLabel'].Enable()
+ self.update()
else:
self.effect['highlightColor'].Disable()
self.effect['highlightWidth'].Disable()
@@ -5370,13 +5345,13 @@
self.effect['borderColor'].Enable()
self.effect['borderWidth'].Enable()
self.effect['borderWidthLabel'].Enable()
+ self.update()
else:
self.effect['borderColor'].Disable()
self.effect['borderWidth'].Disable()
self.effect['borderWidthLabel'].Disable()
def update(self):
-
#text
self.textDict['text'] = self.textCtrl.GetValue()
if not self.textDict['text']:
@@ -5386,14 +5361,9 @@
#font
self.textDict['font'] = self.textPanel.font['fontCtrl'].GetStringSelection()
self.textDict['fontsize'] = self.textPanel.font['fontSizeCtrl'].GetValue()
-## font = self.textPanel.font['fontCtrl'].GetSelectedFont()
-## self.textDict['font'] = font.GetFaceName()
-## self.textDict['fontsize'] = font.GetPointSize()
color = self.textPanel.font['colorCtrl'].GetColour()
-## if color.GetAsString(wx.C2S_NAME) in PSMAP_COLORS:
-## self.textDict['color'] = color.GetAsString(wx.C2S_NAME)
-## else:
self.textDict['color'] = convertRGB(color)
+
#effects
if self.effect['backgroundCtrl'].GetValue():
background = self.effect['backgroundColor'].GetColour()
@@ -5420,6 +5390,7 @@
#offset
self.textDict['xoffset'] = self.xoffCtrl.GetValue()
self.textDict['yoffset'] = self.yoffCtrl.GetValue()
+
#position
if self.paperPositionCtrl.GetValue():
self.textDict['XY'] = True
@@ -5471,6 +5442,8 @@
if self.id not in self.parent.objectId:
self.parent.objectId.append(self.id)
+# self.updateDialog()
+
return True
def updateDialog(self):
@@ -5486,46 +5459,29 @@
e, n = self.textDict['east'], self.textDict['north']
self.eastingCtrl.SetValue(str(self.textDict['east']))
self.northingCtrl.SetValue(str(self.textDict['north']))
-
def convertRGB(rgb):
- """!Converts wx.Colour(255,255,255,255) and string '255:255:255',
- depends on input"""
- psmapColors = { "white" : (1.00, 1.00, 1.00),
- "black" : (0.00, 0.00, 0.00),
- "red" : (1.00, 0.00, 0.00),
- "green" : (0.00, 1.00, 0.00),
- "blue" : (0.00, 0.00, 1.00),
- "yellow" : (1.00, 1.00, 0.00),
- "magenta" : (1.00, 0.00, 1.00),
- "cyan" : (0.00, 1.00, 1.00),
- "aqua" : (0.00, 0.75, 0.75),
- "grey" : (0.75, 0.75, 0.75),
- "gray" : (0.75, 0.75, 0.75),
- "orange" : (1.00, 0.50, 0.00),
- "brown" : (0.75, 0.50, 0.25),
- "purple" : (0.50, 0.00, 1.00),
- "violet" : (0.50, 0.00, 1.00),
- "indigo" : (0.00, 0.50, 1.00)}
-
+ """!Converts wx.Colour(r,g,b,a) to string 'r:g:b' or named color,
+ or named color/r:g:b string to wx.Colour, depending on input"""
+ # transform a wx.Colour tuple into an r:g:b string
if type(rgb) == wx.Colour:
- for name, color in psmapColors.items():
+ for name, color in grass.named_colors.items():
if rgb.Red() == int(color[0] * 255) and\
rgb.Green() == int(color[1] * 255) and\
rgb.Blue() == int(color[2] * 255):
return name
return str(rgb.Red()) + ':' + str(rgb.Green()) + ':' + str(rgb.Blue())
- elif type(rgb) == str or type(rgb) == unicode:
- if ':' in rgb:
- return wx.Colour(*map(int, rgb.split(':')))
- else:
- color = map(lambda x: int(x * 255), psmapColors[rgb])
- color = wx.Color(*color)
- if color.IsOk():
- return color
+ # transform a GRASS named color or an r:g:b string into a wx.Colour tuple
+ else:
+ color = (grass.parse_color(rgb)[0]*255,
+ grass.parse_color(rgb)[1]*255,
+ grass.parse_color(rgb)[2]*255)
+ color = wx.Color(*color)
+ if color.IsOk():
+ return color
+ else:
return None
-
def PaperMapCoordinates(map, x, y, paperToMap = True):
"""!Converts paper (inch) coordinates -> map coordinates"""
unitConv = UnitConversion()
More information about the grass-commit
mailing list