diff --git a/gooey/gui/imageutil.py b/gooey/gui/imageutil.py index 9e46568..a4375e1 100644 --- a/gooey/gui/imageutil.py +++ b/gooey/gui/imageutil.py @@ -3,31 +3,34 @@ Created on Jan 20, 2014 @author: Chris ''' + import wx +from gooey.gui.three_to_four import imageFromBitmap, bitmapFromImage + + def _load_image(image_path): - try: - return wx.Bitmap(image_path) - except: - raise IOError('Invalid 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 89 pixels (the - size of the top panel), while keeping aspect ratio - in tact - ''' - image = _bitmap.ConvertToImage() - _width, _height = image.GetSize() - if _height < target_height: - return wx.StaticBitmap(parent, -1, wx.Bitmap(image)) - ratio = float(_width) / _height - image = image.Scale(target_height * ratio, target_height, wx.IMAGE_QUALITY_HIGH) - return wx.StaticBitmap(parent, -1, wx.Bitmap(image)) - + ''' + Resizes a bitmap to a height of 89 pixels (the + size of the top panel), while keeping aspect ratio + in tact + ''' + image = imageFromBitmap(_bitmap) + _width, _height = image.GetSize() + if _height < target_height: + return wx.StaticBitmap(parent, -1, bitmapFromImage(image)) + ratio = float(_width) / _height + image = image.Scale(target_height * ratio, target_height, wx.IMAGE_QUALITY_HIGH) + return wx.StaticBitmap(parent, -1, bitmapFromImage(image)) if __name__ == '__main__': - pass + pass diff --git a/gooey/gui/three_to_four.py b/gooey/gui/three_to_four.py new file mode 100644 index 0000000..33dbfe2 --- /dev/null +++ b/gooey/gui/three_to_four.py @@ -0,0 +1,47 @@ +''' +Util for supporting WxPython 3 & 4 +''' + +import wx +try: + import wx.adv +except ImportError: + pass + +isLatestVersion = wx.version().startswith('4') + + +class Constants: + if isLatestVersion: + WX_FONTSTYLE_NORMAL = wx.FONTSTYLE_NORMAL + WX_DP_DROPDOWN = wx.adv.DP_DROPDOWN + else: + WX_FONTSTYLE_NORMAL = wx.FONTWEIGHT_NORMAL + WX_DP_DROPDOWN = wx.DP_DROPDOWN + + +class Classes: + if isLatestVersion: + DatePickerCtrl = wx.adv.DatePickerCtrl + else: + DatePickerCtrl = wx.DatePickerCtrl + + + + +def imageFromBitmap(bitmap): + if isLatestVersion: + return bitmap.ConvertToImage() + else: + return wx.ImageFromBitmap(bitmap) + + +def bitmapFromImage(image): + if isLatestVersion: + return wx.Bitmap(image) + else: + return wx.BitmapFromImage(image) + + + + diff --git a/gooey/gui/util/wx_util.py b/gooey/gui/util/wx_util.py index 327bada..1b8184b 100644 --- a/gooey/gui/util/wx_util.py +++ b/gooey/gui/util/wx_util.py @@ -4,46 +4,61 @@ Collection of Utility methods for creating often used, pre-styled wx Widgets import wx +from gooey.gui.three_to_four import Constants + + +styles = { + 'h0': (wx.FONTFAMILY_DEFAULT, Constants.WX_FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False), + 'h1': (wx.FONTFAMILY_DEFAULT, Constants.WX_FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False), + 'h2': (wx.FONTFAMILY_DEFAULT, Constants.WX_FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False), + 'bold': (wx.FONTFAMILY_DEFAULT, Constants.WX_FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False) +} + def make_bold(statictext): - pointsize = statictext.GetFont().GetPointSize() - font = wx.Font(pointsize, wx.FONTFAMILY_DEFAULT, - wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False) - statictext.SetFont(font) + pointsize = statictext.GetFont().GetPointSize() + font = wx.Font(pointsize, *styles['bold']) + statictext.SetFont(font) + def dark_grey(statictext): - darkgray = (54, 54, 54) - statictext.SetForegroundColour(darkgray) + darkgray = (54, 54, 54) + statictext.SetForegroundColour(darkgray) + def h0(parent, label): - text = wx.StaticText(parent, label=label) - font_size = text.GetFont().GetPointSize() - font = wx.Font(font_size * 1.4, *(wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False)) - text.SetFont(font) - return text + text = wx.StaticText(parent, label=label) + font_size = text.GetFont().GetPointSize() + font = wx.Font(font_size * 1.4, *styles['h0']) + text.SetFont(font) + return text + def h1(parent, label): - return _header(parent, label, (wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False)) + return _header(parent, label, styles['h1']) + def h2(parent, label): - return _header(parent, label, (wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False)) + return _header(parent, label, styles['h2']) + def _header(parent, label, styles): - text = wx.StaticText(parent, label=label) - font_size = text.GetFont().GetPointSize() - font = wx.Font(font_size * 1.2, *styles) - text.SetFont(font) - return text + text = wx.StaticText(parent, label=label) + font_size = text.GetFont().GetPointSize() + font = wx.Font(font_size * 1.2, *styles) + text.SetFont(font) + return text + def horizontal_rule(parent): - return _rule(parent, wx.LI_HORIZONTAL) + return _rule(parent, wx.LI_HORIZONTAL) -def vertical_rule(parent): - return _rule(parent, wx.LI_VERTICAL) -def _rule(parent, direction): - line = wx.StaticLine(parent, -1, style=direction) - line.SetSize((10, 10)) - return line +def vertical_rule(parent): + return _rule(parent, wx.LI_VERTICAL) +def _rule(parent, direction): + line = wx.StaticLine(parent, -1, style=direction) + line.SetSize((10, 10)) + return line diff --git a/gooey/gui/widgets/calender_dialog.py b/gooey/gui/widgets/calender_dialog.py index 40509cc..4b98161 100644 --- a/gooey/gui/widgets/calender_dialog.py +++ b/gooey/gui/widgets/calender_dialog.py @@ -1,10 +1,11 @@ __author__ = 'Chris' import wx -import wx.adv from gooey.gui.util import wx_util +from gooey.gui.three_to_four import Classes, Constants + class CalendarDlg(wx.Dialog): def __init__(self, parent): @@ -13,7 +14,7 @@ class CalendarDlg(wx.Dialog): self.SetBackgroundColour('#ffffff') self.ok_button = wx.Button(self, wx.ID_OK, label='Ok') - self.datepicker = wx.adv.DatePickerCtrl(self, style=wx.adv.DP_DROPDOWN) + self.datepicker = Classes.DatePickerCtrl(self, style=Constants.WX_DP_DROPDOWN) vertical_container = wx.BoxSizer(wx.VERTICAL) vertical_container.AddSpacer(10) diff --git a/gooey/gui/windows/runtime_display_panel.py b/gooey/gui/windows/runtime_display_panel.py index c3a8292..b3c1444 100644 --- a/gooey/gui/windows/runtime_display_panel.py +++ b/gooey/gui/windows/runtime_display_panel.py @@ -7,6 +7,8 @@ Created on Dec 23, 2013 import wx from gooey.gui.lang import i18n +from gooey.gui.three_to_four import Constants + class RuntimeDisplay(wx.Panel): ''' @@ -22,7 +24,7 @@ class RuntimeDisplay(wx.Panel): def set_font_style(self, style): pointsize = self.cmd_textbox.GetFont().GetPointSize() font = wx.Font(pointsize, style, - wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False) + Constants.WX_FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False) self.cmd_textbox.SetFont(font) def _init_properties(self): diff --git a/setup.py b/setup.py index dcbd229..3a499f5 100644 --- a/setup.py +++ b/setup.py @@ -18,6 +18,10 @@ setup( 'application with one line'), license='MIT', packages=find_packages(), + install_requires=[ + 'wxpython==5.7', + 'Rx==1.5.9' + ], include_package_data=True, dependency_links = ["http://www.wxpython.org/download.php"], classifiers = [