Browse Source

Updated Controller to accept instance of controlled class -- going to refactor so that the weird "register_controller" thing doesn't need to happen

Resolved PEP issues
pull/1/head
chriskiehl 10 years ago
parent
commit
6e2a063da1
5 changed files with 74 additions and 73 deletions
  1. 14
      gooey/gui/base_window.py
  2. 12
      gooey/gui/controller.py
  3. 46
      gooey/gui/footer.py
  4. 68
      gooey/gui/header.py
  5. 7
      gooey/gui/styling.py

14
gooey/gui/base_window.py

@ -32,18 +32,20 @@ class BaseWindow(wx.Frame):
self._controller = None self._controller = None
# Components
self.icon = None
self.head_panel = None
self.config_panel = None
self.runtime_display = None
self.foot_panel = None
self.panels = None
self._init_properties() self._init_properties()
self._init_components(BodyPanel) self._init_components(BodyPanel)
self._do_layout() self._do_layout()
self._init_controller() self._init_controller()
self.registerControllers() self.registerControllers()
# self.icon = None
# self.head_panel = None
# self.config_panel = None
# self.runtime_display = None
# self.foot_panel = None
# self.panels = None
def _init_properties(self): def _init_properties(self):
if not self._params['program_name']: if not self._params['program_name']:

12
gooey/gui/controller.py

@ -39,9 +39,9 @@ class Controller(object):
self._foot = footer_panel self._foot = footer_panel
self._model = model self._model = model
self._payload_runner = Process(target=self.RunClientCode).start self._payload_runner = Process(target=self.RunClientCode)
def OnCancelButton(self, event): def OnCancelButton(self, widget, event):
msg = i18n.translate('sure_you_want_to_exit') msg = i18n.translate('sure_you_want_to_exit')
dlg = wx.MessageDialog(None, msg, dlg = wx.MessageDialog(None, msg,
i18n.translate('close_program'), wx.YES_NO) i18n.translate('close_program'), wx.YES_NO)
@ -53,7 +53,7 @@ class Controller(object):
sys.exit() sys.exit()
dlg.Destroy() dlg.Destroy()
def OnStartButton(self, event): def OnStartButton(self, widget, event):
cmd_line_args = self._body.GetOptions() cmd_line_args = self._body.GetOptions()
if not self._model.IsValidArgString(cmd_line_args): if not self._model.IsValidArgString(cmd_line_args):
error_msg = self._model.GetErrorMsg(cmd_line_args) error_msg = self._model.GetErrorMsg(cmd_line_args)
@ -61,14 +61,14 @@ class Controller(object):
return return
self._model.AddToArgv(cmd_line_args) self._model.AddToArgv(cmd_line_args)
self._base.NextPage() self._base.NextPage()
self._payload_runner() self._payload_runner.start()
def ManualStart(self): def ManualStart(self):
self._base.NextPage() self._base.NextPage()
wx.CallAfter(wx.ActivateEvent) wx.CallAfter(wx.ActivateEvent)
self._payload_runner() self._payload_runner.start()
def OnCloseButton(self, event): def OnCloseButton(self, widget, event):
self._base.Destroy() self._base.Destroy()
sys.exit() sys.exit()

46
gooey/gui/footer.py

@ -22,6 +22,12 @@ class AbstractFooter(wx.Panel):
self._controller = None self._controller = None
# components
self.cancel_button = None
self.start_button = None
self.running_animation = None
self.close_button = None
self._init_components() self._init_components()
self._init_pages() self._init_pages()
self._do_layout() self._do_layout()
@ -41,20 +47,22 @@ class AbstractFooter(wx.Panel):
self.close_button = self._Button(i18n.translate("close"), wx.ID_OK) self.close_button = self._Button(i18n.translate("close"), wx.ID_OK)
def _init_pages(self): def _init_pages(self):
_pages = [[ def PageOne():
self.cancel_button.Hide, self.cancel_button.Hide()
self.start_button.Hide, self.start_button.Hide()
self.running_animation.Show, self.running_animation.Show()
self.running_animation.Play, self.running_animation.Play()
self.Layout self.Layout()
], def PageTwo():
[ self.running_animation.Stop()
self.running_animation.Stop, self.running_animation.Hide()
self.running_animation.Hide, self.close_button.Show()
self.close_button.Show, self.Layout()
self.Layout self._pages = iter([PageOne, PageTwo])
]]
self._pages = iter(_pages)
def _do_layout(self): def _do_layout(self):
v_sizer = wx.BoxSizer(wx.VERTICAL) v_sizer = wx.BoxSizer(wx.VERTICAL)
@ -86,9 +94,7 @@ class AbstractFooter(wx.Panel):
self._controller = controller self._controller = controller
def NextPage(self): def NextPage(self):
page = next(self._pages) next(self._pages)()
for action in page:
action()
def _load_image(self, img_path, height=70): def _load_image(self, img_path, height=70):
return imageutil.resize_bitmap( return imageutil.resize_bitmap(
@ -115,14 +121,14 @@ class Footer(AbstractFooter):
self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.close_button) self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.close_button)
def OnCancelButton(self, event): def OnCancelButton(self, event):
self._controller.OnCancelButton(event) self._controller.OnCancelButton(self, event)
event.Skip() event.Skip()
def OnCloseButton(self, event): def OnCloseButton(self, event):
self._controller.OnCloseButton(event) self._controller.OnCloseButton(self, event)
event.Skip() event.Skip()
def OnStartButton(self, event): def OnStartButton(self, event):
self._controller.OnStartButton(event) self._controller.OnStartButton(event, self)
event.Skip() event.Skip()

