icon.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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 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 overlay"),
  142. desc=_("Add graphic overlays to 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 PNG file")),
  149. "printmap" : MetaIcon (img=Icons["printmap"],
  150. label=_("Print display")),
  151. # gis manager
  152. "newdisplay" : MetaIcon (img=Icons["newdisplay"],
  153. label=_("Start new display")),
  154. "workspaceNew" : MetaIcon (img=Icons["workspaceNew"],
  155. label=_("Create new workspace file")),
  156. "workspaceLoad" : MetaIcon (img=Icons["workspaceLoad"],
  157. label=_("Load map layers into workspace")),
  158. "workspaceOpen" : MetaIcon (img=Icons["workspaceOpen"],
  159. label=_("Open existing workspace file")),
  160. "workspaceSave" : MetaIcon (img=Icons["workspaceSave"],
  161. label=_("Save current workspace to file")),
  162. # TODO: "layer" is not conformant with GRASS vocabulary (vector layer: 1..x) !
  163. "addrast" : MetaIcon (img=Icons["addrast"],
  164. label=_("Add raster map layer")),
  165. "addvect" : MetaIcon (img=Icons["addvect"],
  166. label=_("Add vector map layer")),
  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 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. # digit
  206. "digAddPoint": MetaIcon (img=Icons["digAddPoint"],
  207. label=_("Digitize new point"),
  208. desc=_("Left: new point")),
  209. "digAddLine" : MetaIcon (img=Icons["digAddLine"],
  210. label=_("Digitize new line"),
  211. desc=_("Left: new point; Middle: undo last point; Right: close line")),
  212. "digAddBoundary": MetaIcon (img=Icons["digAddBoundary"],
  213. label=_("Digitize new boundary"),
  214. desc=_("Left: new point; Middle: undo last point; Right: close line")),
  215. "digAddCentroid": MetaIcon (img=Icons["digAddCentroid"],
  216. label=_("Digitize new centroid"),
  217. desc=_("Left: new point")),
  218. "digAddVertex": MetaIcon (img=Icons["digAddVertex"],
  219. label=_("Add new vertex"),
  220. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  221. "digCopyCats": MetaIcon (img=Icons["digCopyCats"],
  222. label=_("Copy categories"),
  223. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  224. "digDeleteLine": MetaIcon (img=Icons["digDeleteLine"],
  225. label=_("Delete feature(s)"),
  226. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  227. "digDispAttr": MetaIcon (img=Icons["digDispAttr"],
  228. label=_("Display/update attributes"),
  229. desc=_("Left: Select")),
  230. "digDispCats": MetaIcon (img=Icons["digDispCats"],
  231. label=_("Display/update categories"),
  232. desc=_("Left: Select")),
  233. "digEditLine": MetaIcon (img=Icons["digEditLine"],
  234. label=_("Edit line/boundary"),
  235. desc=_("Left: new point; Middle: undo last point; Right: close line")),
  236. "digMoveLine": MetaIcon (img=Icons["digMoveLine"],
  237. label=_("Move feature(s)"),
  238. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  239. "digMoveVertex": MetaIcon (img=Icons["digMoveVertex"],
  240. label=_("Move vertex"),
  241. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  242. "digRemoveVertex": MetaIcon (img=Icons["digRemoveVertex"],
  243. label=_("Remove vertex"),
  244. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  245. "digSettings": MetaIcon (img=Icons["digSettings"],
  246. label=_("Settings"),
  247. desc=_("Settings dialog for digitization tool")),
  248. "digSplitLine": MetaIcon (img=Icons["digSplitLine"],
  249. label=_("Split line/boundary"),
  250. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  251. "digExit" : MetaIcon (img=Icons["quit"],
  252. label=_("Quit digitizing tool")),
  253. "digAdditionalTools" : MetaIcon (img=Icons["digAdditionalTools"],
  254. label=_("Additional tools " \
  255. "(copy, flip, connect, etc.)"),
  256. desc=_("Left: Select; Middle: Unselect; Right: Confirm")),
  257. "digUndo" : MetaIcon (img=Icons["digUndo"],
  258. label=_("Undo"),
  259. desc=_("Undo previous changes")),
  260. # analyze raster
  261. "analyze" : MetaIcon (img=Icons["analyze"],
  262. label=_("Analyze map")),
  263. "measure" : MetaIcon (img=Icons["measure"],
  264. label=_("Measure distance")),
  265. "transect" : MetaIcon (img=Icons["transect"],
  266. label=_("Draw transect in map display window to profile")),
  267. "profile" : MetaIcon (img=Icons["profile"],
  268. label=_("Profile surface map")),
  269. "profiledraw": MetaIcon (img=Icons["profiledraw"],
  270. label=_("Draw/re-draw profile")),
  271. "profileopt" : MetaIcon (img=Icons["profileopt"],
  272. label=_("Profile options")),
  273. "histogram" : MetaIcon (img=Icons["histogram"],
  274. label=_("Create histogram of image or raster file")),
  275. "font" : MetaIcon (img=Icons["font"],
  276. label=_("Select font")),
  277. "color" : MetaIcon (img=Icons["color"],
  278. label=_("Select color")),
  279. "layeropts" : MetaIcon (img=Icons["layeropts"],
  280. label=_("Set options")),
  281. "analyze" : MetaIcon (img=Icons["analyze"],
  282. label=_("Analyze")),
  283. # georectify
  284. 'grGcpSet' : MetaIcon (img=Icons["grGcpSet"],
  285. label=_("Set GCP"),
  286. desc=_("Define GCP (Ground Control Points)")),
  287. 'grGeorect' : MetaIcon (img=Icons["grGeorect"],
  288. label=_("Georectify")),
  289. 'grGcpRms' : MetaIcon (img=Icons["grGcpRms"],
  290. label=_("Recalculate RMS error")),
  291. 'grGcpRefresh' : MetaIcon (img=Icons["grGcpRefresh"],
  292. label=_("Redraw GCP markers in map displays")),
  293. 'grGcpSave' : MetaIcon (img=Icons["grGcpSave"],
  294. label=_("Save GCPs to POINTS file")),
  295. 'grGcpAdd' : MetaIcon (img=Icons["grGcpAdd"],
  296. label=_("Add new GCP")),
  297. 'grGcpDelete' : MetaIcon (img=Icons["grGcpDelete"],
  298. label=_("Delete selected GCP")),
  299. 'grGcpClear' : MetaIcon (img=Icons["grGcpClear"],
  300. label=_("Clear selected GCP")),
  301. 'grGcpReload' : MetaIcon (img=Icons["grGcpReload"],
  302. label=_("Reload GCPs from selected POINTS file")),
  303. 'grGcpQuit' : MetaIcon (img=Icons["quit"],
  304. label=_("Quit georectification module")),
  305. "grSettings": MetaIcon (img=Icons["grSettings"],
  306. label=_("Settings"),
  307. desc=_("Settings dialog for georectification tool")),
  308. # nviz
  309. "nvizSettings": MetaIcon (img=Icons["nvizSettings"],
  310. label=_("Settings"),
  311. desc=_("Show Nviz settings dialog")),
  312. }
  313. # testing ...
  314. if __name__ == "__main__":
  315. for k, v in Icons.iteritems():
  316. print v.GetImageName()