# This file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Printrun is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Printrun. If not, see .
import xml.etree.ElementTree
import wx
import time
def parsesvg(name):
et= xml.etree.ElementTree.ElementTree(file=name)
zlast=0
zdiff=0
ol=[]
for i in et.findall("{http://www.w3.org/2000/svg}g")[0].findall("{http://www.w3.org/2000/svg}g"):
z=float(i.get('id').split("z:")[-1])
zdiff=z-zlast
zlast=z
path=i.find('{http://www.w3.org/2000/svg}path')
ol+=[(path.get("d").split("z"))[:-1]]
return ol,zdiff
class dispframe(wx.Frame):
def __init__(self, parent, title, res=(1600,1200),printer=None):
wx.Frame.__init__(self, parent=parent, title=title)
self.p=printer
self.pic=wx.StaticBitmap(self)
self.bitmap=wx.EmptyBitmap(*res)
self.bbitmap=wx.EmptyBitmap(*res)
dc=wx.MemoryDC()
dc.SelectObject(self.bbitmap)
dc.SetBackground(wx.Brush("black"))
dc.Clear()
dc.SelectObject(wx.NullBitmap)
self.SetBackgroundColour("black")
self.pic.Hide()
self.pen=wx.Pen("white")
self.brush=wx.Brush("white")
self.SetDoubleBuffered(True)
self.Show()
def drawlayer(self,svg):
try:
dc=wx.MemoryDC()
dc.SelectObject(self.bitmap)
dc.SetBackground(wx.Brush("black"))
dc.Clear()
dc.SetPen(self.pen)
dc.SetBrush(self.brush)
for i in svg:
#print i
points=[wx.Point(*map(lambda x:int(round(float(x)*self.scale)),j.strip().split())) for j in i.strip().split("M")[1].split("L")]
dc.DrawPolygon(points,self.size[0]/2,self.size[1]/2)
dc.SelectObject(wx.NullBitmap)
self.pic.SetBitmap(self.bitmap)
self.pic.Show()
self.Refresh()
#self.pic.SetBitmap(self.bitmap)
except:
raise
pass
def showimgdelay(self,image):
self.drawlayer(image)
self.pic.Show()
self.Refresh()
# time.sleep(self.interval)
#self.pic.Hide()
self.Refresh()
if self.p!=None and self.p.online:
self.p.send_now("G91")
self.p.send_now("G1 Z%f F300"%(self.thickness,))
self.p.send_now("G90")
def nextimg(self,event):
#print "b"
if self.index