icon.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. "rendermap" : MetaIcon (img=Icons["rendermap"],
  117. label=_("Re-render map"),
  118. desc=_("Force re-rendering of all layers")),
  119. "erase" : MetaIcon (img=Icons["erase"],
  120. label=_("Erase display")),
  121. "pointer" : MetaIcon (img=Icons["pointer"],
  122. label=_("Pointer")),
  123. "zoom_in" : MetaIcon (img=Icons["zoom_in"],
  124. label=_("Zoom in"),
  125. desc=_("Drag or click mouse to zoom")),
  126. "zoom_out" : MetaIcon (img=Icons["zoom_out"],
  127. label=_("Zoom out"),
  128. desc=_("Drag or click mouse to unzoom")),
  129. "pan" : MetaIcon (img=Icons["pan"],
  130. label=_("Pan"),
  131. desc=_("Drag with mouse to pan")),
  132. "query" : MetaIcon (img=Icons["query"],
  133. label=_("Query raster/vector map(s)"),
  134. desc=_("Query selected raster/vector map(s)")),
  135. "zoom_back" : MetaIcon (img=Icons["zoom_back"],
  136. label=_("Return to previous zoom")),
  137. "zoommenu" : MetaIcon (img=Icons["zoommenu"],
  138. label=_("Zoom options"),
  139. desc=_("Display zoom management")),
  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 display")),
  154. "workspaceNew" : MetaIcon (img=Icons["fileNew"],
  155. label=_("Create new workspace file (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. "addrast" : MetaIcon (img=Icons["addrast"],
  163. label=_("Add raster map layer (Ctrl+R)")),
  164. "addvect" : MetaIcon (img=Icons["addvect"],
  165. label=_("Add vector map layer (Ctrl+V)")),
  166. "addcmd" : MetaIcon (img=Icons["addcmd"],
  167. label=_("Add command layer")),
  168. "addgrp" : MetaIcon (img=Icons["addgrp"],
  169. label=_("Add layer group")),
  170. "addovl" : MetaIcon (img=Icons["addovl"],
  171. label=_("Add grid or vector labels overlay")),
  172. "delcmd" : MetaIcon (img=Icons["delcmd"],
  173. label=_("Delete selected layer")),
  174. "quit" : MetaIcon (img=Icons["quit"],
  175. label=_("Quit")),
  176. "attrtable" : MetaIcon (img=Icons["attrtable"],
  177. label=_("Show attribute table")),
  178. "addrgb" : MetaIcon (img=Icons["addrgb"],
  179. label=_("Add RGB layer")),
  180. "addhis" : MetaIcon (img=Icons["addhis"],
  181. label=_("Add HIS layer")),
  182. "addshaded" : MetaIcon (img=Icons["addshaded"],
  183. label=_("Add shaded relief map layer")),
  184. "addrarrow" : MetaIcon (img=Icons["addrarrow"],
  185. label=_("Add raster flow arrows")),
  186. "addrnum" : MetaIcon (img=Icons["addrnum"],
  187. label=_("Add raster cell numbers")),
  188. "addthematic": MetaIcon (img=Icons["addthematic"],
  189. label=_("Add thematic area (choropleth) map layer")),
  190. "addchart" : MetaIcon (img=Icons["addchart"],
  191. label=_("Add thematic chart layer")),
  192. "addgrid" : MetaIcon (img=Icons["addgrid"],
  193. label=_("Add grid layer")),
  194. "addgeodesic": MetaIcon (img=Icons["addgeodesic"],
  195. label=_("Add geodesic line layer")),
  196. "addrhumb" : MetaIcon (img=Icons["addrhumb"],
  197. label=_("Add rhumbline layer")),
  198. "addlabels" : MetaIcon (img=Icons["addlabels"],
  199. label=_("Add labels")),
  200. "addtext" : MetaIcon (img=Icons["addtext"],
  201. label=_("Add text layer")),
  202. "addrast3d" : MetaIcon (img=Icons["addrast3d"],
  203. label=_("Add 3D raster map")),
  204. # digit
  205. "digAddPoint": MetaIcon (img=Icons["digAddPoint"],
  206. label=_("Digitize new point"),
  207. desc=_("Left: new point")),
  208. "digAddLine" : MetaIcon (img=Icons["digAddLine"],
  209. label=_("Digitize new line"),
  210. desc=_("Left: new point; Middle: undo last point; Right: close line")),
  211. "digAddBoundary": MetaIcon (img=Icons["digAddBoundary"],
  212. label=_("Digitize new boundary"),
  213. desc=_("Left: new point; Middle: undo last point; Right: close line")),
  214. "digAddCentroid": MetaIcon (img=Icons["digAddCentroid"],
  215. label=_("Digitize new centroid"),
  216. desc=_("Left: new point")),
  217. "digAddVertex": MetaIcon (img=Icons["digAddVertex"],
  218. label=_("Add new vertex"),
  219. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  220. "digCopyCats": MetaIcon (img=Icons["digCopyCats"],
  221. label=_("Copy categories"),
  222. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  223. "digDeleteLine": MetaIcon (img=Icons["digDeleteLine"],
  224. label=_("Delete feature(s)"),
  225. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  226. "digDispAttr": MetaIcon (img=Icons["digDispAttr"],
  227. label=_("Display/update attributes"),
  228. desc=_("Left: Select")),
  229. "digDispCats": MetaIcon (img=Icons["digDispCats"],
  230. label=_("Display/update categories"),
  231. desc=_("Left: Select")),
  232. "digEditLine": MetaIcon (img=Icons["digEditLine"],
  233. label=_("Edit line/boundary"),
  234. desc=_("Left: new point; Middle: undo last point; Right: close line")),
  235. "digMoveLine": MetaIcon (img=Icons["digMoveLine"],
  236. label=_("Move feature(s)"),
  237. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  238. "digMoveVertex": MetaIcon (img=Icons["digMoveVertex"],
  239. label=_("Move vertex"),
  240. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  241. "digRemoveVertex": MetaIcon (img=Icons["digRemoveVertex"],
  242. label=_("Remove vertex"),
  243. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  244. "digSettings": MetaIcon (img=Icons["digSettings"],
  245. label=_("Settings"),
  246. desc=_("Settings dialog for digitization tool")),
  247. "digSplitLine": MetaIcon (img=Icons["digSplitLine"],
  248. label=_("Split line/boundary"),
  249. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  250. "digExit" : MetaIcon (img=Icons["quit"],
  251. label=_("Quit digitizing tool")),
  252. "digAdditionalTools" : MetaIcon (img=Icons["digAdditionalTools"],
  253. label=_("Additional tools " \
  254. "(copy, flip, connect, etc.)"),
  255. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  256. "digUndo" : MetaIcon (img=Icons["digUndo"],
  257. label=_("Undo"),
  258. desc=_("Undo previous changes")),
  259. # analyze raster
  260. "analyze" : MetaIcon (img=Icons["analyze"],
  261. label=_("Analyze map")),
  262. "measure" : MetaIcon (img=Icons["measure"],
  263. label=_("Measure distance")),
  264. "transect" : MetaIcon (img=Icons["transect"],
  265. label=_("Draw transect in map display window to profile")),
  266. "profile" : MetaIcon (img=Icons["profile"],
  267. label=_("Profile surface map")),
  268. "profiledraw": MetaIcon (img=Icons["profiledraw"],
  269. label=_("Draw/re-draw profile")),
  270. "profileopt" : MetaIcon (img=Icons["profileopt"],
  271. label=_("Profile options")),
  272. "datasave" : MetaIcon (img=Icons["datasave"],
  273. label=_("Save profile data to csv file")),
  274. "histogram" : MetaIcon (img=Icons["histogram"],
  275. label=_("Create histogram of image or raster file")),
  276. "font" : MetaIcon (img=Icons["font"],
  277. label=_("Select font")),
  278. "color" : MetaIcon (img=Icons["color"],
  279. label=_("Select color")),
  280. "layeropts" : MetaIcon (img=Icons["layeropts"],
  281. label=_("Set options")),
  282. "analyze" : MetaIcon (img=Icons["analyze"],
  283. label=_("Analyze")),
  284. # georectify
  285. 'grGcpSet' : MetaIcon (img=Icons["grGcpSet"],
  286. label=_("Set GCP"),
  287. desc=_("Define GCP (Ground Control Points)")),
  288. 'grGeorect' : MetaIcon (img=Icons["grGeorect"],
  289. label=_("Georectify")),
  290. 'grGcpRms' : MetaIcon (img=Icons["grGcpRms"],
  291. label=_("Recalculate RMS error")),
  292. 'grGcpRefresh' : MetaIcon (img=Icons["grGcpRefresh"],
  293. label=_("Redraw GCP markers in map displays")),
  294. 'grGcpSave' : MetaIcon (img=Icons["grGcpSave"],
  295. label=_("Save GCPs to POINTS file")),
  296. 'grGcpAdd' : MetaIcon (img=Icons["grGcpAdd"],
  297. label=_("Add new GCP")),
  298. 'grGcpDelete' : MetaIcon (img=Icons["grGcpDelete"],
  299. label=_("Delete selected GCP")),
  300. 'grGcpClear' : MetaIcon (img=Icons["grGcpClear"],
  301. label=_("Clear selected GCP")),
  302. 'grGcpReload' : MetaIcon (img=Icons["grGcpReload"],
  303. label=_("Reload GCPs from selected POINTS file")),
  304. 'grGcpQuit' : MetaIcon (img=Icons["quit"],
  305. label=_("Quit georectification module")),
  306. "grSettings": MetaIcon (img=Icons["grSettings"],
  307. label=_("Settings"),
  308. desc=_("Settings dialog for georectification tool")),
  309. # nviz
  310. "nvizSettings": MetaIcon (img=Icons["nvizSettings"],
  311. label=_("Settings"),
  312. desc=_("Show Nviz settings dialog")),
  313. # modeler
  314. "modelNew" : MetaIcon (img=Icons["fileNew"],
  315. label=_("Create new model (Ctrl+N)")),
  316. "modelOpen" : MetaIcon (img=Icons["fileOpen"],
  317. label=_("Load model from file (Ctrl+O)")),
  318. "modelSave" : MetaIcon (img=Icons["fileSave"],
  319. label=_("Save current model to file (Ctrl+S)")),
  320. "modelActionAdd" : MetaIcon (img=Icons["modelActionAdd"],
  321. label=_("Add action (GRASS module) to model")),
  322. }
  323. # testing ...
  324. if __name__ == "__main__":
  325. for k, v in Icons.iteritems():
  326. print v.GetImageName()