printrun-src/printrun/excluder.py

changeset 46
cce0af6351f0
parent 15
0bbb006204fc
equal deleted inserted replaced
45:c82943fb205f 46:cce0af6351f0
22 class ExcluderWindow(gviz.GvizWindow): 22 class ExcluderWindow(gviz.GvizWindow):
23 23
24 def __init__(self, excluder, *args, **kwargs): 24 def __init__(self, excluder, *args, **kwargs):
25 super(ExcluderWindow, self).__init__(*args, **kwargs) 25 super(ExcluderWindow, self).__init__(*args, **kwargs)
26 self.SetTitle(_("Part excluder: draw rectangles where print instructions should be ignored")) 26 self.SetTitle(_("Part excluder: draw rectangles where print instructions should be ignored"))
27 self.toolbar.AddLabelTool(128, " " + _("Reset selection"), 27 self.toolbar.AddTool(128, " " + _("Reset selection"),
28 wx.Image(imagefile('reset.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 28 wx.Image(imagefile('reset.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(),
29 shortHelp = _("Reset selection"), 29 _("Reset selection"))
30 longHelp = "")
31 self.Bind(wx.EVT_TOOL, self.reset_selection, id = 128) 30 self.Bind(wx.EVT_TOOL, self.reset_selection, id = 128)
32 self.parent = excluder 31 self.parent = excluder
33 self.p.paint_overlay = self.paint_selection 32 self.p.paint_overlay = self.paint_selection
34 self.p.layerup() 33 self.p.layerup()
35 34
44 def mouse(self, event): 43 def mouse(self, event):
45 if event.ButtonUp(wx.MOUSE_BTN_LEFT) \ 44 if event.ButtonUp(wx.MOUSE_BTN_LEFT) \
46 or event.ButtonUp(wx.MOUSE_BTN_RIGHT): 45 or event.ButtonUp(wx.MOUSE_BTN_RIGHT):
47 self.initpos = None 46 self.initpos = None
48 elif event.Dragging() and event.RightIsDown(): 47 elif event.Dragging() and event.RightIsDown():
49 e = event.GetPositionTuple() 48 e = event.GetPosition()
50 if not self.initpos or not hasattr(self, "basetrans"): 49 if not self.initpos or not hasattr(self, "basetrans"):
51 self.initpos = e 50 self.initpos = e
52 self.basetrans = self.p.translate 51 self.basetrans = self.p.translate
53 self.p.translate = [self.basetrans[0] + (e[0] - self.initpos[0]), 52 self.p.translate = [self.basetrans[0] + (e[0] - self.initpos[0]),
54 self.basetrans[1] + (e[1] - self.initpos[1])] 53 self.basetrans[1] + (e[1] - self.initpos[1])]
55 self.p.dirty = 1 54 self.p.dirty = 1
56 wx.CallAfter(self.p.Refresh) 55 wx.CallAfter(self.p.Refresh)
57 elif event.Dragging() and event.LeftIsDown(): 56 elif event.Dragging() and event.LeftIsDown():
58 x, y = event.GetPositionTuple() 57 x, y = event.GetPosition()
59 if not self.initpos: 58 if not self.initpos:
60 self.basetrans = self.p.translate 59 self.basetrans = self.p.translate
61 x = (x - self.basetrans[0]) / self.p.scale[0] 60 x = (x - self.basetrans[0]) / self.p.scale[0]
62 y = (y - self.basetrans[1]) / self.p.scale[1] 61 y = (y - self.basetrans[1]) / self.p.scale[1]
63 x, y = self.real_to_gcode(x, y) 62 x, y = self.real_to_gcode(x, y)
95 94
96 def reset_selection(self, event): 95 def reset_selection(self, event):
97 self.parent.rectangles = [] 96 self.parent.rectangles = []
98 wx.CallAfter(self.p.Refresh) 97 wx.CallAfter(self.p.Refresh)
99 98
100 class Excluder(object): 99 class Excluder:
101 100
102 def __init__(self): 101 def __init__(self):
103 self.rectangles = [] 102 self.rectangles = []
104 self.window = None 103 self.window = None
105 104
118 self.window.Destroy() 117 self.window.Destroy()
119 self.window = None 118 self.window = None
120 119
121 if __name__ == '__main__': 120 if __name__ == '__main__':
122 import sys 121 import sys
123 import gcoder 122 from . import gcoder
124 gcode = gcoder.GCode(open(sys.argv[1])) 123 gcode = gcoder.GCode(open(sys.argv[1]))
125 app = wx.App(False) 124 app = wx.App(False)
126 ex = Excluder() 125 ex = Excluder()
127 ex.pop_window(gcode) 126 ex.pop_window(gcode)
128 app.MainLoop() 127 app.MainLoop()

mercurial