Browse Source

Man, I suck at version controll. Added too much to list

pull/1/head
Chris Kiehl 10 years ago
parent
commit
3a0b3e5c29
16 changed files with 204 additions and 57 deletions
  1. 22
      src/app/dialogs/base_window.py
  2. 2
      src/app/dialogs/basic_config_panel.py
  3. 23
      src/app/dialogs/controller.py
  4. 8
      src/app/dialogs/display_main.py
  5. 52
      src/app/dialogs/footer.py
  6. BIN
      src/app/dialogs/footer.pyc
  7. 31
      src/app/dialogs/header.py
  8. BIN
      src/app/dialogs/header.pyc
  9. 72
      src/app/dialogs/runtime_display_panel.py
  10. 2
      src/app/dialogs/window.py
  11. BIN
      src/app/images/harwen_monitor.png
  12. 1
      src/app/images/image_store.py
  13. BIN
      src/app/images/image_store.pyc
  14. 39
      src/experiments/thread_interupt.py
  15. 4
      src/languages/eng.py
  16. 5
      src/languages/english.json

22
src/app/dialogs/base_window.py

@ -15,13 +15,14 @@ import sys
import wx
import header
import footer
from app.dialogs.runtime_display_panel import RuntimeDisplay
from app.dialogs.controller import Controller
from app.images import image_store
from app.dialogs.config_model import Model
class BaseWindow(wx.Frame):
def __init__(self, body_panel, model):
def __init__(self, body_panel, model, payload):
wx.Frame.__init__(
self,
parent=None,
@ -31,6 +32,7 @@ class BaseWindow(wx.Frame):
)
self._model = model
self._payload = payload
self._controller = None
@ -56,9 +58,10 @@ class BaseWindow(wx.Frame):
parent=self,
size=(30,90))
self.body_panel = BodyPanel(self, self._model)
self.cfg_foot_panel = footer.ConfigFooter(self, self._controller)
self.runtime_display = RuntimeDisplay(self)
self.foot_panel = footer.Footer(self, self._controller)
self.panels = [self.head_panel, self.body_panel, self.cfg_foot_panel]
self.panels = [self.head_panel, self.body_panel, self.foot_panel]
# self.main_foot_panel = footer.MainFooter(self, self._controller)
# self.main_foot_panel.Hide()
@ -67,8 +70,10 @@ class BaseWindow(wx.Frame):
sizer.Add(self.head_panel, 0, wx.EXPAND)
self._draw_horizontal_line(sizer)
sizer.Add(self.body_panel, 1, wx.EXPAND)
self.runtime_display.Hide()
sizer.Add(self.runtime_display, 1, wx.EXPAND)
self._draw_horizontal_line(sizer)
sizer.Add(self.cfg_foot_panel, 0, wx.EXPAND)
sizer.Add(self.foot_panel, 0, wx.EXPAND)
self.SetSizer(sizer)
def _draw_horizontal_line(self, sizer):
@ -81,13 +86,20 @@ class BaseWindow(wx.Frame):
base_frame = self,
head_panel = self.head_panel,
body_panel = self.body_panel,
footer_panel = self.cfg_foot_panel,
footer_panel = self.foot_panel,
model = self._model)
def registerControllers(self):
for panel in self.panels:
panel.RegisterController(self._controller)
def NextPage(self):
self.head_panel.NextPage()
self.foot_panel.NextPage()
self.body_panel.Hide()
self.runtime_display.Show()
self.Layout()
def AttachPayload(self, payload):
self._payload = payload

2
src/app/dialogs/basic_config_panel.py

@ -10,7 +10,7 @@ import wx
import os
from app.dialogs.option_reader import OptionReader
class BasicDisplayPanel(wx.Panel, OptionReader):
class RuntimeDisplay(wx.Panel, OptionReader):
def __init__(self, parent, **kwargs):
wx.Panel.__init__(self, parent, **kwargs)

23
src/app/dialogs/controller.py

