Browse Source

moved image resizing funtion into own module. Changed header and footer to support 'pages' and updated their images

pull/1/head
Chris Kiehl 10 years ago
parent
commit
f6b4645013
12 changed files with 158 additions and 83 deletions
  1. 7
      src/app/dialogs/controller.py
  2. 51
      src/app/dialogs/footer.py
  3. BIN
      src/app/dialogs/footer.pyc
  4. 86
      src/app/dialogs/header.py
  5. BIN
      src/app/dialogs/header.pyc
  6. 43
      src/app/dialogs/imageutil.py
  7. 2
      src/app/images/__init__.py
  8. BIN
      src/app/images/__init__.pyc
  9. 1
      src/app/images/image_store.py
  10. BIN
      src/app/images/image_store.pyc
  11. BIN
      src/app/images/loader.gif
  12. 51
      src/experiments/command.py

7
src/app/dialogs/controller.py

@ -62,13 +62,16 @@ class Controller(object):
self._base.NextPage()
self._payload_runner()
def OnCancelRunButton(self, event):
pass
def OnCloseButton(self, event):
self._base.Destroy()
sys.exit()
def RunClientCode(self):
pool = Pool(1)
try:
pool.apply(self._base._payload)
self._head.NextPage()
self._foot.NextPage()
self.ShowGoodFinishedDialog()
except:
self.ShowBadFinishedDialog(traceback.format_exc())

51
src/app/dialogs/footer.py

@ -5,6 +5,8 @@ Created on Dec 23, 2013
'''
import wx
import wx.animate
import imageutil
from app.images import image_store
class AbstractFooter(wx.Panel):
@ -18,8 +20,10 @@ class AbstractFooter(wx.Panel):
self._controller = None
self._init_components()
self._init_pages()
self._do_layout()
def _init_components(self):
'''
initialize all of the components used in the footer
@ -30,10 +34,24 @@ class AbstractFooter(wx.Panel):
'''
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)
# _bitmap = wx.Bitmap(image_store.alessandro_rei_checkmark)
# wx.StaticBitmap(self, -1, _bitmap)
self.running_animation = wx.animate.GIFAnimationCtrl(self, -1, image_store.loader)
self.close_button = self._Button("Close", wx.ID_OK)
def _init_pages(self):
_pages = [[
self.cancel_button.Hide,
self.start_button.Hide,
self.running_animation.Show,
self.running_animation.Play,
self.Layout
],
[
self.running_animation.Stop,
self.running_animation.Hide,
self.close_button.Show,
self.Layout
]]
self._pages = iter(_pages)
def _do_layout(self):
v_sizer = wx.BoxSizer(wx.VERTICAL)
@ -45,8 +63,10 @@ class AbstractFooter(wx.Panel):
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.Add(self.running_animation, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.RIGHT, 20)
self.running_animation.Hide()
v_sizer.Add(self.close_button, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.RIGHT, 20)
self.close_button.Hide()
v_sizer.AddStretchSpacer(1)
self.SetSizer(v_sizer)
@ -63,10 +83,15 @@ class AbstractFooter(wx.Panel):
self._controller = controller
def NextPage(self):
self.cancel_button.Hide()
self.start_button.Hide()
# self.cancel_run_button.Show()
self.Layout()
page = next(self._pages)
for action in page:
action()
def _load_image(self, img_path, height=70):
return imageutil._resize_bitmap(
self,
imageutil._load_image(img_path),
height)
class Footer(AbstractFooter):
@ -84,14 +109,14 @@ class Footer(AbstractFooter):
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)
self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.close_button)
def OnCancelButton(self, event):
self._controller.OnCancelButton(event)
event.Skip()
def OnCancelRunButton(self, event):
self._controller.OnCancelRunButton(event)
def OnCloseButton(self, event):
self._controller.OnCloseButton(event)
event.Skip()
def OnStartButton(self, event):

BIN
src/app/dialogs/footer.pyc

86
src/app/dialogs/header.py

@ -5,9 +5,11 @@ Created on Dec 23, 2013
'''
import wx
import itertools
import imageutil
from app.images import image_store
PAD_SIZE = 10
class FrameHeader(wx.Panel):
@ -25,6 +27,7 @@ class FrameHeader(wx.Panel):
self._init_properties()
self._init_components(heading, subheading, image_path)
self._init_pages()
self._do_layout()
@ -35,8 +38,10 @@ class FrameHeader(wx.Panel):
def _init_components(self, heading, subheading, 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)
self._settings_img = self._load_image(image_path, height=79)
self._running_img = self._load_image(image_store.computer3, 79)
self._check_mark = self._load_image(image_store.alessandro_rei_checkmark, height=75)
def _do_layout(self):
vsizer = wx.BoxSizer(wx.VERTICAL)
@ -45,7 +50,9 @@ class FrameHeader(wx.Panel):
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()
sizer.Add(self._check_mark, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, PAD_SIZE)
self._running_img.Hide()
self._check_mark.Hide()
vsizer.Add(sizer, 1, wx.EXPAND)
self.SetSizer(vsizer)
@ -56,6 +63,11 @@ class FrameHeader(wx.Panel):
wx.FONTWEIGHT_NORMAL, wx.FONTWEIGHT_BOLD, False)
)
return txt
def _load_image(self, img_path, height=70):
return imageutil._resize_bitmap(self,
imageutil._load_image(img_path),
height)
def build_heading_sizer(self):
sizer = wx.BoxSizer(wx.VERTICAL)
@ -65,42 +77,48 @@ class FrameHeader(wx.Panel):
sizer.AddStretchSpacer(1)
return sizer
def _load_image(self, image_path):
try:
bitmap = wx.Bitmap(image_path)
print bitmap
bitmap = self._resize_bitmap(bitmap)
return wx.StaticBitmap(self, -1, bitmap)
except:
raise IOError('Invalid Image path')
def _resize_bitmap(self, bmap):
'''
Resizes a bitmap to a height of 89 pixels (the
size of the top panel), while keeping aspect ratio
in tact
'''
image = wx.ImageFromBitmap(bmap)
width, height = image.GetSize()
ratio = float(width) / height
target_height = 79
image = image.Scale(target_height * ratio, target_height,
wx.IMAGE_QUALITY_HIGH
)
return wx.BitmapFromImage(image)
def RegisterController(self, controller):
if self._controller is None:
self._controller = controller
def _init_pages(self):
messages = [[
"Running",
'Please wait while the application performs its tasks. ' +
'\nThis may take a few moments'
],[
'Finished',
'All done! You may now safely close the program.'
]]
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):
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()
messages = next(self._messages)
commands = next(self._pages)
_zipl = itertools.izip_longest
for func, arg in _zipl(commands, messages, fillvalue=None):
if arg:
func(arg)
else:
func()

