Add decorator to redraw window

This commit adds a decorator that will handle redrawing of gui.

The pattern sizer.clear() ... pnl.SetupScrolling() and
sizer.layout() is very common and easy to handle with a decorator.
main
Micke Nordin 4 years ago
parent cda0ecbd40
commit 602ff241ad
Signed by: micke
GPG Key ID: 014B273D614BE877

@ -15,6 +15,23 @@ class PassUi(wx.Frame):
The wx.Frame for passui The wx.Frame for passui
""" """
def redraw(*args):
"""Decorator used for redrawing the widgets in the sizer
Returns:
function: The decorated function
"""
func = args[0]
def wrapper(self, *wrapper_args):
"""The wrapper function for the decorator
"""
self.sizer.Clear(delete_windows=True)
func(self, *wrapper_args)
self.sizer.Layout()
return wrapper
def __init__(self, *args, **kw): def __init__(self, *args, **kw):
"""__init__. """__init__.
@ -31,9 +48,9 @@ class PassUi(wx.Frame):
self.pnl.SetSizer(self.sizer) self.pnl.SetSizer(self.sizer)
self.add_buttons() self.add_buttons()
@redraw
def add_buttons(self): def add_buttons(self):
"""add_buttons.""" """add_buttons."""
self.sizer.Clear(delete_windows=True)
self.add_tools() self.add_tools()
if self.pass_handler.cur_dir != self.pass_handler.top_dir: if self.pass_handler.cur_dir != self.pass_handler.top_dir:
btn = self.make_back_button() btn = self.make_back_button()
@ -63,7 +80,6 @@ class PassUi(wx.Frame):
btn) btn)
index = index + 1 index = index + 1
self.pnl.SetupScrolling() self.pnl.SetupScrolling()
self.sizer.Layout()
def add_push_pull(self): def add_push_pull(self):
"""add_push_pull.""" """add_push_pull."""
@ -185,11 +201,11 @@ class PassUi(wx.Frame):
self.pass_handler.save_to_pass(password, path, fullpath) self.pass_handler.save_to_pass(password, path, fullpath)
self.back_button_clicked() self.back_button_clicked()
@redraw
def show_new_dialog(self): def show_new_dialog(self):
"""show_new_dialog. """show_new_dialog.
""" """
self.sizer.Clear(delete_windows=True)
passpath = self.pass_handler.cur_dir.replace(self.pass_handler.top_dir, '') passpath = self.pass_handler.cur_dir.replace(self.pass_handler.top_dir, '')
btn = self.make_back_button() btn = self.make_back_button()
self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member
@ -216,15 +232,14 @@ class PassUi(wx.Frame):
save_to_pass(path, mtext, mname), save_to_pass(path, mtext, mname),
sbtn) sbtn)
self.pnl.SetupScrolling() self.pnl.SetupScrolling()
self.sizer.Layout()
name.SetFocus() name.SetFocus()
@redraw
def show_password_dialog(self, index): def show_password_dialog(self, index):
"""show_password_dialog. """show_password_dialog.
:param index: :param index:
""" """
self.sizer.Clear(delete_windows=True)
self.add_tools(index) self.add_tools(index)
passpath = self.pass_handler.get_pass_path_from_index(index, "password") passpath = self.pass_handler.get_pass_path_from_index(index, "password")
@ -256,14 +271,13 @@ class PassUi(wx.Frame):
lambda event, mindex=index: self.delete_password(mindex), lambda event, mindex=index: self.delete_password(mindex),
dbtn) dbtn)
self.pnl.SetupScrolling() self.pnl.SetupScrolling()
self.sizer.Layout()
@redraw
def show_password(self, index): def show_password(self, index):
"""show_password. """show_password.
:param index: :param index:
""" """
self.sizer.Clear(delete_windows=True)
self.add_tools(index) self.add_tools(index)
passpath = self.pass_handler.get_pass_path_from_index(index, "password") passpath = self.pass_handler.get_pass_path_from_index(index, "password")
cpath = self.pass_handler.top_dir + os.path.dirname(passpath) cpath = self.pass_handler.top_dir + os.path.dirname(passpath)
@ -291,14 +305,13 @@ class PassUi(wx.Frame):
path, mtext), path, mtext),
sbtn) sbtn)
self.pnl.SetupScrolling() self.pnl.SetupScrolling()
self.sizer.Layout()
@redraw
def show_tools(self, index=None): def show_tools(self, index=None):
"""show_tools. """show_tools.
:param index: :param index:
""" """
self.sizer.Clear(delete_windows=True)
btn = wx.Button(self.pnl, label="Go back") btn = wx.Button(self.pnl, label="Go back")
font = btn.GetFont().MakeBold() font = btn.GetFont().MakeBold()
btn.SetFont(font) btn.SetFont(font)
@ -315,7 +328,6 @@ class PassUi(wx.Frame):
nbtn) nbtn)
self.add_push_pull() self.add_push_pull()
self.pnl.SetupScrolling() self.pnl.SetupScrolling()
self.sizer.Layout()
if __name__ == '__main__': if __name__ == '__main__':

Loading…
Cancel
Save