@ -7,6 +7,7 @@ Created on Dec 22, 2013
import wx
import sys
from app.dialogs.config_model import Model
from multiprocessing.dummy import Pool
YES = 5103
NO = 5104
@ -34,7 +35,7 @@ class Controller(object):
self._model = model
def OnConfigCancel(self, event):
def OnCancelButton(self, event):
msg = "Are you sure you want to exit?"
dlg = wx.MessageDialog(None, msg, "Close Program?", wx.YES_NO)
result = dlg.ShowModal()
@ -44,7 +45,7 @@ class Controller(object):
self._base.Destroy()
sys.exit()
def OnConfigNext(self, event):
def OnStartButton(self, event):
cmd_line_args = self._body.GetOptions()
if not self._model.IsValidArgString(cmd_line_args):
error_msg = self._model.GetErrorMsg(cmd_line_args)
@ -53,21 +54,17 @@ class Controller(object):
self._model.AddToArgv(cmd_line_args)
self._base.NextPage()
self.RunClientCode()
def RunClientCode(self):
pass
def AddPayload(self, payload):
def OnCancelRunButton(self, event):
pass
def OnMainCancel(self, event):
print 'OnMaingCancel pressed!'
def OnMainNext(self, event):
print 'OnCongigNext pressed!'
def ShowArgumentErrorDlg(self, error):
a = wx.MessageDialog(None, error, 'Argument Error')
a.ShowModal()
a.Destroy()
def RunClientCode(self):
pool = Pool(1)
pool.apply_async(self._base._payload)

8
src/app/dialogs/display_main.py

@ -11,8 +11,8 @@ import threading
from app.dialogs.controller import Controller
from app.images import image_store
from app.dialogs.header import FrameHeader
from app.dialogs.basic_config_panel import BasicDisplayPanel
from app.dialogs.footer import ConfigFooter
from app.dialogs.basic_config_panel import RuntimeDisplay
from app.dialogs.footer import Footer
from app.dialogs.advanced_config import AdvancedConfigPanel
class MessagePump(object):
@ -78,8 +78,8 @@ class MainWindow(wx.Frame):
def _init_components(self):
# init components
self.head_panel = FrameHeader(image_path=image_store.computer3, parent=self, size=(30,90))
self.body_panel = BasicDisplayPanel(parent=self)
self.foot_panel = ConfigFooter(self, self._controller)
self.body_panel = RuntimeDisplay(parent=self)
self.foot_panel = Footer(self, self._controller)
def _do_layout(self):
sizer = wx.BoxSizer(wx.VERTICAL)

52
src/app/dialogs/footer.py

@ -15,26 +15,31 @@ class AbstractFooter(wx.Panel):
self.SetMinSize((30, 53))
self._controller = None
self.cancel_button = self._button('Cancel', wx.ID_CANCEL)
self.next_button = self._button("Start", wx.ID_OK)
self._init_components()
self._do_layout()
def _init_components(self):
self.cancel_button = self._Button('Cancel', wx.ID_CANCEL)
self.start_button = self._Button("Start", wx.ID_OK)
self.cancel_run_button = self._Button('Cancel', wx.ID_CANCEL)
def _do_layout(self):
v_sizer = wx.BoxSizer(wx.VERTICAL)
h_sizer = wx.BoxSizer(wx.HORIZONTAL)
h_sizer.AddStretchSpacer(1)
h_sizer.Add(self.cancel_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
h_sizer.Add(self.next_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
h_sizer.Add(self.start_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
v_sizer.AddStretchSpacer(1)
v_sizer.Add(h_sizer, 0, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
v_sizer.Add(self.cancel_run_button, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.RIGHT, 20)
self.cancel_run_button.Hide()
v_sizer.AddStretchSpacer(1)
self.SetSizer(v_sizer)
def _button(self,label=None, style=None):
def _Button(self,label=None, style=None):
return wx.Button(
parent=self,
id=-1,
@ -45,9 +50,15 @@ class AbstractFooter(wx.Panel):
def RegisterController(self, controller):
if self._controller is None:
self._controller = controller
def NextPage(self):
self.cancel_button.Hide()
self.start_button.Hide()
self.cancel_run_button.Show()
self.Layout()
class ConfigFooter(AbstractFooter):
class Footer(AbstractFooter):
'''
Footer section used on the configuration
screen of the application
@ -60,15 +71,20 @@ class ConfigFooter(AbstractFooter):
def __init__(self, parent, controller, **kwargs):
AbstractFooter.__init__(self, parent, **kwargs)
self.Bind(wx.EVT_BUTTON, self.OnConfigCancel, self.cancel_button)
self.Bind(wx.EVT_BUTTON, self.OnConfigNext, self.next_button)
self.Bind(wx.EVT_BUTTON, self.OnCancelButton, self.cancel_button)
self.Bind(wx.EVT_BUTTON, self.OnStartButton, self.start_button)
self.Bind(wx.EVT_BUTTON, self.OnCancelRunButton, self.cancel_run_button)
def OnCancelButton(self, event):
self._controller.OnCancelButton(event)
event.Skip()
def OnConfigCancel(self, event):
self._controller.OnConfigCancel(event)
def OnCancelRunButton(self, event):
self._controller.OnCancelRunButton(event)
event.Skip()
def OnConfigNext(self, event):
self._controller.OnConfigNext(event)
def OnStartButton(self, event):
self._controller.OnStartButton(event)
event.Skip()
@ -84,18 +100,14 @@ class MainFooter(AbstractFooter):
def __init__(self, parent, controller, **kwargs):
AbstractFooter.__init__(self, parent, **kwargs)
self.Bind(wx.EVT_BUTTON, self.OnConfigCancel, self.cancel_button)
self.Bind(wx.EVT_BUTTON, self.OnConfigNext, self.next_button)
self.start_button = None
self.Bind(wx.EVT_BUTTON, self.OnMainCancel, self.cancel_button)
def OnMainCancel(self, event):
self._controller.OnMainCancel(event)
# event.Skip()
def OnMainNext(self, event):
self._controller.OnMainNext(event)
event.Skip()

BIN
src/app/dialogs/footer.pyc

31
src/app/dialogs/header.py

@ -7,6 +7,7 @@ Created on Dec 23, 2013
import wx
import imageutil
from app.dialogs.segoe_statictext import SegoeText
from app.images import image_store
PAD_SIZE = 10
@ -33,16 +34,19 @@ class FrameHeader(wx.Panel):
self.SetMinSize((120, 80))
def _init_components(self, heading, subheading, image_path):
self.header = self._bold_static_text(heading)
self.subheader = wx.StaticText(self, label=subheading)
self.img = self._load_image(image_path)
self._header = self._bold_static_text(heading)
self._subheader = wx.StaticText(self, label=subheading)
self._settings_img = self._load_image(image_path)
self._running_img = self._load_image(image_store.harwen_monitor)
def _do_layout(self):
vsizer = wx.BoxSizer(wx.VERTICAL)
sizer = wx.BoxSizer(wx.HORIZONTAL)
headings_sizer = self.build_heading_sizer()
sizer.Add(headings_sizer, 1, wx.ALIGN_LEFT | wx.EXPAND | wx.LEFT, PAD_SIZE)
sizer.Add(self.img, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, PAD_SIZE)
sizer.Add(headings_sizer, 1, wx.ALIGN_LEFT | wx.ALIGN_CENTER_HORIZONTAL | wx.EXPAND | wx.LEFT, PAD_SIZE)
sizer.Add(self._settings_img, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, PAD_SIZE)
sizer.Add(self._running_img, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, PAD_SIZE)
self._running_img.Hide()
vsizer.Add(sizer, 1, wx.EXPAND)
self.SetSizer(vsizer)
@ -57,8 +61,8 @@ class FrameHeader(wx.Panel):
def build_heading_sizer(self):
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.AddStretchSpacer(1)
sizer.Add(self.header, 1)
sizer.Add(self.subheader, 1)
sizer.Add(self._header, 0)
sizer.Add(self._subheader, 0)
sizer.AddStretchSpacer(1)
return sizer
@ -86,12 +90,19 @@ class FrameHeader(wx.Panel):
)
return wx.BitmapFromImage(image)
def UpdateImage(self, image):
pass
def RegisterController(self, controller):
if self._controller is None:
self._controller = controller
def NextPage(self):
self._header.SetLabel("Running")
self._subheader.SetLabel('Please wait while the application performs its tasks. '
'\nThis may take a few moments')
self._settings_img.Hide()
self._running_img.Show()
self.Layout()

BIN
src/app/dialogs/header.pyc

72
src/app/dialogs/runtime_display_panel.py

@ -0,0 +1,72 @@
'''
Created on Dec 23, 2013
@author: Chris
'''
import wx
import sys
import Queue
import threading
from model.i18n import I18N
class MessagePump(object):
def __init__(self, queue):
self.queue = queue
self.stdout = sys.stdout
# Overrides stdout's write method
def write(self, text):
if text != '':
self.queue.put(text)
class Listener(threading.Thread):
def __init__(self, queue, textbox):
threading.Thread.__init__(self)
self.queue = queue
self.update_text = lambda x: textbox.AppendText(x)
def run(self):
while True:
try:
stdout_msg = self.queue.get(timeout=1)
if stdout_msg != '':
self.update_text(stdout_msg)
except Exception as e:
pass # Timeout. Aint nobody care 'bout dat
class RuntimeDisplay(wx.Panel):
def __init__(self, parent, **kwargs):
wx.Panel.__init__(self, parent, **kwargs)
self._translator = I18N()
self._init_properties()
self._init_components()
self._do_layout()
self.queue = Queue.Queue()
_stdout = sys.stdout
sys.stdout = MessagePump(self.queue)
listener = Listener(self.queue, self.cmd_textbox)
listener.start()
def _init_properties(self):
self.SetBackgroundColour('#F0F0F0')
def _init_components(self):
self.text = wx.StaticText(self, label=self._translator["status"])
self.cmd_textbox = wx.TextCtrl(
self, -1, "",
style=wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_RICH)
def _do_layout(self):
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.AddSpacer(10)
sizer.Add(self.text, 0, wx.LEFT, 30)
sizer.AddSpacer(10)
sizer.Add(self.cmd_textbox, 1, wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, 30)
sizer.AddSpacer(20)
self.SetSizer(sizer)

2
src/app/dialogs/window.py

@ -34,7 +34,7 @@ from app.dialogs import argparse_test_data
def WithAdvancedOptions(parser, payload):
app = wx.App(False)
model = Model(parser)
frame = BaseWindow(advanced_config.AdvancedConfigPanel, model)
frame = BaseWindow(advanced_config.AdvancedConfigPanel, model, payload)
frame.Show(True) # Show the frame.
app.MainLoop()

BIN
src/app/images/harwen_monitor.png

Before After
Width: 128  |  Height: 128  |  Size: 21 KiB

1
src/app/images/image_store.py

@ -10,6 +10,7 @@ Convenience module for keeping the filepaths in one place.
computer = r"C:\Users\Chris\Dropbox\pretty_gui\Gooey\src\app\images\computer.png"
computer2 = r"C:\Users\Chris\Dropbox\pretty_gui\Gooey\src\app\images\computer2.png"
computer3 = r"C:\Users\Chris\Dropbox\pretty_gui\Gooey\src\app\images\computer3.png"
harwen_monitor = r"C:\Users\Chris\Dropbox\pretty_gui\Gooey\src\app\images\harwen_monitor.png"
icon = r"C:\Users\Chris\Dropbox\pretty_gui\Gooey\src\app\images\icon.ico"
settings = r"C:\Users\Chris\Dropbox\pretty_gui\Gooey\src\app\images\settings.png"
settings2 = r"C:\Users\Chris\Dropbox\pretty_gui\Gooey\src\app\images\settings2.png"

BIN
src/app/images/image_store.pyc

39
src/experiments/thread_interupt.py

@ -0,0 +1,39 @@
'''
Created on Jan 26, 2014
@author: Chris
'''
import time
import threading
from multiprocessing import Process
class MyClass(threading.Thread):
'''
classdocs
'''
def __init__(self):
threading.Thread.__init__(self)
self.start_time = time.time()
def run(self):
while time.time() - self.start_time < 10:
pass
def throw_exception(self):
raise KeyboardInterrupt
if __name__ == '__main__':
a = MyClass()
a.start()
time.sleep(2)
a.exit()
time.sleep(2)
print a.is_alive()
a.join()

4
src/languages/eng.py

@ -17,8 +17,8 @@ if __name__ == '__main__':
'optional_args_msg':'Optional Arguments',
'running':'Running',
"sure_you_want_to_exit":"Are you sure you want to exit?",
'close_program': 'Close Program?'
'close_program': 'Close Program?',
'status':'Status'
}
with open('english.json', 'wb') as f:

5
src/languages/english.json

@ -1,9 +1,12 @@
{
"cancel": "Cancel",
"close_program": "Close Program?",
"next": "Next",
"optional_args_msg": "Optional Arguments",
"required_args_msg": "Required Arguments",
"running": "Running",
"settings": "Settings",
"simple_config": "Enter Command Line Arguments"
"simple_config": "Enter Command Line Arguments",
"status": "Status",
"sure_you_want_to_exit": "Are you sure you want to exit?"
}
Loading…
Cancel
Save