icon.py 17 KB

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