68
gooey/gui/header.py

@ -10,7 +10,7 @@ import wx
from gooey import i18n from gooey import i18n
from gooey.gui import imageutil from gooey.gui import imageutil
from gooey import image_repository from gooey import image_repository
import styling
PAD_SIZE = 10 PAD_SIZE = 10
@ -22,6 +22,12 @@ class FrameHeader(wx.Panel):
self._controller = None self._controller = None
self._header = None
self._subheader = None
self._settings_img = None
self._running_img = None
self._check_mark = None
self._init_properties() self._init_properties()
self._init_components(heading, subheading) self._init_components(heading, subheading)
self._init_pages() self._init_pages()
@ -34,8 +40,10 @@ class FrameHeader(wx.Panel):
self.SetMinSize((120, 80)) self.SetMinSize((120, 80))
def _init_components(self, heading, subheading): def _init_components(self, heading, subheading):
self._header = self._bold_static_text(heading) self._header = styling.H1(self, heading)
self._subheader = wx.StaticText(self, label=subheading) self._subheader = wx.StaticText(self, label=subheading)
self._settings_img = self._load_image(image_repository.settings2, height=79) self._settings_img = self._load_image(image_repository.settings2, height=79)
self._running_img = self._load_image(image_repository.computer3, 79) self._running_img = self._load_image(image_repository.computer3, 79)
self._check_mark = self._load_image(image_repository.alessandro_rei_checkmark, height=75) self._check_mark = self._load_image(image_repository.alessandro_rei_checkmark, height=75)
@ -54,18 +62,8 @@ class FrameHeader(wx.Panel):
vsizer.Add(sizer, 1, wx.EXPAND) vsizer.Add(sizer, 1, wx.EXPAND)
self.SetSizer(vsizer) self.SetSizer(vsizer)
def _bold_static_text(self, label):
txt = wx.StaticText(self, label=label)
font_size = txt.GetFont().GetPointSize()
txt.SetFont(wx.Font(font_size * 1.2, wx.FONTFAMILY_DEFAULT,
wx.FONTWEIGHT_NORMAL, wx.FONTWEIGHT_BOLD, False)
)
return txt
def _load_image(self, img_path, height=70): def _load_image(self, img_path, height=70):
return imageutil.resize_bitmap(self, return imageutil.resize_bitmap(self, imageutil._load_image(img_path), height)
imageutil._load_image(img_path),
height)
def build_heading_sizer(self): def build_heading_sizer(self):
sizer = wx.BoxSizer(wx.VERTICAL) sizer = wx.BoxSizer(wx.VERTICAL)
@ -80,34 +78,22 @@ class FrameHeader(wx.Panel):
self._controller = controller self._controller = controller
def _init_pages(self): def _init_pages(self):
messages = [[
i18n.translate("running_title"),
i18n.translate('running_msg')
], [
i18n.translate('finished_title'),
i18n.translate('finished_msg')
]]
pages = [[
self._header.SetLabel,
self._subheader.SetLabel,
self._settings_img.Hide,
self._running_img.Show,
self.Layout,
], [
self._header.SetLabel,
self._subheader.SetLabel,
self._running_img.Hide,
self._check_mark.Show,
self.Layout,
]]
self._messages = iter(messages)
self._pages = iter(pages)
def NextPage(self): def PageOne():
messages = next(self._messages) self._header.SetLabel(i18n.translate("running_title"))
commands = next(self._pages) self._subheader.SetLabel(i18n.translate('running_msg'))
self._settings_img.Hide()
self._running_img.Show()
self.Layout()
_zipl = itertools.izip_longest def PageTwo():
self._header.SetLabel(i18n.translate('finished_title'))
self._subheader.SetLabel(i18n.translate('finished_msg'))
self._running_img.Hide()
self._check_mark.Show()
self.Layout()
for func, arg in _zipl(commands, messages, fillvalue=None): self._pages = iter([PageOne, PageTwo])
func(arg) if arg else func() def NextPage(self):
next(self._pages)()

7
gooey/gui/styling.py

@ -14,6 +14,7 @@ def MakeBold(statictext):
wx.FONTWEIGHT_NORMAL, wx.FONTWEIGHT_BOLD, False) wx.FONTWEIGHT_NORMAL, wx.FONTWEIGHT_BOLD, False)
statictext.SetFont(font) statictext.SetFont(font)
def _bold_static_text(parent, text_label): def _bold_static_text(parent, text_label):
text = wx.StaticText(parent, label=text_label) text = wx.StaticText(parent, label=text_label)
font_size = text.GetFont().GetPointSize() font_size = text.GetFont().GetPointSize()
@ -21,6 +22,12 @@ def _bold_static_text(parent, text_label):
text.SetFont(bold) text.SetFont(bold)
return text return text
def H1(parent, label):
text = wx.StaticText(parent, label=label)
font_size = text.GetFont().GetPointSize()
font = wx.Font(font_size * 1.2, wx.FONTFAMILY_DEFAULT, wx.FONTWEIGHT_NORMAL, wx.FONTWEIGHT_BOLD, False)
text.SetFont(font)
return text
def MakeDarkGrey(statictext): def MakeDarkGrey(statictext):
darkgray = (54, 54, 54) darkgray = (54, 54, 54)
|||||||
100:0
Loading…
Cancel
Save