Commit 77eb2440 authored by Guillaume Seguin's avatar Guillaume Seguin

Semi-automated coding style cleanup

parent cbd8cc06
Some cleanup commands :
To add a space after each comma :
sed -e "s/\(\w\),\(\w\)/\1, \2/g" -i *.py printrun/*.py printrun/svg/*.py
To add spaces around each = :
sed -e "s/\(\w\)=\(\w\)/\1 = \2/g" -i *.py printrun/*.py printrun/svg/*.py
sed -e "s/\(\w\)=\(\"\)/\1 = \2/g" -i *.py printrun/*.py printrun/svg/*.py
sed -e "s/\(\w\)=\((\)/\1 = \2/g" -i *.py printrun/*.py printrun/svg/*.py
To add spaces around each == :
sed -e "s/\(\w\)==\(\w\)/\1 == \2/g" -i *.py printrun/*.py printrun/svg/*.py
sed -e "s/\(\w\)==\(\"\)/\1 == \2/g" -i *.py printrun/*.py printrun/svg/*.py
sed -e "s/\(\w\)==\((\)/\1 == \2/g" -i *.py printrun/*.py printrun/svg/*.py
sed -e "s/\()\)==\(\w\)/\1 == \2/g" -i *.py printrun/*.py printrun/svg/*.py
sed -e "s/\()\)==\((\)/\1 == \2/g" -i *.py printrun/*.py printrun/svg/*.py
Obviously this is not a perfect solution, it WILL break the code. Juste check the diff and fix what's wrong before commiting.
...@@ -46,7 +46,7 @@ def evalme(s): ...@@ -46,7 +46,7 @@ def evalme(s):
class stlwrap: class stlwrap:
def __init__(self, obj, name=None): def __init__(self, obj, name = None):
self.obj = obj self.obj = obj
self.name = name self.name = name
if name is None: if name is None:
...@@ -58,7 +58,7 @@ class stlwrap: ...@@ -58,7 +58,7 @@ class stlwrap:
class showstl(wx.Window): class showstl(wx.Window):
def __init__(self, parent, size, pos): def __init__(self, parent, size, pos):
wx.Window.__init__(self, parent, size=size, pos=pos) wx.Window.__init__(self, parent, size = size, pos = pos)
#self.SetBackgroundColour((0, 0, 0)) #self.SetBackgroundColour((0, 0, 0))
#wx.FutureCall(200, self.paint) #wx.FutureCall(200, self.paint)
self.i = 0 self.i = 0
...@@ -141,7 +141,7 @@ class showstl(wx.Window): ...@@ -141,7 +141,7 @@ class showstl(wx.Window):
self.i += angle self.i += angle
if not self.triggered: if not self.triggered:
self.triggered = 1 self.triggered = 1
threading.Thread(target=self.cr).start() threading.Thread(target = self.cr).start()
def keypress(self, event): def keypress(self, event):
"""gets keypress events and moves/rotates acive shape""" """gets keypress events and moves/rotates acive shape"""
...@@ -200,9 +200,9 @@ class showstl(wx.Window): ...@@ -200,9 +200,9 @@ class showstl(wx.Window):
def repaint(self, event): def repaint(self, event):
dc = wx.PaintDC(self) dc = wx.PaintDC(self)
self.paint(dc=dc) self.paint(dc = dc)
def paint(self, coord1="x", coord2="y", dc=None): def paint(self, coord1 = "x", coord2 = "y", dc = None):
coords = {"x": 0, "y": 1, "z": 2} coords = {"x": 0, "y": 1, "z": 2}
if dc is None: if dc is None:
dc = wx.ClientDC(self) dc = wx.ClientDC(self)
...@@ -231,7 +231,7 @@ class showstl(wx.Window): ...@@ -231,7 +231,7 @@ class showstl(wx.Window):
bm = wx.BitmapFromImage(im) bm = wx.BitmapFromImage(im)
dcs.SelectObject(bm) dcs.SelectObject(bm)
bsz = bm.GetSize() bsz = bm.GetSize()
dc.Blit(scale * m.offsets[0] - bsz[0] / 2, 400 - (scale * m.offsets[1] + bsz[1] / 2), bsz[0], bsz[1], dcs, 0, 0, useMask=1) dc.Blit(scale * m.offsets[0] - bsz[0] / 2, 400 - (scale * m.offsets[1] + bsz[1] / 2), bsz[0], bsz[1], dcs, 0, 0, useMask = 1)
#for i in m.facets:#random.sample(m.facets, min(100000, len(m.facets))): #for i in m.facets:#random.sample(m.facets, min(100000, len(m.facets))):
# dc.DrawPolygon([wx.Point(offset[0]+scale*m.offsets[0]+scale*p[0], 400-(offset[1]+scale*m.offsets[1]+scale*p[1])) for p in i[1]]) # dc.DrawPolygon([wx.Point(offset[0]+scale*m.offsets[0]+scale*p[0], 400-(offset[1]+scale*m.offsets[1]+scale*p[1])) for p in i[1]])
#if(time.time()-t)>5: #if(time.time()-t)>5:
...@@ -242,29 +242,29 @@ class showstl(wx.Window): ...@@ -242,29 +242,29 @@ class showstl(wx.Window):
class stlwin(wx.Frame): class stlwin(wx.Frame):
def __init__(self, size=(800, 580), callback=None, parent=None): def __init__(self, size = (800, 580), callback = None, parent = None):
wx.Frame.__init__(self, parent, title=_("Plate building tool"), size=size) wx.Frame.__init__(self, parent, title = _("Plate building tool"), size = size)
self.SetIcon(wx.Icon(pixmapfile("plater.ico"), wx.BITMAP_TYPE_ICO)) self.SetIcon(wx.Icon(pixmapfile("plater.ico"), wx.BITMAP_TYPE_ICO))
self.mainsizer = wx.BoxSizer(wx.HORIZONTAL) self.mainsizer = wx.BoxSizer(wx.HORIZONTAL)
self.panel = wx.Panel(self, -1, size=(150, 600), pos=(0, 0)) self.panel = wx.Panel(self, -1, size = (150, 600), pos = (0, 0))
#self.panel.SetBackgroundColour((10, 10, 10)) #self.panel.SetBackgroundColour((10, 10, 10))
self.l = wx.ListBox(self.panel, size=(300, 180), pos=(0, 30)) self.l = wx.ListBox(self.panel, size = (300, 180), pos = (0, 30))
self.cl = wx.Button(self.panel, label=_("Clear"), pos=(0, 205)) self.cl = wx.Button(self.panel, label = _("Clear"), pos = (0, 205))
self.lb = wx.Button(self.panel, label=_("Load"), pos=(0, 0)) self.lb = wx.Button(self.panel, label = _("Load"), pos = (0, 0))
if(callback is None): if(callback is None):
self.eb = wx.Button(self.panel, label=_("Export"), pos=(100, 0)) self.eb = wx.Button(self.panel, label = _("Export"), pos = (100, 0))
self.eb.Bind(wx.EVT_BUTTON, self.export) self.eb.Bind(wx.EVT_BUTTON, self.export)
else: else:
self.eb = wx.Button(self.panel, label=_("Export"), pos=(200, 205)) self.eb = wx.Button(self.panel, label = _("Export"), pos = (200, 205))
self.eb.Bind(wx.EVT_BUTTON, self.export) self.eb.Bind(wx.EVT_BUTTON, self.export)
self.edb = wx.Button(self.panel, label=_("Done"), pos=(100, 0)) self.edb = wx.Button(self.panel, label = _("Done"), pos = (100, 0))
self.edb.Bind(wx.EVT_BUTTON, lambda e: self.done(e, callback)) self.edb.Bind(wx.EVT_BUTTON, lambda e: self.done(e, callback))
self.eb = wx.Button(self.panel, label=_("Cancel"), pos=(200, 0)) self.eb = wx.Button(self.panel, label = _("Cancel"), pos = (200, 0))
self.eb.Bind(wx.EVT_BUTTON, lambda e: self.Destroy()) self.eb.Bind(wx.EVT_BUTTON, lambda e: self.Destroy())
self.sb = wx.Button(self.panel, label=_("Snap to Z = 0"), pos=(00, 255)) self.sb = wx.Button(self.panel, label = _("Snap to Z = 0"), pos = (00, 255))
self.cb = wx.Button(self.panel, label=_("Put at 100, 100"), pos=(0, 280)) self.cb = wx.Button(self.panel, label = _("Put at 100, 100"), pos = (0, 280))
self.db = wx.Button(self.panel, label=_("Delete"), pos=(0, 305)) self.db = wx.Button(self.panel, label = _("Delete"), pos = (0, 305))
self.ab = wx.Button(self.panel, label=_("Auto"), pos=(0, 330)) self.ab = wx.Button(self.panel, label = _("Auto"), pos = (0, 330))
self.cl.Bind(wx.EVT_BUTTON, self.clear) self.cl.Bind(wx.EVT_BUTTON, self.clear)
self.lb.Bind(wx.EVT_BUTTON, self.right) self.lb.Bind(wx.EVT_BUTTON, self.right)
self.sb.Bind(wx.EVT_BUTTON, self.snap) self.sb.Bind(wx.EVT_BUTTON, self.snap)
...@@ -368,7 +368,7 @@ class stlwin(wx.Frame): ...@@ -368,7 +368,7 @@ class stlwin(wx.Frame):
self.Destroy() self.Destroy()
def export(self, event): def export(self, event):
dlg = wx.FileDialog(self, _("Pick file to save to"), self.basedir, style=wx.FD_SAVE) dlg = wx.FileDialog(self, _("Pick file to save to"), self.basedir, style = wx.FD_SAVE)
dlg.SetWildcard(_("STL files (;*.stl;*.STL;)")) dlg.SetWildcard(_("STL files (;*.stl;*.STL;)"))
if(dlg.ShowModal() == wx.ID_OK): if(dlg.ShowModal() == wx.ID_OK):
name = dlg.GetPath() name = dlg.GetPath()
...@@ -393,7 +393,7 @@ class stlwin(wx.Frame): ...@@ -393,7 +393,7 @@ class stlwin(wx.Frame):
print _("wrote %s") % name print _("wrote %s") % name
def right(self, event): def right(self, event):
dlg = wx.FileDialog(self, _("Pick file to load"), self.basedir, style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) dlg = wx.FileDialog(self, _("Pick file to load"), self.basedir, style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
dlg.SetWildcard(_("STL files (;*.stl;*.STL;)|*.stl|OpenSCAD files (;*.scad;)|*.scad")) dlg.SetWildcard(_("STL files (;*.stl;*.STL;)|*.stl|OpenSCAD files (;*.scad;)|*.scad"))
if(dlg.ShowModal() == wx.ID_OK): if(dlg.ShowModal() == wx.ID_OK):
name = dlg.GetPath() name = dlg.GetPath()
...@@ -443,7 +443,7 @@ class stlwin(wx.Frame): ...@@ -443,7 +443,7 @@ class stlwin(wx.Frame):
self.Refresh() self.Refresh()
#print time.time()-t #print time.time()-t
def load_stl_into_model(self, path, name, offset=[0, 0, 0], rotation=0, scale=[1.0, 1.0, 1.0]): def load_stl_into_model(self, path, name, offset=[0, 0, 0], rotation = 0, scale=[1.0, 1.0, 1.0]):
newname = os.path.split(name.lower())[1] newname = os.path.split(name.lower())[1]
c = 1 c = 1
while newname in self.models: while newname in self.models:
......
...@@ -83,7 +83,7 @@ class printcore(): ...@@ -83,7 +83,7 @@ class printcore():
self.online = False self.online = False
self.printing = False self.printing = False
def connect(self,port=None,baud=None): def connect(self, port = None, baud = None):
"""Set port and baudrate if given, then connect to printer """Set port and baudrate if given, then connect to printer
""" """
if self.printer: if self.printer:
...@@ -96,7 +96,7 @@ class printcore(): ...@@ -96,7 +96,7 @@ class printcore():
disable_hup(self.port) disable_hup(self.port)
self.printer = Serial(port = self.port, baudrate = self.baud, timeout = 0.25) self.printer = Serial(port = self.port, baudrate = self.baud, timeout = 0.25)
self.stop_read_thread = False self.stop_read_thread = False
self.read_thread = Thread(target=self._listen) self.read_thread = Thread(target = self._listen)
self.read_thread.start() self.read_thread.start()
def reset(self): def reset(self):
...@@ -183,7 +183,7 @@ class printcore(): ...@@ -183,7 +183,7 @@ class printcore():
self.clear = True self.clear = True
def _checksum(self, command): def _checksum(self, command):
return reduce(lambda x,y:x^y, map(ord, command)) return reduce(lambda x, y:x^y, map(ord, command))
def startprint(self, data, startindex = 0): def startprint(self, data, startindex = 0):
"""Start a print, data is an array of gcode commands. """Start a print, data is an array of gcode commands.
...@@ -289,7 +289,7 @@ class printcore(): ...@@ -289,7 +289,7 @@ class printcore():
self.clear = True self.clear = True
return return
if self.resendfrom < self.lineno and self.resendfrom > -1: if self.resendfrom < self.lineno and self.resendfrom > -1:
self._send(self.sentlines[self.resendfrom],self.resendfrom,False) self._send(self.sentlines[self.resendfrom],self.resendfrom, False)
self.resendfrom += 1 self.resendfrom += 1
return return
self.resendfrom = -1 self.resendfrom = -1
...@@ -369,7 +369,7 @@ if __name__ == '__main__': ...@@ -369,7 +369,7 @@ if __name__ == '__main__':
try: try:
if statusreport: if statusreport:
p.loud=False p.loud = False
sys.stdout.write("Progress: 00.0%") sys.stdout.write("Progress: 00.0%")
sys.stdout.flush() sys.stdout.flush()
while p.printing: while p.printing:
......
...@@ -35,7 +35,7 @@ class SkeinforgeQuickEditDialog(wx.Dialog): ...@@ -35,7 +35,7 @@ class SkeinforgeQuickEditDialog(wx.Dialog):
'speed':['Main Feed Rate (mm/s):','Main Flow Rate (scaler):','Perimeter Feed Rate (mm/s):','Perimeter Flow Rate (scaler):','Travel Feed Rate (mm/s):'] 'speed':['Main Feed Rate (mm/s):','Main Flow Rate (scaler):','Perimeter Feed Rate (mm/s):','Perimeter Flow Rate (scaler):','Travel Feed Rate (mm/s):']
} }
self.scrollbarPanel = wx.ScrolledWindow(self, -1, style=wx.TAB_TRAVERSAL) self.scrollbarPanel = wx.ScrolledWindow(self, -1, style = wx.TAB_TRAVERSAL)
self.settingsSizer = self.getProfileSettings() self.settingsSizer = self.getProfileSettings()
self.scrollbarPanel.SetSizer(self.settingsSizer) self.scrollbarPanel.SetSizer(self.settingsSizer)
...@@ -67,7 +67,7 @@ class SkeinforgeQuickEditDialog(wx.Dialog): ...@@ -67,7 +67,7 @@ class SkeinforgeQuickEditDialog(wx.Dialog):
self.Layout() self.Layout()
def getProfileSettings(self): def getProfileSettings(self):
settingsSizer = wx.GridBagSizer(hgap=2, vgap=1) settingsSizer = wx.GridBagSizer(hgap = 2, vgap = 1)
settingsRow = 0 settingsRow = 0
for craftName in sorted(self.moduleSettingsMap.keys()): for craftName in sorted(self.moduleSettingsMap.keys()):
...@@ -86,28 +86,28 @@ class SkeinforgeQuickEditDialog(wx.Dialog): ...@@ -86,28 +86,28 @@ class SkeinforgeQuickEditDialog(wx.Dialog):
for setting in settings.getReadRepository(repo).preferences: for setting in settings.getReadRepository(repo).preferences:
if setting.name in self.moduleSettingsMap[craftName]: if setting.name in self.moduleSettingsMap[craftName]:
settingSizer = wx.GridBagSizer(hgap=2, vgap=2) settingSizer = wx.GridBagSizer(hgap = 2, vgap = 2)
settingSizer.AddGrowableCol(0) settingSizer.AddGrowableCol(0)
settingRow = 0 settingRow = 0
settingLabel = wx.StaticText(self.scrollbarPanel, -1, setting.name) settingLabel = wx.StaticText(self.scrollbarPanel, -1, setting.name)
settingLabel.Wrap(400) settingLabel.Wrap(400)
settingSizer.Add(settingLabel, pos=(settingRow, 0)) settingSizer.Add(settingLabel, pos = (settingRow, 0))
if (isinstance(setting.value, bool)): if (isinstance(setting.value, bool)):
checkbox = wx.CheckBox(self.scrollbarPanel) checkbox = wx.CheckBox(self.scrollbarPanel)
checkbox.SetName(craftName + '.' + setting.name) checkbox.SetName(craftName + '.' + setting.name)
checkbox.SetValue(setting.value) checkbox.SetValue(setting.value)
settingSizer.Add(checkbox, pos=(settingRow, 1)) settingSizer.Add(checkbox, pos = (settingRow, 1))
settingSizer.AddSpacer((25, -1), pos=(settingRow, 2)) settingSizer.AddSpacer((25, -1), pos = (settingRow, 2))
else: else:
textCtrl = wx.TextCtrl(self.scrollbarPanel, value=str(setting.value), size=(50, -1)) textCtrl = wx.TextCtrl(self.scrollbarPanel, value = str(setting.value), size = (50, -1))
textCtrl.SetName(craftName + '.' + setting.name) textCtrl.SetName(craftName + '.' + setting.name)
settingSizer.Add(textCtrl, pos=(settingRow, 1)) settingSizer.Add(textCtrl, pos = (settingRow, 1))
craftStaticBoxSizer.Add(settingSizer, 1, wx.EXPAND, 0) craftStaticBoxSizer.Add(settingSizer, 1, wx.EXPAND, 0)
settingRow += 1 settingRow += 1
col = settingsRow % 2 col = settingsRow % 2
settingsSizer.Add(craftStaticBoxSizer, pos=(settingsRow - col, col)) settingsSizer.Add(craftStaticBoxSizer, pos = (settingsRow - col, col))
settingsRow += 1 settingsRow += 1
return settingsSizer return settingsSizer
......
...@@ -11,7 +11,7 @@ import shutil ...@@ -11,7 +11,7 @@ import shutil
class MyFrame(wx.Frame): class MyFrame(wx.Frame):
def __init__(self, parent, mysize): def __init__(self, parent, mysize):
wx.Frame.__init__(self, parent, wx.ID_ANY, size=mysize) wx.Frame.__init__(self, parent, wx.ID_ANY, size = mysize)
self.SetBackgroundColour('black') self.SetBackgroundColour('black')
# milliseconds per frame # milliseconds per frame
...@@ -49,7 +49,7 @@ class MyFrame(wx.Frame): ...@@ -49,7 +49,7 @@ class MyFrame(wx.Frame):
if self.mytmpdir: if self.mytmpdir:
shutil.rmtree(self.mytmpdir) shutil.rmtree(self.mytmpdir)
def onPaint(self, event=None): def onPaint(self, event = None):
# this is the wxPython drawing surface/canvas # this is the wxPython drawing surface/canvas
dc = wx.PaintDC(self) dc = wx.PaintDC(self)
while self.loops: while self.loops:
...@@ -59,7 +59,7 @@ class MyFrame(wx.Frame): ...@@ -59,7 +59,7 @@ class MyFrame(wx.Frame):
w, h = bmp.GetSize() w, h = bmp.GetSize()
info = "%s %dx%d" % (self.name_list[ix], w, h) info = "%s %dx%d" % (self.name_list[ix], w, h)
self.SetTitle(info) self.SetTitle(info)
#self.SetSize((w,h)) #self.SetSize((w, h))
# draw the image # draw the image
dc.DrawBitmap(bmp, 0, 0, True) dc.DrawBitmap(bmp, 0, 0, True)
wx.MilliSleep(self.delay) wx.MilliSleep(self.delay)
......
...@@ -66,10 +66,10 @@ class BufferedCanvas(wx.Panel): ...@@ -66,10 +66,10 @@ class BufferedCanvas(wx.Panel):
def __init__(self, def __init__(self,
parent, parent,
ID=-1, ID=-1,
pos=wx.DefaultPosition, pos = wx.DefaultPosition,
size=wx.DefaultSize, size = wx.DefaultSize,
style=wx.NO_FULL_REPAINT_ON_RESIZE|wx.WANTS_CHARS): style = wx.NO_FULL_REPAINT_ON_RESIZE|wx.WANTS_CHARS):
wx.Panel.__init__(self,parent,ID,pos,size,style) wx.Panel.__init__(self, parent, ID, pos, size, style)
# Bind events # Bind events
self.Bind(wx.EVT_PAINT, self.onPaint) self.Bind(wx.EVT_PAINT, self.onPaint)
...@@ -83,7 +83,7 @@ class BufferedCanvas(wx.Panel): ...@@ -83,7 +83,7 @@ class BufferedCanvas(wx.Panel):
## General methods ## General methods
## ##
def draw(self,dc): def draw(self, dc):
""" """
Stub: called when the canvas needs to be re-drawn. Stub: called when the canvas needs to be re-drawn.
""" """
...@@ -96,7 +96,7 @@ class BufferedCanvas(wx.Panel): ...@@ -96,7 +96,7 @@ class BufferedCanvas(wx.Panel):
self.Refresh() self.Refresh()
def getWidthHeight(self): def getWidthHeight(self):
width,height = self.GetClientSizeTuple() width, height = self.GetClientSizeTuple()
if width == 0: if width == 0:
width = 1 width = 1
if height == 0: if height == 0:
......
...@@ -2,36 +2,36 @@ ...@@ -2,36 +2,36 @@
#Interactive RepRap e axis calibration program #Interactive RepRap e axis calibration program
#(C) Nathan Zadoks 2011 #(C) Nathan Zadoks 2011
#Licensed under CC-BY-SA or GPLv2 and higher - Pick your poison. #Licensed under CC-BY-SA or GPLv2 and higher - Pick your poison.
s=300 #Extrusion speed (mm/min) s = 300 #Extrusion speed (mm/min)
n=100 #Default length to extrude n = 100 #Default length to extrude
m= 0 #User-entered measured extrusion length m= 0 #User-entered measured extrusion length
k=300 #Default amount of steps per mm k = 300 #Default amount of steps per mm
port='/dev/ttyUSB0' #Default serial port to connect to printer port='/dev/ttyUSB0' #Default serial port to connect to printer
temp=210 #Default extrusion temperature temp = 210 #Default extrusion temperature
tempmax=250 #Maximum extrusion temperature tempmax = 250 #Maximum extrusion temperature
t=int(n*60)/s #Time to wait for extrusion t = int(n*60)/s #Time to wait for extrusion
try: try:
from printdummy import printcore from printdummy import printcore
except ImportError: except ImportError:
from printcore import printcore from printcore import printcore
import time,getopt,sys,os import time, getopt, sys, os
def float_input(prompt=''): def float_input(prompt=''):
import sys import sys
f=None f = None
while f==None: while f == None:
s=raw_input(prompt) s = raw_input(prompt)
try: try:
f=float(s) f = float(s)
except ValueError: except ValueError:
sys.stderr.write("Not a valid floating-point number.\n") sys.stderr.write("Not a valid floating-point number.\n")
sys.stderr.flush() sys.stderr.flush()
return f return f
def wait(t,m=''): def wait(t, m=''):
import time,sys import time, sys
sys.stdout.write(m+'['+(' '*t)+']\r'+m+'[') sys.stdout.write(m+'['+(' '*t)+']\r'+m+'[')
sys.stdout.flush() sys.stdout.flush()
for i in range(t): for i in range(t):
...@@ -45,19 +45,19 @@ def w(s): ...@@ -45,19 +45,19 @@ def w(s):
sys.stdout.flush() sys.stdout.flush()
def heatup(p,temp,s=0): def heatup(p, temp, s = 0):
curtemp=gettemp(p) curtemp = gettemp(p)
p.send_now('M109 S%03d'%temp) p.send_now('M109 S%03d'%temp)
p.temp=0 p.temp = 0
if not s: w("Heating extruder up..") if not s: w("Heating extruder up..")
f=False f = False
while curtemp<=(temp-1): while curtemp<=(temp-1):
p.send_now('M105') p.send_now('M105')
time.sleep(0.5) time.sleep(0.5)
if not f: if not f:
time.sleep(1.5) time.sleep(1.5)
f=True f = True
curtemp=gettemp(p) curtemp = gettemp(p)
if curtemp: w(u"\rHeating extruder up.. %3d \xb0C"%curtemp) if curtemp: w(u"\rHeating extruder up.. %3d \xb0C"%curtemp)
if s: print if s: print
else: print "\nReady." else: print "\nReady."
...@@ -67,47 +67,47 @@ def gettemp(p): ...@@ -67,47 +67,47 @@ def gettemp(p):
except: setattr(p,'logl',0) except: setattr(p,'logl',0)
try: p.temp try: p.temp
except: setattr(p,'temp',0) except: setattr(p,'temp',0)
for n in range(p.logl,len(p.log)): for n in range(p.logl, len(p.log)):
line=p.log[n] line = p.log[n]
if 'T:' in line: if 'T:' in line:
try: try:
setattr(p,'temp',int(line.split('T:')[1].split()[0])) setattr(p,'temp',int(line.split('T:')[1].split()[0]))
except: print line except: print line
p.logl=len(p.log) p.logl = len(p.log)
return p.temp return p.temp
if not os.path.exists(port): if not os.path.exists(port):
port=0 port = 0
#Parse options #Parse options
help=u""" help = u"""
%s [ -l DISTANCE ] [ -s STEPS ] [ -t TEMP ] [ -p PORT ] %s [ -l DISTANCE ] [ -s STEPS ] [ -t TEMP ] [ -p PORT ]
-l --length Length of filament to extrude for each calibration step (default: %d mm) -l --length Length of filament to extrude for each calibration step (default: %d mm)
-s --steps Initial amount of steps to use (default: %d steps) -s --steps Initial amount of steps to use (default: %d steps)
-t --temp Extrusion temperature in degrees Celsius (default: %d \xb0C, max %d \xb0C) -t --temp Extrusion temperature in degrees Celsius (default: %d \xb0C, max %d \xb0C)
-p --port Serial port the printer is connected to (default: %s) -p --port Serial port the printer is connected to (default: %s)
-h --help This cruft. -h --help This cruft.
"""[1:-1].encode('utf-8')%(sys.argv[0],n,k,temp,tempmax,port if port else 'auto') """[1:-1].encode('utf-8')%(sys.argv[0],n, k,temp, tempmax, port if port else 'auto')
try: try:
opts,args=getopt.getopt(sys.argv[1:],"hl:s:t:p:",["help","length=","steps=","temp=","port="]) opts, args = getopt.getopt(sys.argv[1:],"hl:s:t:p:",["help","length = ","steps = ","temp = ","port = "])
except getopt.GetoptError,err: except getopt.GetoptError, err:
print str(err) print str(err)
print help print help
sys.exit(2) sys.exit(2)
for o,a in opts: for o, a in opts:
if o in ('-h','--help'): if o in ('-h','--help'):
print help print help
sys.exit() sys.exit()
elif o in ('-l','--length'): elif o in ('-l','--length'):
n=float(a) n = float(a)
elif o in ('-s','--steps'): elif o in ('-s','--steps'):
k=int(a) k = int(a)
elif o in ('-t','--temp'): elif o in ('-t','--temp'):
temp=int(a) temp = int(a)
if temp>=tempmax: if temp>=tempmax:
print (u'%d \xb0C? Are you insane?'.encode('utf-8')%temp)+(" That's over nine thousand!" if temp>9000 else '') print (u'%d \xb0C? Are you insane?'.encode('utf-8')%temp)+(" That's over nine thousand!" if temp>9000 else '')
sys.exit(255) sys.exit(255)
elif o in ('-p','--port'): elif o in ('-p','--port'):
port=a port = a
#Show initial parameters #Show initial parameters
print "Initial parameters" print "Initial parameters"
...@@ -116,12 +116,12 @@ print "Length extruded: %3d mm"%n ...@@ -116,12 +116,12 @@ print "Length extruded: %3d mm"%n
print print
print "Serial port: %s"%(port if port else 'auto') print "Serial port: %s"%(port if port else 'auto')
p=None p = None
try: try:
#Connect to printer #Connect to printer
w("Connecting to printer..") w("Connecting to printer..")
try: try:
p=printcore(port,115200) p = printcore(port, 115200)
except: except:
print 'Error.' print 'Error.'
raise raise
...@@ -130,18 +130,18 @@ try: ...@@ -130,18 +130,18 @@ try:
w('.') w('.')
print " connected." print " connected."
heatup(p,temp) heatup(p, temp)
#Calibration loop #Calibration loop
while n!=m: while n!=m:
heatup(p,temp,True) heatup(p, temp, True)
p.send_now("G92 E0") #Reset e axis p.send_now("G92 E0") #Reset e axis
p.send_now("G1 E%d F%d"%(n,s)) #Extrude length of filament p.send_now("G1 E%d F%d"%(n, s)) #Extrude length of filament
wait(t,'Extruding.. ') wait(t,'Extruding.. ')
m=float_input("How many millimeters of filament were extruded? ") m = float_input("How many millimeters of filament were extruded? ")
if m==0: continue if m == 0: continue
if n!=m: if n!=m:
k=(n/m)*k k = (n/m)*k
p.send_now("M92 E%d"%int(round(k))) #Set new step count p.send_now("M92 E%d"%int(round(k))) #Set new step count
print "Steps per mm: %3d steps"%k #Tell user print "Steps per mm: %3d steps"%k #Tell user
print 'Calibration completed.' #Yay! print 'Calibration completed.' #Yay!
......
...@@ -19,8 +19,8 @@ import threading ...@@ -19,8 +19,8 @@ import threading
class GLPanel(wx.Panel): class GLPanel(wx.Panel):
'''A simple class for using OpenGL with wxPython.''' '''A simple class for using OpenGL with wxPython.'''
def __init__(self, parent, id, pos=wx.DefaultPosition, def __init__(self, parent, id, pos = wx.DefaultPosition,
size=wx.DefaultSize, style=0): size = wx.DefaultSize, style = 0):
# Forcing a no full repaint to stop flickering # Forcing a no full repaint to stop flickering
style = style | wx.NO_FULL_REPAINT_ON_RESIZE style = style | wx.NO_FULL_REPAINT_ON_RESIZE
#call super function #call super function
...@@ -33,7 +33,7 @@ class GLPanel(wx.Panel): ...@@ -33,7 +33,7 @@ class GLPanel(wx.Panel):
glcanvas.WX_GL_DEPTH_SIZE, 24) # 24 bit glcanvas.WX_GL_DEPTH_SIZE, 24) # 24 bit
# Create the canvas # Create the canvas
self.sizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer = wx.BoxSizer(wx.HORIZONTAL)
self.canvas = glcanvas.GLCanvas(self, attribList=attribList) self.canvas = glcanvas.GLCanvas(self, attribList = attribList)
self.sizer.Add(self.canvas, 1, wx.EXPAND) self.sizer.Add(self.canvas, 1, wx.EXPAND)
self.SetSizer(self.sizer) self.SetSizer(self.sizer)
#self.sizer.Fit(self) #self.sizer.Fit(self)
...@@ -200,7 +200,7 @@ def _dist(dist): ...@@ -200,7 +200,7 @@ def _dist(dist):
class gcpoint(object): class gcpoint(object):
"""gcode point """gcode point
stub for first line""" stub for first line"""
def __init__(self, x=0,y=0,z=0,e=0): def __init__(self, x = 0, y = 0, z = 0, e = 0):
self.x = x self.x = x
self.y = y self.y = y
self.z = z self.z = z
...@@ -210,10 +210,10 @@ class gcpoint(object): ...@@ -210,10 +210,10 @@ class gcpoint(object):
class gcline(object): class gcline(object):
"""gcode move line """gcode move line
Once initialised,it knows its position, length and extrusion ratio Once initialised, it knows its position, length and extrusion ratio
Returns lines into gcview batch() Returns lines into gcview batch()
""" """
def __init__(self, x=None, y=None, z=None, e=None, f=None, prev_gcline=None, orgline = False): def __init__(self, x = None, y = None, z = None, e = None, f = None, prev_gcline = None, orgline = False):
if prev_gcline is None: if prev_gcline is None:
self.prev_gcline = gcpoint() self.prev_gcline = gcpoint()
else: else:
...@@ -255,7 +255,7 @@ class gcline(object): ...@@ -255,7 +255,7 @@ class gcline(object):
self.orgline, self.orgline,
) )
def calc_delta(self, prev_gcline=None): def calc_delta(self, prev_gcline = None):
if prev_gcline is None: if prev_gcline is None:
prev_gcline = self.prev_gcline prev_gcline = self.prev_gcline
if self.prev_gcline is not None: if self.prev_gcline is not None:
...@@ -290,7 +290,7 @@ class gcline(object): ...@@ -290,7 +290,7 @@ class gcline(object):
] ]
def glcolor(self, upper_limit = None, lower_limit = 0, max_feedrate = 0): def glcolor(self, upper_limit = None, lower_limit = 0, max_feedrate = 0):
if self.extrusion_ratio == 0: if self.extrusion_ratio == 0:
return [255,255,255,0,0,0] return [255, 255, 255, 0,0, 0]
else: else:
blue_color = 0 blue_color = 0
green_color = 0 green_color = 0
...@@ -312,7 +312,7 @@ class gcline(object): ...@@ -312,7 +312,7 @@ class gcline(object):
blue_color = 255 blue_color = 255
if blue_color < 0: if blue_color < 0:
blue_color = 0 blue_color = 0
return[255,green_color,blue_color,128,green_color,blue_color/4] return[255, green_color, blue_color, 128, green_color, blue_color/4]
def float_from_line(axe, line): def float_from_line(axe, line):
...@@ -340,7 +340,7 @@ class gcview(object): ...@@ -340,7 +340,7 @@ class gcview(object):
"""gcode visualiser """gcode visualiser
Holds opengl objects for all layers Holds opengl objects for all layers
""" """
def __init__(self, lines, batch, w=0.5, h=0.5): def __init__(self, lines, batch, w = 0.5, h = 0.5):
if len(lines) == 0: if len(lines) == 0:
return return
print "Loading %s lines" % (len(lines)) print "Loading %s lines" % (len(lines))
...@@ -430,7 +430,7 @@ class gcview(object): ...@@ -430,7 +430,7 @@ class gcview(object):
else: else:
self.lastf = cur[4] self.lastf = cur[4]
r = gcline(x=cur[0], y=cur[1], z=cur[2],e=cur[3], f=cur[4], prev_gcline=self.prev, orgline=orgline) r = gcline(x = cur[0], y = cur[1], z = cur[2],e = cur[3], f = cur[4], prev_gcline = self.prev, orgline = orgline)
self.prev = r self.prev = r
return r return r
return None return None
...@@ -524,7 +524,7 @@ def mulquat(q1, rq): ...@@ -524,7 +524,7 @@ def mulquat(q1, rq):
class TestGlPanel(GLPanel): class TestGlPanel(GLPanel):
def __init__(self, parent, size, id=wx.ID_ANY): def __init__(self, parent, size, id = wx.ID_ANY):
super(TestGlPanel, self).__init__(parent, id, wx.DefaultPosition, size, 0) super(TestGlPanel, self).__init__(parent, id, wx.DefaultPosition, size, 0)
self.batches = [] self.batches = []
self.rot = 0 self.rot = 0
...@@ -553,7 +553,7 @@ class TestGlPanel(GLPanel): ...@@ -553,7 +553,7 @@ class TestGlPanel(GLPanel):
def forceresize(self): def forceresize(self):
self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] + 1)) self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] + 1))
self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] - 1)) self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] - 1))
threading.Thread(target=self.update).start() threading.Thread(target = self.update).start()
self.initialized = 0 self.initialized = 0
def move_shape(self, delta): def move_shape(self, delta):
...@@ -605,7 +605,7 @@ class TestGlPanel(GLPanel): ...@@ -605,7 +605,7 @@ class TestGlPanel(GLPanel):
p1y = -(float(p1[1]) - sz[1] / 2) / (sz[1] / 2) p1y = -(float(p1[1]) - sz[1] / 2) / (sz[1] / 2)
p2x = (float(p2[0]) - sz[0] / 2) / (sz[0] / 2) p2x = (float(p2[0]) - sz[0] / 2) / (sz[0] / 2)
p2y = -(float(p2[1]) - sz[1] / 2) / (sz[1] / 2) p2y = -(float(p2[1]) - sz[1] / 2) / (sz[1] / 2)
#print p1x,p1y,p2x,p2y #print p1x, p1y, p2x, p2y
quat = trackball(p1x, p1y, p2x, p2y, -self.transv[2] / 250.0) quat = trackball(p1x, p1y, p2x, p2y, -self.transv[2] / 250.0)
if self.rot: if self.rot:
self.basequat = mulquat(self.basequat, quat) self.basequat = mulquat(self.basequat, quat)
...@@ -768,7 +768,7 @@ class TestGlPanel(GLPanel): ...@@ -768,7 +768,7 @@ class TestGlPanel(GLPanel):
def drawmodel(self, m, n): def drawmodel(self, m, n):
batch = pyglet.graphics.Batch() batch = pyglet.graphics.Batch()
stl = stlview(m.facets, batch=batch) stl = stlview(m.facets, batch = batch)
m.batch = batch m.batch = batch
m.animoffset = 300 m.animoffset = 300
#print m #print m
...@@ -907,8 +907,8 @@ class TestGlPanel(GLPanel): ...@@ -907,8 +907,8 @@ class TestGlPanel(GLPanel):
class GCFrame(wx.Frame): class GCFrame(wx.Frame):
'''A simple class for using OpenGL with wxPython.''' '''A simple class for using OpenGL with wxPython.'''
def __init__(self, parent, ID, title, pos=wx.DefaultPosition, def __init__(self, parent, ID, title, pos = wx.DefaultPosition,
size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE): size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE):
super(GCFrame, self).__init__(parent, ID, title, pos, (size[0] + 150, size[1]), style) super(GCFrame, self).__init__(parent, ID, title, pos, (size[0] + 150, size[1]), style)
class d: class d:
...@@ -921,7 +921,7 @@ class GCFrame(wx.Frame): ...@@ -921,7 +921,7 @@ class GCFrame(wx.Frame):
m.curlayer = -1 m.curlayer = -1
m.scale = [1.0, 1.0, 1.0] m.scale = [1.0, 1.0, 1.0]
m.batch = pyglet.graphics.Batch() m.batch = pyglet.graphics.Batch()
m.gc = gcview([], batch=m.batch) m.gc = gcview([], batch = m.batch)
self.models = {"GCODE": m} self.models = {"GCODE": m}
self.l = d() self.l = d()
self.modelindex = 0 self.modelindex = 0
...@@ -929,14 +929,14 @@ class GCFrame(wx.Frame): ...@@ -929,14 +929,14 @@ class GCFrame(wx.Frame):
def addfile(self, gcode=[]): def addfile(self, gcode=[]):
self.models["GCODE"].gc.delete() self.models["GCODE"].gc.delete()
self.models["GCODE"].gc = gcview(gcode, batch=self.models["GCODE"].batch) self.models["GCODE"].gc = gcview(gcode, batch = self.models["GCODE"].batch)
self.setlayerindex(None) self.setlayerindex(None)
def clear(self): def clear(self):
self.models["GCODE"].gc.delete() self.models["GCODE"].gc.delete()
self.models["GCODE"].gc = gcview([], batch=self.models["GCODE"].batch) self.models["GCODE"].gc = gcview([], batch = self.models["GCODE"].batch)
def Show(self, arg=True): def Show(self, arg = True):
wx.Frame.Show(self, arg) wx.Frame.Show(self, arg)
self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] + 1)) self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] + 1))
self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] - 1)) self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] - 1))
...@@ -975,8 +975,8 @@ class GCFrame(wx.Frame): ...@@ -975,8 +975,8 @@ class GCFrame(wx.Frame):
def main(): def main():
app = wx.App(redirect=False) app = wx.App(redirect = False)
frame = GCFrame(None, wx.ID_ANY, 'Gcode view, shift to move view, mousewheel to set layer', size=(400, 400)) frame = GCFrame(None, wx.ID_ANY, 'Gcode view, shift to move view, mousewheel to set layer', size = (400, 400))
import sys import sys
for filename in sys.argv: for filename in sys.argv:
if ".gcode" in filename: if ".gcode" in filename:
...@@ -985,8 +985,8 @@ def main(): ...@@ -985,8 +985,8 @@ def main():
#TODO: add stl here #TODO: add stl here
pass pass
#frame = wx.Frame(None, -1, "GL Window", size=(400, 400)) #frame = wx.Frame(None, -1, "GL Window", size = (400, 400))
#panel = TestGlPanel(frame, size=(300,300)) #panel = TestGlPanel(frame, size = (300, 300))
frame.Show(True) frame.Show(True)
app.MainLoop() app.MainLoop()
app.Destroy() app.Destroy()
......
...@@ -22,8 +22,8 @@ from bufferedcanvas import * ...@@ -22,8 +22,8 @@ from bufferedcanvas import *
class Graph(BufferedCanvas): class Graph(BufferedCanvas):
'''A class to show a Graph with Pronterface.''' '''A class to show a Graph with Pronterface.'''
def __init__(self, parent, id, pos=wx.DefaultPosition, def __init__(self, parent, id, pos = wx.DefaultPosition,
size=wx.DefaultSize, style=0): size = wx.DefaultSize, style = 0):
# Forcing a no full repaint to stop flickering # Forcing a no full repaint to stop flickering
style = style | wx.NO_FULL_REPAINT_ON_RESIZE style = style | wx.NO_FULL_REPAINT_ON_RESIZE
#call super function #call super function
...@@ -53,7 +53,7 @@ class Graph(BufferedCanvas): ...@@ -53,7 +53,7 @@ class Graph(BufferedCanvas):
#self.sizer = wx.BoxSizer(wx.HORIZONTAL) #self.sizer = wx.BoxSizer(wx.HORIZONTAL)
#self.sizer.Add(wx.Button(self, -1, "Button1", (0,0))) #self.sizer.Add(wx.Button(self, -1, "Button1", (0, 0)))
#self.SetSizer(self.sizer) #self.SetSizer(self.sizer)
...@@ -78,23 +78,23 @@ class Graph(BufferedCanvas): ...@@ -78,23 +78,23 @@ class Graph(BufferedCanvas):
def drawgrid(self, dc, gc): def drawgrid(self, dc, gc):
#cold,medium,hot = wx.Colour(0,167,223),wx.Colour(239,233,119),wx.Colour(210,50.100) #cold, medium, hot = wx.Colour(0, 167, 223),wx.Colour(239, 233, 119),wx.Colour(210, 50.100)
#col1 = wx.Colour(255,0,0, 255) #col1 = wx.Colour(255, 0,0, 255)
#col2 = wx.Colour(255,255,255, 128) #col2 = wx.Colour(255, 255, 255, 128)
#b = gc.CreateLinearGradientBrush(0, 0, w, h, col1, col2) #b = gc.CreateLinearGradientBrush(0, 0, w, h, col1, col2)
gc.SetPen(wx.Pen(wx.Colour(255,0,0,0), 4)) gc.SetPen(wx.Pen(wx.Colour(255, 0,0, 0), 4))
#gc.SetBrush(gc.CreateBrush(wx.Brush(wx.Colour(245,245,255,252)))) #gc.SetBrush(gc.CreateBrush(wx.Brush(wx.Colour(245, 245, 255, 252))))
#gc.SetBrush(b) #gc.SetBrush(b)
gc.DrawRectangle(0, 0, self.width, self.height) gc.DrawRectangle(0, 0, self.width, self.height)
#gc.SetBrush(wx.Brush(wx.Colour(245,245,255,52))) #gc.SetBrush(wx.Brush(wx.Colour(245, 245, 255, 52)))
#gc.SetBrush(gc.CreateBrush(wx.Brush(wx.Colour(0,0,0,255)))) #gc.SetBrush(gc.CreateBrush(wx.Brush(wx.Colour(0, 0,0, 255))))
#gc.SetPen(wx.Pen(wx.Colour(255,0,0,0), 4)) #gc.SetPen(wx.Pen(wx.Colour(255, 0,0, 0), 4))
#gc.DrawLines(wx.Point(0,0), wx.Point(50,10)) #gc.DrawLines(wx.Point(0, 0), wx.Point(50, 10))
#path = gc.CreatePath() #path = gc.CreatePath()
#path.MoveToPoint(0.0, 0.0) #path.MoveToPoint(0.0, 0.0)
...@@ -107,34 +107,34 @@ class Graph(BufferedCanvas): ...@@ -107,34 +107,34 @@ class Graph(BufferedCanvas):
font = wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD) font = wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD)
gc.SetFont(font, wx.Colour(23,44,44)) gc.SetFont(font, wx.Colour(23, 44, 44))
dc.SetPen(wx.Pen(wx.Colour(225,225,225), 1)) dc.SetPen(wx.Pen(wx.Colour(225, 225, 225), 1))
for x in range(self.xbars): for x in range(self.xbars):
dc.DrawLine(x*(float(self.width)/self.xbars), 0, x*(float(self.width)/self.xbars), self.height) dc.DrawLine(x*(float(self.width)/self.xbars), 0, x*(float(self.width)/self.xbars), self.height)
dc.SetPen(wx.Pen(wx.Colour(225,225,225), 1)) dc.SetPen(wx.Pen(wx.Colour(225, 225, 225), 1))
for y in range(self.ybars): for y in range(self.ybars):
y_pos = y*(float(self.height)/self.ybars) y_pos = y*(float(self.height)/self.ybars)
dc.DrawLine(0,y_pos, self.width,y_pos) dc.DrawLine(0, y_pos, self.width, y_pos)
gc.DrawText(unicode(int(self.maxyvalue - (y * (self.maxyvalue/self.ybars)))), 1, y_pos - (font.GetPointSize() / 2)) gc.DrawText(unicode(int(self.maxyvalue - (y * (self.maxyvalue/self.ybars)))), 1, y_pos - (font.GetPointSize() / 2))
if self.timer.IsRunning() == False: if self.timer.IsRunning() == False:
font = wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.BOLD) font = wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.BOLD)
gc.SetFont(font, wx.Colour(3,4,4)) gc.SetFont(font, wx.Colour(3, 4,4))
gc.DrawText("Graph offline", self.width/2 - (font.GetPointSize() * 3), self.height/2 - (font.GetPointSize() * 1)) gc.DrawText("Graph offline", self.width/2 - (font.GetPointSize() * 3), self.height/2 - (font.GetPointSize() * 1))
#dc.DrawCircle(50,50, 1) #dc.DrawCircle(50, 50, 1)
#gc.SetPen(wx.Pen(wx.Colour(255,0,0,0), 1)) #gc.SetPen(wx.Pen(wx.Colour(255, 0,0, 0), 1))
#gc.DrawLines([[20,30], [10,53]]) #gc.DrawLines([[20, 30], [10, 53]])
#dc.SetPen(wx.Pen(wx.Colour(255,0,0,0), 1)) #dc.SetPen(wx.Pen(wx.Colour(255, 0,0, 0), 1))
def drawtemperature(self, dc, gc, temperature_list, text, text_xoffset, r, g, b, a): def drawtemperature(self, dc, gc, temperature_list, text, text_xoffset, r, g, b, a):
if self.timer.IsRunning() == False: if self.timer.IsRunning() == False:
dc.SetPen(wx.Pen(wx.Colour(128,128,128,128), 1)) dc.SetPen(wx.Pen(wx.Colour(128, 128, 128, 128), 1))
else: else:
dc.SetPen(wx.Pen(wx.Colour(r,g,b,a), 1)) dc.SetPen(wx.Pen(wx.Colour(r, g,b, a), 1))
x_add = float(self.width)/self.xsteps x_add = float(self.width)/self.xsteps
x_pos = float(0.0) x_pos = float(0.0)
...@@ -143,7 +143,7 @@ class Graph(BufferedCanvas): ...@@ -143,7 +143,7 @@ class Graph(BufferedCanvas):
for temperature in (temperature_list): for temperature in (temperature_list):
y_pos = int((float(self.height-self.y_offset)/self.maxyvalue)*temperature) + self.y_offset y_pos = int((float(self.height-self.y_offset)/self.maxyvalue)*temperature) + self.y_offset
if (x_pos > 0.0): # One need 2 points to draw a line. if (x_pos > 0.0): # One need 2 points to draw a line.
dc.DrawLine(lastxvalue,self.height-self._lastyvalue, x_pos, self.height-y_pos) dc.DrawLine(lastxvalue, self.height-self._lastyvalue, x_pos, self.height-y_pos)
lastxvalue = x_pos lastxvalue = x_pos
x_pos = float(x_pos) + x_add x_pos = float(x_pos) + x_add
...@@ -153,9 +153,9 @@ class Graph(BufferedCanvas): ...@@ -153,9 +153,9 @@ class Graph(BufferedCanvas):
font = wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD) font = wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD)
#font = wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.NORMAL) #font = wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
if self.timer.IsRunning() == False: if self.timer.IsRunning() == False:
gc.SetFont(font, wx.Colour(128,128,128)) gc.SetFont(font, wx.Colour(128, 128, 128))
else: else:
gc.SetFont(font, wx.Colour(r,g,b)) gc.SetFont(font, wx.Colour(r, g,b))
#gc.DrawText(text, self.width - (font.GetPointSize() * ((len(text) * text_xoffset + 1))), self.height - self._lastyvalue - (font.GetPointSize() / 2)) #gc.DrawText(text, self.width - (font.GetPointSize() * ((len(text) * text_xoffset + 1))), self.height - self._lastyvalue - (font.GetPointSize() / 2))
gc.DrawText(text, x_pos - x_add - (font.GetPointSize() * ((len(text) * text_xoffset + 1))), self.height - self._lastyvalue - (font.GetPointSize() / 2)) gc.DrawText(text, x_pos - x_add - (font.GetPointSize() * ((len(text) * text_xoffset + 1))), self.height - self._lastyvalue - (font.GetPointSize() / 2))
...@@ -163,24 +163,24 @@ class Graph(BufferedCanvas): ...@@ -163,24 +163,24 @@ class Graph(BufferedCanvas):
def drawbedtemp(self, dc, gc): def drawbedtemp(self, dc, gc):
self.drawtemperature(dc, gc, self.bedtemps, "Bed",2, 255,0,0, 128) self.drawtemperature(dc, gc, self.bedtemps, "Bed",2, 255, 0,0, 128)
def drawbedtargettemp(self, dc, gc): def drawbedtargettemp(self, dc, gc):
self.drawtemperature(dc, gc, self.bedtargettemps, "Bed Target",2, 255,120,0, 128) self.drawtemperature(dc, gc, self.bedtargettemps, "Bed Target",2, 255, 120, 0, 128)
def drawextruder0temp(self, dc, gc): def drawextruder0temp(self, dc, gc):
self.drawtemperature(dc, gc, self.extruder0temps, "Ex0",1, 0,155,255, 128) self.drawtemperature(dc, gc, self.extruder0temps, "Ex0",1, 0, 155, 255, 128)
def drawextruder0targettemp(self, dc, gc): def drawextruder0targettemp(self, dc, gc):
self.drawtemperature(dc, gc, self.extruder0targettemps, "Ex0 Target",2, 0,5,255, 128) self.drawtemperature(dc, gc, self.extruder0targettemps, "Ex0 Target",2, 0, 5,255, 128)
def drawextruder1temp(self, dc, gc): def drawextruder1temp(self, dc, gc):
self.drawtemperature(dc, gc, self.extruder1temps, "Ex1",3, 55,55,0, 128) self.drawtemperature(dc, gc, self.extruder1temps, "Ex1",3, 55, 55, 0, 128)
def drawextruder1targettemp(self, dc, gc): def drawextruder1targettemp(self, dc, gc):
self.drawtemperature(dc, gc, self.extruder1targettemps, "Ex1 Target",2, 55,55,0, 128) self.drawtemperature(dc, gc, self.extruder1targettemps, "Ex1 Target",2, 55, 55, 0, 128)
def SetBedTemperature(self, value): def SetBedTemperature(self, value):
......
This diff is collapsed.
...@@ -5,11 +5,11 @@ import gettext ...@@ -5,11 +5,11 @@ import gettext
# searching for installed locales on /usr/share; uses relative folder if not found (windows) # searching for installed locales on /usr/share; uses relative folder if not found (windows)
def install_locale(domain): def install_locale(domain):
if os.path.exists('/usr/share/pronterface/locale'): if os.path.exists('/usr/share/pronterface/locale'):
gettext.install(domain, '/usr/share/pronterface/locale', unicode=1) gettext.install(domain, '/usr/share/pronterface/locale', unicode = 1)
elif os.path.exists('/usr/local/share/pronterface/locale'): elif os.path.exists('/usr/local/share/pronterface/locale'):
gettext.install(domain, '/usr/local/share/pronterface/locale', unicode=1) gettext.install(domain, '/usr/local/share/pronterface/locale', unicode = 1)
else: else:
gettext.install(domain, './locale', unicode=1) gettext.install(domain, './locale', unicode = 1)
def imagefile(filename): def imagefile(filename):
for prefix in ['/usr/local/share/pronterface/images', '/usr/share/pronterface/images']: for prefix in ['/usr/local/share/pronterface/images', '/usr/share/pronterface/images']:
......
...@@ -23,8 +23,8 @@ import svg.document as wxpsvgdocument ...@@ -23,8 +23,8 @@ import svg.document as wxpsvgdocument
import imghdr import imghdr
class dispframe(wx.Frame): class dispframe(wx.Frame):
def __init__(self, parent, title, res=(800, 600), printer=None): def __init__(self, parent, title, res = (800, 600), printer = None):
wx.Frame.__init__(self, parent=parent, title=title) wx.Frame.__init__(self, parent = parent, title = title)
self.p = printer self.p = printer
self.pic = wx.StaticBitmap(self) self.pic = wx.StaticBitmap(self)
self.bitmap = wx.EmptyBitmap(*res) self.bitmap = wx.EmptyBitmap(*res)
...@@ -101,7 +101,7 @@ class dispframe(wx.Frame): ...@@ -101,7 +101,7 @@ class dispframe(wx.Frame):
wx.CallAfter(self.ShowFullScreen, 0) wx.CallAfter(self.ShowFullScreen, 0)
wx.CallAfter(self.timer.Stop) wx.CallAfter(self.timer.Stop)
def present(self, layers, interval=0.5, pause=0.2, thickness=0.4, scale=20, size=(800, 600), offset=(0, 0)): def present(self, layers, interval = 0.5, pause = 0.2, thickness = 0.4, scale = 20, size = (800, 600), offset = (0, 0)):
wx.CallAfter(self.pic.Hide) wx.CallAfter(self.pic.Hide)
wx.CallAfter(self.Refresh) wx.CallAfter(self.Refresh)
self.layers = layers self.layers = layers
...@@ -118,47 +118,47 @@ class dispframe(wx.Frame): ...@@ -118,47 +118,47 @@ class dispframe(wx.Frame):
class setframe(wx.Frame): class setframe(wx.Frame):
def __init__(self, parent, printer=None): def __init__(self, parent, printer = None):
wx.Frame.__init__(self, parent, title="Projector setup") wx.Frame.__init__(self, parent, title = "Projector setup")
self.f = dispframe(None, "", printer=printer) self.f = dispframe(None, "", printer = printer)
self.panel = wx.Panel(self) self.panel = wx.Panel(self)
self.panel.SetBackgroundColour("orange") self.panel.SetBackgroundColour("orange")
self.bload = wx.Button(self.panel, -1, "Load", pos=(0, 0)) self.bload = wx.Button(self.panel, -1, "Load", pos = (0, 0))
self.bload.Bind(wx.EVT_BUTTON, self.loadfile) self.bload.Bind(wx.EVT_BUTTON, self.loadfile)
wx.StaticText(self.panel, -1, "Layer:", pos=(0, 30)) wx.StaticText(self.panel, -1, "Layer:", pos = (0, 30))
wx.StaticText(self.panel, -1, "mm", pos=(130, 30)) wx.StaticText(self.panel, -1, "mm", pos = (130, 30))
self.thickness = wx.TextCtrl(self.panel, -1, "0.5", pos=(50, 30)) self.thickness = wx.TextCtrl(self.panel, -1, "0.5", pos = (50, 30))
wx.StaticText(self.panel, -1, "Exposure:", pos=(0, 60)) wx.StaticText(self.panel, -1, "Exposure:", pos = (0, 60))
wx.StaticText(self.panel, -1, "s", pos=(130, 60)) wx.StaticText(self.panel, -1, "s", pos = (130, 60))
self.interval = wx.TextCtrl(self.panel, -1, "0.5", pos=(50, 60)) self.interval = wx.TextCtrl(self.panel, -1, "0.5", pos = (50, 60))
wx.StaticText(self.panel, -1, "Blank:", pos=(0, 90)) wx.StaticText(self.panel, -1, "Blank:", pos = (0, 90))
wx.StaticText(self.panel, -1, "s", pos=(130, 90)) wx.StaticText(self.panel, -1, "s", pos = (130, 90))
self.delay = wx.TextCtrl(self.panel, -1, "0.5", pos=(50, 90)) self.delay = wx.TextCtrl(self.panel, -1, "0.5", pos = (50, 90))
wx.StaticText(self.panel, -1, "Scale:", pos=(0, 120)) wx.StaticText(self.panel, -1, "Scale:", pos = (0, 120))
wx.StaticText(self.panel, -1, "x", pos=(130, 120)) wx.StaticText(self.panel, -1, "x", pos = (130, 120))
self.scale = wx.TextCtrl(self.panel, -1, "5", pos=(50, 120)) self.scale = wx.TextCtrl(self.panel, -1, "5", pos = (50, 120))
wx.StaticText(self.panel, -1, "X:", pos=(160, 30)) wx.StaticText(self.panel, -1, "X:", pos = (160, 30))
self.X = wx.TextCtrl(self.panel, -1, "1024", pos=(210, 30)) self.X = wx.TextCtrl(self.panel, -1, "1024", pos = (210, 30))
wx.StaticText(self.panel, -1, "Y:", pos=(160, 60)) wx.StaticText(self.panel, -1, "Y:", pos = (160, 60))
self.Y = wx.TextCtrl(self.panel, -1, "768", pos=(210, 60)) self.Y = wx.TextCtrl(self.panel, -1, "768", pos = (210, 60))
wx.StaticText(self.panel, -1, "OffsetX:", pos=(160, 90)) wx.StaticText(self.panel, -1, "OffsetX:", pos = (160, 90))
self.offsetX = wx.TextCtrl(self.panel, -1, "50", pos=(210, 90)) self.offsetX = wx.TextCtrl(self.panel, -1, "50", pos = (210, 90))
wx.StaticText(self.panel, -1, "OffsetY:", pos=(160, 120)) wx.StaticText(self.panel, -1, "OffsetY:", pos = (160, 120))
self.offsetY = wx.TextCtrl(self.panel, -1, "50", pos=(210, 120)) self.offsetY = wx.TextCtrl(self.panel, -1, "50", pos = (210, 120))
self.bload = wx.Button(self.panel, -1, "Present", pos=(0, 150)) self.bload = wx.Button(self.panel, -1, "Present", pos = (0, 150))
self.bload.Bind(wx.EVT_BUTTON, self.startdisplay) self.bload.Bind(wx.EVT_BUTTON, self.startdisplay)
wx.StaticText(self.panel, -1, "Fullscreen:", pos=(160, 150)) wx.StaticText(self.panel, -1, "Fullscreen:", pos = (160, 150))
self.fullscreen = wx.CheckBox(self.panel, -1, pos=(220, 150)) self.fullscreen = wx.CheckBox(self.panel, -1, pos = (220, 150))
self.fullscreen.SetValue(True) self.fullscreen.SetValue(True)
self.Show() self.Show()
...@@ -168,7 +168,7 @@ class setframe(wx.Frame): ...@@ -168,7 +168,7 @@ class setframe(wx.Frame):
shutil.rmtree(self.image_dir) shutil.rmtree(self.image_dir)
def parsesvg(self, name): def parsesvg(self, name):
et = xml.etree.ElementTree.ElementTree(file=name) et = xml.etree.ElementTree.ElementTree(file = name)
#xml.etree.ElementTree.dump(et) #xml.etree.ElementTree.dump(et)
slicer = 'Slic3r' if et.getroot().find('{http://www.w3.org/2000/svg}metadata') == None else 'Skeinforge' slicer = 'Slic3r' if et.getroot().find('{http://www.w3.org/2000/svg}metadata') == None else 'Skeinforge'
zlast = 0 zlast = 0
...@@ -214,7 +214,7 @@ class setframe(wx.Frame): ...@@ -214,7 +214,7 @@ class setframe(wx.Frame):
return ol, -1, "bitmap" return ol, -1, "bitmap"
def loadfile(self, event): def loadfile(self, event):
dlg = wx.FileDialog(self, ("Open file to print"), style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) dlg = wx.FileDialog(self, ("Open file to print"), style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
dlg.SetWildcard(("Slic3r or Skeinforge svg files (;*.svg;*.SVG;);3DLP Zip (;*.3dlp.zip;)")) dlg.SetWildcard(("Slic3r or Skeinforge svg files (;*.svg;*.SVG;);3DLP Zip (;*.3dlp.zip;)"))
if(dlg.ShowModal() == wx.ID_OK): if(dlg.ShowModal() == wx.ID_OK):
name = dlg.GetPath() name = dlg.GetPath()
...@@ -240,12 +240,12 @@ class setframe(wx.Frame): ...@@ -240,12 +240,12 @@ class setframe(wx.Frame):
self.f.ShowFullScreen(1) self.f.ShowFullScreen(1)
l = self.layers[0][:] l = self.layers[0][:]
self.f.present(l, self.f.present(l,
thickness=float(self.thickness.GetValue()), thickness = float(self.thickness.GetValue()),
interval=float(self.interval.GetValue()), interval = float(self.interval.GetValue()),
scale=float(self.scale.GetValue()), scale = float(self.scale.GetValue()),
pause=float(self.delay.GetValue()), pause = float(self.delay.GetValue()),
size=(float(self.X.GetValue()), float(self.Y.GetValue())), size = (float(self.X.GetValue()), float(self.Y.GetValue())),
offset=(float(self.offsetX.GetValue()), float(self.offsetY.GetValue()))) offset = (float(self.offsetX.GetValue()), float(self.offsetY.GetValue())))
if __name__ == "__main__": if __name__ == "__main__":
a = wx.App() a = wx.App()
......
This diff is collapsed.
This diff is collapsed.
...@@ -32,8 +32,8 @@ from pyglet.gl import * ...@@ -32,8 +32,8 @@ from pyglet.gl import *
class GLPanel(wx.Panel): class GLPanel(wx.Panel):
'''A simple class for using OpenGL with wxPython.''' '''A simple class for using OpenGL with wxPython.'''
def __init__(self, parent, id, pos=wx.DefaultPosition, def __init__(self, parent, id, pos = wx.DefaultPosition,
size=wx.DefaultSize, style=0): size = wx.DefaultSize, style = 0):
# Forcing a no full repaint to stop flickering # Forcing a no full repaint to stop flickering
style = style | wx.NO_FULL_REPAINT_ON_RESIZE style = style | wx.NO_FULL_REPAINT_ON_RESIZE
#call super function #call super function
...@@ -46,7 +46,7 @@ class GLPanel(wx.Panel): ...@@ -46,7 +46,7 @@ class GLPanel(wx.Panel):
glcanvas.WX_GL_DEPTH_SIZE, 24) # 24 bit glcanvas.WX_GL_DEPTH_SIZE, 24) # 24 bit
# Create the canvas # Create the canvas
self.sizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer = wx.BoxSizer(wx.HORIZONTAL)
self.canvas = glcanvas.GLCanvas(self, attribList=attribList) self.canvas = glcanvas.GLCanvas(self, attribList = attribList)
self.sizer.Add(self.canvas, 1, wx.EXPAND) self.sizer.Add(self.canvas, 1, wx.EXPAND)
self.SetSizer(self.sizer) self.SetSizer(self.sizer)
#self.sizer.Fit(self) #self.sizer.Fit(self)
...@@ -215,7 +215,7 @@ class stlview(object): ...@@ -215,7 +215,7 @@ class stlview(object):
normals.extend(i[0]) normals.extend(i[0])
# Create a list of triangle indices. # Create a list of triangle indices.
indices = range(3 * len(facets)) # [[3*i,3*i+1,3*i+2] for i in xrange(len(facets))] indices = range(3 * len(facets)) # [[3*i, 3*i+1, 3*i+2] for i in xrange(len(facets))]
#print indices[:10] #print indices[:10]
self.vertex_list = batch.add_indexed(len(vertices) // 3, self.vertex_list = batch.add_indexed(len(vertices) // 3,
GL_TRIANGLES, GL_TRIANGLES,
...@@ -233,7 +233,7 @@ def vdiff(v, o): ...@@ -233,7 +233,7 @@ def vdiff(v, o):
class gcview(object): class gcview(object):
def __init__(self, lines, batch, w=0.5, h=0.5): def __init__(self, lines, batch, w = 0.5, h = 0.5):
# Create the vertex and normal arrays. # Create the vertex and normal arrays.
vertices = [] vertices = []
normals = [] normals = []
...@@ -258,7 +258,7 @@ class gcview(object): ...@@ -258,7 +258,7 @@ class gcview(object):
if lasth is not None: if lasth is not None:
self.layers[lasth] = pyglet.graphics.Batch() self.layers[lasth] = pyglet.graphics.Batch()
lt = layertemp[lasth][0] lt = layertemp[lasth][0]
indices = range(len(layertemp[lasth][0]) // 3) # [[3*i,3*i+1,3*i+2] for i in xrange(len(facets))] indices = range(len(layertemp[lasth][0]) // 3) # [[3*i, 3*i+1, 3*i+2] for i in xrange(len(facets))]
self.vlists.append(self.layers[lasth].add_indexed(len(layertemp[lasth][0]) // 3, self.vlists.append(self.layers[lasth].add_indexed(len(layertemp[lasth][0]) // 3,
GL_TRIANGLES, GL_TRIANGLES,
None, # group, None, # group,
...@@ -296,7 +296,7 @@ class gcview(object): ...@@ -296,7 +296,7 @@ class gcview(object):
t0 = time.time() t0 = time.time()
# Create a list of triangle indices. # Create a list of triangle indices.
indices = range(3 * 16 * len(lines)) # [[3*i,3*i+1,3*i+2] for i in xrange(len(facets))] indices = range(3 * 16 * len(lines)) # [[3*i, 3*i+1, 3*i+2] for i in xrange(len(facets))]
self.vlists.append(batch.add_indexed(len(vertices) // 3, self.vlists.append(batch.add_indexed(len(vertices) // 3,
GL_TRIANGLES, GL_TRIANGLES,
None, # group, None, # group,
...@@ -305,7 +305,7 @@ class gcview(object): ...@@ -305,7 +305,7 @@ class gcview(object):
('n3f/static', normals))) ('n3f/static', normals)))
if lasth is not None: if lasth is not None:
self.layers[lasth] = pyglet.graphics.Batch() self.layers[lasth] = pyglet.graphics.Batch()
indices = range(len(layertemp[lasth][0])) # [[3*i,3*i+1,3*i+2] for i in xrange(len(facets))] indices = range(len(layertemp[lasth][0])) # [[3*i, 3*i+1, 3*i+2] for i in xrange(len(facets))]
self.vlists.append(self.layers[lasth].add_indexed(len(layertemp[lasth][0]) // 3, self.vlists.append(self.layers[lasth].add_indexed(len(layertemp[lasth][0]) // 3,
GL_TRIANGLES, GL_TRIANGLES,
None, # group, None, # group,
...@@ -466,7 +466,7 @@ def mulquat(q1, rq): ...@@ -466,7 +466,7 @@ def mulquat(q1, rq):
class TestGlPanel(GLPanel): class TestGlPanel(GLPanel):
def __init__(self, parent, size, id=wx.ID_ANY): def __init__(self, parent, size, id = wx.ID_ANY):
super(TestGlPanel, self).__init__(parent, id, wx.DefaultPosition, size, 0) super(TestGlPanel, self).__init__(parent, id, wx.DefaultPosition, size, 0)
self.batches = [] self.batches = []
self.rot = 0 self.rot = 0
...@@ -495,7 +495,7 @@ class TestGlPanel(GLPanel): ...@@ -495,7 +495,7 @@ class TestGlPanel(GLPanel):
def forceresize(self): def forceresize(self):
self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] + 1)) self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] + 1))
self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] - 1)) self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] - 1))
threading.Thread(target=self.update).start() threading.Thread(target = self.update).start()
self.initialized = 0 self.initialized = 0
def move_shape(self, delta): def move_shape(self, delta):
...@@ -547,7 +547,7 @@ class TestGlPanel(GLPanel): ...@@ -547,7 +547,7 @@ class TestGlPanel(GLPanel):
p1y = -(float(p1[1]) - sz[1] / 2) / (sz[1] / 2) p1y = -(float(p1[1]) - sz[1] / 2) / (sz[1] / 2)
p2x = (float(p2[0]) - sz[0] / 2) / (sz[0] / 2) p2x = (float(p2[0]) - sz[0] / 2) / (sz[0] / 2)
p2y = -(float(p2[1]) - sz[1] / 2) / (sz[1] / 2) p2y = -(float(p2[1]) - sz[1] / 2) / (sz[1] / 2)
#print p1x,p1y,p2x,p2y #print p1x, p1y, p2x, p2y
quat = trackball(p1x, p1y, p2x, p2y, -self.transv[2] / 250.0) quat = trackball(p1x, p1y, p2x, p2y, -self.transv[2] / 250.0)
if self.rot: if self.rot:
self.basequat = mulquat(self.basequat, quat) self.basequat = mulquat(self.basequat, quat)
...@@ -710,7 +710,7 @@ class TestGlPanel(GLPanel): ...@@ -710,7 +710,7 @@ class TestGlPanel(GLPanel):
def drawmodel(self, m, n): def drawmodel(self, m, n):
batch = pyglet.graphics.Batch() batch = pyglet.graphics.Batch()
stl = stlview(m.facets, batch=batch) stl = stlview(m.facets, batch = batch)
m.batch = batch m.batch = batch
m.animoffset = 300 m.animoffset = 300
#print m #print m
...@@ -819,8 +819,8 @@ class TestGlPanel(GLPanel): ...@@ -819,8 +819,8 @@ class TestGlPanel(GLPanel):
class GCFrame(wx.Frame): class GCFrame(wx.Frame):
'''A simple class for using OpenGL with wxPython.''' '''A simple class for using OpenGL with wxPython.'''
def __init__(self, parent, ID, title, pos=wx.DefaultPosition, def __init__(self, parent, ID, title, pos = wx.DefaultPosition,
size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE): size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE):
super(GCFrame, self).__init__(parent, ID, title, pos, (size[0] + 150, size[1]), style) super(GCFrame, self).__init__(parent, ID, title, pos, (size[0] + 150, size[1]), style)
class d: class d:
...@@ -833,7 +833,7 @@ class GCFrame(wx.Frame): ...@@ -833,7 +833,7 @@ class GCFrame(wx.Frame):
m.curlayer = 0.0 m.curlayer = 0.0
m.scale = [1.0, 1.0, 1.0] m.scale = [1.0, 1.0, 1.0]
m.batch = pyglet.graphics.Batch() m.batch = pyglet.graphics.Batch()
m.gc = gcview([], batch=m.batch) m.gc = gcview([], batch = m.batch)
self.models = {"": m} self.models = {"": m}
self.l = d() self.l = d()
self.modelindex = 0 self.modelindex = 0
...@@ -841,13 +841,13 @@ class GCFrame(wx.Frame): ...@@ -841,13 +841,13 @@ class GCFrame(wx.Frame):
def addfile(self, gcode=[]): def addfile(self, gcode=[]):
self.models[""].gc.delete() self.models[""].gc.delete()
self.models[""].gc = gcview(gcode, batch=self.models[""].batch) self.models[""].gc = gcview(gcode, batch = self.models[""].batch)
def clear(self): def clear(self):
self.models[""].gc.delete() self.models[""].gc.delete()
self.models[""].gc = gcview([], batch=self.models[""].batch) self.models[""].gc = gcview([], batch = self.models[""].batch)
def Show(self, arg=True): def Show(self, arg = True):
wx.Frame.Show(self, arg) wx.Frame.Show(self, arg)
self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] + 1)) self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] + 1))
self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] - 1)) self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] - 1))
...@@ -868,10 +868,10 @@ class GCFrame(wx.Frame): ...@@ -868,10 +868,10 @@ class GCFrame(wx.Frame):
def main(): def main():
app = wx.App(redirect=False) app = wx.App(redirect = False)
frame = GCFrame(None, wx.ID_ANY, 'Gcode view, shift to move view, mousewheel to set layer', size=(400, 400)) frame = GCFrame(None, wx.ID_ANY, 'Gcode view, shift to move view, mousewheel to set layer', size = (400, 400))
frame.addfile(list(open("carriage dump_export.gcode"))) frame.addfile(list(open("carriage dump_export.gcode")))
#frame = wx.Frame(None, -1, "GL Window", size=(400, 400)) #frame = wx.Frame(None, -1, "GL Window", size = (400, 400))
#panel = TestGlPanel(frame) #panel = TestGlPanel(frame)
#frame.Show(True) #frame.Show(True)
#app.MainLoop() #app.MainLoop()
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
import wx import wx
def AddEllipticalArc(self, x, y, w, h, startAngle, endAngle, clockwise=False): def AddEllipticalArc(self, x, y, w, h, startAngle, endAngle, clockwise = False):
""" Draws an arc of an ellipse within bounding rect (x,y,w,h) """ Draws an arc of an ellipse within bounding rect (x, y,w, h)
from startArc to endArc (in radians, relative to the horizontal line of the eclipse)""" from startArc to endArc (in radians, relative to the horizontal line of the eclipse)"""
if True: if True:
......
...@@ -22,7 +22,7 @@ colorDeclaration = none | currentColor | colourValue ...@@ -22,7 +22,7 @@ colorDeclaration = none | currentColor | colourValue
urlEnd = ( urlEnd = (
Literal(")").suppress() + Literal(")").suppress() +
Optional(Group(colorDeclaration), default=()) + Optional(Group(colorDeclaration), default = ()) +
StringEnd() StringEnd()
) )
...@@ -30,12 +30,12 @@ url = ( ...@@ -30,12 +30,12 @@ url = (
CaselessLiteral("URL") CaselessLiteral("URL")
+ +
Literal("(").suppress()+ Literal("(").suppress()+
Group(SkipTo(urlEnd, include=True).setParseAction(parsePossibleURL)) Group(SkipTo(urlEnd, include = True).setParseAction(parsePossibleURL))
) )
#paint value will parse into a (type, details) tuple. #paint value will parse into a (type, details) tuple.
#For none and currentColor, the details tuple will be the empty tuple #For none and currentColor, the details tuple will be the empty tuple
#for CSS color declarations, it will be (type, (R,G,B)) #for CSS color declarations, it will be (type, (R, G,B))
#for URLs, it will be ("URL", ((url tuple), fallback)) #for URLs, it will be ("URL", ((url tuple), fallback))
#The url tuple will be as returned by urlparse.urlsplit, and can be #The url tuple will be as returned by urlparse.urlsplit, and can be
#an empty tuple if the parser has an error #an empty tuple if the parser has an error
......
...@@ -14,22 +14,22 @@ from svg.css.colour import colourValue ...@@ -14,22 +14,22 @@ from svg.css.colour import colourValue
from svg.css import values from svg.css import values
from attributes import paintValue from attributes import paintValue
document = """<?xml version="1.0" standalone="no"?> document = """<?xml version = "1.0" standalone = "no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="4cm" height="4cm" viewBox="0 0 400 400" <svg width = "4cm" height = "4cm" viewBox = "0 0 400 400"
xmlns="http://www.w3.org/2000/svg" version="1.1"> xmlns = "http://www.w3.org/2000/svg" version = "1.1">
<title>Example triangle01- simple example of a 'path'</title> <title>Example triangle01- simple example of a 'path'</title>
<desc>A path that draws a triangle</desc> <desc>A path that draws a triangle</desc>
<rect x="1" y="1" width="398" height="398" <rect x = "1" y = "1" width = "398" height = "398"
fill="none" stroke="blue" /> fill = "none" stroke = "blue" />
<path d="M 100 100 L 300 100 L 200 300 z" <path d = "M 100 100 L 300 100 L 200 300 z"
fill="red" stroke="blue" stroke-width="3" /> fill = "red" stroke = "blue" stroke-width = "3" />
</svg>""" </svg>"""
makePath = lambda: wx.GraphicsRenderer_GetDefaultRenderer().CreatePath() makePath = lambda: wx.GraphicsRenderer_GetDefaultRenderer().CreatePath()
def attrAsFloat(node, attr, defaultValue="0"): def attrAsFloat(node, attr, defaultValue = "0"):
val = node.get(attr, defaultValue) val = node.get(attr, defaultValue)
#TODO: process stuff like "inherit" by walking back up the nodes #TODO: process stuff like "inherit" by walking back up the nodes
#fast path optimization - if it's a valid float, don't #fast path optimization - if it's a valid float, don't
...@@ -39,7 +39,7 @@ def attrAsFloat(node, attr, defaultValue="0"): ...@@ -39,7 +39,7 @@ def attrAsFloat(node, attr, defaultValue="0"):
except ValueError: except ValueError:
return valueToPixels(val) return valueToPixels(val)
def valueToPixels(val, defaultUnits="px"): def valueToPixels(val, defaultUnits = "px"):
#TODO manage default units #TODO manage default units
from pyparsing import ParseException from pyparsing import ParseException
try: try:
...@@ -175,14 +175,14 @@ class SVGDocument(object): ...@@ -175,14 +175,14 @@ class SVGDocument(object):
) )
if transform == 'skewX': if transform == 'skewX':
matrix = wx.GraphicsRenderer_GetDefaultRenderer().CreateMatrix( matrix = wx.GraphicsRenderer_GetDefaultRenderer().CreateMatrix(
1,0,math.tan(math.radians(args[0])),1,0,0 1, 0,math.tan(math.radians(args[0])),1, 0,0
) )
ops.append( ops.append(
(wx.GraphicsContext.ConcatTransform, (matrix,)) (wx.GraphicsContext.ConcatTransform, (matrix,))
) )
if transform == 'skewY': if transform == 'skewY':
matrix = wx.GraphicsRenderer_GetDefaultRenderer().CreateMatrix( matrix = wx.GraphicsRenderer_GetDefaultRenderer().CreateMatrix(
1,math.tan(math.radians(args[0])),0,1,0,0 1, math.tan(math.radians(args[0])),0, 1,0, 0
) )
ops.append( ops.append(
(wx.GraphicsContext.ConcatTransform, (matrix,)) (wx.GraphicsContext.ConcatTransform, (matrix,))
...@@ -231,7 +231,7 @@ class SVGDocument(object): ...@@ -231,7 +231,7 @@ class SVGDocument(object):
def addTextToDocument(self, node): def addTextToDocument(self, node):
x, y = [attrAsFloat(node, attr) for attr in ('x', 'y')] x, y = [attrAsFloat(node, attr) for attr in ('x', 'y')]
def DoDrawText(context, text, x, y, brush=wx.NullGraphicsBrush): def DoDrawText(context, text, x, y, brush = wx.NullGraphicsBrush):
#SVG spec appears to originate text from the bottom #SVG spec appears to originate text from the bottom
#rather than the top as with our API. This function #rather than the top as with our API. This function
#will measure and then re-orient the text as needed. #will measure and then re-orient the text as needed.
...@@ -259,7 +259,7 @@ class SVGDocument(object): ...@@ -259,7 +259,7 @@ class SVGDocument(object):
rx = node.get('rx') rx = node.get('rx')
ry = node.get('ry') ry = node.get('ry')
if not (w and h): if not (w and h):
path.MoveToPoint(x,y) #keep the current point correct path.MoveToPoint(x, y) #keep the current point correct
return return
if rx or ry: if rx or ry:
if rx and ry: if rx and ry:
...@@ -449,7 +449,7 @@ class SVGDocument(object): ...@@ -449,7 +449,7 @@ class SVGDocument(object):
pen.SetJoin(joinmap.get(self.state.get('stroke-linejoin', None), wx.JOIN_MITER)) pen.SetJoin(joinmap.get(self.state.get('stroke-linejoin', None), wx.JOIN_MITER))
return wx.GraphicsRenderer_GetDefaultRenderer().CreatePen(pen) return wx.GraphicsRenderer_GetDefaultRenderer().CreatePen(pen)
def getBrushFromState(self, path=None): def getBrushFromState(self, path = None):
brushcolour = self.state.get('fill', 'black').strip() brushcolour = self.state.get('fill', 'black').strip()
type, details = paintValue.parseString(brushcolour) type, details = paintValue.parseString(brushcolour)
if type == "URL": if type == "URL":
...@@ -465,29 +465,29 @@ class SVGDocument(object): ...@@ -465,29 +465,29 @@ class SVGDocument(object):
box = path.GetBox() box = path.GetBox()
x, y, w, h = box.Get() x, y, w, h = box.Get()
return wx.GraphicsRenderer.GetDefaultRenderer().CreateLinearGradientBrush( return wx.GraphicsRenderer.GetDefaultRenderer().CreateLinearGradientBrush(
x,y,x+w,y+h,wx.Colour(0,0,255,128), wx.RED x, y,x+w, y+h, wx.Colour(0, 0,255, 128), wx.RED
) )
elif element.tag == '{http://www.w3.org/2000/svg}radialGradient': elif element.tag == '{http://www.w3.org/2000/svg}radialGradient':
box = path.GetBox() box = path.GetBox()
x, y, w, h = box.Get() x, y, w, h = box.Get()
#print w #print w
mx = wx.GraphicsRenderer.GetDefaultRenderer().CreateMatrix(x,y,w,h) mx = wx.GraphicsRenderer.GetDefaultRenderer().CreateMatrix(x, y,w, h)
cx, cy = mx.TransformPoint(0.5, 0.5) cx, cy = mx.TransformPoint(0.5, 0.5)
fx, fy = cx, cy fx, fy = cx, cy
return wx.GraphicsRenderer.GetDefaultRenderer().CreateRadialGradientBrush( return wx.GraphicsRenderer.GetDefaultRenderer().CreateRadialGradientBrush(
cx,cy, cx, cy,
fx,fy, fx, fy,
(max(w,h))/2, (max(w, h))/2,
wx.Colour(0,0,255,128), wx.RED wx.Colour(0, 0,255, 128), wx.RED
) )
else: else:
#invlid gradient specified #invlid gradient specified
return wx.NullBrush return wx.NullBrush
r,g,b = 0,0,0 r, g,b = 0, 0,0
if type == 'CURRENTCOLOR': if type == 'CURRENTCOLOR':
type, details = paintValue.parseString(self.state.get('color', 'none')) type, details = paintValue.parseString(self.state.get('color', 'none'))
if type == 'RGB': if type == 'RGB':
r,g,b = details r, g,b = details
elif type == "NONE": elif type == "NONE":
return wx.NullBrush return wx.NullBrush
opacity = self.state.get('fill-opacity', self.state.get('opacity', '1')) opacity = self.state.get('fill-opacity', self.state.get('opacity', '1'))
...@@ -499,9 +499,9 @@ class SVGDocument(object): ...@@ -499,9 +499,9 @@ class SVGDocument(object):
#be created every time anyway in order to pass them, #be created every time anyway in order to pass them,
#defeating the purpose of the cache #defeating the purpose of the cache
try: try:
return SVGDocument.brushCache[(r,g,b,a)] return SVGDocument.brushCache[(r, g,b, a)]
except KeyError: except KeyError:
return SVGDocument.brushCache.setdefault((r,g,b,a), wx.Brush(wx.Colour(r,g,b,a))) return SVGDocument.brushCache.setdefault((r, g,b, a), wx.Brush(wx.Colour(r, g,b, a)))
def resolveURL(self, urlData): def resolveURL(self, urlData):
...@@ -571,7 +571,7 @@ class SVGDocument(object): ...@@ -571,7 +571,7 @@ class SVGDocument(object):
#~ cp = path.GetCurrentPoint() #~ cp = path.GetCurrentPoint()
#~ path.AddCircle(c1x, c1y, 5) #~ path.AddCircle(c1x, c1y, 5)
#~ path.AddCircle(c2x, c2y, 3) #~ path.AddCircle(c2x, c2y, 3)
#~ path.AddCircle(x,y, 7) #~ path.AddCircle(x, y, 7)
#~ path.MoveToPoint(cp) #~ path.MoveToPoint(cp)
#~ print "C", control1, control2, endpoint #~ print "C", control1, control2, endpoint
...@@ -592,7 +592,7 @@ class SVGDocument(object): ...@@ -592,7 +592,7 @@ class SVGDocument(object):
endpoint endpoint
) )
elif type == "Q": elif type == "Q":
(cx, cy), (x,y) = map(normalizePoint, arg) (cx, cy), (x, y) = map(normalizePoint, arg)
self.lastControlQ = (cx, cy) self.lastControlQ = (cx, cy)
path.AddQuadCurveToPoint(cx, cy, x, y) path.AddQuadCurveToPoint(cx, cy, x, y)
elif type == "T": elif type == "T":
...@@ -607,12 +607,12 @@ class SVGDocument(object): ...@@ -607,12 +607,12 @@ class SVGDocument(object):
elif type == "V": elif type == "V":
_, y = normalizePoint((0, arg)) _, y = normalizePoint((0, arg))
x, _ = path.GetCurrentPoint() x, _ = path.GetCurrentPoint()
path.AddLineToPoint(x,y) path.AddLineToPoint(x, y)
elif type == "H": elif type == "H":
x, _ = normalizePoint((arg, 0)) x, _ = normalizePoint((arg, 0))
_, y = path.GetCurrentPoint() _, y = path.GetCurrentPoint()
path.AddLineToPoint(x,y) path.AddLineToPoint(x, y)
elif type == "A": elif type == "A":
#wxGC currently only supports circular arcs, #wxGC currently only supports circular arcs,
...@@ -625,14 +625,14 @@ class SVGDocument(object): ...@@ -625,14 +625,14 @@ class SVGDocument(object):
(x, y) #endpoint on the arc (x, y) #endpoint on the arc
) = arg ) = arg
x, y = normalizePoint((x,y)) x, y = normalizePoint((x, y))
cx, cy = path.GetCurrentPoint() cx, cy = path.GetCurrentPoint()
if (cx, cy) == (x, y): if (cx, cy) == (x, y):
return #noop return #noop
if (rx == 0 or ry == 0): if (rx == 0 or ry == 0):
#no radius is effectively a line #no radius is effectively a line
path.AddLineToPoint(x,y) path.AddLineToPoint(x, y)
return return
#find the center point for the ellipse #find the center point for the ellipse
...@@ -685,7 +685,7 @@ class SVGDocument(object): ...@@ -685,7 +685,7 @@ class SVGDocument(object):
path.MoveToPoint(x, y) path.MoveToPoint(x, y)
#~ npath = makePath() #~ npath = makePath()
#~ npath.AddEllipticalArc(cnx-rx, cny-ry, rx*2, ry*2, firstArc, lastArc, False) #~ npath.AddEllipticalArc(cnx-rx, cny-ry, rx*2, ry*2, firstArc, lastArc, False)
#~ npath.MoveToPoint(x,y) #~ npath.MoveToPoint(x, y)
#~ path.AddPath(npath) #~ path.AddPath(npath)
elif type == 'Z': elif type == 'Z':
......
...@@ -27,12 +27,12 @@ class CaselessPreservingLiteral(CaselessLiteral): ...@@ -27,12 +27,12 @@ class CaselessPreservingLiteral(CaselessLiteral):
instead of as defined. instead of as defined.
""" """
def __init__( self, matchString ): def __init__( self, matchString ):
super(CaselessPreservingLiteral,self).__init__( matchString.upper() ) super(CaselessPreservingLiteral, self).__init__( matchString.upper() )
self.name = "'%s'" % matchString self.name = "'%s'" % matchString
self.errmsg = "Expected " + self.name self.errmsg = "Expected " + self.name
self.myException.msg = self.errmsg self.myException.msg = self.errmsg
def parseImpl( self, instring, loc, doActions=True ): def parseImpl( self, instring, loc, doActions = True ):
test = instring[ loc:loc+self.matchLen ] test = instring[ loc:loc+self.matchLen ]
if test.upper() == self.match: if test.upper() == self.match:
return loc+self.matchLen, test return loc+self.matchLen, test
...@@ -117,7 +117,7 @@ ellipticalArcArgument = Group( ...@@ -117,7 +117,7 @@ ellipticalArcArgument = Group(
arcRadius + maybeComma + #rx, ry arcRadius + maybeComma + #rx, ry
number + maybeComma +#rotation number + maybeComma +#rotation
arcFlags + #large-arc-flag, sweep-flag arcFlags + #large-arc-flag, sweep-flag
coordinatePair #(x,y) coordinatePair #(x, y)
) )
......
This diff is collapsed.
...@@ -41,7 +41,7 @@ class XYButtons(BufferedCanvas): ...@@ -41,7 +41,7 @@ class XYButtons(BufferedCanvas):
center = (124, 121) center = (124, 121)
spacer = 7 spacer = 7
def __init__(self, parent, moveCallback=None, cornerCallback=None, spacebarCallback=None, bgcolor="#FFFFFF", ID=-1): def __init__(self, parent, moveCallback = None, cornerCallback = None, spacebarCallback = None, bgcolor = "#FFFFFF", ID=-1):
self.bg_bmp = wx.Image(imagefile("control_xy.png"),wx.BITMAP_TYPE_PNG).ConvertToBitmap() self.bg_bmp = wx.Image(imagefile("control_xy.png"),wx.BITMAP_TYPE_PNG).ConvertToBitmap()
self.keypad_bmp = wx.Image(imagefile("arrow_keys.png"),wx.BITMAP_TYPE_PNG).ConvertToBitmap() self.keypad_bmp = wx.Image(imagefile("arrow_keys.png"),wx.BITMAP_TYPE_PNG).ConvertToBitmap()
self.keypad_idx = -1 self.keypad_idx = -1
...@@ -181,7 +181,7 @@ class XYButtons(BufferedCanvas): ...@@ -181,7 +181,7 @@ class XYButtons(BufferedCanvas):
self.drawPartialPie(gc, center, r1-inner_ring_radius, r2-inner_ring_radius, a1+fudge, a2-fudge) self.drawPartialPie(gc, center, r1-inner_ring_radius, r2-inner_ring_radius, a1+fudge, a2-fudge)
def drawCorner(self, gc, x, y, angle=0.0): def drawCorner(self, gc, x, y, angle = 0.0):
w, h = XYButtons.corner_size w, h = XYButtons.corner_size
gc.PushState() gc.PushState()
...@@ -197,7 +197,7 @@ class XYButtons(BufferedCanvas): ...@@ -197,7 +197,7 @@ class XYButtons(BufferedCanvas):
gc.DrawPath(path) gc.DrawPath(path)
gc.PopState() gc.PopState()
def highlightCorner(self, gc, corner=0): def highlightCorner(self, gc, corner = 0):
w, h = XYButtons.corner_size w, h = XYButtons.corner_size
cx, cy = XYButtons.center cx, cy = XYButtons.center
ww, wh = self.GetSizeTuple() ww, wh = self.GetSizeTuple()
...@@ -229,8 +229,8 @@ class XYButtons(BufferedCanvas): ...@@ -229,8 +229,8 @@ class XYButtons(BufferedCanvas):
if self.enabled: if self.enabled:
# Brush and pen for grey overlay when mouse hovers over # Brush and pen for grey overlay when mouse hovers over
gc.SetPen(wx.Pen(wx.Colour(100,100,100,172), 4)) gc.SetPen(wx.Pen(wx.Colour(100, 100, 100, 172), 4))
gc.SetBrush(wx.Brush(wx.Colour(0,0,0,128))) gc.SetBrush(wx.Brush(wx.Colour(0, 0,0, 128)))
if self.concentric != None: if self.concentric != None:
if self.concentric < len(XYButtons.concentric_circle_radii): if self.concentric < len(XYButtons.concentric_circle_radii):
...@@ -246,8 +246,8 @@ class XYButtons(BufferedCanvas): ...@@ -246,8 +246,8 @@ class XYButtons(BufferedCanvas):
gc.DrawBitmap(self.keypad_bmp, pos[0], pos[1], padw, padh) gc.DrawBitmap(self.keypad_bmp, pos[0], pos[1], padw, padh)
# Draw label overlays # Draw label overlays
gc.SetPen(wx.Pen(wx.Colour(255,255,255,128), 1)) gc.SetPen(wx.Pen(wx.Colour(255, 255, 255, 128), 1))
gc.SetBrush(wx.Brush(wx.Colour(255,255,255,128+64))) gc.SetBrush(wx.Brush(wx.Colour(255, 255, 255, 128+64)))
for idx, kpos in XYButtons.label_overlay_positions.items(): for idx, kpos in XYButtons.label_overlay_positions.items():
if idx != self.concentric: if idx != self.concentric:
r = kpos[2] r = kpos[2]
......
...@@ -32,7 +32,7 @@ class ZButtons(BufferedCanvas): ...@@ -32,7 +32,7 @@ class ZButtons(BufferedCanvas):
3: None 3: None
} }
def __init__(self, parent, moveCallback=None, bgcolor="#FFFFFF", ID=-1): def __init__(self, parent, moveCallback = None, bgcolor = "#FFFFFF", ID=-1):
self.bg_bmp = wx.Image(imagefile("control_z.png"),wx.BITMAP_TYPE_PNG).ConvertToBitmap() self.bg_bmp = wx.Image(imagefile("control_z.png"),wx.BITMAP_TYPE_PNG).ConvertToBitmap()
self.range = None self.range = None
self.direction = None self.direction = None
...@@ -108,16 +108,16 @@ class ZButtons(BufferedCanvas): ...@@ -108,16 +108,16 @@ class ZButtons(BufferedCanvas):
if self.enabled: if self.enabled:
# Draw label overlays # Draw label overlays
gc.SetPen(wx.Pen(wx.Colour(255,255,255,128), 1)) gc.SetPen(wx.Pen(wx.Colour(255, 255, 255, 128), 1))
gc.SetBrush(wx.Brush(wx.Colour(255,255,255,128+64))) gc.SetBrush(wx.Brush(wx.Colour(255, 255, 255, 128+64)))
for idx, kpos in ZButtons.label_overlay_positions.items(): for idx, kpos in ZButtons.label_overlay_positions.items():
if kpos and idx != self.range: if kpos and idx != self.range:
r = kpos[2] r = kpos[2]
gc.DrawEllipse(ZButtons.center[0]-kpos[0]-r, ZButtons.center[1]-kpos[1]-r, r*2, r*2) gc.DrawEllipse(ZButtons.center[0]-kpos[0]-r, ZButtons.center[1]-kpos[1]-r, r*2, r*2)
# Top 'layer' is the mouse-over highlights # Top 'layer' is the mouse-over highlights
gc.SetPen(wx.Pen(wx.Colour(100,100,100,172), 4)) gc.SetPen(wx.Pen(wx.Colour(100, 100, 100, 172), 4))
gc.SetBrush(wx.Brush(wx.Colour(0,0,0,128))) gc.SetBrush(wx.Brush(wx.Colour(0, 0,0, 128)))
if self.range != None and self.direction != None: if self.range != None and self.direction != None:
self.highlight(gc, self.range, self.direction) self.highlight(gc, self.range, self.direction)
else: else:
......
...@@ -13,63 +13,63 @@ ...@@ -13,63 +13,63 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Printrun. If not, see <http://www.gnu.org/licenses/>. # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
import wx,math import wx, math
from stltool import * from stltool import *
a=wx.App() a = wx.App()
def genscape(data=[[0,1,0,0],[1,0,2,0],[1,0,0,0],[0,1,0,1]],pscale=1.0,bheight=1.0,zscale=1.0): def genscape(data=[[0, 1,0, 0],[1, 0,2, 0],[1, 0,0, 0],[0, 1,0, 1]],pscale = 1.0, bheight = 1.0, zscale = 1.0):
o=stl(None) o = stl(None)
datal=len(data) datal = len(data)
datah=len(data[0]) datah = len(data[0])
#create bottom: #create bottom:
bmidpoint=(pscale*(datal-1)/2.0,pscale*(datah-1)/2.0) bmidpoint = (pscale*(datal-1)/2.0, pscale*(datah-1)/2.0)
#print range(datal),bmidpoint #print range(datal),bmidpoint
for i in zip(range(datal+1)[:-1],range(datal+1)[1:])[:-1]: for i in zip(range(datal+1)[:-1],range(datal+1)[1:])[:-1]:
#print (pscale*i[0],pscale*i[1]) #print (pscale*i[0],pscale*i[1])
o.facets+=[[[0,0,-1],[[0.0,pscale*i[0],0.0],[0.0,pscale*i[1],0.0],[bmidpoint[0],bmidpoint[1],0.0]]]] o.facets+=[[[0, 0,-1],[[0.0, pscale*i[0],0.0],[0.0, pscale*i[1],0.0],[bmidpoint[0],bmidpoint[1],0.0]]]]
o.facets+=[[[0,0,-1],[[2.0*bmidpoint[1],pscale*i[1],0.0],[2.0*bmidpoint[1],pscale*i[0],0.0],[bmidpoint[0],bmidpoint[1],0.0]]]] o.facets+=[[[0, 0,-1],[[2.0*bmidpoint[1],pscale*i[1],0.0],[2.0*bmidpoint[1],pscale*i[0],0.0],[bmidpoint[0],bmidpoint[1],0.0]]]]
o.facets+=[genfacet([[0.0,pscale*i[0],data[i[0]][0]*zscale+bheight],[0.0,pscale*i[1],data[i[1]][0]*zscale+bheight],[0.0,pscale*i[1],0.0]])] o.facets+=[genfacet([[0.0, pscale*i[0],data[i[0]][0]*zscale+bheight],[0.0, pscale*i[1],data[i[1]][0]*zscale+bheight],[0.0, pscale*i[1],0.0]])]
o.facets+=[genfacet([[2.0*bmidpoint[1],pscale*i[1],data[i[1]][datah-1]*zscale+bheight],[2.0*bmidpoint[1],pscale*i[0],data[i[0]][datah-1]*zscale+bheight],[2.0*bmidpoint[1],pscale*i[1],0.0]])] o.facets+=[genfacet([[2.0*bmidpoint[1],pscale*i[1],data[i[1]][datah-1]*zscale+bheight],[2.0*bmidpoint[1],pscale*i[0],data[i[0]][datah-1]*zscale+bheight],[2.0*bmidpoint[1],pscale*i[1],0.0]])]
o.facets+=[genfacet([[0.0,pscale*i[0],data[i[0]][0]*zscale+bheight],[0.0,pscale*i[1],0.0],[0.0,pscale*i[0],0.0]])] o.facets+=[genfacet([[0.0, pscale*i[0],data[i[0]][0]*zscale+bheight],[0.0, pscale*i[1],0.0],[0.0, pscale*i[0],0.0]])]
o.facets+=[genfacet([[2.0*bmidpoint[1],pscale*i[1],0.0],[2.0*bmidpoint[1],pscale*i[0],data[i[0]][datah-1]*zscale+bheight],[2.0*bmidpoint[1],pscale*i[0],0.0]])] o.facets+=[genfacet([[2.0*bmidpoint[1],pscale*i[1],0.0],[2.0*bmidpoint[1],pscale*i[0],data[i[0]][datah-1]*zscale+bheight],[2.0*bmidpoint[1],pscale*i[0],0.0]])]
#print o.facets[-1] #print o.facets[-1]
pass pass
#print o.facets[-4:] #print o.facets[-4:]
for i in zip(range(datah+1)[:-1],range(datah+1)[1:])[:-1]: for i in zip(range(datah+1)[:-1],range(datah+1)[1:])[:-1]:
#print (pscale*i[0],pscale*i[1]) #print (pscale*i[0],pscale*i[1])
o.facets+=[[[0,0,-1],[[pscale*i[1],0.0,0.0],[pscale*i[0],0.0,0.0],[bmidpoint[0],bmidpoint[1],0.0]]]] o.facets+=[[[0, 0,-1],[[pscale*i[1],0.0, 0.0],[pscale*i[0],0.0, 0.0],[bmidpoint[0],bmidpoint[1],0.0]]]]
o.facets+=[[[0,0,-1],[[pscale*i[0],2.0*bmidpoint[0],0.0],[pscale*i[1],2.0*bmidpoint[0],0.0],[bmidpoint[0],bmidpoint[1],0.0]]]] o.facets+=[[[0, 0,-1],[[pscale*i[0],2.0*bmidpoint[0],0.0],[pscale*i[1],2.0*bmidpoint[0],0.0],[bmidpoint[0],bmidpoint[1],0.0]]]]
o.facets+=[genfacet([[pscale*i[1],0.0,data[0][i[1]]*zscale+bheight],[pscale*i[0],0.0,data[0][i[0]]*zscale+bheight],[pscale*i[1],0.0,0.0]])] o.facets+=[genfacet([[pscale*i[1],0.0, data[0][i[1]]*zscale+bheight],[pscale*i[0],0.0, data[0][i[0]]*zscale+bheight],[pscale*i[1],0.0, 0.0]])]
#break #break
o.facets+=[genfacet([[pscale*i[0],2.0*bmidpoint[0],data[datal-1][i[0]]*zscale+bheight],[pscale*i[1],2.0*bmidpoint[0],data[datal-1][i[1]]*zscale+bheight],[pscale*i[1],2.0*bmidpoint[0],0.0]])] o.facets+=[genfacet([[pscale*i[0],2.0*bmidpoint[0],data[datal-1][i[0]]*zscale+bheight],[pscale*i[1],2.0*bmidpoint[0],data[datal-1][i[1]]*zscale+bheight],[pscale*i[1],2.0*bmidpoint[0],0.0]])]
o.facets+=[genfacet([[pscale*i[1],0.0,0.0],[pscale*i[0],0.0,data[0][i[0]]*zscale+bheight],[pscale*i[0],0.0,0.0]])] o.facets+=[genfacet([[pscale*i[1],0.0, 0.0],[pscale*i[0],0.0, data[0][i[0]]*zscale+bheight],[pscale*i[0],0.0, 0.0]])]
o.facets+=[genfacet([[pscale*i[0],2.0*bmidpoint[0],data[datal-1][i[0]]*zscale+bheight],[pscale*i[1],2.0*bmidpoint[0],0.0],[pscale*i[0],2.0*bmidpoint[0],0.0]])] o.facets+=[genfacet([[pscale*i[0],2.0*bmidpoint[0],data[datal-1][i[0]]*zscale+bheight],[pscale*i[1],2.0*bmidpoint[0],0.0],[pscale*i[0],2.0*bmidpoint[0],0.0]])]
pass pass
for i in xrange(datah-1): for i in xrange(datah-1):
for j in xrange(datal-1): for j in xrange(datal-1):
o.facets+=[genfacet([[pscale*i,pscale*j,data[j][i]*zscale+bheight],[pscale*(i+1),pscale*(j),data[j][i+1]*zscale+bheight],[pscale*(i+1),pscale*(j+1),data[j+1][i+1]*zscale+bheight]])] o.facets+=[genfacet([[pscale*i, pscale*j, data[j][i]*zscale+bheight],[pscale*(i+1),pscale*(j),data[j][i+1]*zscale+bheight],[pscale*(i+1),pscale*(j+1),data[j+1][i+1]*zscale+bheight]])]
o.facets+=[genfacet([[pscale*(i),pscale*(j+1),data[j+1][i]*zscale+bheight],[pscale*i,pscale*j,data[j][i]*zscale+bheight],[pscale*(i+1),pscale*(j+1),data[j+1][i+1]*zscale+bheight]])] o.facets+=[genfacet([[pscale*(i),pscale*(j+1),data[j+1][i]*zscale+bheight],[pscale*i, pscale*j, data[j][i]*zscale+bheight],[pscale*(i+1),pscale*(j+1),data[j+1][i+1]*zscale+bheight]])]
#print o.facets[-1] #print o.facets[-1]
facet=[[0,0,0],[[0,0,0],[0,0,0],[0,0,0]]] facet=[[0, 0,0],[[0, 0,0],[0, 0,0],[0, 0,0]]]
return o return o
def zimage(name,out): def zimage(name, out):
i=wx.Image(name) i = wx.Image(name)
s=i.GetSize() s = i.GetSize()
print len(map(ord,i.GetData()[::3])) print len(map(ord, i.GetData()[::3]))
b=map(ord,i.GetData()[::3]) b = map(ord, i.GetData()[::3])
data=[] data=[]
for i in xrange(s[0]): for i in xrange(s[0]):
data+=[b[i*s[1]:(i+1)*s[1]]] data+=[b[i*s[1]:(i+1)*s[1]]]
#data=[i[::5] for i in data[::5]] #data=[i[::5] for i in data[::5]]
emitstl(out,genscape(data,zscale=0.1).facets,name) emitstl(out, genscape(data, zscale = 0.1).facets, name)
""" """
class scapewin(wx.Frame): class scapewin(wx.Frame):
def __init__(self,size=(400,530)): def __init__(self, size = (400, 530)):
wx.Frame.__init__(self,None,title="Right-click to load an image",size=size) wx.Frame.__init__(self, None, title = "Right-click to load an image",size = size)
self.SetIcon(wx.Icon("plater.ico",wx.BITMAP_TYPE_ICO)) self.SetIcon(wx.Icon("plater.ico",wx.BITMAP_TYPE_ICO))
self.SetClientSize(size) self.SetClientSize(size)
self.panel=wx.Panel(self,size=size) self.panel = wx.Panel(self, size = size)
""" """
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment