[GRASS-SVN] r45743 - grass-addons/gui/wxpython/psmap/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Mar 24 14:55:54 EDT 2011


Author: annakrat
Date: 2011-03-24 11:55:54 -0700 (Thu, 24 Mar 2011)
New Revision: 45743

Modified:
   grass-addons/gui/wxpython/psmap/gui_modules/psmap.py
   grass-addons/gui/wxpython/psmap/gui_modules/psmap_dialogs.py
Log:
nonmodal instead of modal dialogs, header in instruction file changed

Modified: grass-addons/gui/wxpython/psmap/gui_modules/psmap.py
===================================================================
--- grass-addons/gui/wxpython/psmap/gui_modules/psmap.py	2011-03-23 22:29:03 UTC (rev 45742)
+++ grass-addons/gui/wxpython/psmap/gui_modules/psmap.py	2011-03-24 18:55:54 UTC (rev 45743)
@@ -257,6 +257,8 @@
         
         # instructions
         self.instruction = Instruction(parent = self, objectsToDraw = self.objectId)
+        # open dialogs
+        self.openDialogs = dict()
         
         self.pageId = wx.NewId()
         #current page of flatnotebook
@@ -264,7 +266,7 @@
         #canvas for draft mode
         self.canvas = PsMapBufferedWindow(parent = self, mouse = self.mouse, pen = self.pen,
                                             brush = self.brush, cursors = self.cursors, 
-                                            instruction = self.instruction,
+                                            instruction = self.instruction, openDialogs = self.openDialogs,
                                             pageId = self.pageId, objectId = self.objectId,
                                             preview = False)
                                         
@@ -433,7 +435,7 @@
         return filename
                         
     def OnInstructionFile(self, event):
-        filename = self.getFile(wildcard = "All files(*.*)|*.*|Text file|*.txt")        
+        filename = self.getFile(wildcard = "*.psmap|*.psmap|Text file(*.txt)|*.txt|All files(*.*)|*.*")        
         if filename:    
             instrFile = open(filename, "w")
             instrFile.write(self.InstructionFile())
@@ -514,6 +516,7 @@
         
         
     def OnAddMap(self, event, notebook = False):
+        """!Add or edit map frame"""
         if event is not None:
             if event.GetId() != self.toolbar.action['id']:
                 self.actionOld = self.toolbar.action['id']
@@ -525,6 +528,7 @@
             mapId = self.instruction.FindInstructionByType('map').id
         else: mapId = None
         id = [mapId, None, None]
+        
         if notebook:
             if self.instruction.FindInstructionByType('vector'):
                 vectorId = self.instruction.FindInstructionByType('vector').id
@@ -546,11 +550,34 @@
             except AttributeError:
                 pass
    
-            dlg = MapDialog(parent = self, id  = id, settings = self.instruction,
-                            notebook = notebook)
-            dlg.ShowModal()  
+##            dlg = MapDialog(parent = self, id  = id, settings = self.instruction,
+##                            notebook = notebook)
+##            dlg.ShowModal()  
+            if notebook:
+                #check map, raster, vector and save, destroy them
+                if 'map' in self.openDialogs:
+                    self.openDialogs['map'].OnOK(event = None)
+                if 'raster' in self.openDialogs:
+                    self.openDialogs['raster'].OnOK(event = None)
+                if 'vector' in self.openDialogs:
+                    self.openDialogs['vector'].OnOK(event = None)
+                        
+                if 'mapNotebook' not in self.openDialogs:
+                    dlg = MapDialog(parent = self, id  = id, settings = self.instruction,
+                                notebook = notebook)
+                    self.openDialogs['mapNotebook'] = dlg
+                self.openDialogs['mapNotebook'].Show()
+            else:
+                if 'mapNotebook' in self.openDialogs:
+                    self.openDialogs['mapNotebook'].notebook.ChangeSelection(0)
+                else:
+                    if 'map' not in self.openDialogs:
+                        dlg = MapDialog(parent = self, id  = id, settings = self.instruction,
+                                    notebook = notebook)
+                        self.openDialogs['map'] = dlg
+                    self.openDialogs['map'].Show()
+ 
 
-
         else:    # sofar no map
             self.mouse["use"] = "addMap"
             self.canvas.SetCursor(self.cursors["cross"])
@@ -559,6 +586,7 @@
                 self.currentPage = 0
                 
     def OnAddRaster(self, event):
+        """!Add raster map"""
         if self.instruction.FindInstructionByType('raster'):
             id = self.instruction.FindInstructionByType('raster').id
         else: id = None
@@ -571,12 +599,18 @@
                 GMessage(message = _("Please, create map frame first."))
                 return
             
-        dlg = RasterDialog(self, id = id, settings = self.instruction)
-        dlg.ShowModal()
-        
-        
+##        dlg = RasterDialog(self, id = id, settings = self.instruction)
+##        dlg.ShowModal()
+        if 'mapNotebook' in self.openDialogs:
+            self.openDialogs['mapNotebook'].notebook.ChangeSelection(1)
+        else:
+            if 'raster' not in self.openDialogs:
+                dlg = RasterDialog(self, id = id, settings = self.instruction)
+                self.openDialogs['raster'] = dlg
+            self.openDialogs['raster'].Show()
                 
     def OnAddVect(self, event):
