Skip to content

Commit

Permalink
wxGUI: refactoring: build GUI tools' status bars based on wx.StatusBa…
Browse files Browse the repository at this point in the history
…r widget (OSGeo#1689)

Builds status bars based on wx.StatusBar for SwipeMapFrame, IClassMapFrame, Image2Target Frame, Photo2Image Frame, and GCP manager MapFrame.
Some general methods related to a status bar and toolbars moved to gui_core class MapFrameBase.
  • Loading branch information
lindakarlovska authored and ninsbl committed Feb 17, 2023
1 parent ecccca5 commit 606a12b
Show file tree
Hide file tree
Showing 7 changed files with 429 additions and 442 deletions.
117 changes: 55 additions & 62 deletions gui/wxpython/gcp/mapdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,9 @@ def __init__(
self._mgr.SetDockSizeConstraint(0.5, 0.5)

#
# Add statusbar
# Create statusbar
#

# items for choice
self.statusbarItems = [
statusbarItems = [
sb.SbCoordinates,
sb.SbRegionExtent,
sb.SbCompRegionExtent,
Expand All @@ -113,23 +111,7 @@ def __init__(
sbgcp.SbGoToGCP,
sbgcp.SbRMSError,
]

# create statusbar and its manager
statusbar = self.CreateStatusBar(number=4, style=0)
statusbar.SetStatusWidths([-5, -2, -1, -1])
self.statusbarManager = sb.SbManager(mapframe=self, statusbar=statusbar)

# fill statusbar manager
self.statusbarManager.AddStatusbarItemsByClass(
self.statusbarItems, mapframe=self, statusbar=statusbar
)
self.statusbarManager.AddStatusbarItem(
sb.SbMask(self, statusbar=statusbar, position=2)
)
self.statusbarManager.AddStatusbarItem(
sb.SbRender(self, statusbar=statusbar, position=3)
)

self.statusbar = self.CreateStatusbar(statusbarItems)
self.statusbarManager.SetMode(8) # goto GCP

#
Expand Down Expand Up @@ -190,44 +172,7 @@ def __init__(
# self.SrcMapWindow.SetSize((300, 300))
# self.TgtMapWindow.SetSize((300, 300))
self.list.SetSize((100, 150))
self._mgr.AddPane(
self.list,
wx.aui.AuiPaneInfo()
.Name("gcplist")
.Caption(_("GCP List"))
.LeftDockable(False)
.RightDockable(False)
.PinButton()
.FloatingSize((600, 200))
.CloseButton(False)
.DestroyOnClose(True)
.Top()
.Layer(1)
.MinSize((200, 100)),
)
self._mgr.AddPane(
self.SrcMapWindow,
wx.aui.AuiPaneInfo()
.Name("source")
.Caption(_("Source Display"))
.Dockable(False)
.CloseButton(False)
.DestroyOnClose(True)
.Floatable(False)
.Centre(),
)
self._mgr.AddPane(
self.TgtMapWindow,
wx.aui.AuiPaneInfo()
.Name("target")
.Caption(_("Target Display"))
.Dockable(False)
.CloseButton(False)
.DestroyOnClose(True)
.Floatable(False)
.Right()
.Layer(0),
)
self._addPanes()

srcwidth, srcheight = self.SrcMapWindow.GetSize()
tgtwidth, tgtheight = self.TgtMapWindow.GetSize()
Expand Down Expand Up @@ -297,7 +242,10 @@ def AddToolbar(self, name):
"""
# default toolbar
if name == "map":
self.toolbars["map"] = MapToolbar(self, self._toolSwitcher, self._giface)
if "map" not in self.toolbars:
self.toolbars["map"] = MapToolbar(
self, self._toolSwitcher, self._giface
)

self._mgr.AddPane(
self.toolbars["map"],
Expand All @@ -317,7 +265,8 @@ def AddToolbar(self, name):

# GCP display
elif name == "gcpdisp":
self.toolbars["gcpdisp"] = GCPDisplayToolbar(self, self._toolSwitcher)
if "gcpdisp" not in self.toolbars:
self.toolbars["gcpdisp"] = GCPDisplayToolbar(self, self._toolSwitcher)

self._mgr.AddPane(
self.toolbars["gcpdisp"],
Expand All @@ -337,7 +286,8 @@ def AddToolbar(self, name):
if not self.show_target:
self.toolbars["gcpdisp"].Enable("zoommenu", enable=False)

self.toolbars["gcpman"] = GCPManToolbar(self)
if "gcpman" not in self.toolbars:
self.toolbars["gcpman"] = GCPManToolbar(self)

self._mgr.AddPane(
self.toolbars["gcpman"],
Expand All @@ -357,6 +307,49 @@ def AddToolbar(self, name):

self._mgr.Update()

def _addPanes(self):
"""Add mapwindows, toolbars and statusbar to aui manager"""
self._mgr.AddPane(
self.list,
wx.aui.AuiPaneInfo()
.Name("gcplist")
.Caption(_("GCP List"))
.LeftDockable(False)
.RightDockable(False)
.PinButton()
.FloatingSize((600, 200))
.CloseButton(False)
.DestroyOnClose(True)
.Top()
.Layer(1)
.MinSize((200, 100)),
)
self._mgr.AddPane(
self.SrcMapWindow,
wx.aui.AuiPaneInfo()
.Name("source")
.Caption(_("Source Display"))
.Dockable(False)
.CloseButton(False)
.DestroyOnClose(True)
.Floatable(False)
.Centre(),
)
self._mgr.AddPane(
self.TgtMapWindow,
wx.aui.AuiPaneInfo()
.Name("target")
.Caption(_("Target Display"))
.Dockable(False)
.CloseButton(False)
.DestroyOnClose(True)
.Floatable(False)
.Right()
.Layer(0),
)
# statusbar
self.AddStatusbarPane()

def OnUpdateProgress(self, event):
"""
Update progress bar info
Expand Down
96 changes: 95 additions & 1 deletion gui/wxpython/gui_core/mapdisp.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from core.debug import Debug
from gui_core.toolbars import ToolSwitcher
from gui_core.wrap import NewId
from mapdisp import statusbar as sb

from grass.script import core as grass

Expand Down Expand Up @@ -169,7 +170,7 @@ def OnSize(self, event):

def OnFullScreen(self, event):
"""!Switch fullscreen mode, hides also toolbars"""
for toolbar in self.toolbars.keys():
for toolbar in self.toolbars:
self._mgr.GetPane(self.toolbars[toolbar]).Show(self.IsFullScreen())
self._mgr.Update()
self.ShowFullScreen(not self.IsFullScreen())
Expand Down Expand Up @@ -339,6 +340,58 @@ def CoordinatesChanged(self):
if self.statusbarManager.GetMode() == 0:
self.statusbarManager.ShowItem("coordinates")

def CreateStatusbar(self, statusbarItems):
"""Create statusbar (default items)."""
# create statusbar and its manager
statusbar = wx.StatusBar(self, id=wx.ID_ANY)
statusbar.SetMinHeight(24)
statusbar.SetFieldsCount(4)
statusbar.SetStatusWidths([-5, -2, -1, -1])
self.statusbarManager = sb.SbManager(mapframe=self, statusbar=statusbar)

# fill statusbar manager
self.statusbarManager.AddStatusbarItemsByClass(
statusbarItems, mapframe=self, statusbar=statusbar
)
self.statusbarManager.AddStatusbarItem(
sb.SbMask(self, statusbar=statusbar, position=2)
)
self.statusbarManager.AddStatusbarItem(
sb.SbRender(self, statusbar=statusbar, position=3)
)
self.statusbarManager.Update()
return statusbar

def AddStatusbarPane(self):
"""Add statusbar as a pane"""
self._mgr.AddPane(
self.statusbar,
wx.aui.AuiPaneInfo()
.Bottom()
.MinSize(30, 30)
.Fixed()
.Name("statusbar")
.CloseButton(False)
.DestroyOnClose(True)
.ToolbarPane()
.Dockable(False)
.PaneBorder(False)
.Gripper(False),
)

def SetStatusText(self, *args):
"""Overide wx.StatusBar method"""
self.statusbar.SetStatusText(*args)

def ShowStatusbar(self, show):
"""Show/hide statusbar and associated pane"""
self._mgr.GetPane("statusbar").Show(show)
self._mgr.Update()

def IsStatusbarShown(self):
"""Check if statusbar is shown"""
return self._mgr.GetPane("statusbar").IsShown()

def StatusbarReposition(self):
"""Reposition items in statusbar"""
if self.statusbarManager:
Expand All @@ -349,6 +402,47 @@ def StatusbarEnableLongHelp(self, enable=True):
for toolbar in six.itervalues(self.toolbars):
toolbar.EnableLongHelp(enable)

def ShowAllToolbars(self, show=True):
if not show: # hide
action = self.RemoveToolbar
else:
action = self.AddToolbar
for toolbar in self.GetToolbarNames():
action(toolbar)

def AreAllToolbarsShown(self):
return self.GetMapToolbar().IsShown()

def GetToolbarNames(self):
"""Return toolbar names"""
return list(self.toolbars.keys())

def AddToolbar(self):
"""Add defined toolbar to the window"""
raise NotImplementedError("AddToolbar")

def RemoveToolbar(self, name, destroy=False):
"""Removes defined toolbar from the window
:param name toolbar to remove
:param destroy True to destroy otherwise toolbar is only hidden
"""
self._mgr.DetachPane(self.toolbars[name])
if destroy:
self._toolSwitcher.RemoveToolbarFromGroup("mouseUse", self.toolbars[name])
self.toolbars[name].Destroy()
self.toolbars.pop(name)
else:
self.toolbars[name].Hide()

self._mgr.Update()

def IsPaneShown(self, name):
"""Check if pane (toolbar, mapWindow ...) of given name is currently shown"""
if self._mgr.GetPane(name).IsOk():
return self._mgr.GetPane(name).IsShown()
return False

def OnRender(self, event):
"""Re-render map composition (each map layer)"""
raise NotImplementedError("OnRender")
Expand Down
Loading

0 comments on commit 606a12b

Please sign in to comment.