icon.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. """!
  2. @package icon
  3. @brief Icon themes
  4. @code
  5. from icons import Icons as Icons
  6. @endcode
  7. Classes:
  8. - MetaIcon
  9. (C) 2007-2008, 2010-2011 by the GRASS Development Team
  10. This program is free software under the GNU General Public
  11. License (>=v2). Read the file COPYING that comes with GRASS
  12. for details.
  13. @author Martin Landa <landa.martin gmail.com>
  14. """
  15. import os
  16. import sys
  17. sys.path.append(os.path.join(os.getenv("GISBASE"), "etc", "wxpython", "gui_modules"))
  18. import globalvar
  19. if not os.getenv("GRASS_WXBUNDLED"):
  20. globalvar.CheckForWx()
  21. import wx
  22. from preferences import globalSettings as UserSettings
  23. import grass_icons # default icon set
  24. iconpath_default = grass_icons.iconpath
  25. iconpath_vdigit = grass_icons.iconpath_vdigit
  26. Icons_default = grass_icons.IconsGrass
  27. iconTheme = UserSettings.Get(group='advanced', key='iconTheme', subkey='type')
  28. if iconTheme == 'silk':
  29. import silk_icons
  30. iconpath = silk_icons.iconpath
  31. Icons = silk_icons.IconsSilk
  32. elif iconTheme == 'grass2':
  33. import grass2_icons
  34. iconpath = grass2_icons.iconpath
  35. Icons = grass2_icons.IconsGrass2
  36. else:
  37. iconpath = iconpath_default
  38. Icons = grass_icons.IconsGrass
  39. # merge icons dictionaries, join paths
  40. try:
  41. if iconpath and not os.path.exists(iconpath):
  42. raise OSError
  43. if iconTheme != 'grass':
  44. # use default icons if no icon is available
  45. for key, img in Icons_default.iteritems():
  46. if not Icons.has_key(key) or \
  47. Icons[key] is None: # add key
  48. Icons[key] = img
  49. if Icons[key] == img:
  50. if key[0:3] == 'dig':
  51. iconpath_tmp = iconpath_vdigit
  52. else:
  53. iconpath_tmp = iconpath_default
  54. else:
  55. iconpath_tmp = iconpath
  56. Icons[key] = os.path.join(iconpath_tmp, Icons[key])
  57. else:
  58. for key, img in Icons.iteritems():
  59. if img and type (Icons[key]) == type(''):
  60. if key[0:3] == 'dig':
  61. Icons[key] = os.path.join(iconpath_vdigit, img)
  62. else:
  63. Icons[key] = os.path.join(iconpath_default, img)
  64. except:
  65. sys.exit(_("Unable to load icon theme..."))
  66. class MetaIcon:
  67. """!Handle icon metadata (image path, tooltip, ...)
  68. """
  69. def __init__(self, img, label, desc = None):
  70. self.imagepath = img
  71. if not self.imagepath:
  72. self.type = 'unknown'
  73. else:
  74. if self.imagepath.find ('wxART_') > -1:
  75. self.type = 'wx'
  76. else:
  77. self.type = 'img'
  78. self.label = label
  79. if desc:
  80. self.description = desc
  81. else:
  82. self.description = ''
  83. def __str__(self):
  84. """!Debugging"""
  85. return "label=%s, img=%s, type=%s" % (self.label, self.imagepath, self.type)
  86. def GetBitmap(self, size = None):
  87. """!Get bitmap"""
  88. bmp = None
  89. if self.type == 'wx':
  90. bmp = wx.ArtProvider.GetBitmap(id = self.imagepath, client = wx.ART_TOOLBAR, size = size)
  91. elif self.type == 'img':
  92. if os.path.isfile(self.imagepath) and os.path.getsize(self.imagepath):
  93. if size and len(size) == 2:
  94. image = wx.Image(name = self.imagepath)
  95. image.Rescale(size[0], size[1])
  96. bmp = image.ConvertToBitmap()
  97. elif self.imagepath:
  98. bmp = wx.Bitmap(name = self.imagepath)
  99. return bmp
  100. def GetLabel(self):
  101. return self.label
  102. def GetDesc(self):
  103. return self.description
  104. def GetImageName(self):
  105. return os.path.basename(self.imagepath)
  106. #
  107. # create list of icon instances
  108. #
  109. Icons = {
  110. # map display
  111. "displaymap" : MetaIcon (img=Icons["displaymap"],
  112. label=_("Display map"),
  113. desc = _("Re-render modified map layers")),
  114. "rendermap" : MetaIcon (img=Icons["rendermap"],
  115. label=_("Re-render map"),
  116. desc=_("Force re-rendering all map layers")),
  117. "erase" : MetaIcon (img=Icons["erase"],
  118. label=_("Erase display")),
  119. "pointer" : MetaIcon (img=Icons["pointer"],
  120. label=_("Pointer")),
  121. "zoom_in" : MetaIcon (img=Icons["zoom_in"],
  122. label=_("Zoom in"),
  123. desc=_("Drag or click mouse to zoom")),
  124. "zoom_out" : MetaIcon (img=Icons["zoom_out"],
  125. label=_("Zoom out"),
  126. desc=_("Drag or click mouse to unzoom")),
  127. "pan" : MetaIcon (img=Icons["pan"],
  128. label=_("Pan"),
  129. desc=_("Drag with mouse to pan")),
  130. "query" : MetaIcon (img=Icons["query"],
  131. label=_("Query raster/vector map(s)"),
  132. desc=_("Query selected raster/vector map(s)")),
  133. "zoom_back" : MetaIcon (img=Icons["zoom_back"],
  134. label=_("Return to previous zoom")),
  135. "zoommenu" : MetaIcon (img=Icons["zoommenu"],
  136. label=_("Zoom options"),
  137. desc=_("Display zoom management")),
  138. "zoom_extent" : MetaIcon (img=Icons["zoom_extent"],
  139. label=_("Zoom to selected map layer(s)")),
  140. "overlay" : MetaIcon (img=Icons["overlay"],
  141. label=_("Add map elements"),
  142. desc=_("Overlay elements like scale and legend onto map")),
  143. "addbarscale": MetaIcon (img=Icons["addbarscale"],
  144. label=_("Add scalebar and north arrow")),
  145. "addlegend" : MetaIcon (img=Icons["addlegend"],
  146. label=_("Add legend")),
  147. "savefile" : MetaIcon (img=Icons["savefile"],
  148. label=_("Save display to graphic file")),
  149. "printmap" : MetaIcon (img=Icons["printmap"],
  150. label=_("Print display")),
  151. # layer manager
  152. "newdisplay" : MetaIcon (img=Icons["newdisplay"],
  153. label=_("Start new map display")),
  154. "workspaceNew" : MetaIcon (img=Icons["fileNew"],
  155. label=_("Create new workspace (Ctrl+N)")),
  156. "workspaceLoad" : MetaIcon (img=Icons["fileLoad"],
  157. label=_("Load map layers into workspace (Ctrl+L)")),
  158. "workspaceOpen" : MetaIcon (img=Icons["fileOpen"],
  159. label=_("Open existing workspace file (Ctrl+O)")),
  160. "workspaceSave" : MetaIcon (img=Icons["fileSave"],
  161. label=_("Save current workspace to file (Ctrl+S)")),
  162. "rastImport" : MetaIcon (img=Icons["fileImport"],
  163. label=_("Import raster data")),
  164. "rastLink" : MetaIcon (img=Icons["fileImport"],
  165. label=_("Link external raster data")),
  166. "vectImport" : MetaIcon (img=Icons["fileImport"],
  167. label=_("Import vector data")),
  168. "vectLink" : MetaIcon (img=Icons["fileImport"],
  169. label=_("Link external vector data")),
  170. "addrast" : MetaIcon (img=Icons["addrast"],
  171. label=_("Add raster map layer (Ctrl+R)")),
  172. "rastmisc" : MetaIcon (img=Icons["rastmisc"],
  173. label=_("Add various raster map layers (RGB, HIS, shaded relief...)")),
  174. "addvect" : MetaIcon (img=Icons["addvect"],
  175. label=_("Add vector map layer (Ctrl+V)")),
  176. "vectmisc" : MetaIcon (img=Icons["vectmisc"],
  177. label=_("Add various vector map layers (thematic, chart...)")),
  178. "addcmd" : MetaIcon (img=Icons["addcmd"],
  179. label=_("Add command layer")),
  180. "addgrp" : MetaIcon (img=Icons["addgrp"],
  181. label=_("Add group")),
  182. "addovl" : MetaIcon (img=Icons["addovl"],
  183. label=_("Add grid or vector labels overlay")),
  184. "delcmd" : MetaIcon (img=Icons["delcmd"],
  185. label=_("Delete selected map layer")),
  186. "quit" : MetaIcon (img=Icons["quit"],
  187. label=_("Quit")),
  188. "attrtable" : MetaIcon (img=Icons["attrtable"],
  189. label=_("Show attribute table")),
  190. "vdigit" : MetaIcon (img=Icons["vdigit"],
  191. label=_("Edit vector maps")),
  192. "addrgb" : MetaIcon (img=Icons["addrgb"],
  193. label=_("Add RGB map layer")),
  194. "addhis" : MetaIcon (img=Icons["addhis"],
  195. label=_("Add HIS map layer")),
  196. "addshaded" : MetaIcon (img=Icons["addshaded"],
  197. label=_("Add shaded relief map layer")),
  198. "addrarrow" : MetaIcon (img=Icons["addrarrow"],
  199. label=_("Add raster flow arrows")),
  200. "addrnum" : MetaIcon (img=Icons["addrnum"],
  201. label=_("Add raster cell numbers")),
  202. "addthematic": MetaIcon (img=Icons["addthematic"],
  203. label=_("Add thematic area (choropleth) map layer")),
  204. "addchart" : MetaIcon (img=Icons["addchart"],
  205. label=_("Add thematic chart layer")),
  206. "addgrid" : MetaIcon (img=Icons["addgrid"],
  207. label=_("Add grid layer")),
  208. "addgeodesic": MetaIcon (img=Icons["addgeodesic"],
  209. label=_("Add geodesic line layer")),
  210. "addrhumb" : MetaIcon (img=Icons["addrhumb"],
  211. label=_("Add rhumbline layer")),
  212. "addlabels" : MetaIcon (img=Icons["addlabels"],
  213. label=_("Add labels")),
  214. "addtext" : MetaIcon (img=Icons["addtext"],
  215. label=_("Add text layer")),
  216. "addrast3d" : MetaIcon (img=Icons["addrast3d"],
  217. label=_("Add 3D raster map layer"),
  218. desc = _("Note that 3D raster data are rendered only in 3D view mode")),
  219. "settings" : MetaIcon (img=Icons["settings"],
  220. label=_("Show GUI settings")),
  221. # digit
  222. "digAddPoint": MetaIcon (img=Icons["digAddPoint"],
  223. label=_("Digitize new point"),
  224. desc=_("Left: new point")),
  225. "digAddLine" : MetaIcon (img=Icons["digAddLine"],
  226. label=_("Digitize new line"),
  227. desc=_("Left: new point; Middle: undo last point; Right: close line")),
  228. "digAddBoundary": MetaIcon (img=Icons["digAddBoundary"],
  229. label=_("Digitize new boundary"),
  230. desc=_("Left: new point; Middle: undo last point; Right: close line")),
  231. "digAddCentroid": MetaIcon (img=Icons["digAddCentroid"],
  232. label=_("Digitize new centroid"),
  233. desc=_("Left: new point")),
  234. "digAddArea": MetaIcon (img=Icons["digAddArea"],
  235. label=_("Digitize new area (composition of bondaries without category and one centroid with category)"),
  236. desc=_("Left: new point")),
  237. "digAddVertex": MetaIcon (img=Icons["digAddVertex"],
  238. label=_("Add new vertex"),
  239. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  240. "digCopyCats": MetaIcon (img=Icons["digCopyCats"],
  241. label=_("Copy categories"),
  242. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  243. "digDeleteLine": MetaIcon (img=Icons["digDeleteLine"],
  244. label=_("Delete feature(s)"),
  245. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  246. "digDispAttr": MetaIcon (img=Icons["digDispAttr"],
  247. label=_("Display/update attributes"),
  248. desc=_("Left: Select")),
  249. "digDispCats": MetaIcon (img=Icons["digDispCats"],
  250. label=_("Display/update categories"),
  251. desc=_("Left: Select")),
  252. "digEditLine": MetaIcon (img=Icons["digEditLine"],
  253. label=_("Edit line/boundary"),
  254. desc=_("Left: new point; Middle: undo last point; Right: close line")),
  255. "digMoveLine": MetaIcon (img=Icons["digMoveLine"],
  256. label=_("Move feature(s)"),
  257. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  258. "digMoveVertex": MetaIcon (img=Icons["digMoveVertex"],
  259. label=_("Move vertex"),
  260. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  261. "digRemoveVertex": MetaIcon (img=Icons["digRemoveVertex"],
  262. label=_("Remove vertex"),
  263. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  264. "digSettings": MetaIcon (img=Icons["settings"],
  265. label=_("Settings"),
  266. desc=_("Settings dialog for digitization tool")),
  267. "digSplitLine": MetaIcon (img=Icons["digSplitLine"],
  268. label=_("Split line/boundary"),
  269. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  270. "digExit" : MetaIcon (img=Icons["quit"],
  271. label=_("Quit digitizing tool")),
  272. "digAdditionalTools" : MetaIcon (img=Icons["digAdditionalTools"],
  273. label=_("Additional tools " \
  274. "(copy, flip, connect, etc.)"),
  275. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  276. "digUndo" : MetaIcon (img=Icons["digUndo"],
  277. label=_("Undo"),
  278. desc=_("Undo previous changes")),
  279. # analyze raster
  280. "analyze" : MetaIcon (img=Icons["analyze"],
  281. label=_("Analyze map")),
  282. "measure" : MetaIcon (img=Icons["measure"],
  283. label=_("Measure distance")),
  284. "transect" : MetaIcon (img=Icons["transect"],
  285. label=_("Draw transect in map display window to profile")),
  286. "profile" : MetaIcon (img=Icons["profile"],
  287. label=_("Profile surface map")),
  288. "profiledraw": MetaIcon (img=Icons["profiledraw"],
  289. label=_("Draw/re-draw profile")),
  290. "profileopt" : MetaIcon (img=Icons["settings"],
  291. label=_("Profile options")),
  292. "datasave" : MetaIcon (img=Icons["fileSave"],
  293. label=_("Save profile data to csv file")),
  294. "histogram" : MetaIcon (img=Icons["histogram"],
  295. label=_("Create histogram of image or raster file")),
  296. "font" : MetaIcon (img=Icons["font"],
  297. label=_("Select font")),
  298. "color" : MetaIcon (img=Icons["color"],
  299. label=_("Select color")),
  300. "layeropts" : MetaIcon (img=Icons["layeropts"],
  301. label=_("Set options")),
  302. "analyze" : MetaIcon (img=Icons["analyze"],
  303. label=_("Analyze")),
  304. # georectify
  305. 'grGcpSet' : MetaIcon (img=Icons["grGcpSet"],
  306. label=_("Set GCP"),
  307. desc=_("Define GCP (Ground Control Points)")),
  308. 'grGeorect' : MetaIcon (img=Icons["grGeorect"],
  309. label=_("Georectify")),
  310. 'grGcpRms' : MetaIcon (img=Icons["grGcpRms"],
  311. label=_("Recalculate RMS error")),
  312. 'grGcpSave' : MetaIcon (img=Icons["grGcpSave"],
  313. label=_("Save GCPs to POINTS file")),
  314. 'grGcpAdd' : MetaIcon (img=Icons["grGcpAdd"],
  315. label=_("Add new GCP")),
  316. 'grGcpDelete' : MetaIcon (img=Icons["grGcpDelete"],
  317. label=_("Delete selected GCP")),
  318. 'grGcpClear' : MetaIcon (img=Icons["grGcpClear"],
  319. label=_("Clear selected GCP")),
  320. 'grGcpReload' : MetaIcon (img=Icons["grGcpReload"],
  321. label=_("Reload GCPs from POINTS file")),
  322. 'grGcpQuit' : MetaIcon (img=Icons["quit"],
  323. label=_("Quit georectification module")),
  324. "grSettings": MetaIcon (img=Icons["settings"],
  325. label=_("Settings"),
  326. desc=_("Settings dialog for georectification tool")),
  327. "grHelp": MetaIcon (img=Icons["help"],
  328. label=_('Show help'),
  329. desc = _('Display GCP Manager manual page')),
  330. # nviz
  331. "nvizView": MetaIcon (img=Icons["nvizView"],
  332. label=_("Switch to view control page"),
  333. desc=_("Change view settings")),
  334. "nvizSurface": MetaIcon (img=Icons["nvizSurface"],
  335. label=_("Switch to surface (raster) control page"),
  336. desc=_("Change surface (loaded raster maps) settings")),
  337. "nvizVector": MetaIcon (img=Icons["nvizVector"],
  338. label=_("Switch to vector (2D/3D) control page"),
  339. desc=_("Change 2D/3D vector settings")),
  340. "nvizVolume": MetaIcon (img=Icons["nvizVolume"],
  341. label=_("Switch to volume (3D raster) control page"),
  342. desc=_("Change volume (loaded 3D raster maps) settings")),
  343. "nvizLight": MetaIcon (img=Icons["nvizLight"],
  344. label=_("Switch to lighting control page"),
  345. desc=_("Change lighting settings")),
  346. "nvizFringe": MetaIcon (img=Icons["nvizFringe"],
  347. label=_("Switch to fringe control page"),
  348. desc=_("Switch on/off fringes")),
  349. "nvizSettings": MetaIcon (img=Icons["settings"],
  350. label=_("3D view mode tools"),
  351. desc=_("Show/hide 3D view mode settings dialog")),
  352. "nvizHelp" : MetaIcon (img=Icons["help"],
  353. label=_("Show help"),
  354. desc = _("Display 3D view mode manual page")),
  355. "nvizQuit": MetaIcon (img=Icons["quit"],
  356. label=_("Quit 3D view mode"),
  357. desc=_("Switch back to 2D view mode")),
  358. # modeler
  359. "modeler" : MetaIcon (img=Icons["modeler"],
  360. label=_("Start Graphical Modeler")),
  361. "modelNew" : MetaIcon (img=Icons["fileNew"],
  362. label=_("Create new model (Ctrl+N)")),
  363. "modelOpen" : MetaIcon (img=Icons["fileOpen"],
  364. label=_("Load model from file (Ctrl+O)")),
  365. "modelSave" : MetaIcon (img=Icons["fileSave"],
  366. label=_("Save current model to file (Ctrl+S)")),
  367. "modelToImage" : MetaIcon (img=Icons["imageSave"],
  368. label=_("Export model to image")),
  369. "modelToPython" : MetaIcon (img=Icons["pythonSave"],
  370. label=_("Export model to Python script")),
  371. "modelActionAdd" : MetaIcon (img=Icons["modelActionAdd"],
  372. label=_("Add action (GRASS module) to model")),
  373. "modelDataAdd" : MetaIcon (img=Icons["modelDataAdd"],
  374. label=_("Add data item to model")),
  375. "modelRelation" : MetaIcon (img=Icons["modelRelation"],
  376. label=_("Define relation between data and action items")),
  377. "modelRun" : MetaIcon (img=Icons["modelRun"],
  378. label=_("Run model")),
  379. "modelValidate" : MetaIcon (img=Icons["modelValidate"],
  380. label=_("Validate model")),
  381. "modelSettings" : MetaIcon (img=Icons["settings"],
  382. label=_("Show modeler settings")),
  383. "modelProperties" : MetaIcon (img=Icons["modelProperties"],
  384. label=_("Show model properties")),
  385. "modelVariables" : MetaIcon (img=Icons["modelVariables"],
  386. label=_("Manage model variables")),
  387. "modelRedraw" : MetaIcon (img=Icons["redraw"],
  388. label=_("Redraw model canvas")),
  389. "modelHelp" : MetaIcon (img=Icons["help"],
  390. label=_("Show help"),
  391. desc = _("Display Graphical Modeler manual page")),
  392. # ps.map
  393. "psScript" : MetaIcon (img=Icons["psScript"],
  394. label=_("Generate instruction file")),
  395. "psExport" : MetaIcon (img=Icons["psExport"],
  396. label=_("Generate PostScript output")),
  397. }
  398. # testing ...
  399. if __name__ == "__main__":
  400. for k, v in Icons.iteritems():
  401. print v.GetImageName()