Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

Commit

Permalink
do not create a view more than once.
Browse files Browse the repository at this point in the history
make it invisible rather than destroying it.
close #228
  • Loading branch information
mfrasca committed Dec 20, 2015
1 parent 139769e commit 5fc181e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions bauble/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ def main(uri=None):
prefs.save()

# set the default command handler
import bauble.view as view
pluginmgr.register_command(view.DefaultCommandHandler)
from bauble.view import DefaultCommandHandler
pluginmgr.register_command(DefaultCommandHandler)

# now that we have a connection create the gui, start before the plugins
# are initialized in case they have to do anything like add a menu
Expand Down
15 changes: 12 additions & 3 deletions bauble/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,16 +355,25 @@ def set_view(self, view=None):
:param view: default=None
'''
view_box = self.widgets.view_box
must_add_this_view = True
for kid in view_box.get_children():
view_box.remove(kid)
view_box.pack_start(view, True, True, 0)
if view == kid:
must_add_this_view = False
kid.set_visible(True)
else:
kid.set_visible(False)
if must_add_this_view:
view_box.pack_start(view, True, True, 0)
view.show_all()

def get_view(self):
'''
return the current view in the view box
'''
return self.widgets.view_box.get_children()[0]
for kid in self.widgets.view_box.get_children():
if kid.get_visible():
return kid
return None

def create_main_menu(self):
"""
Expand Down
8 changes: 4 additions & 4 deletions bauble/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,14 +1270,14 @@ class DefaultCommandHandler(pluginmgr.CommandHandler):

def __init__(self):
super(DefaultCommandHandler, self).__init__()
self.view = None

command = [None]
view = None

def get_view(self):
if self.view is None:
self.view = SearchView()
return self.view
if self.__class__.view is None:
self.__class__.view = SearchView()
return self.__class__.view

def __call__(self, cmd, arg):
self.view.search(arg)

0 comments on commit 5fc181e

Please sign in to comment.