Skip to content

Commit

Permalink
wxGUI: move datacatalog search below toolbar, make it stretch (#2207)
Browse files Browse the repository at this point in the history
  • Loading branch information
petrasovaa committed Feb 16, 2022
1 parent 5c34325 commit bba41c0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 39 deletions.
11 changes: 10 additions & 1 deletion gui/wxpython/datacatalog/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from core.debug import Debug
from datacatalog.tree import DataCatalogTree
from datacatalog.toolbars import DataCatalogToolbar
from datacatalog.toolbars import DataCatalogToolbar, DataCatalogSearch
from gui_core.infobar import InfoBar
from datacatalog.infomanager import DataCatalogInfoManager
from gui_core.wrap import Menu
Expand Down Expand Up @@ -66,6 +66,9 @@ def __init__(
# toolbar
self.toolbar = DataCatalogToolbar(parent=self)

# search
self.search = DataCatalogSearch(parent=self, filter_function=self.Filter)

# tree with layers
self.tree = DataCatalogTree(self, giface=giface)
self.tree.showNotification.connect(self.showNotification)
Expand Down Expand Up @@ -106,6 +109,12 @@ def _layout(self):
"""Do layout"""
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.toolbar, proportion=0, flag=wx.EXPAND)
sizer.Add(
self.search,
proportion=0,
flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
border=5,
)
sizer.Add(self.infoBar, proportion=0, flag=wx.EXPAND)
sizer.Add(self.tree.GetControl(), proportion=1, flag=wx.EXPAND)

Expand Down
75 changes: 37 additions & 38 deletions gui/wxpython/datacatalog/toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,18 @@
}


class DataCatalogToolbar(BaseToolbar):
"""Main data catalog toolbar"""

def __init__(self, parent):
"""Main toolbar constructor"""

BaseToolbar.__init__(self, parent)

self.InitToolbar(self._toolbarData())
class DataCatalogSearch(SearchCtrl):
def __init__(self, parent, filter_function):
super().__init__(parent)
self.filter_function = filter_function
self.filter_element = None
self.filter = SearchCtrl(parent=self)
self.filter.SetDescriptiveText(_("Search"))
self.filter.ShowCancelButton(True)
self.filter.SetSize((150, self.filter.GetBestSize()[1]))
self.filter.Bind(
self.SetDescriptiveText(_("Search"))
self.ShowCancelButton(True)
self.Bind(
wx.EVT_TEXT,
lambda event: self.parent.Filter(
self.filter.GetValue(), self.filter_element
),
lambda event: self.filter_function(self.GetValue(), self.filter_element),
)
self.filter.Bind(
wx.EVT_SEARCHCTRL_CANCEL_BTN, lambda evt: self.parent.Filter("")
)
self.AddControl(self.filter)
self.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, lambda evt: self.filter_function(""))
filterMenu = wx.Menu()
item = filterMenu.AppendRadioItem(-1, "All")
self.Bind(wx.EVT_MENU, self.OnFilterMenu, item)
Expand All @@ -86,12 +74,37 @@ def __init__(self, parent):
self.Bind(wx.EVT_MENU, self.OnFilterMenu, item)
item = filterMenu.AppendRadioItem(-1, "3D raster maps")
self.Bind(wx.EVT_MENU, self.OnFilterMenu, item)
self.filter.SetMenu(filterMenu)
help = _(
self.SetMenu(filterMenu)
helpTip = _(
"Type to search database by map type or name. "
"Use Python regular expressions to refine your search."
)
self.SetToolShortHelp(self.filter.GetId(), help)
self.SetToolTip(helpTip)

def OnFilterMenu(self, event):
"""Decide the element to filter by"""
filterMenu = self.GetMenu().GetMenuItems()
self.filter_element = None
if filterMenu[1].IsChecked():
self.filter_element = "raster"
elif filterMenu[2].IsChecked():
self.filter_element = "vector"
elif filterMenu[3].IsChecked():
self.filter_element = "raster_3d"
# trigger filter on change
if self.GetValue():
self.filter_function(self.GetValue(), self.filter_element)


class DataCatalogToolbar(BaseToolbar):
"""Main data catalog toolbar"""

def __init__(self, parent):
"""Main toolbar constructor"""

BaseToolbar.__init__(self, parent)

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

Expand Down Expand Up @@ -122,20 +135,6 @@ def _toolbarData(self):
)
)

def OnFilterMenu(self, event):
"""Decide the element to filter by"""
filterMenu = self.filter.GetMenu().GetMenuItems()
self.filter_element = None
if filterMenu[1].IsChecked():
self.filter_element = "raster"
elif filterMenu[2].IsChecked():
self.filter_element = "vector"
elif filterMenu[3].IsChecked():
self.filter_element = "raster_3d"
# trigger filter on change
if self.filter.GetValue():
self.parent.Filter(self.filter.GetValue(), self.filter_element)

def OnSetRestriction(self, event):
if self.GetToolState(self.lock):
self.SetToolNormalBitmap(self.lock, icons["unlocked"].GetBitmap())
Expand Down

0 comments on commit bba41c0

Please sign in to comment.