Commit 7333e93c authored by kliment's avatar kliment

Merge pull request #286 from iXce/split-gui

GUI creation split
parents ab7c2782 9c55677e
...@@ -51,13 +51,10 @@ class Graph(BufferedCanvas): ...@@ -51,13 +51,10 @@ class Graph(BufferedCanvas):
self._lastyvalue = 0 self._lastyvalue = 0
#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)
def OnPaint(self, evt): def OnPaint(self, evt):
dc = wx.PaintDC(self) dc = wx.PaintDC(self)
gc = wx.GraphicsContext.Create(dc) gc = wx.GraphicsContext.Create(dc)
...@@ -66,7 +63,6 @@ class Graph(BufferedCanvas): ...@@ -66,7 +63,6 @@ class Graph(BufferedCanvas):
#call the super method #call the super method
super(wx.Panel, self).Destroy() super(wx.Panel, self).Destroy()
def updateTemperatures(self, event): def updateTemperatures(self, event):
self.AddBedTemperature(self.bedtemps[-1]) self.AddBedTemperature(self.bedtemps[-1])
self.AddBedTargetTemperature(self.bedtargettemps[-1]) self.AddBedTargetTemperature(self.bedtargettemps[-1])
...@@ -76,7 +72,6 @@ class Graph(BufferedCanvas): ...@@ -76,7 +72,6 @@ class Graph(BufferedCanvas):
#self.AddExtruder1TargetTemperature(self.extruder1targettemps[-1]) #self.AddExtruder1TargetTemperature(self.extruder1targettemps[-1])
self.Refresh() self.Refresh()
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)
...@@ -105,7 +100,6 @@ class Graph(BufferedCanvas): ...@@ -105,7 +100,6 @@ class Graph(BufferedCanvas):
#gc.DrawPath(path) #gc.DrawPath(path)
#gc.StrokePath(path) #gc.StrokePath(path)
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))
...@@ -192,7 +186,6 @@ class Graph(BufferedCanvas): ...@@ -192,7 +186,6 @@ class Graph(BufferedCanvas):
if (len(self.bedtemps)-1) * float(self.width)/self.xsteps > self.width: if (len(self.bedtemps)-1) * float(self.width)/self.xsteps > self.width:
self.bedtemps.pop(0) self.bedtemps.pop(0)
def SetBedTargetTemperature(self, value): def SetBedTargetTemperature(self, value):
self.bedtargettemps.pop() self.bedtargettemps.pop()
self.bedtargettemps.append(value) self.bedtargettemps.append(value)
...@@ -202,7 +195,6 @@ class Graph(BufferedCanvas): ...@@ -202,7 +195,6 @@ class Graph(BufferedCanvas):
if (len(self.bedtargettemps)-1) * float(self.width)/self.xsteps > self.width: if (len(self.bedtargettemps)-1) * float(self.width)/self.xsteps > self.width:
self.bedtargettemps.pop(0) self.bedtargettemps.pop(0)
def SetExtruder0Temperature(self, value): def SetExtruder0Temperature(self, value):
self.extruder0temps.pop() self.extruder0temps.pop()
self.extruder0temps.append(value) self.extruder0temps.append(value)
...@@ -212,7 +204,6 @@ class Graph(BufferedCanvas): ...@@ -212,7 +204,6 @@ class Graph(BufferedCanvas):
if (len(self.extruder0temps)-1) * float(self.width)/self.xsteps > self.width: if (len(self.extruder0temps)-1) * float(self.width)/self.xsteps > self.width:
self.extruder0temps.pop(0) self.extruder0temps.pop(0)
def SetExtruder0TargetTemperature(self, value): def SetExtruder0TargetTemperature(self, value):
self.extruder0targettemps.pop() self.extruder0targettemps.pop()
self.extruder0targettemps.append(value) self.extruder0targettemps.append(value)
...@@ -222,7 +213,6 @@ class Graph(BufferedCanvas): ...@@ -222,7 +213,6 @@ class Graph(BufferedCanvas):
if (len(self.extruder0targettemps)-1) * float(self.width)/self.xsteps > self.width: if (len(self.extruder0targettemps)-1) * float(self.width)/self.xsteps > self.width:
self.extruder0targettemps.pop(0) self.extruder0targettemps.pop(0)
def SetExtruder1Temperature(self, value): def SetExtruder1Temperature(self, value):
self.extruder1temps.pop() self.extruder1temps.pop()
self.extruder1temps.append(value) self.extruder1temps.append(value)
...@@ -232,7 +222,6 @@ class Graph(BufferedCanvas): ...@@ -232,7 +222,6 @@ class Graph(BufferedCanvas):
if (len(self.extruder1temps)-1) * float(self.width)/self.xsteps > self.width: if (len(self.extruder1temps)-1) * float(self.width)/self.xsteps > self.width:
self.extruder1temps.pop(0) self.extruder1temps.pop(0)
def SetExtruder1TargetTemperature(self, value): def SetExtruder1TargetTemperature(self, value):
self.extruder1targettemps.pop() self.extruder1targettemps.pop()
self.extruder1targettemps.append(value) self.extruder1targettemps.append(value)
...@@ -242,7 +231,6 @@ class Graph(BufferedCanvas): ...@@ -242,7 +231,6 @@ class Graph(BufferedCanvas):
if (len(self.extruder1targettemps)-1) * float(self.width)/self.xsteps > self.width: if (len(self.extruder1targettemps)-1) * float(self.width)/self.xsteps > self.width:
self.extruder1targettemps.pop(0) self.extruder1targettemps.pop(0)
def StartPlotting(self, time): def StartPlotting(self, time):
self.Refresh() self.Refresh()
self.timer.Start(time) self.timer.Start(time)
......
This diff is collapsed.
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
import wx import wx
import re import re
class macroed(wx.Dialog): class MacroEditor(wx.Dialog):
"""Really simple editor to edit macro definitions""" """Really simple editor to edit macro definitions"""
def __init__(self, macro_name, definition, callback, gcode = False): def __init__(self, macro_name, definition, callback, gcode = False):
...@@ -91,10 +91,10 @@ class macroed(wx.Dialog): ...@@ -91,10 +91,10 @@ class macroed(wx.Dialog):
self.callback(self.reindent(self.e.GetValue())) self.callback(self.reindent(self.e.GetValue()))
else: else:
self.callback(self.e.GetValue().split("\n")) self.callback(self.e.GetValue().split("\n"))
def close(self, ev): def close(self, ev):
self.Destroy() self.Destroy()
if self.webInterface:
webinterface.KillWebInterfaceThread()
def unindent(self, text): def unindent(self, text):
self.indent_chars = text[:len(text)-len(text.lstrip())] self.indent_chars = text[:len(text)-len(text.lstrip())]
if len(self.indent_chars) == 0: if len(self.indent_chars) == 0:
...@@ -211,108 +211,21 @@ class ButtonEdit(wx.Dialog): ...@@ -211,108 +211,21 @@ class ButtonEdit(wx.Dialog):
if self.name.GetValue()=="": if self.name.GetValue()=="":
self.name.SetValue(macro) self.name.SetValue(macro)
class TempGauge(wx.Panel): class SpecialButton(object):
def __init__(self, parent, size = (200, 22), title = "", maxval = 240, gaugeColour = None): label = None
wx.Panel.__init__(self, parent,-1, size = size) command = None
self.Bind(wx.EVT_PAINT, self.paint) background = None
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) pos = None
self.width, self.height = size span = None
self.title = title tooltip = None
self.max = maxval custom = None
self.gaugeColour = gaugeColour
self.value = 0 def __init__(self, label, command, background = None, pos = None, span = None, tooltip = None, custom = False):
self.setpoint = 0 self.label = label
self.recalc() self.command = command
self.pos = pos
def recalc(self): self.background = background
mmax = max(int(self.setpoint*1.05), self.max) self.span = span
self.scale = float(self.width-2)/float(mmax) self.tooltip = tooltip
self.ypt = max(16, int(self.scale*max(self.setpoint, self.max/6))) self.custom = custom
def SetValue(self, value):
self.value = value
wx.CallAfter(self.Refresh)
def SetTarget(self, value):
self.setpoint = value
self.recalc()
wx.CallAfter(self.Refresh)
def interpolatedColour(self, val, vmin, vmid, vmax, cmin, cmid, cmax):
if val < vmin: return cmin
if val > vmax: return cmax
if val <= vmid:
lo, hi, val, valhi = cmin, cmid, val-vmin, vmid-vmin
else:
lo, hi, val, valhi = cmid, cmax, val-vmid, vmax-vmid
vv = float(val)/valhi
rgb = lo.Red()+(hi.Red()-lo.Red())*vv, lo.Green()+(hi.Green()-lo.Green())*vv, lo.Blue()+(hi.Blue()-lo.Blue())*vv
rgb = map(lambda x:x*0.8, rgb)
return wx.Colour(*map(int, rgb))
def paint(self, ev):
x0, y0, x1, y1, xE, yE = 1, 1, self.ypt+1, 1, self.width+1-2, 20
dc = wx.PaintDC(self)
dc.SetBackground(wx.Brush((255, 255, 255)))
dc.Clear()
cold, medium, hot = wx.Colour(0, 167, 223), wx.Colour(239, 233, 119), wx.Colour(210, 50.100)
gauge1, gauge2 = wx.Colour(255, 255, 210), (self.gaugeColour or wx.Colour(234, 82, 0))
shadow1, shadow2 = wx.Colour(110, 110, 110), wx.Colour(255, 255, 255)
gc = wx.GraphicsContext.Create(dc)
# draw shadow first
# corners
gc.SetBrush(gc.CreateRadialGradientBrush(xE-7, 9, xE-7, 9, 8, shadow1, shadow2))
gc.DrawRectangle(xE-7, 1, 8, 8)
gc.SetBrush(gc.CreateRadialGradientBrush(xE-7, 17, xE-7, 17, 8, shadow1, shadow2))
gc.DrawRectangle(xE-7, 17, 8, 8)
gc.SetBrush(gc.CreateRadialGradientBrush(x0+6, 17, x0+6, 17, 8, shadow1, shadow2))
gc.DrawRectangle(0, 17, x0+6, 8)
# edges
gc.SetBrush(gc.CreateLinearGradientBrush(xE-13, 0, xE-6, 0, shadow1, shadow2))
gc.DrawRectangle(xE-6, 9, 10, 8)
gc.SetBrush(gc.CreateLinearGradientBrush(x0, yE-2, x0, yE+5, shadow1, shadow2))
gc.DrawRectangle(x0+6, yE-2, xE-12, 7)
# draw gauge background
gc.SetBrush(gc.CreateLinearGradientBrush(x0, y0, x1+1, y1, cold, medium))
gc.DrawRoundedRectangle(x0, y0, x1+4, yE, 6)
gc.SetBrush(gc.CreateLinearGradientBrush(x1-2, y1, xE, y1, medium, hot))
gc.DrawRoundedRectangle(x1-2, y1, xE-x1, yE, 6)
# draw gauge
width = 12
w1 = y0+9-width/2
w2 = w1+width
value = x0+max(10, min(self.width+1-2, int(self.value*self.scale)))
#gc.SetBrush(gc.CreateLinearGradientBrush(x0, y0+3, x0, y0+15, gauge1, gauge2))
#gc.SetBrush(gc.CreateLinearGradientBrush(0, 3, 0, 15, wx.Colour(255, 255, 255), wx.Colour(255, 90, 32)))
gc.SetBrush(gc.CreateLinearGradientBrush(x0, y0+3, x0, y0+15, gauge1, self.interpolatedColour(value, x0, x1, xE, cold, medium, hot)))
val_path = gc.CreatePath()
val_path.MoveToPoint(x0, w1)
val_path.AddLineToPoint(value, w1)
val_path.AddLineToPoint(value+2, w1+width/4)
val_path.AddLineToPoint(value+2, w2-width/4)
val_path.AddLineToPoint(value, w2)
#val_path.AddLineToPoint(value-4, 10)
val_path.AddLineToPoint(x0, w2)
gc.DrawPath(val_path)
# draw setpoint markers
setpoint = x0+max(10, int(self.setpoint*self.scale))
gc.SetBrush(gc.CreateBrush(wx.Brush(wx.Colour(0, 0, 0))))
setp_path = gc.CreatePath()
setp_path.MoveToPoint(setpoint-4, y0)
setp_path.AddLineToPoint(setpoint+4, y0)
setp_path.AddLineToPoint(setpoint, y0+5)
setp_path.MoveToPoint(setpoint-4, yE)
setp_path.AddLineToPoint(setpoint+4, yE)
setp_path.AddLineToPoint(setpoint, yE-5)
gc.DrawPath(setp_path)
# draw readout
text = u"T\u00B0 %u/%u"%(self.value, self.setpoint)
#gc.SetFont(gc.CreateFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD), wx.WHITE))
#gc.DrawText(text, 29,-2)
gc.SetFont(gc.CreateFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD), wx.WHITE))
gc.DrawText(self.title, x0+19, y0+4)
gc.DrawText(text, x0+119, y0+4)
gc.SetFont(gc.CreateFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)))
gc.DrawText(self.title, x0+18, y0+3)
gc.DrawText(text, x0+118, y0+3)
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