+        """!Add vector map"""
         if self.instruction.FindInstructionByType('vector'):
             id = self.instruction.FindInstructionByType('vector').id
         else: id = None
@@ -588,8 +622,15 @@
                 GMessage(message = _("Please, create map frame first."))
                 return
             
-        dlg = MainVectorDialog(self, id = id, settings = self.instruction)
-        dlg.ShowModal()
+##        dlg = MainVectorDialog(self, id = id, settings = self.instruction)
+##        dlg.ShowModal()
+        if 'mapNotebook' in self.openDialogs:
+            self.openDialogs['mapNotebook'].notebook.ChangeSelection(2)
+        else:
+            if 'vector' not in self.openDialogs:
+                dlg =  MainVectorDialog(self, id = id, settings = self.instruction)
+                self.openDialogs['vector'] = dlg
+            self.openDialogs['vector'].Show()
         
     def OnDecoration(self, event):
         """!Decorations overlay menu
@@ -628,10 +669,11 @@
         if self.instruction.FindInstructionByType('scalebar'):
             id = self.instruction.FindInstructionByType('scalebar').id
         else: id = None
-
-        dlg = ScalebarDialog(self, id = id, settings = self.instruction)
-        dlg.ShowModal()  
         
+        if 'scalebar' not in self.openDialogs:
+            dlg = ScalebarDialog(self, id = id, settings = self.instruction)
+            self.openDialogs['scalebar'] = dlg
+        self.openDialogs['scalebar'].Show()
         
     def OnAddLegend(self, event, page = 0):
         """!Add raster or vector legend"""
@@ -642,24 +684,36 @@
             idV = self.instruction.FindInstructionByType('vectorLegend').id
         else: idV = None
 
-        dlg = LegendDialog(self, id = [idR, idV], settings = self.instruction, page = page)
-        dlg.ShowModal()
-        
+        if 'rasterLegend' not in self.openDialogs:    
+            dlg = LegendDialog(self, id = [idR, idV], settings = self.instruction, page = page)
+            self.openDialogs['rasterLegend'] = dlg
+            self.openDialogs['vectorLegend'] = dlg
+        self.openDialogs['rasterLegend'].notebook.ChangeSelection(page)
+        self.openDialogs['rasterLegend'].Show()
 
-
     def OnAddMapinfo(self, event):
         if self.instruction.FindInstructionByType('mapinfo'):
             id = self.instruction.FindInstructionByType('mapinfo').id
         else: id = None
-
-        dlg = MapinfoDialog(self, id = id, settings = self.instruction)
-        dlg.ShowModal()
-
         
-    def OnAddText(self, event, id = None):            
-        dlg = TextDialog(self, id = id, settings = self.instruction) 
-        dlg.ShowModal()
+        if 'mapinfo' not in self.openDialogs:
+            dlg = MapinfoDialog(self, id = id, settings = self.instruction)
+            self.openDialogs['mapinfo'] = dlg
+        self.openDialogs['mapinfo'].Show()
         
+    def OnAddText(self, event, id = None):
+        """!Show dialog for text adding and editing"""
+        position = None
+        if 'text' in self.openDialogs:
+            position = self.openDialogs['text'].GetPosition()
+            self.openDialogs['text'].OnApply(event = None)
+            self.openDialogs['text'].Destroy()
+        dlg = TextDialog(self, id = id, settings = self.instruction)
+        self.openDialogs['text'] = dlg 
+        if position: 
+            dlg.SetPosition(position)
+        dlg.Show()
+        
     def getModifiedTextBounds(self, x, y, textExtent, rotation):
         """!computes bounding box of rotated text, not very precisely"""
         w, h = textExtent
@@ -785,6 +839,9 @@
                     resol = RunCommand('r.info', read = True, flags = 's', map = self.instruction[id]['raster'])
                     resol = grass.parse_key_val(resol, val_type = float)
                     RunCommand('g.region', nsres = resol['nsres'], ewres = resol['ewres'])
+                    # change current raster in raster legend
+                if 'rasterLegend' in self.openDialogs:
+                    self.openDialogs['rasterLegend'].updateDialog()
                 id = self.instruction.FindInstructionByType('map').id
                    
                 rectCanvas = self.canvas.CanvasPaperCoordinates(rect = self.instruction[id]['rect'],
@@ -797,6 +854,8 @@
                 # redraw select box  
                 self.canvas.RedrawSelectBox(id)
                 self.canvas.pdcTmp.RemoveId(self.canvas.idZoomBoxTmp)
+                # redraw to get map to the bottom layer
+                self.canvas.Zoom(zoomFactor = 1, view = (0, 0))
                 
             if itype == 'rasterLegend':
                 if self.instruction[id]['rLegend']:
@@ -890,6 +949,8 @@
         
         if kwargs.has_key('instruction'):
             self.instruction = kwargs['instruction']
+        if kwargs.has_key('openDialogs'):
+            self.openDialogs = kwargs['openDialogs']
         if kwargs.has_key('pageId'):
             self.pageId = kwargs['pageId']
         if kwargs.has_key('objectId'):
@@ -1080,6 +1141,7 @@
                 else:
                     self.parent.SetStatusText(_(''), 0)
                     self.SetCursor(self.cursors["default"])
+                    
         elif event.LeftDown():
             self.mouse['begin'] = event.GetPosition()
             self.begin = self.mouse['begin']
@@ -1166,24 +1228,35 @@
             # draw map frame    
             if self.mouse['use'] == 'addMap':
                 rectTmp = self.pdcTmp.GetIdBounds(self.idZoomBoxTmp)
+                # too small rectangle, it's usually some mistake
+                if rectTmp.GetWidth() < 20 or rectTmp.GetHeight() < 20:
+                    self.pdcTmp.RemoveId(self.idZoomBoxTmp)
+                    self.Refresh()
+                    return
                 rectPaper = self.CanvasPaperCoordinates(rect = rectTmp, canvasToPaper = True)                
+##                
+##                dlg = MapDialog(parent = self.parent, id = [None, None, None], settings = self.instruction, 
+##                                         rect = rectPaper)
+##                dlg.ShowModal()
                 
                 dlg = MapDialog(parent = self.parent, id = [None, None, None], settings = self.instruction, 
                                          rect = rectPaper)
-                dlg.ShowModal()
-                if  self.instruction.FindInstructionByType('map'):
-                    #redraw objects to lower map to the bottom
-                    self.Zoom(zoomFactor = 1, view = (0, 0))
+                self.openDialogs['map'] = dlg
+                self.openDialogs['map'].Show()
+                
+##                if  self.instruction.FindInstructionByType('map'):
+##                    #redraw objects to lower map to the bottom
+                
 
-                    self.mouse['use'] = self.parent.mouseOld
+                self.mouse['use'] = self.parent.mouseOld
 
-                    self.SetCursor(self.parent.cursorOld)
-                    self.parent.toolbar.ToggleTool(self.parent.actionOld, True)
-                    self.parent.toolbar.ToggleTool(self.parent.toolbar.action['id'], False)
-                    self.parent.toolbar.action['id'] = self.parent.actionOld
+                self.SetCursor(self.parent.cursorOld)
+                self.parent.toolbar.ToggleTool(self.parent.actionOld, True)
+                self.parent.toolbar.ToggleTool(self.parent.toolbar.action['id'], False)
+                self.parent.toolbar.action['id'] = self.parent.actionOld
                     
-                self.pdcTmp.RemoveId(self.idZoomBoxTmp)
-                self.Refresh() 
+##                self.pdcTmp.RemoveId(self.idZoomBoxTmp)
+##                self.Refresh() 
 
 
             # resize resizable objects (only map sofar)
@@ -1221,6 +1294,7 @@
                         ComputeSetRegion(self, mapDict = self.instruction[mapId].GetInstruction())
                         
                     self.RedrawSelectBox(mapId)
+                    self.Zoom(zoomFactor = 1, view = (0, 0))
                 self.mouse['use'] = 'pointer'
                 
             # recalculate the position of objects after dragging    
@@ -1228,6 +1302,8 @@
                 if self.mouse['begin'] != event.GetPosition(): #for double click
                     
                     self.RecalculatePosition(ids = [self.dragId])
+                    if self.instruction[self.dragId].type in self.openDialogs:
+                        self.openDialogs[self.instruction[self.dragId].type].updateDialog()
 
         # double click launches dialogs
         elif event.LeftDClick():

Modified: grass-addons/gui/wxpython/psmap/gui_modules/psmap_dialogs.py
===================================================================
--- grass-addons/gui/wxpython/psmap/gui_modules/psmap_dialogs.py	2011-03-23 22:29:03 UTC (rev 45742)
+++ grass-addons/gui/wxpython/psmap/gui_modules/psmap_dialogs.py	2011-03-24 18:55:54 UTC (rev 45743)
@@ -23,6 +23,7 @@
 import string
 from math import ceil, floor
 from copy import deepcopy
+from time import strftime, localtime
 
 import grass.script as grass
 if int(grass.version()['version'].split('.')[0]) > 6:
@@ -212,11 +213,15 @@
         
     def __str__(self):
         """!Returns text for instruction file"""
+        comment = "# timestamp: " + strftime("%Y-%m-%d %H:%M", localtime()) + '\n'
+        env = grass.gisenv()
+        comment += "# location: {0}\n".format(env['LOCATION_NAME'])
+        comment += "# mapset: {0}\n".format(env['MAPSET'])
         border = ''
         if not self.FindInstructionByType('map'):
             border = 'border n\n'
         text = [str(each) for each in self.instruction]
-        return border + '\n'.join(text) + '\nend'
+        return comment + border + '\n'.join(text) + '\nend'
     
     def __getitem__(self, id):
         for each in self.instruction:
@@ -251,14 +256,18 @@
             
     def AddInstruction(self, instruction):
         """!Add instruction"""
+        # add to instructions
         if instruction.type == 'map':
             self.instruction.insert(0, instruction)
         else:
             self.instruction.append(instruction)
+        # add to drawable objects
         if instruction.type not in ('page', 'raster', 'vector', 'vProperties', 'initMap'):
-            self.objectsToDraw.append(instruction.id)    
+            if instruction.type == 'map':
+                self.objectsToDraw.insert(0, instruction.id) 
+            else:
+                self.objectsToDraw.append(instruction.id) 
                 
-
             
     def FindInstructionByType(self, type, list = False):
         """!Find instruction(s) with the given type"""
@@ -314,7 +323,7 @@
             line = line.strip()
             if isBuffer:
                 buffer.append(line)
-                if line.startswith('end'):
+                if 'end' in line:
                     isBuffer = False
                     kwargs = {}
                     if instruction == 'scalebar':
@@ -399,8 +408,6 @@
                 isBuffer = True
                 buffer.append(line)
 
-            elif line.startswith('end'):
-                break
 
         
         rasterLegend = self.FindInstructionByType('rasterLegend')
@@ -628,6 +635,7 @@
     def __str__(self):
         instr = ''
         comment = ''
+        
         #region settings
         if self.instruction['scaleType'] == 0: #match map
             map = self.instruction['map']
@@ -639,12 +647,13 @@
         elif self.instruction['scaleType'] in (2, 3): #current region, fixed scale
             region = grass.region()
             comment = "# g.region n={n} s={s} e={e} w={w} rows={rows} cols={cols}\n".format(**region)
+        
         instr += comment
         instr += '\n'
         # maploc
-        maplocInstruction = "maploc {rect.x} {rect.y}".format(**self.instruction)
+        maplocInstruction = "maploc {rect.x:.3f} {rect.y:.3f}".format(**self.instruction)
         if self.instruction['scaleType'] != 3:
-            maplocInstruction += "  {rect.width} {rect.height}".format(**self.instruction)
+            maplocInstruction += "  {rect.width:.3f} {rect.height:.3f}".format(**self.instruction)
         instr += maplocInstruction
         instr += '\n'
         
@@ -660,7 +669,7 @@
         else:
             borderInstruction = "border y\n"
             borderInstruction += "    width {width}\n    color {color}\n".format(**self.instruction)
-            borderInstruction += "end"
+            borderInstruction += "    end"
         instr += borderInstruction
         instr += '\n'
 
@@ -737,7 +746,7 @@
         else:
             instr = "paper {Format}\n".format(**self.instruction)
         instr += "    left {Left}\n    right {Right}\n"    \
-                            "    bottom {Bottom}\n    top {Top}\nend".format(**self.instruction)
+                            "    bottom {Bottom}\n    top {Top}\n    end".format(**self.instruction)
 
         return instr
     
@@ -803,10 +812,10 @@
         
     def __str__(self):
         instr = "mapinfo\n"
-        instr += "    where {where[0]} {where[1]}\n".format(**self.instruction)
+        instr += "    where {where[0]:.3f} {where[1]:.3f}\n".format(**self.instruction)
         instr += "    font {font}\n    fontsize {fontsize}\n    color {color}\n".format(**self.instruction)            
         instr += "    background {background}\n    border {border}\n".format(**self.instruction)  
-        instr += "end"
+        instr += "    end"
         return instr
     
     def Read(self, instruction, text):
@@ -826,7 +835,7 @@
                 elif sub[0] == 'border':
                     instr['border'] = sub[1]
                 elif sub[0] == 'where':
-                    instr['where'] = tuple(sub[1].split())
+                    instr['where'] = float(sub[1].split()[0]), float(sub[1].split()[1])
         except (ValueError, IndexError):
             GError(_("Failed to read instruction {0}").format(instruction))
             return False
@@ -857,7 +866,7 @@
         
     def __str__(self):
         text = self.instruction['text'].replace('\n','\\n')
-        instr = "text {east} {north}".format(**self.instruction)
+        instr = "text {east:.3f} {north:.3f}".format(**self.instruction)
         instr += " {0}\n".format(text)
         instr += "    font {font}\n    fontsize {fontsize}\n    color {color}\n".format(**self.instruction)
         instr += "    hcolor {hcolor}\n".format(**self.instruction)
@@ -873,7 +882,7 @@
             instr += "    rotate {rotate}\n".format(**self.instruction)
         if float(self.instruction["xoffset"]) or float(self.instruction["yoffset"]):
             instr += "    xoffset {xoffset}\n    yoffset {yoffset}\n".format(**self.instruction)
-        instr += "end"
+        instr += "    end"
         return instr
     
     def Read(self, instruction, text, **kwargs):
@@ -954,12 +963,12 @@
         
     def __str__(self):
         instr = "scalebar {scalebar}\n".format(**self.instruction)
-        instr += "    where {where[0]} {where[1]}\n".format(**self.instruction)
+        instr += "    where {where[0]:.3f} {where[1]:.3f}\n".format(**self.instruction)
         instr += "    length {length}\n    units {unitsLength}\n".format(**self.instruction)
         instr += "    height {height}\n".format(**self.instruction)
         instr += "    segment {segment}\n    numbers {numbers}\n".format(**self.instruction)
         instr += "    fontsize {fontsize}\n    background {background}\n".format(**self.instruction)
-        instr += "end"
+        instr += "    end"
         return instr
     
     def Read(self, instruction, text, **kwargs):
@@ -974,7 +983,7 @@
                     else:
                         instr['scalebar'] = 'f'
                 elif line.startswith('where'):
-                    instr['where'] = line.split()[1:3]
+                    instr['where'] = map(float, line.split()[1:3])
                 elif line.startswith('length'):
                     instr['length'] = float(line.split()[1])
                 elif line.startswith('units'):
@@ -999,8 +1008,8 @@
                 
         self.instruction.update(instr)
         w, h = self.EstimateSize(scalebarDict = self.instruction, scale = scale)
-        x = float(self.instruction['where'][0]) - w / 2 
-        y = float(self.instruction['where'][1]) - h / 2
+        x = self.instruction['where'][0] - w / 2 
+        y = self.instruction['where'][1] - h / 2
         self.instruction['rect'] = wx.Rect2D(x, y, w, h)
         return True 
     
@@ -1038,7 +1047,7 @@
     def __str__(self):
         instr = "colortable y\n"
         instr += "    raster {raster}\n".format(**self.instruction)
-        instr += "    where {where[0]} {where[1]}\n".format(**self.instruction)
+        instr += "    where {where[0]:.3f} {where[1]:.3f}\n".format(**self.instruction)
         if self.instruction['width']:
             instr += "    width {width}\n".format(**self.instruction)
         instr += "    discrete {discrete}\n".format(**self.instruction)
@@ -1053,7 +1062,7 @@
             instr += "    nodata {nodata}\n".format(**self.instruction)
         instr += "    font {font}\n    fontsize {fontsize}\n    color {color}\n"\
                                 .format(**self.instruction)
-        instr += "end"
+        instr += "    end"
         return instr    
     
     
@@ -1064,7 +1073,7 @@
         for line in text:
             try:
                 if line.startswith('where'):
-                    instr['where'] = line.split()[1:3]
+                    instr['where'] = map(float, line.split()[1:3])
                 elif line.startswith('font '):
                     instr['font'] = line.split()[1]
                 elif line.startswith('fontsize'):
@@ -1186,13 +1195,13 @@
         
     def __str__(self):
         instr = "vlegend\n"
-        instr += "    where {where[0]} {where[1]}\n".format(**self.instruction)
+        instr += "    where {where[0]:.3f} {where[1]:.3f}\n".format(**self.instruction)
         instr += "    font {font}\n    fontsize {fontsize}\n".format(**self.instruction)
         instr += "    width {width}\n    cols {cols}\n".format(**self.instruction)
         if self.instruction['span']:
             instr += "    span {span}\n".format(**self.instruction)
         instr += "    border {border}\n".format(**self.instruction)  
-        instr += "end"  
+        instr += "    end"  
         return instr
 
     def Read(self, instruction, text, **kwargs):
@@ -1202,7 +1211,7 @@
         for line in text:
             try:
                 if line.startswith('where'):
-                    instr['where'] = line.split()[1:3]
+                    instr['where'] = map(float, line.split()[1:3])
                 elif line.startswith('font '):
                     instr['font'] = line.split()[1]
                 elif line.startswith('fontsize'):
@@ -1409,7 +1418,7 @@
         #position and label in vlegend
         vInstruction += "    label {label}\n    lpos {lpos}\n".format(**dic)
         
-        vInstruction += "end"
+        vInstruction += "    end"
         return vInstruction
     
     def Read(self, instruction, text, **kwargs):
@@ -1528,16 +1537,20 @@
 class PsmapDialog(wx.Dialog):
     def __init__(self, parent, id,  title, settings, apply = True):
         wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY, 
-                            title = title, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE)
+                            title = title, size = wx.DefaultSize,
+                            style = wx.CAPTION|wx.CLOSE_BOX|wx.MINIMIZE_BOX)
         self.apply = apply
         self.id = id
         self.parent = parent
         self.instruction = settings
-
+        self.objectType = None
         self.unitConv = UnitConversion(self)
         self.spinCtrlSize = (50, -1)
-
         
+        self.Bind(wx.EVT_CLOSE, self.OnClose)
+        
+    
+        
     def AddUnits(self, parent, dialogDict):
         parent.units = dict()
         parent.units['unitsLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Units:"))
@@ -1608,14 +1621,24 @@
             return False
         
     def OnOK(self, event):
+        """!Apply changes, close dialog"""
         ok = self.OnApply(event)
         if ok:
-            event.Skip()
-        
+            self.Close()
+    
     def OnCancel(self, event):
+        """!Close dialog"""
+        self.Close()
+
+    def OnClose(self, event):
+        """!Destroy dialog and delete it from open dialogs"""
+        if self.objectType:
+            for each in  self.objectType:
+                if each in self.parent.openDialogs:
+                    del self.parent.openDialogs[each]
         event.Skip()
+        self.Destroy()
         
-        
     def _layout(self, panel):
         #buttons
         btnCancel = wx.Button(self, wx.ID_CANCEL)
@@ -1628,8 +1651,9 @@
         # bindigs
         btnOK.Bind(wx.EVT_BUTTON, self.OnOK)
         btnOK.SetToolTipString(_("Close dialog and apply changes"))
+        #btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
+        btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
         btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
-        btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
         if self.apply:
             btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
             btnApply.SetToolTipString(_("Apply changes"))
@@ -1647,7 +1671,6 @@
         mainSizer.Add(item = btnSizer, proportion = 0,
                       flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
         
-        self.Bind(wx.EVT_CLOSE, self.OnCancel)
         
         self.SetSizer(mainSizer)
         mainSizer.Layout()
@@ -1795,21 +1818,22 @@
     def __init__(self, parent, id, settings,  rect = None, notebook = False):
         PsmapDialog.__init__(self, parent = parent, id = id, title = "", settings = settings)
  
-        self.instruction = settings
         self.isNotebook = notebook
+        self.objectType = ('mapNotebook',) if self.isNotebook else ('map',)
+        
         #notebook
         if self.isNotebook:
-            notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
-            self.mPanel = MapFramePanel(parent = notebook, id = self.id[0], settings = self.instruction, 
+            self.notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
+            self.mPanel = MapFramePanel(parent = self.notebook, id = self.id[0], settings = self.instruction, 
                                         rect = rect, notebook = True)
             self.id[0] = self.mPanel.getId()
-            self.rPanel = RasterPanel(parent = notebook, id = self.id[1], settings = self.instruction, 
+            self.rPanel = RasterPanel(parent = self.notebook, id = self.id[1], settings = self.instruction, 
                                         notebook = True)
             self.id[1] = self.rPanel.getId()
-            self.vPanel = VectorPanel(parent = notebook, id = self.id[2], settings = self.instruction,
+            self.vPanel = VectorPanel(parent = self.notebook, id = self.id[2], settings = self.instruction,
                                         notebook = True)
             self.id[2] = self.vPanel.getId()
-            self._layout(notebook)
+            self._layout(self.notebook)
             self.SetTitle(_("Map settings"))
         else:
             self.mPanel = MapFramePanel(parent = self, id = self.id[0], settings = self.instruction, 
@@ -1837,7 +1861,25 @@
             return True 
         
         return False
-
+    
+    def updateDialog(self):
+        """!Update raster and vector information"""
+        if self.mPanel.scaleChoice.GetSelection() == 0:
+            if self.mPanel.rasterTypeRadio.GetValue():
+                if 'raster' in self.parent.openDialogs:
+                    if self.parent.openDialogs['raster'].rPanel.rasterYesRadio.GetValue() and \
+                            self.parent.openDialogs['raster'].rPanel.rasterSelect.GetValue() == self.mPanel.select.GetValue():
+                            self.mPanel.drawMap.SetValue(True)
+                    else:
+                        self.mPanel.drawMap.SetValue(False)
+            else:
+                if 'vector' in self.parent.openDialogs:
+                    found = False
+                    for each in self.parent.openDialogs['vector'].vPanel.vectorList:
+                        if each[0] == self.mPanel.select.GetValue():
+                            found = True
+                    self.mPanel.drawMap.SetValue(found)    
+                        
 class MapFramePanel(wx.Panel):
     """!wx.Panel with map (scale, region, border) settings"""
     def __init__(self, parent, id, settings, rect, notebook = True):
@@ -1927,7 +1969,7 @@
 
         self.rasterTypeRadio = wx.RadioButton(self, id = wx.ID_ANY, label = " {0} ".format(_("raster")), style = wx.RB_GROUP)
         self.vectorTypeRadio = wx.RadioButton(self, id = wx.ID_ANY, label = " {0} ".format(_("vector")))
-        self.drawMap = wx.CheckBox(self, id = wx.ID_ANY, label = "draw selected map")
+        self.drawMap = wx.CheckBox(self, id = wx.ID_ANY, label = "add selected map")
         
         self.mapOrRegionText = [_("Map:"), _("Region:")] 
         dc = wx.PaintDC(self)# determine size of labels
@@ -2010,7 +2052,7 @@
         
         
         if projInfo()['proj'] == 'll':
-            self.scaleChoice.SetItems(self.scaleChoice.GetItems()[0:2])
+            self.scaleChoice.SetItems(self.scaleChoice.GetItems()[0:3])
             boxC.Hide()
             for each in self.centerSizer.GetChildren():
                 each.GetWindow().Hide()
@@ -2180,7 +2222,7 @@
                                     topoType = 'lines'
                                 else:
                                     topoType = 'points'
-                                label = '('.join(mapFrameDict['map'].split('@'))
+                                label = '('.join(mapFrameDict['map'].split('@')) + ')'
                             except grass.ScriptError:
                                 pass
                             else:
@@ -2388,7 +2430,8 @@
                 self.instruction.AddInstruction(raster)
             self.instruction[self.id].SetInstruction(self.rasterDict)
             
-        
+        if 'map' in self.mainDialog.parent.openDialogs:
+            self.mainDialog.parent.openDialogs['map'].updateDialog()
         return True
         
     def getId(self):
@@ -2628,13 +2671,16 @@
         else:
             if self.id in self.instruction:
                 del self.instruction[self.id]
-
+                
+        if 'map' in self.parent.parent.openDialogs:
+            self.parent.parent.openDialogs['map'].updateDialog()
         return True
     
 class RasterDialog(PsmapDialog):
     def __init__(self, parent, id, settings):
         PsmapDialog.__init__(self, parent = parent, id = id, title = "Choose raster map", settings = settings)
-        self.instruction = settings
+        self.objectType = ('raster',)
+        
         self.rPanel = RasterPanel(parent = self, id = self.id, settings = self.instruction, notebook = False)
 
         self.id = self.rPanel.getId()
@@ -2657,11 +2703,20 @@
             mapId = self.instruction.FindInstructionByType('map').id
             self.parent.DialogDataChanged(id = mapId)
         return True
- 
+    
+    def updateDialog(self):
+        """!Update information (not used)"""
+        pass
+##        if 'map' in self.parent.openDialogs:
+##            if self.parent.openDialogs['map'].mPanel.rasterTypeRadio.GetValue()\
+##                    and self.parent.openDialogs['map'].mPanel.select.GetValue():
+##                if self.parent.openDialogs['map'].mPanel.drawMap.IsChecked():
+##                    self.rPanel.rasterSelect.SetValue(self.parent.openDialogs['map'].mPanel.select.GetValue())   
+                
 class MainVectorDialog(PsmapDialog):
     def __init__(self, parent, id, settings):
         PsmapDialog.__init__(self, parent = parent, id = id, title = "Choose vector maps", settings = settings)
-        self.instruction = settings
+        self.objectType = ('vector',)
         self.vPanel = VectorPanel(parent = self, id = self.id, settings = self.instruction, notebook = False)
 
         self.id = self.vPanel.getId()
@@ -2679,7 +2734,10 @@
             self.parent.DialogDataChanged(id = mapId)
         return True
         
-
+    def updateDialog(self):
+        """!Update information (not used)"""
+        pass
+        
 class VPropertiesDialog(PsmapDialog):
     def __init__(self, parent, id, settings, vectors, tmpSettings):
         PsmapDialog.__init__(self, parent = parent, id = id, title = "", settings = settings, apply = False)
@@ -3423,7 +3481,7 @@
 class LegendDialog(PsmapDialog):
     def __init__(self, parent, id, settings, page):
         PsmapDialog.__init__(self, parent = parent, id = id, title = "Legend settings", settings = settings)
-        
+        self.objectType = ('rasterLegend', 'vectorLegend')
         self.instruction = settings
         map = self.instruction.FindInstructionByType('map')
         self.mapId = map.id if map else None
@@ -3463,7 +3521,6 @@
         self.notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
         self.panelRaster = self._rasterLegend(self.notebook)
         self.panelVector = self._vectorLegend(self.notebook)  
-##        self.OnDefaultSize(None)
         self.OnRaster(None)
         self.OnRange(None)
         self.OnIsLegend(None)
@@ -3499,7 +3556,8 @@
 
         rasterType = getRasterType(map = self.currRaster)
 
-        self.rasterCurrent = wx.StaticText(panel, id = wx.ID_ANY, label = _("{0}: type {1}").format(self.currRaster, str(rasterType)))
+        self.rasterCurrent = wx.StaticText(panel, id = wx.ID_ANY,
+                                label = _("{0}: type {1}").format(self.currRaster, str(rasterType)))
         self.rasterSelect = Select( panel, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
                                     type = 'raster', multiple = False,
                                     updateOnPopup = True, onPopup = None)
@@ -3607,6 +3665,7 @@
         self.vectorListCtrl.InsertColumn(1, _("Label"))
         if self.vectorId:
             vectors = sorted(self.instruction[self.vectorId]['list'], key = lambda x: x[3])
+            
             for vector in vectors:
                 index = self.vectorListCtrl.InsertStringItem(sys.maxint, vector[0].split('@')[0])
                 self.vectorListCtrl.SetStringItem(index, 1, vector[4])
@@ -3945,7 +4004,7 @@
     def OnBorder(self, event):
         """!Enables/disables colorPickerCtrl for border"""    
         self.borderColorCtrl.Enable(self.borderCheck.GetValue())
-        
+    
     def updateRasterLegend(self):
         """!Save information from raster legend dialog to dictionary"""
 
@@ -4054,6 +4113,8 @@
     def updateVectorLegend(self):
         """!Save information from vector legend dialog to dictionary"""
 
+        vector = self.instruction.FindInstructionByType('vector')
+        self.vectorId = vector.id if vector else None
         #is vector legend
         if not self.isVLegend.GetValue():
             self.vLegendDict['vLegend'] = False
@@ -4142,14 +4203,57 @@
             return True
         return False
         
-    
+    def updateDialog(self):
+        """!Update legend coordinates after moving"""
         
-
+        # raster legend
+        
+        if 'rect' in self.rLegendDict:
+            x, y = self.rLegendDict['rect'][:2]
+            currUnit = self.panelRaster.units['unitsCtrl'].GetStringSelection()
+            x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
+            y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
+            self.panelRaster.position['xCtrl'].SetValue("{0:5.3f}".format(x))
+            self.panelRaster.position['yCtrl'].SetValue("{0:5.3f}".format(y))
+        #update name and type of raster
+        raster = self.instruction.FindInstructionByType('raster')
+        self.rasterId = raster.id if raster else None 
+        currRaster = raster['raster'] if raster else None
+        rasterType = getRasterType(map = currRaster)
+        self.rasterCurrent.SetLabel( _("{0}: type {1}").format(currRaster, str(rasterType)))
+        
+        # vector legend
+        
+        if 'rect' in self.vLegendDict:
+            x, y = self.vLegendDict['rect'][:2]
+            currUnit = self.panelVector.units['unitsCtrl'].GetStringSelection()
+            x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
+            y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
+            self.panelVector.position['xCtrl'].SetValue("{0:5.3f}".format(x))
+            self.panelVector.position['yCtrl'].SetValue("{0:5.3f}".format(y))
+        # update vector maps
+        if self.instruction.FindInstructionByType('vector'):
+            vectors = sorted(self.instruction.FindInstructionByType('vector')['list'], key = lambda x: x[3])
+            self.vectorListCtrl.DeleteAllItems()
+            for vector in vectors:
+                index = self.vectorListCtrl.InsertStringItem(sys.maxint, vector[0].split('@')[0])
+                self.vectorListCtrl.SetStringItem(index, 1, vector[4])
+                self.vectorListCtrl.SetItemData(index, index)
+                self.vectorListCtrl.CheckItem(index, True)
+                if vector[3] == 0:
+                    self.vectorListCtrl.CheckItem(index, False)
+            self.panelVector.colsCtrl.SetRange(1, min(10, len(self.instruction.FindInstructionByType('vector')['list'])))
+            self.panelVector.colsCtrl.SetValue(1)
+        else:
+            self.vectorListCtrl.DeleteAllItems()
+            self.panelVector.colsCtrl.SetRange(0,0)
+            self.panelVector.colsCtrl.SetValue(0)
              
 class MapinfoDialog(PsmapDialog):
     def __init__(self, parent, id, settings):
         PsmapDialog.__init__(self, parent = parent, id = id, title = "Mapinfo settings", settings = settings)
-        self.instruction = settings
+        
+        self.objectType = ('mapinfo',)
         if self.id is not None:
             self.mapinfo = self.instruction[self.id]
             self.mapinfoDict = self.mapinfo.GetInstruction()
@@ -4167,6 +4271,7 @@
         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)
@@ -4310,13 +4415,23 @@
             self.parent.objectId.append(self.id)
             
         return True
-      
     
+    def updateDialog(self):
+        """!Update mapinfo coordinates, after moving"""
+        x, y = self.mapinfoDict['where']
+        currUnit = self.panel.units['unitsCtrl'].GetStringSelection()
+        x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
+        y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
+        self.panel.position['xCtrl'].SetValue("{0:5.3f}".format(x))
+        self.panel.position['yCtrl'].SetValue("{0:5.3f}".format(y))
+           
+        
+    
 class ScalebarDialog(PsmapDialog):
     """!Dialog for scale bar"""
     def __init__(self, parent, id, settings):
         PsmapDialog.__init__(self, parent = parent, id = id, title = "Scale bar settings", settings = settings)
-        self.instruction = settings
+        self.objectType = ('scalebar',)
         if self.id is not None:
             self.scalebar = self.instruction[id]
             self.scalebarDict = self.scalebar.GetInstruction()
@@ -4444,7 +4559,7 @@
                 bitmap = wx.EmptyBitmap(0,0)
             else:
                 bitmap = wx.Bitmap(path)
-            self.sbCombo.Append(item = item, bitmap = bitmap, clientData = item[0])
+            self.sbCombo.Append(item = '', bitmap = bitmap, clientData = item[0])
         #self.sbCombo.Append(item = 'simple', bitmap = wx.Bitmap("./images/scalebar-simple.png"), clientData = 's')
         if self.scalebarDict['scalebar'] == 'f':
             self.sbCombo.SetSelection(0)
@@ -4557,11 +4672,21 @@
             
         return True
     
-      
+    def updateDialog(self):
+        """!Update scalebar coordinates, after moving"""
+        x, y = self.scalebarDict['rect'][:2]
+        currUnit = self.panel.units['unitsCtrl'].GetStringSelection()
+        x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
+        y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
+        self.panel.position['xCtrl'].SetValue("{0:5.3f}".format(x))
+        self.panel.position['yCtrl'].SetValue("{0:5.3f}".format(y))
+        
+ 
+        
 class TextDialog(PsmapDialog):
     def __init__(self, parent, id, settings):
         PsmapDialog.__init__(self, parent = parent, id = id, title = "Text settings", settings = settings)
-        
+        self.objectType = ('text',)
         if self.id is not None:
             self.textDict = self.instruction[id].GetInstruction()
         else:
@@ -4934,15 +5059,31 @@
 
         return True
     
-    
+    def updateDialog(self):
+        """!Update text coordinates, after moving"""
+        # XY coordinates
+        x, y = self.textDict['where'][:2]
+        currUnit = self.positionPanel.units['unitsCtrl'].GetStringSelection()
+        x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
+        y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
+        self.positionPanel.position['xCtrl'].SetValue("{0:5.3f}".format(x))
+        self.positionPanel.position['yCtrl'].SetValue("{0:5.3f}".format(y))
+        # EN coordinates
+        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"""    
     if type(rgb) == wx.Colour:
         return str(rgb.Red()) + ':' + str(rgb.Green()) + ':' + str(rgb.Blue())
     elif type(rgb) == str:
-        return wx.Colour(*map(int, rgb.split(':')))
+        if ':' in rgb:
+            return wx.Colour(*map(int, rgb.split(':')))
+        else:
+            return rgb
         
         
 def PaperMapCoordinates(map, x, y, paperToMap = True):



More information about the grass-commit mailing list