File: toolbars.py

package info (click to toggle)
grass 8.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 277,040 kB
  • sloc: ansic: 460,798; python: 227,732; cpp: 42,026; sh: 11,262; makefile: 7,007; xml: 3,637; sql: 968; lex: 520; javascript: 484; yacc: 450; asm: 387; perl: 157; sed: 25; objc: 6; ruby: 4
file content (151 lines) | stat: -rw-r--r-- 4,378 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
"""
@package example.toolbars

@brief Example toolbars and icons.

Classes:
 - toolbars::ExampleMapToolbar
 - toolbars::ExampleMainToolbar
 - toolbars::ExampleMiscToolbar

(C) 2011-2014 by the GRASS Development Team
This program is free software under the GNU General Public
License (>=v2). Read the file COPYING that comes with GRASS
for details.

@author Anna Petrasova <kratochanna gmail.com>
"""

import wx

from gui_core.toolbars import BaseToolbar, BaseIcons


class ExampleMapToolbar(BaseToolbar):
    """!Map toolbar (to control map zoom and rendering)"""

    def __init__(self, parent, toolSwitcher):
        """!Map toolbar constructor"""
        BaseToolbar.__init__(self, parent, toolSwitcher)

        self.InitToolbar(self._toolbarData())

        # realize the toolbar
        self.Realize()

        self._default = self.pan

        for tool in (self.pan, self.zoomIn, self.zoomOut):
            self.toolSwitcher.AddToolToGroup(group="mouseUse", toolbar=self, tool=tool)

        self.EnableTool(self.zoomBack, False)

    def _toolbarData(self):
        """!Returns toolbar data (name, icon, handler)"""
        # BaseIcons are a set of often used icons. It is possible
        # to reuse icons in gui/icons/grass or add new ones there.
        icons = BaseIcons
        return self._getToolbarData(
            (
                (
                    ("displaymap", icons["display"].label),
                    icons["display"],
                    self.parent.OnDraw,
                ),
                (
                    ("rendermap", icons["render"].label),
                    icons["render"],
                    self.parent.OnRender,
                ),
                (
                    ("erase", icons["erase"].label),
                    icons["erase"],
                    self.parent.OnErase,
                ),
                (None,),  # creates separator
                (
                    ("pan", icons["pan"].label),
                    icons["pan"],
                    self.parent.OnPan,
                    wx.ITEM_CHECK,
                ),  # toggle tool
                (
                    ("zoomIn", icons["zoomIn"].label),
                    icons["zoomIn"],
                    self.parent.OnZoomIn,
                    wx.ITEM_CHECK,
                ),
                (
                    ("zoomOut", icons["zoomOut"].label),
                    icons["zoomOut"],
                    self.parent.OnZoomOut,
                    wx.ITEM_CHECK,
                ),
                (None,),
                (
                    ("zoomBack", icons["zoomBack"].label),
                    icons["zoomBack"],
                    self.parent.OnZoomBack,
                ),
                (
                    ("zoomToMap", icons["zoomExtent"].label),
                    icons["zoomExtent"],
                    self.parent.OnZoomToMap,
                ),
            )
        )


class ExampleMainToolbar(BaseToolbar):
    """!Toolbar with tools related to application functionality"""

    def __init__(self, parent):
        """!Toolbar constructor"""
        BaseToolbar.__init__(self, parent)

        self.InitToolbar(self._toolbarData())

        # realize the toolbar
        self.Realize()

    def _toolbarData(self):
        """!Toolbar data"""
        return self._getToolbarData(
            (
                (
                    ("addRaster", BaseIcons["addRast"].label),
                    BaseIcons["addRast"],
                    self.parent.OnSelectRaster,
                ),
            )
        )


class ExampleMiscToolbar(BaseToolbar):
    """!Toolbar with miscellaneous tools related to app"""

    def __init__(self, parent):
        """!Toolbar constructor"""
        BaseToolbar.__init__(self, parent)

        self.InitToolbar(self._toolbarData())
        # realize the toolbar
        self.Realize()

    def _toolbarData(self):
        """!Toolbar data"""
        icons = BaseIcons
        return self._getToolbarData(
            (
                (
                    ("help", icons["help"].label),
                    icons["help"],
                    self.parent.OnHelp,
                ),
                (
                    ("quit", icons["quit"].label),
                    icons["quit"],
                    self.parent.OnCloseWindow,
                ),
            )
        )