Browse Source

added custom imports for wx 3/4 compatibility

wxpy3
chriskiehl 7 years ago
parent
commit
2289abfc4a
6 changed files with 118 additions and 46 deletions
  1. 39
      gooey/gui/imageutil.py
  2. 47
      gooey/gui/three_to_four.py
  3. 65
      gooey/gui/util/wx_util.py
  4. 5
      gooey/gui/widgets/calender_dialog.py
  5. 4
      gooey/gui/windows/runtime_display_panel.py
  6. 4
      setup.py

39
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

47
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)

65
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

5
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)

4
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):

4
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 = [

Loading…
Cancel
Save