BIN
src/app/dialogs/header.pyc

43
src/app/dialogs/imageutil.py

@ -8,20 +8,30 @@ from PIL import Image # @UnresolvedImport
from app.images import image_store
def LoadAndResizeImage(path):
im = Image.open(path)
return PilImageToWxImage(_Resize(im))
def _Resize(pil_image):
def _load_image(image_path):
try:
return wx.Bitmap(image_path)
except:
raise IOError('Invalid Image path')
def _resize_bitmap(parent, _bitmap, target_height):
'''
Resizes a bitmap to a height of 79 pixels (the
size of the top panel -1), while keeping aspect ratio
Resizes a bitmap to a height of 89 pixels (the
size of the top panel), while keeping aspect ratio
in tact
'''
target_size = _GetTargetSize(pil_image.size)
return pil_image.resize(target_size)
image = wx.ImageFromBitmap(_bitmap)
_width, _height = image.GetSize()
if _height < target_height:
print 'returning image without resizing'
return wx.StaticBitmap(parent, -1, wx.BitmapFromImage(image))
print 'returning resized image'
ratio = float(_width) / _height
image = image.Scale(target_height * ratio, target_height,
wx.IMAGE_QUALITY_HIGH
)
return wx.StaticBitmap(parent, -1, wx.BitmapFromImage(image))
def _GetTargetSize(size):
width, height = size
aspect_ratio = float(width)/height
@ -29,17 +39,8 @@ def _GetTargetSize(size):
tWidth = int(tHeight * aspect_ratio)
return (tWidth, tHeight)
def PilImageToWxImage(p_image):
wx_image = wx.EmptyImage(*p_image.size)
wx_image.SetData(p_image.convert( 'RGB' ).tostring())
return wx_image.ConvertToBitmap()
if __name__ == '__main__':
app = wx.App()
print 'adsfasdf',LoadAndResizeImage(image_store.computer)
print 'asdfadf'
app.MainLoop()
pass

2
src/app/images/__init__.py

@ -31,7 +31,7 @@ def load_imagepaths():
file_extension = lambda x: os.path.splitext(x)[-1]
return [os.path.join(PATH, f) for f in os.listdir(PATH)
if file_extension(f) in ('.jpeg','.png', '.ico')]
if file_extension(f) in ('.jpeg','.png', '.ico', '.gif')]

BIN
src/app/images/__init__.pyc

1
src/app/images/image_store.py

@ -13,6 +13,7 @@ computer2 = r"C:\Users\Chris\Dropbox\pretty_gui\Gooey\src\app\images\computer2.p
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"
loader = r"C:\Users\Chris\Dropbox\pretty_gui\Gooey\src\app\images\loader.gif"
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"
terminal = r"C:\Users\Chris\Dropbox\pretty_gui\Gooey\src\app\images\terminal.png"

BIN
src/app/images/image_store.pyc

BIN
src/app/images/loader.gif

Before After
Width: 220  |  Height: 19  |  Size: 11 KiB

51
src/experiments/command.py

@ -7,23 +7,50 @@ Created on Jan 7, 2014
import sys
import time
from itertools import izip_longest
def doo(x):
print x
def foo(x):
print x
def zoo():
print 'zoo'
def coo():
print 'coo'
msgs = [[
'msg1',
'msg2'
],[
'msg3',
'msg4'
]]
commands = [[
doo,
foo,
zoo,
coo
],[
doo,
foo,
zoo,
coo
]]
_msgs = iter(msgs)
_cmds = iter(commands)
for i in izip_longest(next(_msgs), next(_cmds), fillvalue=None):
print i
from multiprocessing.dummy import Process, Pool
def myFunc():
time.sleep(2)
print 'whoo!'
raise ValueError("Graaaaaaahhhhh")
if __name__ == '__main__':
pool = Pool(1)
try:
pool.apply(myFunc)
except:
print 'Yo, shit is broken, son!'
Loading…
Cancel
Save