~ubuntu-branches/ubuntu/karmic/grass/karmic

« back to all changes in this revision

Viewing changes to gui/wxpython/wxgui.py

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine
  • Date: 2009-07-13 13:34:03 UTC
  • mfrom: (3.1.15 karmic)
  • Revision ID: james.westby@ubuntu.com-20090713133403-0x81m7hb1q06zu13
Tags: 6.4.0~rc5-2
* Added a grass menu item (Hamish).
* Added a grass.menu.in template with related icon.
* Added a simple x-grass wrapper to allow running grass without a pre-running
  controlling terminal. At least it works within ordinary WMs launchers.
  (closes: #503371)
* Added newlocation.dpatch patch to manage correctly new locations.
  (closes: #533738)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import re
28
28
import string
29
29
import getopt
 
30
import platform
 
31
import shlex
30
32
 
31
33
### XML 
32
34
import xml.sax
67
69
except:
68
70
    import compat.subprocess as subprocess
69
71
 
 
72
grassPath = os.path.join(globalvar.ETCDIR, "python")
 
73
sys.path.append(grassPath)
 
74
from grass.script import core as grass
 
75
 
70
76
import gui_modules.utils as utils
71
77
import gui_modules.preferences as preferences
72
78
import gui_modules.wxgui_utils as wxgui_utils
102
108
        self.baseTitle = title
103
109
        self.iconsize  = (16, 16)
104
110
 
105
 
        wx.Frame.__init__(self, parent=parent, id=id, size=(500, 400),
 
111
        wx.Frame.__init__(self, parent=parent, id=id, size=(550, 400),
106
112
                          style=wx.DEFAULT_FRAME_STYLE)
107
113
                          
108
114
        self.SetTitle(self.baseTitle)
186
192
        self.goutput.Redirect()
187
193
        
188
194
        # start with layer manager on top
 
195
        self.curr_page.maptree.mapdisplay.Raise()
189
196
        self.Raise()
190
197
 
191
198
    def __doLayout(self):
449
456
 
450
457
    def OnRunCmd(self, event):
451
458
        """Run command"""
452
 
        cmd = event.GetString()
 
459
        cmdString = event.GetString()
453
460
 
454
 
        if cmd[:2] == 'd.' and not self.curr_page:
 
461
        if cmdString[:2] == 'd.' and not self.curr_page:
455
462
            self.NewDisplay(show=True)
456
463
        
457
 
        if len(cmd.split(' ')) > 1:
 
464
        cmd = shlex.split(str(cmdString))
 
465
        if len(cmd) > 1:
458
466
            self.goutput.RunCmd(cmd, switchPage=True)
459
467
        else:
460
468
            self.goutput.RunCmd(cmd, switchPage=False)
530
538
    def OnAboutGRASS(self, event):
531
539
        """Display 'About GRASS' dialog"""
532
540
        info = wx.AboutDialogInfo()
533
 
 
534
 
        rev = "$Revision: 36287 $"
 
541
        
535
542
        # name
536
543
        info.SetName("GRASS GIS")
537
544
        # version
538
 
        versionCmd = gcmd.Command(['g.version'])
539
 
        info.SetVersion(versionCmd.ReadStdOutput()[0].replace('GRASS', '').strip())
 
545
        version, svn_gis_h_rev, svn_gis_h_date = gcmd.RunCommand('g.version',
 
546
                                                                 flags = 'r',
 
547
                                                                 read = True).splitlines()
 
548
        version = version.replace('GRASS', '').strip()
 
549
        info.SetVersion(version)
540
550
        # description
541
551
        copyrightFile = open(os.path.join(os.getenv("GISBASE"), "COPYING"), 'r')
542
552
        copyrightOut = []
543
553
        copyright = copyrightFile.readlines()
544
 
        info.SetCopyright(rev + '\n\n' + wordwrap(''.join(copyright[:11] + copyright[26:-3]),
545
 
                                                  550, wx.ClientDC(self)))
 
554
        info.SetCopyright('GIS Library '+ svn_gis_h_rev + '(' + svn_gis_h_date.split(' ')[1] + ')' + 
 
555
                          '\n\n' + wordwrap(''.join(copyright[:11] + copyright[26:-3]),
 
556
                                                  575, wx.ClientDC(self)))
546
557
        copyrightFile.close()
547
558
        # website
548
559
        info.SetWebSite(("http://grass.osgeo.org", "The official GRASS site"))
1015
1026
        runbat = os.path.join(gisbase,'etc','grass-run.bat')
1016
1027
        xtermwrapper = os.path.join(gisbase,'etc','grass-xterm-wrapper')
1017
1028
        grassrun = os.path.join(gisbase,'etc','grass-run.sh')
1018
 
        command = ' '.join(command)
 
1029
        command = shlex.split(str(command))
1019
1030
        
1020
 
        if 'OS' in os.environ and os.environ['OS'] == "Windows_NT":
 
1031
        if platform.system() == 'Windows':
1021
1032
            cmdlist = ["cmd.exe", "/c", 'start "%s"' % runbat, command]
1022
1033
        else:
1023
1034
            cmdlist = [xtermwrapper, '-e "%s"' % grassrun, command]
1094
1105
                 ('', '', '', ''),
1095
1106
                 ('addrast', Icons["addrast"].GetBitmap(),
1096
1107
                  Icons["addrast"].GetLabel(), self.OnAddRaster),
 
1108
                 ('addshaded', Icons["addshaded"].GetBitmap(),
 
1109
                  _("Add various raster-based map layers"), self.OnAddRasterMisc),
1097
1110
                 ('addvect', Icons["addvect"].GetBitmap(),
1098
1111
                  Icons["addvect"].GetLabel(), self.OnAddVector),
 
1112
                 ('addthematic', Icons["addthematic"].GetBitmap(),
 
1113
                  _("Add various vector-based map layer"), self.OnAddVectorMisc),
1099
1114
                 ('addcmd',  Icons["addcmd"].GetBitmap(),
1100
1115
                  Icons["addcmd"].GetLabel(),  self.OnAddCommand),
1101
1116
                 ('addgrp',  Icons["addgrp"].GetBitmap(),
1102
1117
                  Icons["addgrp"].GetLabel(), self.OnAddGroup),
1103
1118
                 ('addovl',  Icons["addovl"].GetBitmap(),
1104
1119
                  Icons["addovl"].GetLabel(), self.OnAddOverlay),
1105
 
                 ('addlabels',  Icons["addlabels"].GetBitmap(),
1106
 
                  Icons["addlabels"].GetLabel(), self.OnAddLabels),
1107
1120
                 ('delcmd',  Icons["delcmd"].GetBitmap(),
1108
1121
                  Icons["delcmd"].GetLabel(), self.OnDeleteLayer),
1109
1122
                 ('', '', '', ''),
1239
1252
 
1240
1253
    # toolBar button handlers
1241
1254
    def OnAddRaster(self, event):
 
1255
        """Add raster map layer"""
 
1256
        # start new map display if no display is available
 
1257
        if not self.curr_page:
 
1258
            self.NewDisplay(show=False)
 
1259
        
 
1260
        self.AddRaster(event)
 
1261
        
 
1262
    def OnAddRasterMisc(self, event):
1242
1263
        """Add raster menu"""
1243
1264
        # start new map display if no display is available
1244
1265
        if not self.curr_page:
1248
1269
        rastmenu = wx.Menu()
1249
1270
 
1250
1271
        # add items to the menu
1251
 
        addrast = wx.MenuItem(rastmenu, -1, Icons["addrast"].GetLabel())
1252
 
        addrast.SetBitmap(Icons["addrast"].GetBitmap(self.iconsize))
1253
 
        rastmenu.AppendItem(addrast)
1254
 
        self.Bind(wx.EVT_MENU, self.AddRaster, addrast)
1255
 
 
1256
1272
        if self.curr_page.maptree.mapdisplay.toolbars['nviz']:
1257
1273
            addrast3d = wx.MenuItem(rastmenu, -1, Icons ["addrast3d"].GetLabel())
1258
1274
            addrast3d.SetBitmap(Icons["addrast3d"].GetBitmap (self.iconsize))
1293
1309
        self.curr_page.maptree.mapdisplay.Show()
1294
1310
 
1295
1311
    def OnAddVector(self, event):
 
1312
        """Add vector map layer"""
 
1313
        # start new map display if no display is available
 
1314
        if not self.curr_page:
 
1315
            self.NewDisplay(show=False)
 
1316
        
 
1317
        self.AddVector(event)
 
1318
        
 
1319
    def OnAddVectorMisc(self, event):
1296
1320
        """Add vector menu"""
1297
1321
        # start new map display if no display is available
1298
1322
        if not self.curr_page:
1300
1324
 
1301
1325
        point = wx.GetMousePosition()
1302
1326
        vectmenu = wx.Menu()
1303
 
 
1304
 
        addvect = wx.MenuItem(vectmenu, -1, Icons["addvect"].GetLabel())
1305
 
        addvect.SetBitmap(Icons["addvect"].GetBitmap(self.iconsize))
1306
 
        vectmenu.AppendItem(addvect)
1307
 
        self.Bind(wx.EVT_MENU, self.AddVector, addvect)
1308
 
 
 
1327
        
1309
1328
        addtheme = wx.MenuItem(vectmenu, -1, Icons["addthematic"].GetLabel())
1310
1329
        addtheme.SetBitmap(Icons["addthematic"].GetBitmap(self.iconsize))
1311
1330
        vectmenu.AppendItem(addtheme)
1333
1352
        point = wx.GetMousePosition()
1334
1353
        ovlmenu = wx.Menu()
1335
1354
 
1336
 
        addgrid = wx.MenuItem(ovlmenu, -1, Icons["addgrid"].GetLabel())
 
1355
        addgrid = wx.MenuItem(ovlmenu, wx.ID_ANY, Icons["addgrid"].GetLabel())
1337
1356
        addgrid.SetBitmap(Icons["addgrid"].GetBitmap(self.iconsize))
1338
1357
        ovlmenu.AppendItem(addgrid)
1339
1358
        self.Bind(wx.EVT_MENU, self.AddGrid, addgrid)
1340
 
 
1341
 
        addgeodesic = wx.MenuItem(ovlmenu, -1, Icons["addgeodesic"].GetLabel())
 
1359
        
 
1360
        addlabels = wx.MenuItem(ovlmenu, wx.ID_ANY, Icons["addlabels"].GetLabel())
 
1361
        addlabels.SetBitmap(Icons["addlabels"].GetBitmap(self.iconsize))
 
1362
        ovlmenu.AppendItem(addlabels)
 
1363
        self.Bind(wx.EVT_MENU, self.OnAddLabels, addlabels)
 
1364
        
 
1365
        addgeodesic = wx.MenuItem(ovlmenu, wx.ID_ANY, Icons["addgeodesic"].GetLabel())
1342
1366
        addgeodesic.SetBitmap(Icons["addgeodesic"].GetBitmap(self.iconsize))
1343
1367
        ovlmenu.AppendItem(addgeodesic)
1344
1368
        self.Bind(wx.EVT_MENU, self.AddGeodesic, addgeodesic)
1345
 
 
1346
 
        addrhumb = wx.MenuItem(ovlmenu, -1, Icons["addrhumb"].GetLabel())
 
1369
        
 
1370
        addrhumb = wx.MenuItem(ovlmenu, wx.ID_ANY, Icons["addrhumb"].GetLabel())
1347
1371
        addrhumb.SetBitmap(Icons["addrhumb"].GetBitmap(self.iconsize))
1348
1372
        ovlmenu.AppendItem(addrhumb)
1349
1373
        self.Bind(wx.EVT_MENU, self.AddRhumb, addrhumb)