Skip to content
Permalink
Browse files

Add ability to select some other SVG file to view

  • Loading branch information...
RobinD42 committed Sep 11, 2019
1 parent 41bb70c commit 9e45e484dde1416b03493327c09b882d74d3ae8d
Showing with 40 additions and 8 deletions.
  1. +20 −4 demo/SVGImage_Bitmap.py
  2. +20 −4 demo/SVGImage_Render.py
@@ -28,14 +28,16 @@ def UpdateSVG(self, svg_filename):




#---------------------------------------------------------------------- #----------------------------------------------------------------------
ADD_NEW = '[Double-click to Add New File]'


class TestPanel(wx.Panel): class TestPanel(wx.Panel):
def __init__(self, parent, log): def __init__(self, parent, log):
self.log = log self.log = log
wx.Panel.__init__(self, parent, -1) wx.Panel.__init__(self, parent, -1)


self.listbox = wx.ListBox(self, style=wx.LB_SINGLE, size=(250, -1)) self.listbox = wx.ListBox(self, style=wx.LB_SINGLE, size=(250, -1))
self.listbox.AppendItems(glob.glob(os.path.join('data', '*.svg'))) self.listbox.Append(ADD_NEW)
self.listbox.Append(glob.glob(os.path.join('data', '*.svg')))


self.updateables = [] self.updateables = []
rightSizer = wx.BoxSizer(wx.VERTICAL) rightSizer = wx.BoxSizer(wx.VERTICAL)
@@ -59,15 +61,29 @@ def __init__(self, parent, log):
self.Sizer.Add(rightSizer, wx.SizerFlags(2).Border(wx.RIGHT|wx.BOTTOM|wx.TOP, 10).Expand()) self.Sizer.Add(rightSizer, wx.SizerFlags(2).Border(wx.RIGHT|wx.BOTTOM|wx.TOP, 10).Expand())


self.Bind(wx.EVT_LISTBOX, self.OnSelectItem) self.Bind(wx.EVT_LISTBOX, self.OnSelectItem)
self.listbox.SetSelection(0) self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnDClickItem)

self.listbox.SetSelection(1)


# Load the first SVG in the list into the static bitmaps # Load the first SVG in the list into the static bitmaps
self.UpdateAll(self.listbox.GetString(0)) self.UpdateAll(self.listbox.GetString(1))




def OnSelectItem(self, evt): def OnSelectItem(self, evt):
filename = self.listbox.GetStringSelection() filename = self.listbox.GetStringSelection()
self.UpdateAll(filename) if filename != ADD_NEW:
self.UpdateAll(filename)


def OnDClickItem(self, evt):
if self.listbox.GetSelection() == 0:
with wx.FileDialog(self, "Select SVG file", "data",
wildcard="SVG files (*.svg)|*.svg",
style=wx.FD_OPEN) as dlg:
if dlg.ShowModal() == wx.ID_OK:
self.listbox.Insert(dlg.GetPath(), 1)
self.listbox.SetSelection(1)
self.UpdateAll(self.listbox.GetString(1))




def UpdateAll(self, svg_filename): def UpdateAll(self, svg_filename):
@@ -48,14 +48,16 @@ def OnPaint(self, event):




#---------------------------------------------------------------------- #----------------------------------------------------------------------
ADD_NEW = '[Double-click to Add New File]'


class TestPanel(wx.Panel): class TestPanel(wx.Panel):
def __init__(self, parent, log): def __init__(self, parent, log):
self.log = log self.log = log
wx.Panel.__init__(self, parent, -1) wx.Panel.__init__(self, parent, -1)


self.listbox = wx.ListBox(self, style=wx.LB_SINGLE, size=(250, -1)) self.listbox = wx.ListBox(self, style=wx.LB_SINGLE, size=(250, -1))
self.listbox.AppendItems(glob.glob(os.path.join('data', '*.svg'))) self.listbox.Append(ADD_NEW)
self.listbox.Append(glob.glob(os.path.join('data', '*.svg')))


self.renderPanel = SVGRenderPanel(self) self.renderPanel = SVGRenderPanel(self)
rightSizer = wx.BoxSizer(wx.VERTICAL) rightSizer = wx.BoxSizer(wx.VERTICAL)
@@ -66,7 +68,9 @@ def __init__(self, parent, log):
self.Sizer.Add(rightSizer, wx.SizerFlags(2).Border(wx.RIGHT|wx.BOTTOM|wx.TOP, 10).Expand()) self.Sizer.Add(rightSizer, wx.SizerFlags(2).Border(wx.RIGHT|wx.BOTTOM|wx.TOP, 10).Expand())


self.Bind(wx.EVT_LISTBOX, self.OnSelectItem) self.Bind(wx.EVT_LISTBOX, self.OnSelectItem)
self.listbox.SetSelection(0) self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnDClickItem)

self.listbox.SetSelection(1)


# TODO: Add ability for the user to select the renderer # TODO: Add ability for the user to select the renderer
if 'wxMSW' in wx.PlatformInfo: if 'wxMSW' in wx.PlatformInfo:
@@ -77,12 +81,24 @@ def __init__(self, parent, log):
self.renderPanel.SetRenderer(renderer) self.renderPanel.SetRenderer(renderer)


# Load the first SVG in the list into the static bitmaps # Load the first SVG in the list into the static bitmaps
self.renderPanel.SetSVGFile(self.listbox.GetString(0)) self.renderPanel.SetSVGFile(self.listbox.GetString(1))




def OnSelectItem(self, evt): def OnSelectItem(self, evt):
filename = self.listbox.GetStringSelection() filename = self.listbox.GetStringSelection()
self.renderPanel.SetSVGFile(filename) if filename != ADD_NEW:
self.renderPanel.SetSVGFile(filename)


def OnDClickItem(self, evt):
if self.listbox.GetSelection() == 0:
with wx.FileDialog(self, "Select SVG file", "data",
wildcard="SVG files (*.svg)|*.svg",
style=wx.FD_OPEN) as dlg:
if dlg.ShowModal() == wx.ID_OK:
self.listbox.Insert(dlg.GetPath(), 1)
self.listbox.SetSelection(1)
self.renderPanel.SetSVGFile(self.listbox.GetString(1))




#---------------------------------------------------------------------- #----------------------------------------------------------------------

0 comments on commit 9e45e48

Please sign in to comment.
You can’t perform that action at this time.