printrun-src/printrun/pronterface.py

Sat, 04 Jun 2016 15:18:06 +0200

author
mbayer
date
Sat, 04 Jun 2016 15:18:06 +0200
changeset 26
5c98c7e24b02
parent 25
0e3e7fbf0bc6
child 29
c96f20e95029
permissions
-rw-r--r--

Add quick access button to laser options

15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1 #!/usr/bin/env python
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2
16
36d478bde840 Implemented svg, png and hpgl compilers to pronterface
mbayer
parents: 15
diff changeset
3 # FILE MODIFIED BY NEOSOFT - MALTE BAYER
36d478bde840 Implemented svg, png and hpgl compilers to pronterface
mbayer
parents: 15
diff changeset
4 # Embed Lasercut functions from laser.py
20
03b34402d405 Code cleanup
mbayer
parents: 19
diff changeset
5 import laser
16
36d478bde840 Implemented svg, png and hpgl compilers to pronterface
mbayer
parents: 15
diff changeset
6
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
7 # This file is part of the Printrun suite.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
8 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
9 # Printrun is free software: you can redistribute it and/or modify
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
10 # it under the terms of the GNU General Public License as published by
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
11 # the Free Software Foundation, either version 3 of the License, or
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
12 # (at your option) any later version.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
13 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
14 # Printrun is distributed in the hope that it will be useful,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
17 # GNU General Public License for more details.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
18 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
19 # You should have received a copy of the GNU General Public License
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
20 # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
21
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
22 import os
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
23 import Queue
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
24 import sys
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
25 import time
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
26 import threading
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
27 import traceback
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
28 import cStringIO as StringIO
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
29 import subprocess
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
30 import glob
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
31 import logging
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
32
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
33 try: import simplejson as json
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
34 except ImportError: import json
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
35
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
36 from . import pronsole
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
37 from . import printcore
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
38
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
39 from .utils import install_locale, setup_logging, dosify, \
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
40 iconfile, configfile, format_time, format_duration, \
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
41 hexcolor_to_float, parse_temperature_report, \
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
42 prepare_command, check_rgb_color, check_rgba_color
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
43 install_locale('pronterface')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
44
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
45 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
46 import wx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
47 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
48 logging.error(_("WX is not installed. This program requires WX to run."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
49 raise
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
50
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
51 from .gui.widgets import SpecialButton, MacroEditor, PronterOptions, ButtonEdit
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
52
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
53 winsize = (800, 500)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
54 layerindex = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
55 if os.name == "nt":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
56 winsize = (800, 530)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
57
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
58 pronterface_quitting = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
59
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
60 class PronterfaceQuitException(Exception):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
61 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
62
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
63 from .gui import MainWindow
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
64 from .settings import wxSetting, HiddenSetting, StringSetting, SpinSetting, \
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
65 FloatSpinSetting, BooleanSetting, StaticTextSetting
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
66 from printrun import gcoder
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
67 from .pronsole import REPORT_NONE, REPORT_POS, REPORT_TEMP, REPORT_MANUAL
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
68
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
69 class ConsoleOutputHandler(object):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
70 """Handle console output. All messages go through the logging submodule. We setup a logging handler to get logged messages and write them to both stdout (unless a log file path is specified, in which case we add another logging handler to write to this file) and the log panel.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
71 We also redirect stdout and stderr to ourself to catch print messages and al."""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
72
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
73 def __init__(self, target, log_path):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
74 self.stdout = sys.stdout
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
75 self.stderr = sys.stderr
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
76 sys.stdout = self
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
77 sys.stderr = self
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
78 if log_path:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
79 self.print_on_stdout = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
80 setup_logging(self, log_path, reset_handlers = True)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
81 self.target = target
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
82 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
83 self.print_on_stdout = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
84 setup_logging(sys.stdout)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
85 self.target = target
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
86
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
87 def __del__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
88 sys.stdout = self.stdout
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
89 sys.stderr = self.stderr
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
90
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
91 def write(self, data):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
92 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
93 self.target(data)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
94 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
95 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
96 if self.print_on_stdout:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
97 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
98 data = data.encode("utf-8")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
99 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
100 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
101 self.stdout.write(data)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
102
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
103 def flush(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
104 if self.stdout:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
105 self.stdout.flush()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
106
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
107 class ComboSetting(wxSetting):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
108
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
109 def __init__(self, name, default, choices, label = None, help = None, group = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
110 super(ComboSetting, self).__init__(name, default, label, help, group)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
111 self.choices = choices
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
112
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
113 def get_specific_widget(self, parent):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
114 import wx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
115 self.widget = wx.ComboBox(parent, -1, str(self.value), choices = self.choices, style = wx.CB_DROPDOWN)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
116 return self.widget
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
117
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
118 class PronterWindow(MainWindow, pronsole.pronsole):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
119
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
120 _fgcode = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
121
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
122 def _get_fgcode(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
123 return self._fgcode
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
124
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
125 def _set_fgcode(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
126 self._fgcode = value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
127 self.excluder = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
128 self.excluder_e = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
129 self.excluder_z_abs = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
130 self.excluder_z_rel = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
131 fgcode = property(_get_fgcode, _set_fgcode)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
132
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
133 def _get_display_graph(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
134 return self.settings.tempgraph
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
135 display_graph = property(_get_display_graph)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
136
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
137 def _get_display_gauges(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
138 return self.settings.tempgauges
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
139 display_gauges = property(_get_display_gauges)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
140
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
141 def __init__(self, app, filename = None, size = winsize):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
142 pronsole.pronsole.__init__(self)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
143 self.app = app
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
144 self.window_ready = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
145 self.ui_ready = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
146 self._add_settings(size)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
147
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
148 for field in dir(self.settings):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
149 if field.startswith("_gcview_color_"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
150 cleanname = field[1:]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
151 color = hexcolor_to_float(getattr(self.settings, cleanname), 4)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
152 setattr(self, cleanname, list(color))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
153
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
154 self.pauseScript = None #"pause.gcode"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
155 self.endScript = None #"end.gcode"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
156
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
157 self.filename = filename
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
158
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
159 self.capture_skip = {}
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
160 self.capture_skip_newline = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
161 self.fgcode = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
162 self.excluder = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
163 self.slicep = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
164 self.current_pos = [0, 0, 0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
165 self.paused = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
166 self.uploading = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
167 self.sentglines = Queue.Queue(0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
168 self.cpbuttons = {
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
169 "motorsoff": SpecialButton(_("Motors off"), ("M84"), (250, 250, 250), _("Switch all motors off")),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
170 "extrude": SpecialButton(_("Extrude"), ("pront_extrude"), (225, 200, 200), _("Advance extruder by set length")),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
171 "reverse": SpecialButton(_("Reverse"), ("pront_reverse"), (225, 200, 200), _("Reverse extruder by set length")),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
172 }
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
173 self.custombuttons = []
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
174 self.btndict = {}
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
175 self.filehistory = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
176 self.autoconnect = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
177 self.parse_cmdline(sys.argv[1:])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
178
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
179 # FIXME: We need to initialize the main window after loading the
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
180 # configs to restore the size, but this might have some unforeseen
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
181 # consequences.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
182 # -- Okai, it seems it breaks things like update_gviz_params ><
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
183 os.putenv("UBUNTU_MENUPROXY", "0")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
184 size = (self.settings.last_window_width, self.settings.last_window_height)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
185 MainWindow.__init__(self, None, title = _("Pronterface"), size = size)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
186 if self.settings.last_window_maximized:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
187 self.Maximize()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
188 self.SetIcon(wx.Icon(iconfile("pronterface.png"), wx.BITMAP_TYPE_PNG))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
189 self.Bind(wx.EVT_SIZE, self.on_resize)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
190 self.Bind(wx.EVT_MAXIMIZE, self.on_maximize)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
191 self.window_ready = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
192
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
193 # set feedrates in printcore for pause/resume
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
194 self.p.xy_feedrate = self.settings.xy_feedrate
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
195 self.p.z_feedrate = self.settings.z_feedrate
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
196
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
197 self.panel.SetBackgroundColour(self.bgcolor)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
198 customdict = {}
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
199 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
200 execfile(configfile("custombtn.txt"), customdict)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
201 if len(customdict["btns"]):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
202 if not len(self.custombuttons):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
203 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
204 self.custombuttons = customdict["btns"]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
205 for n in xrange(len(self.custombuttons)):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
206 self.cbutton_save(n, self.custombuttons[n])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
207 os.rename("custombtn.txt", "custombtn.old")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
208 rco = open("custombtn.txt", "w")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
209 rco.write(_("# I moved all your custom buttons into .pronsolerc.\n# Please don't add them here any more.\n# Backup of your old buttons is in custombtn.old\n"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
210 rco.close()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
211 except IOError, x:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
212 logging.error(str(x))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
213 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
214 logging.warning(_("Note!!! You have specified custom buttons in both custombtn.txt and .pronsolerc"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
215 logging.warning(_("Ignoring custombtn.txt. Remove all current buttons to revert to custombtn.txt"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
216
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
217 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
218 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
219 self.create_menu()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
220 self.update_recent_files("recentfiles", self.settings.recentfiles)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
221
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
222 self.reload_ui()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
223 # disable all printer controls until we connect to a printer
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
224 self.gui_set_disconnected()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
225 self.statusbar = self.CreateStatusBar()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
226 self.statusbar.SetStatusText(_("Not connected to printer."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
227
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
228 self.t = ConsoleOutputHandler(self.catchprint, self.settings.log_path)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
229 self.stdout = sys.stdout
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
230 self.slicing = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
231 self.loading_gcode = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
232 self.loading_gcode_message = ""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
233 self.mini = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
234 self.p.sendcb = self.sentcb
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
235 self.p.preprintsendcb = self.preprintsendcb
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
236 self.p.printsendcb = self.printsentcb
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
237 self.p.startcb = self.startcb
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
238 self.p.endcb = self.endcb
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
239 self.cur_button = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
240 self.predisconnect_mainqueue = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
241 self.predisconnect_queueindex = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
242 self.predisconnect_layer = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
243 self.hsetpoint = 0.0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
244 self.bsetpoint = 0.0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
245 if self.autoconnect:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
246 self.connect()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
247 if self.filename is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
248 self.do_load(self.filename)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
249 if self.settings.monitor:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
250 self.update_monitor()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
251
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
252 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
253 # Main interface handling
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
254 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
255
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
256 def reset_ui(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
257 MainWindow.reset_ui(self)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
258 self.custombuttons_widgets = []
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
259
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
260 def reload_ui(self, *args):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
261 if not self.window_ready: return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
262 self.Freeze()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
263
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
264 # If UI is being recreated, delete current one
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
265 if self.ui_ready:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
266 # Store log console content
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
267 logcontent = self.logbox.GetValue()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
268 # Create a temporary panel to reparent widgets with state we want
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
269 # to retain across UI changes
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
270 temppanel = wx.Panel(self)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
271 # TODO: add viz widgets to statefulControls
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
272 for control in self.statefulControls:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
273 control.GetContainingSizer().Detach(control)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
274 control.Reparent(temppanel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
275 self.panel.DestroyChildren()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
276 self.gwindow.Destroy()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
277 self.reset_ui()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
278
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
279 # Create UI
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
280 if self.settings.uimode in (_("Tabbed"), _("Tabbed with platers")):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
281 self.createTabbedGui()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
282 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
283 self.createGui(self.settings.uimode == _("Compact"),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
284 self.settings.controlsmode == "Mini")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
285
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
286 if hasattr(self, "splitterwindow"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
287 self.splitterwindow.SetSashPosition(self.settings.last_sash_position)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
288
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
289 def splitter_resize(event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
290 self.splitterwindow.UpdateSize()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
291 self.splitterwindow.Bind(wx.EVT_SIZE, splitter_resize)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
292
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
293 def sash_position_changed(event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
294 self.set("last_sash_position", self.splitterwindow.GetSashPosition())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
295 self.splitterwindow.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, sash_position_changed)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
296
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
297 # Set gcview parameters here as they don't get set when viewers are
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
298 # created
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
299 self.update_gcview_params()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
300
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
301 # Finalize
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
302 if self.online:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
303 self.gui_set_connected()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
304 if self.ui_ready:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
305 self.logbox.SetValue(logcontent)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
306 temppanel.Destroy()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
307 self.panel.Layout()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
308 if self.fgcode:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
309 self.start_viz_thread()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
310 if self.settings.monitor:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
311 self.update_monitor()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
312 self.ui_ready = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
313 self.Thaw()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
314
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
315 def on_resize(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
316 wx.CallAfter(self.on_resize_real)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
317 event.Skip()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
318
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
319 def on_resize_real(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
320 maximized = self.IsMaximized()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
321 self.set("last_window_maximized", maximized)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
322 if not maximized and not self.IsIconized():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
323 size = self.GetSize()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
324 self.set("last_window_width", size[0])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
325 self.set("last_window_height", size[1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
326
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
327 def on_maximize(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
328 self.set("last_window_maximized", self.IsMaximized())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
329 event.Skip()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
330
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
331 def on_exit(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
332 self.Close()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
333
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
334 def kill(self, e):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
335 if self.p.printing or self.p.paused:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
336 dlg = wx.MessageDialog(self, _("Print in progress ! Are you really sure you want to quit ?"), _("Exit"), wx.YES_NO | wx.ICON_WARNING)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
337 if dlg.ShowModal() == wx.ID_NO:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
338 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
339 pronsole.pronsole.kill(self)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
340 global pronterface_quitting
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
341 pronterface_quitting = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
342 self.p.recvcb = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
343 self.p.disconnect()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
344 if hasattr(self, "feedrates_changed"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
345 self.save_in_rc("set xy_feedrate", "set xy_feedrate %d" % self.settings.xy_feedrate)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
346 self.save_in_rc("set z_feedrate", "set z_feedrate %d" % self.settings.z_feedrate)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
347 self.save_in_rc("set e_feedrate", "set e_feedrate %d" % self.settings.e_feedrate)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
348 if self.settings.last_extrusion != self.settings.default_extrusion:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
349 self.save_in_rc("set last_extrusion", "set last_extrusion %d" % self.settings.last_extrusion)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
350 if self.excluder:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
351 self.excluder.close_window()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
352 wx.CallAfter(self.gwindow.Destroy)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
353 wx.CallAfter(self.Destroy)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
354
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
355 def _get_bgcolor(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
356 if self.settings.bgcolor != "auto":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
357 return self.settings.bgcolor
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
358 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
359 return wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWFRAME)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
360 bgcolor = property(_get_bgcolor)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
361
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
362 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
363 # Main interface actions
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
364 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
365
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
366 def do_monitor(self, l = ""):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
367 if l.strip() == "":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
368 self.set("monitor", not self.settings.monitor)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
369 elif l.strip() == "off":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
370 self.set("monitor", False)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
371 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
372 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
373 self.monitor_interval = float(l)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
374 self.set("monitor", self.monitor_interval > 0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
375 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
376 self.log(_("Invalid period given."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
377 if self.settings.monitor:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
378 self.log(_("Monitoring printer."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
379 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
380 self.log(_("Done monitoring."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
381
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
382 def do_pront_extrude(self, l = ""):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
383 feed = self.settings.e_feedrate
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
384 self.do_extrude_final(self.edist.GetValue(), feed)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
385
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
386 def do_pront_reverse(self, l = ""):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
387 feed = self.settings.e_feedrate
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
388 self.do_extrude_final(- self.edist.GetValue(), feed)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
389
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
390 def do_settemp(self, l = ""):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
391 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
392 if l.__class__ not in (str, unicode) or not len(l):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
393 l = str(self.htemp.GetValue().split()[0])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
394 l = l.lower().replace(", ", ".")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
395 for i in self.temps.keys():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
396 l = l.replace(i, self.temps[i])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
397 f = float(l)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
398 if f >= 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
399 if self.p.online:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
400 self.p.send_now("M104 S" + l)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
401 self.log(_("Setting hotend temperature to %f degrees Celsius.") % f)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
402 self.sethotendgui(f)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
403 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
404 self.logError(_("Printer is not online."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
405 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
406 self.logError(_("You cannot set negative temperatures. To turn the hotend off entirely, set its temperature to 0."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
407 except Exception, x:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
408 self.logError(_("You must enter a temperature. (%s)") % (repr(x),))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
409
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
410 def do_bedtemp(self, l = ""):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
411 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
412 if l.__class__ not in (str, unicode) or not len(l):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
413 l = str(self.btemp.GetValue().split()[0])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
414 l = l.lower().replace(", ", ".")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
415 for i in self.bedtemps.keys():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
416 l = l.replace(i, self.bedtemps[i])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
417 f = float(l)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
418 if f >= 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
419 if self.p.online:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
420 self.p.send_now("M140 S" + l)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
421 self.log(_("Setting bed temperature to %f degrees Celsius.") % f)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
422 self.setbedgui(f)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
423 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
424 self.logError(_("Printer is not online."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
425 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
426 self.logError(_("You cannot set negative temperatures. To turn the bed off entirely, set its temperature to 0."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
427 except Exception, x:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
428 self.logError(_("You must enter a temperature. (%s)") % (repr(x),))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
429
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
430 def do_setspeed(self, l = ""):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
431 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
432 if l.__class__ not in (str, unicode) or not len(l):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
433 l = str(self.speed_slider.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
434 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
435 l = l.lower()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
436 speed = int(l)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
437 if self.p.online:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
438 self.p.send_now("M220 S" + l)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
439 self.log(_("Setting print speed factor to %d%%.") % speed)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
440 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
441 self.logError(_("Printer is not online."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
442 except Exception, x:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
443 self.logError(_("You must enter a speed. (%s)") % (repr(x),))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
444
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
445 def do_setflow(self, l = ""):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
446 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
447 if l.__class__ not in (str, unicode) or not len(l):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
448 l = str(self.flow_slider.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
449 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
450 l = l.lower()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
451 flow = int(l)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
452 if self.p.online:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
453 self.p.send_now("M221 S" + l)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
454 self.log(_("Setting print flow factor to %d%%.") % flow)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
455 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
456 self.logError(_("Printer is not online."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
457 except Exception, x:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
458 self.logError(_("You must enter a flow. (%s)") % (repr(x),))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
459
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
460 def setbedgui(self, f):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
461 self.bsetpoint = f
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
462 if self.display_gauges: self.bedtgauge.SetTarget(int(f))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
463 if self.display_graph: wx.CallAfter(self.graph.SetBedTargetTemperature, int(f))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
464 if f > 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
465 wx.CallAfter(self.btemp.SetValue, str(f))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
466 self.set("last_bed_temperature", str(f))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
467 wx.CallAfter(self.setboff.SetBackgroundColour, None)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
468 wx.CallAfter(self.setboff.SetForegroundColour, None)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
469 wx.CallAfter(self.setbbtn.SetBackgroundColour, "#FFAA66")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
470 wx.CallAfter(self.setbbtn.SetForegroundColour, "#660000")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
471 wx.CallAfter(self.btemp.SetBackgroundColour, "#FFDABB")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
472 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
473 wx.CallAfter(self.setboff.SetBackgroundColour, "#0044CC")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
474 wx.CallAfter(self.setboff.SetForegroundColour, "white")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
475 wx.CallAfter(self.setbbtn.SetBackgroundColour, None)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
476 wx.CallAfter(self.setbbtn.SetForegroundColour, None)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
477 wx.CallAfter(self.btemp.SetBackgroundColour, "white")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
478 wx.CallAfter(self.btemp.Refresh)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
479
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
480 def sethotendgui(self, f):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
481 self.hsetpoint = f
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
482 if self.display_gauges: self.hottgauge.SetTarget(int(f))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
483 if self.display_graph: wx.CallAfter(self.graph.SetExtruder0TargetTemperature, int(f))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
484 if f > 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
485 wx.CallAfter(self.htemp.SetValue, str(f))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
486 self.set("last_temperature", str(f))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
487 wx.CallAfter(self.settoff.SetBackgroundColour, None)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
488 wx.CallAfter(self.settoff.SetForegroundColour, None)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
489 wx.CallAfter(self.settbtn.SetBackgroundColour, "#FFAA66")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
490 wx.CallAfter(self.settbtn.SetForegroundColour, "#660000")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
491 wx.CallAfter(self.htemp.SetBackgroundColour, "#FFDABB")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
492 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
493 wx.CallAfter(self.settoff.SetBackgroundColour, "#0044CC")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
494 wx.CallAfter(self.settoff.SetForegroundColour, "white")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
495 wx.CallAfter(self.settbtn.SetBackgroundColour, None)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
496 wx.CallAfter(self.settbtn.SetForegroundColour, None)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
497 wx.CallAfter(self.htemp.SetBackgroundColour, "white")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
498 wx.CallAfter(self.htemp.Refresh)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
499
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
500 def rescanports(self, event = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
501 scanned = self.scanserial()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
502 portslist = list(scanned)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
503 if self.settings.port != "" and self.settings.port not in portslist:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
504 portslist.append(self.settings.port)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
505 self.serialport.Clear()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
506 self.serialport.AppendItems(portslist)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
507 if os.path.exists(self.settings.port) or self.settings.port in scanned:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
508 self.serialport.SetValue(self.settings.port)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
509 elif portslist:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
510 self.serialport.SetValue(portslist[0])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
511
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
512 def cbkey(self, e):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
513 if e.GetKeyCode() == wx.WXK_UP:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
514 if self.commandbox.histindex == len(self.commandbox.history):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
515 self.commandbox.history.append(self.commandbox.GetValue()) # save current command
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
516 if len(self.commandbox.history):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
517 self.commandbox.histindex = (self.commandbox.histindex - 1) % len(self.commandbox.history)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
518 self.commandbox.SetValue(self.commandbox.history[self.commandbox.histindex])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
519 self.commandbox.SetSelection(0, len(self.commandbox.history[self.commandbox.histindex]))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
520 elif e.GetKeyCode() == wx.WXK_DOWN:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
521 if self.commandbox.histindex == len(self.commandbox.history):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
522 self.commandbox.history.append(self.commandbox.GetValue()) # save current command
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
523 if len(self.commandbox.history):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
524 self.commandbox.histindex = (self.commandbox.histindex + 1) % len(self.commandbox.history)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
525 self.commandbox.SetValue(self.commandbox.history[self.commandbox.histindex])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
526 self.commandbox.SetSelection(0, len(self.commandbox.history[self.commandbox.histindex]))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
527 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
528 e.Skip()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
529
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
530 def plate(self, e):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
531 from . import stlplater as plater
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
532 self.log(_("Plate function activated"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
533 plater.StlPlater(size = (800, 580), callback = self.platecb,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
534 parent = self,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
535 build_dimensions = self.build_dimensions_list,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
536 circular_platform = self.settings.circular_bed,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
537 simarrange_path = self.settings.simarrange_path,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
538 antialias_samples = int(self.settings.antialias3dsamples)).Show()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
539
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
540 def plate_gcode(self, e):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
541 from . import gcodeplater as plater
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
542 self.log(_("G-Code plate function activated"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
543 plater.GcodePlater(size = (800, 580), callback = self.platecb,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
544 parent = self,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
545 build_dimensions = self.build_dimensions_list,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
546 circular_platform = self.settings.circular_bed,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
547 antialias_samples = int(self.settings.antialias3dsamples)).Show()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
548
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
549 def platecb(self, name):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
550 self.log(_("Plated %s") % name)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
551 self.loadfile(None, name)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
552 if self.settings.uimode in (_("Tabbed"), _("Tabbed with platers")):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
553 # Switch to page 1 (Status tab)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
554 self.notebook.SetSelection(1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
555
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
556 def do_editgcode(self, e = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
557 if self.filename is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
558 MacroEditor(self.filename, [line.raw for line in self.fgcode], self.doneediting, True)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
559
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
560 def doneediting(self, gcode):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
561 open(self.filename, "w").write("\n".join(gcode))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
562 wx.CallAfter(self.loadfile, None, self.filename)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
563
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
564 def sdmenu(self, e):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
565 obj = e.GetEventObject()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
566 popupmenu = wx.Menu()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
567 item = popupmenu.Append(-1, _("SD Upload"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
568 if not self.fgcode:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
569 item.Enable(False)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
570 self.Bind(wx.EVT_MENU, self.upload, id = item.GetId())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
571 item = popupmenu.Append(-1, _("SD Print"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
572 self.Bind(wx.EVT_MENU, self.sdprintfile, id = item.GetId())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
573 self.panel.PopupMenu(popupmenu, obj.GetPosition())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
574
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
575 def htemp_change(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
576 if self.hsetpoint > 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
577 self.do_settemp("")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
578 wx.CallAfter(self.htemp.SetInsertionPoint, 0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
579
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
580 def btemp_change(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
581 if self.bsetpoint > 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
582 self.do_bedtemp("")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
583 wx.CallAfter(self.btemp.SetInsertionPoint, 0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
584
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
585 def tool_change(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
586 self.do_tool(self.extrudersel.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
587
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
588 def show_viz_window(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
589 if self.fgcode:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
590 self.gwindow.Show(True)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
591 self.gwindow.SetToolTip(wx.ToolTip("Mousewheel zooms the display\nShift / Mousewheel scrolls layers"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
592 self.gwindow.Raise()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
593
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
594 def setfeeds(self, e):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
595 self.feedrates_changed = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
596 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
597 if self.efeedc is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
598 self.settings._set("e_feedrate", self.efeedc.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
599 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
600 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
601 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
602 self.settings._set("z_feedrate", self.zfeedc.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
603 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
604 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
605 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
606 self.settings._set("xy_feedrate", self.xyfeedc.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
607 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
608 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
609 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
610 self.settings._set("last_extrusion", self.edist.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
611 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
612 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
613
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
614 def homeButtonClicked(self, axis):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
615 # When user clicks on the XY control, the Z control no longer gets spacebar/repeat signals
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
616 self.zb.clearRepeat()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
617 if axis == "x":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
618 self.onecmd('home X')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
619 elif axis == "y": # upper-right
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
620 self.onecmd('home Y')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
621 elif axis == "z":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
622 self.onecmd('home Z')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
623 elif axis == "all":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
624 self.onecmd('home')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
625 elif axis == "center":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
626 center_x = self.build_dimensions_list[0] / 2 + self.build_dimensions_list[3]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
627 center_y = self.build_dimensions_list[1] / 2 + self.build_dimensions_list[4]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
628 feed = self.settings.xy_feedrate
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
629 self.onecmd('G0 X%s Y%s F%s' % (center_x, center_y, feed))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
630 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
631 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
632 self.p.send_now('M114')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
633
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
634 def clamped_move_message(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
635 self.log(_("Manual move outside of the build volume prevented (see the \"Clamp manual moves\" option)."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
636
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
637 def moveXY(self, x, y):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
638 # When user clicks on the XY control, the Z control no longer gets spacebar/repeat signals
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
639 self.zb.clearRepeat()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
640 if x != 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
641 if self.settings.clamp_jogging:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
642 new_x = self.current_pos[0] + x
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
643 if new_x < self.build_dimensions_list[3] or new_x > self.build_dimensions_list[0] + self.build_dimensions_list[3]:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
644 self.clamped_move_message()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
645 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
646 self.onecmd('move X %s' % x)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
647 elif y != 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
648 if self.settings.clamp_jogging:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
649 new_y = self.current_pos[1] + y
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
650 if new_y < self.build_dimensions_list[4] or new_y > self.build_dimensions_list[1] + self.build_dimensions_list[4]:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
651 self.clamped_move_message()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
652 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
653 self.onecmd('move Y %s' % y)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
654 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
655 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
656 self.p.send_now('M114')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
657
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
658 def moveZ(self, z):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
659 if z != 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
660 if self.settings.clamp_jogging:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
661 new_z = self.current_pos[2] + z
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
662 if new_z < self.build_dimensions_list[5] or new_z > self.build_dimensions_list[2] + self.build_dimensions_list[5]:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
663 self.clamped_move_message()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
664 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
665 self.onecmd('move Z %s' % z)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
666 self.p.send_now('M114')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
667 # When user clicks on the Z control, the XY control no longer gets spacebar/repeat signals
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
668 self.xyb.clearRepeat()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
669
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
670 def spacebarAction(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
671 self.zb.repeatLast()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
672 self.xyb.repeatLast()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
673
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
674 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
675 # Console handling
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
676 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
677
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
678 def catchprint(self, l):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
679 """Called by the Tee operator to write to the log box"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
680 if not self.IsFrozen():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
681 wx.CallAfter(self.addtexttolog, l)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
682
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
683 def addtexttolog(self, text):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
684 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
685 self.logbox.AppendText(text)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
686 max_length = 20000
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
687 current_length = self.logbox.GetLastPosition()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
688 if current_length > max_length:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
689 self.logbox.Remove(0, current_length / 10)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
690 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
691 self.log(_("Attempted to write invalid text to console, which could be due to an invalid baudrate"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
692
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
693 def clear_log(self, e):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
694 self.logbox.Clear()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
695
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
696 def set_verbose_communications(self, e):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
697 self.p.loud = e.IsChecked()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
698
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
699 def sendline(self, e):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
700 command = self.commandbox.GetValue()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
701 if not len(command):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
702 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
703 wx.CallAfter(self.addtexttolog, ">>> " + command + "\n")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
704 line = self.precmd(str(command))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
705 self.onecmd(line)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
706 self.commandbox.SetSelection(0, len(command))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
707 self.commandbox.history.append(command)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
708 self.commandbox.histindex = len(self.commandbox.history)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
709
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
710 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
711 # Main menu handling & actions
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
712 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
713
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
714 def create_menu(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
715 """Create main menu"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
716 self.menustrip = wx.MenuBar()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
717 # File menu
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
718 m = wx.Menu()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
719 self.Bind(wx.EVT_MENU, self.loadfile, m.Append(-1, _("&Open..."), _(" Open file")))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
720 self.savebtn = m.Append(-1, _("&Save..."), _(" Save file"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
721 self.savebtn.Enable(False)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
722 self.Bind(wx.EVT_MENU, self.savefile, self.savebtn)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
723
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
724 self.filehistory = wx.FileHistory(maxFiles = 8, idBase = wx.ID_FILE1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
725 recent = wx.Menu()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
726 self.filehistory.UseMenu(recent)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
727 self.Bind(wx.EVT_MENU_RANGE, self.load_recent_file,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
728 id = wx.ID_FILE1, id2 = wx.ID_FILE9)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
729 m.AppendMenu(wx.ID_ANY, _("&Recent Files"), recent)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
730 self.Bind(wx.EVT_MENU, self.clear_log, m.Append(-1, _("Clear console"), _(" Clear output console")))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
731 self.Bind(wx.EVT_MENU, self.on_exit, m.Append(wx.ID_EXIT, _("E&xit"), _(" Closes the Window")))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
732 self.menustrip.Append(m, _("&File"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
733
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
734 m = wx.Menu()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
735 self.Bind(wx.EVT_MENU, self.do_editgcode, m.Append(-1, _("&Edit..."), _(" Edit open file")))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
736 self.Bind(wx.EVT_MENU, self.plate, m.Append(-1, _("Plater"), _(" Compose 3D models into a single plate")))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
737 self.Bind(wx.EVT_MENU, self.plate_gcode, m.Append(-1, _("G-Code Plater"), _(" Compose G-Codes into a single plate")))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
738 self.Bind(wx.EVT_MENU, self.exclude, m.Append(-1, _("Excluder"), _(" Exclude parts of the bed from being printed")))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
739 self.Bind(wx.EVT_MENU, self.project, m.Append(-1, _("Projector"), _(" Project slices")))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
740 self.menustrip.Append(m, _("&Tools"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
741
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
742 m = wx.Menu()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
743 self.recoverbtn = m.Append(-1, _("Recover"), _(" Recover previous print after a disconnect (homes X, Y, restores Z and E status)"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
744 self.recoverbtn.Disable = lambda *a: self.recoverbtn.Enable(False)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
745 self.Bind(wx.EVT_MENU, self.recover, self.recoverbtn)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
746 self.menustrip.Append(m, _("&Advanced"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
747
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
748 if self.settings.slic3rintegration:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
749 m = wx.Menu()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
750 print_menu = wx.Menu()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
751 filament_menu = wx.Menu()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
752 printer_menu = wx.Menu()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
753 m.AppendSubMenu(print_menu, _("Print &settings"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
754 m.AppendSubMenu(filament_menu, _("&Filament"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
755 m.AppendSubMenu(printer_menu, _("&Printer"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
756 menus = {"print": print_menu,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
757 "filament": filament_menu,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
758 "printer": printer_menu}
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
759 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
760 self.load_slic3r_configs(menus)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
761 self.menustrip.Append(m, _("&Slic3r"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
762 except IOError:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
763 self.logError(_("Failed to load Slic3r configuration:") +
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
764 "\n" + traceback.format_exc())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
765
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
766 # Settings menu
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
767 m = wx.Menu()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
768 self.macros_menu = wx.Menu()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
769 m.AppendSubMenu(self.macros_menu, _("&Macros"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
770 self.Bind(wx.EVT_MENU, self.new_macro, self.macros_menu.Append(-1, _("<&New...>")))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
771 self.Bind(wx.EVT_MENU, lambda *e: PronterOptions(self), m.Append(-1, _("&Options"), _(" Options dialog")))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
772
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
773 self.Bind(wx.EVT_MENU, lambda x: threading.Thread(target = lambda: self.do_slice("set")).start(), m.Append(-1, _("Slicing settings"), _(" Adjust slicing settings")))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
774
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
775 mItem = m.AppendCheckItem(-1, _("Debug communications"),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
776 _("Print all G-code sent to and received from the printer."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
777 m.Check(mItem.GetId(), self.p.loud)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
778 self.Bind(wx.EVT_MENU, self.set_verbose_communications, mItem)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
779
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
780 self.menustrip.Append(m, _("&Settings"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
781 self.update_macros_menu()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
782 self.SetMenuBar(self.menustrip)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
783
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
784 m = wx.Menu()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
785 self.Bind(wx.EVT_MENU, self.about,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
786 m.Append(-1, _("&About Printrun"), _("Show about dialog")))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
787 self.menustrip.Append(m, _("&Help"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
788
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
789 def project(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
790 """Start Projector tool"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
791 from printrun import projectlayer
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
792 projectlayer.SettingsFrame(self, self.p).Show()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
793
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
794 def exclude(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
795 """Start part excluder tool"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
796 if not self.fgcode:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
797 wx.CallAfter(self.statusbar.SetStatusText, _("No file loaded. Please use load first."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
798 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
799 if not self.excluder:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
800 from .excluder import Excluder
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
801 self.excluder = Excluder()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
802 self.excluder.pop_window(self.fgcode, bgcolor = self.bgcolor,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
803 build_dimensions = self.build_dimensions_list)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
804
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
805 def about(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
806 """Show about dialog"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
807
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
808 info = wx.AboutDialogInfo()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
809
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
810 info.SetIcon(wx.Icon(iconfile("pronterface.png"), wx.BITMAP_TYPE_PNG))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
811 info.SetName('Printrun')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
812 info.SetVersion(printcore.__version__)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
813
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
814 description = _("Printrun is a pure Python 3D printing"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
815 " (and other types of CNC) host software.")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
816
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
817 description += "\n\n" + \
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
818 _("%.02fmm of filament have been extruded during prints") \
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
819 % self.settings.total_filament_used
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
820
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
821 info.SetDescription(description)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
822 info.SetCopyright('(C) 2011 - 2015')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
823 info.SetWebSite('https://github.com/kliment/Printrun')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
824
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
825 licence = """\
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
826 Printrun is free software: you can redistribute it and/or modify it under the
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
827 terms of the GNU General Public License as published by the Free Software
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
828 Foundation, either version 3 of the License, or (at your option) any later
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
829 version.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
830
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
831 Printrun is distributed in the hope that it will be useful, but WITHOUT ANY
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
832 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
833 PARTICULAR PURPOSE. See the GNU General Public License for more details.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
834
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
835 You should have received a copy of the GNU General Public License along with
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
836 Printrun. If not, see <http://www.gnu.org/licenses/>."""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
837
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
838 info.SetLicence(licence)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
839 info.AddDeveloper('Kliment Yanev')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
840 info.AddDeveloper('Guillaume Seguin')
22
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
841 info.AddDeveloper('Malte Bayer')
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
842
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
843 wx.AboutBox(info)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
844
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
845 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
846 # Settings & command line handling (including update callbacks)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
847 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
848
22
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
849 def update_lc_settings(self, key, value):
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
850 return True
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
851
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
852 def _add_settings(self, size):
22
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
853
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
854 # first add the lasercutter options
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
855 self.settings._add(StaticTextSetting("separator_lc_general", "General laser settings", "", group = "Laser"))
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
856 self.settings._add(SpinSetting("lc_travel_speed", 120, 10, 300, "Travel speed in mm/s", "", "Laser"), self.update_lc_settings)
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
857 self.settings._add(SpinSetting("lc_engrave_speed", 10, 10, 300, "Engrave speed in mm/s", "", "Laser"), self.update_lc_settings)
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
858
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
859 self.settings._add(StaticTextSetting("separator_lc_bitmap", "PNG Bitmap processing", "", group = "Laser"))
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
860 self.settings._add(FloatSpinSetting("lc_bitmap_speed_factor", 1.0, 0.1, 2.0, "Engrave speed factor", "", "Laser"), self.update_lc_settings)
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
861 self.settings._add(SpinSetting("lc_dpi", 300, 25, 300, "Image DPI", "Image resolution for scaling", "Laser"), self.update_lc_settings)
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
862 self.settings._add(SpinSetting("lc_grey_threshold", 0, 0, 255, "Grey threshold value for RGB", "", "Laser"), self.update_lc_settings)
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
863 self.settings._add(BooleanSetting("lc_invert_cut", True, "PNG: Invert grey threshold", "Invert laser on/off logic", "Laser"), self.update_lc_settings)
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
864 self.settings._add(BooleanSetting("lc_change_dir", True, "PNG: Change direction", "Engrave in both directions on Y Axis", "Laser"), self.update_lc_settings)
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
865
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
866 self.settings._add(StaticTextSetting("separator_lc_hpgl", "HPGL processing", "", group = "Laser"))
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
867 self.settings._add(FloatSpinSetting("lc_hpgl_speed_factor", 1.0, 0.1, 2.0, "Engrave speed factor", "", "Laser"), self.update_lc_settings)
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
868
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
869 self.settings._add(StaticTextSetting("separator_lc_svg", "SVG processing", "", group = "Laser"))
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
870 self.settings._add(FloatSpinSetting("lc_svg_speed_factor", 1.0, 0.1, 2.0, "Engrave speed factor", "", "Laser"), self.update_lc_settings)
25
0e3e7fbf0bc6 Added more svg options to settings
mbayer
parents: 22
diff changeset
871 self.settings._add(FloatSpinSetting("lc_svg_smoothness", 0.2, 0.1, 10.0, "Smoothness", "Smoothness of curves (smaller value = smoother curve)", "Laser"), self.update_lc_settings)
0e3e7fbf0bc6 Added more svg options to settings
mbayer
parents: 22
diff changeset
872 self.settings._add(SpinSetting("lc_svg_width", 50, 1, 200, "Width (mm)", "Image width", "Laser"), self.update_lc_settings)
0e3e7fbf0bc6 Added more svg options to settings
mbayer
parents: 22
diff changeset
873 self.settings._add(SpinSetting("lc_svg_height", 50, 1, 200, "Height (mm)", "Image height", "Laser"), self.update_lc_settings)
0e3e7fbf0bc6 Added more svg options to settings
mbayer
parents: 22
diff changeset
874 self.settings._add(ComboSetting("lc_svg_scalemode", "scale", ["scale", "stretch"], "Scaling mode", "scale to dimensions / stretch to dimensions", "Laser"), self.update_lc_settings)
22
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
875
4c9bb8f93ae8 Added the Lasercut settings to the pronterface options dialog
mbayer
parents: 20
diff changeset
876
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
877 self.settings._add(BooleanSetting("monitor", True, _("Monitor printer status"), _("Regularly monitor printer temperatures (required to have functional temperature graph or gauges)"), "Printer"), self.update_monitor)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
878 self.settings._add(StringSetting("simarrange_path", "", _("Simarrange command"), _("Path to the simarrange binary to use in the STL plater"), "External"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
879 self.settings._add(BooleanSetting("circular_bed", False, _("Circular build platform"), _("Draw a circular (or oval) build platform instead of a rectangular one"), "Printer"), self.update_bed_viz)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
880 self.settings._add(SpinSetting("extruders", 0, 1, 5, _("Extruders count"), _("Number of extruders"), "Printer"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
881 self.settings._add(BooleanSetting("clamp_jogging", False, _("Clamp manual moves"), _("Prevent manual moves from leaving the specified build dimensions"), "Printer"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
882 self.settings._add(ComboSetting("uimode", _("Standard"), [_("Standard"), _("Compact"), _("Tabbed"), _("Tabbed with platers")], _("Interface mode"), _("Standard interface is a one-page, three columns layout with controls/visualization/log\nCompact mode is a one-page, two columns layout with controls + log/visualization\nTabbed mode is a two-pages mode, where the first page shows controls and the second one shows visualization and log.\nTabbed with platers mode is the same as Tabbed, but with two extra pages for the STL and G-Code platers."), "UI"), self.reload_ui)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
883 self.settings._add(ComboSetting("controlsmode", "Standard", ["Standard", "Mini"], _("Controls mode"), _("Standard controls include all controls needed for printer setup and calibration, while Mini controls are limited to the ones needed for daily printing"), "UI"), self.reload_ui)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
884 self.settings._add(BooleanSetting("slic3rintegration", False, _("Enable Slic3r integration"), _("Add a menu to select Slic3r profiles directly from Pronterface"), "UI"), self.reload_ui)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
885 self.settings._add(BooleanSetting("slic3rupdate", False, _("Update Slic3r default presets"), _("When selecting a profile in Slic3r integration menu, also save it as the default Slic3r preset"), "UI"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
886 self.settings._add(ComboSetting("mainviz", "3D", ["2D", "3D", "None"], _("Main visualization"), _("Select visualization for main window."), "Viewer"), self.reload_ui)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
887 self.settings._add(BooleanSetting("viz3d", False, _("Use 3D in GCode viewer window"), _("Use 3D mode instead of 2D layered mode in the visualization window"), "Viewer"), self.reload_ui)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
888 self.settings._add(StaticTextSetting("separator_3d_viewer", _("3D viewer options"), "", group = "Viewer"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
889 self.settings._add(BooleanSetting("light3d", False, _("Use a lighter 3D visualization"), _("Use a lighter visualization with simple lines instead of extruded paths for 3D viewer"), "Viewer"), self.reload_ui)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
890 self.settings._add(ComboSetting("antialias3dsamples", "0", ["0", "2", "4", "8"], _("Number of anti-aliasing samples"), _("Amount of anti-aliasing samples used in the 3D viewer"), "Viewer"), self.reload_ui)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
891 self.settings._add(BooleanSetting("trackcurrentlayer3d", False, _("Track current layer in main 3D view"), _("Track the currently printing layer in the main 3D visualization"), "Viewer"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
892 self.settings._add(FloatSpinSetting("gcview_path_width", 0.4, 0.01, 2, _("Extrusion width for 3D viewer"), _("Width of printed path in 3D viewer"), "Viewer", increment = 0.05), self.update_gcview_params)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
893 self.settings._add(FloatSpinSetting("gcview_path_height", 0.3, 0.01, 2, _("Layer height for 3D viewer"), _("Height of printed path in 3D viewer"), "Viewer", increment = 0.05), self.update_gcview_params)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
894 self.settings._add(BooleanSetting("tempgraph", True, _("Display temperature graph"), _("Display time-lapse temperature graph"), "UI"), self.reload_ui)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
895 self.settings._add(BooleanSetting("tempgauges", False, _("Display temperature gauges"), _("Display graphical gauges for temperatures visualization"), "UI"), self.reload_ui)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
896 self.settings._add(BooleanSetting("lockbox", False, _("Display interface lock checkbox"), _("Display a checkbox that, when check, locks most of Pronterface"), "UI"), self.reload_ui)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
897 self.settings._add(BooleanSetting("lockonstart", False, _("Lock interface upon print start"), _("If lock checkbox is enabled, lock the interface when starting a print"), "UI"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
898 self.settings._add(BooleanSetting("refreshwhenloading", True, _("Update UI during G-Code load"), _("Regularly update visualization during the load of a G-Code file"), "UI"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
899 self.settings._add(HiddenSetting("last_window_width", size[0]))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
900 self.settings._add(HiddenSetting("last_window_height", size[1]))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
901 self.settings._add(HiddenSetting("last_window_maximized", False))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
902 self.settings._add(HiddenSetting("last_sash_position", -1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
903 self.settings._add(HiddenSetting("last_bed_temperature", 0.0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
904 self.settings._add(HiddenSetting("last_file_path", u""))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
905 self.settings._add(HiddenSetting("last_file_filter", 0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
906 self.settings._add(HiddenSetting("last_temperature", 0.0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
907 self.settings._add(StaticTextSetting("separator_2d_viewer", _("2D viewer options"), "", group = "Viewer"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
908 self.settings._add(FloatSpinSetting("preview_extrusion_width", 0.5, 0, 10, _("Preview extrusion width"), _("Width of Extrusion in Preview"), "Viewer", increment = 0.1), self.update_gviz_params)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
909 self.settings._add(SpinSetting("preview_grid_step1", 10., 0, 200, _("Fine grid spacing"), _("Fine Grid Spacing"), "Viewer"), self.update_gviz_params)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
910 self.settings._add(SpinSetting("preview_grid_step2", 50., 0, 200, _("Coarse grid spacing"), _("Coarse Grid Spacing"), "Viewer"), self.update_gviz_params)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
911 self.settings._add(StringSetting("bgcolor", "#FFFFFF", _("Background color"), _("Pronterface background color"), "Colors"), self.reload_ui, validate = check_rgb_color)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
912 self.settings._add(StringSetting("gcview_color_background", "#FAFAC7FF", _("3D view background color"), _("Color of the 3D view background"), "Colors"), self.update_gcview_colors, validate = check_rgba_color)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
913 self.settings._add(StringSetting("gcview_color_travel", "#99999999", _("3D view travel moves color"), _("Color of travel moves in 3D view"), "Colors"), self.update_gcview_colors, validate = check_rgba_color)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
914 self.settings._add(StringSetting("gcview_color_tool0", "#FF000099", _("3D view print moves color"), _("Color of print moves with tool 0 in 3D view"), "Colors"), self.update_gcview_colors, validate = check_rgba_color)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
915 self.settings._add(StringSetting("gcview_color_tool1", "#AC0DFF99", _("3D view tool 1 moves color"), _("Color of print moves with tool 1 in 3D view"), "Colors"), self.update_gcview_colors, validate = check_rgba_color)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
916 self.settings._add(StringSetting("gcview_color_tool2", "#FFCE0099", _("3D view tool 2 moves color"), _("Color of print moves with tool 2 in 3D view"), "Colors"), self.update_gcview_colors, validate = check_rgba_color)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
917 self.settings._add(StringSetting("gcview_color_tool3", "#FF009F99", _("3D view tool 3 moves color"), _("Color of print moves with tool 3 in 3D view"), "Colors"), self.update_gcview_colors, validate = check_rgba_color)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
918 self.settings._add(StringSetting("gcview_color_tool4", "#00FF8F99", _("3D view tool 4 moves color"), _("Color of print moves with tool 4 in 3D view"), "Colors"), self.update_gcview_colors, validate = check_rgba_color)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
919 self.settings._add(StringSetting("gcview_color_printed", "#33BF0099", _("3D view printed moves color"), _("Color of printed moves in 3D view"), "Colors"), self.update_gcview_colors, validate = check_rgba_color)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
920 self.settings._add(StringSetting("gcview_color_current", "#00E5FFCC", _("3D view current layer moves color"), _("Color of moves in current layer in 3D view"), "Colors"), self.update_gcview_colors, validate = check_rgba_color)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
921 self.settings._add(StringSetting("gcview_color_current_printed", "#196600CC", _("3D view printed current layer moves color"), _("Color of already printed moves from current layer in 3D view"), "Colors"), self.update_gcview_colors, validate = check_rgba_color)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
922 self.settings._add(StaticTextSetting("note1", _("Note:"), _("Changing some of these settings might require a restart to get effect"), group = "UI"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
923 recentfilessetting = StringSetting("recentfiles", "[]")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
924 recentfilessetting.hidden = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
925 self.settings._add(recentfilessetting, self.update_recent_files)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
926
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
927 def add_cmdline_arguments(self, parser):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
928 pronsole.pronsole.add_cmdline_arguments(self, parser)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
929 parser.add_argument('-a', '--autoconnect', help = _("automatically try to connect to printer on startup"), action = "store_true")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
930
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
931 def process_cmdline_arguments(self, args):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
932 pronsole.pronsole.process_cmdline_arguments(self, args)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
933 self.autoconnect = args.autoconnect
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
934
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
935 def update_recent_files(self, param, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
936 if self.filehistory is None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
937 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
938 recent_files = []
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
939 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
940 recent_files = json.loads(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
941 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
942 self.logError(_("Failed to load recent files list:") +
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
943 "\n" + traceback.format_exc())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
944 # Clear history
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
945 while self.filehistory.GetCount():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
946 self.filehistory.RemoveFileFromHistory(0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
947 recent_files.reverse()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
948 for f in recent_files:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
949 self.filehistory.AddFileToHistory(f)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
950
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
951 def update_gviz_params(self, param, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
952 params_map = {"preview_extrusion_width": "extrusion_width",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
953 "preview_grid_step1": "grid",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
954 "preview_grid_step2": "grid"}
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
955 if param not in params_map:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
956 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
957 if not hasattr(self, "gviz"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
958 # GUI hasn't been loaded yet, ignore this setting
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
959 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
960 trueparam = params_map[param]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
961 if hasattr(self.gviz, trueparam):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
962 gviz = self.gviz
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
963 elif hasattr(self.gwindow, "p") and hasattr(self.gwindow.p, trueparam):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
964 gviz = self.gwindow.p
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
965 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
966 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
967 if trueparam == "grid":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
968 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
969 item = int(param[-1]) # extract list item position
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
970 grid = list(gviz.grid)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
971 grid[item - 1] = value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
972 value = tuple(grid)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
973 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
974 self.logError(traceback.format_exc())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
975 if hasattr(self.gviz, trueparam):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
976 self.apply_gviz_params(self.gviz, trueparam, value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
977 if hasattr(self.gwindow, "p") and hasattr(self.gwindow.p, trueparam):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
978 self.apply_gviz_params(self.gwindow.p, trueparam, value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
979
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
980 def apply_gviz_params(self, widget, param, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
981 setattr(widget, param, value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
982 widget.dirty = 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
983 wx.CallAfter(widget.Refresh)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
984
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
985 def update_gcview_colors(self, param, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
986 color = hexcolor_to_float(value, 4)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
987 # This is sort of a hack: we copy the color values into the preexisting
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
988 # color tuple so that we don't need to update the tuple used by gcview
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
989 target_color = getattr(self, param)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
990 for i, v in enumerate(color):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
991 target_color[i] = v
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
992 wx.CallAfter(self.Refresh)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
993
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
994 def update_build_dimensions(self, param, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
995 pronsole.pronsole.update_build_dimensions(self, param, value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
996 self.update_bed_viz()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
997
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
998 def update_bed_viz(self, *args):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
999 """Update bed visualization when size/type changed"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1000 if hasattr(self, "gviz") and hasattr(self.gviz, "recreate_platform"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1001 self.gviz.recreate_platform(self.build_dimensions_list, self.settings.circular_bed)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1002 if hasattr(self, "gwindow") and hasattr(self.gwindow, "recreate_platform"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1003 self.gwindow.recreate_platform(self.build_dimensions_list, self.settings.circular_bed)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1004
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1005 def update_gcview_params(self, *args):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1006 need_reload = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1007 if hasattr(self, "gviz") and hasattr(self.gviz, "set_gcview_params"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1008 need_reload |= self.gviz.set_gcview_params(self.settings.gcview_path_width, self.settings.gcview_path_height)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1009 if hasattr(self, "gwindow") and hasattr(self.gwindow, "set_gcview_params"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1010 need_reload |= self.gwindow.set_gcview_params(self.settings.gcview_path_width, self.settings.gcview_path_height)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1011 if need_reload:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1012 self.start_viz_thread()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1013
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1014 def update_monitor(self, *args):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1015 if hasattr(self, "graph") and self.display_graph:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1016 if self.settings.monitor:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1017 wx.CallAfter(self.graph.StartPlotting, 1000)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1018 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1019 wx.CallAfter(self.graph.StopPlotting)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1020
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1021 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1022 # Statusbar handling
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1023 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1024
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1025 def statuschecker_inner(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1026 status_string = ""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1027 if self.sdprinting or self.uploading or self.p.printing:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1028 secondsremain, secondsestimate, progress = self.get_eta()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1029 if self.sdprinting or self.uploading:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1030 if self.uploading:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1031 status_string += _("SD upload: %04.2f%% |") % (100 * progress,)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1032 status_string += _(" Line# %d of %d lines |") % (self.p.queueindex, len(self.p.mainqueue))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1033 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1034 status_string += _("SD printing: %04.2f%% |") % (self.percentdone,)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1035 elif self.p.printing:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1036 status_string += _("Printing: %04.2f%% |") % (100 * float(self.p.queueindex) / len(self.p.mainqueue),)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1037 status_string += _(" Line# %d of %d lines |") % (self.p.queueindex, len(self.p.mainqueue))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1038 if progress > 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1039 status_string += _(" Est: %s of %s remaining | ") % (format_duration(secondsremain),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1040 format_duration(secondsestimate))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1041 status_string += _(" Z: %.3f mm") % self.curlayer
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1042 elif self.loading_gcode:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1043 status_string = self.loading_gcode_message
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1044 wx.CallAfter(self.statusbar.SetStatusText, status_string)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1045 wx.CallAfter(self.gviz.Refresh)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1046 # Call pronsole's statuschecker inner loop function to handle
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1047 # temperature monitoring and status loop sleep
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1048 pronsole.pronsole.statuschecker_inner(self, self.settings.monitor)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1049 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1050 while not self.sentglines.empty():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1051 gc = self.sentglines.get_nowait()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1052 wx.CallAfter(self.gviz.addgcodehighlight, gc)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1053 self.sentglines.task_done()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1054 except Queue.Empty:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1055 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1056
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1057 def statuschecker(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1058 pronsole.pronsole.statuschecker(self)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1059 wx.CallAfter(self.statusbar.SetStatusText, _("Not connected to printer."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1060
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1061 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1062 # Interface lock handling
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1063 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1064
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1065 def lock(self, event = None, force = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1066 if force is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1067 self.locker.SetValue(force)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1068 if self.locker.GetValue():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1069 self.log(_("Locking interface."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1070 for panel in self.panels:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1071 panel.Disable()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1072 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1073 self.log(_("Unlocking interface."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1074 for panel in self.panels:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1075 panel.Enable()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1076
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1077 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1078 # Printer connection handling
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1079 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1080
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1081 def connect(self, event = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1082 self.log(_("Connecting..."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1083 port = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1084 if self.serialport.GetValue():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1085 port = str(self.serialport.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1086 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1087 scanned = self.scanserial()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1088 if scanned:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1089 port = scanned[0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1090 baud = 115200
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1091 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1092 baud = int(self.baud.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1093 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1094 self.logError(_("Could not parse baud rate: ")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1095 + "\n" + traceback.format_exc())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1096 if self.paused:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1097 self.p.paused = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1098 self.p.printing = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1099 wx.CallAfter(self.pausebtn.SetLabel, _("Pause"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1100 wx.CallAfter(self.printbtn.SetLabel, _("Print"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1101 wx.CallAfter(self.toolbarsizer.Layout)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1102 self.paused = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1103 if self.sdprinting:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1104 self.p.send_now("M26 S0")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1105 if not self.connect_to_printer(port, baud, self.settings.dtr):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1106 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1107 if port != self.settings.port:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1108 self.set("port", port)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1109 if baud != self.settings.baudrate:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1110 self.set("baudrate", str(baud))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1111 if self.predisconnect_mainqueue:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1112 self.recoverbtn.Enable()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1113
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1114 def store_predisconnect_state(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1115 self.predisconnect_mainqueue = self.p.mainqueue
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1116 self.predisconnect_queueindex = self.p.queueindex
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1117 self.predisconnect_layer = self.curlayer
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1118
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1119 def disconnect(self, event = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1120 self.log(_("Disconnected."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1121 if self.p.printing or self.p.paused or self.paused:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1122 self.store_predisconnect_state()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1123 self.p.disconnect()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1124 self.statuscheck = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1125 if self.status_thread:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1126 self.status_thread.join()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1127 self.status_thread = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1128
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1129 wx.CallAfter(self.connectbtn.SetLabel, _("Connect"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1130 wx.CallAfter(self.connectbtn.SetToolTip, wx.ToolTip(_("Connect to the printer")))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1131 wx.CallAfter(self.connectbtn.Bind, wx.EVT_BUTTON, self.connect)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1132
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1133 wx.CallAfter(self.gui_set_disconnected)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1134
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1135 if self.paused:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1136 self.p.paused = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1137 self.p.printing = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1138 wx.CallAfter(self.pausebtn.SetLabel, _("Pause"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1139 wx.CallAfter(self.printbtn.SetLabel, _("Print"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1140 self.paused = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1141 if self.sdprinting:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1142 self.p.send_now("M26 S0")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1143
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1144 # Relayout the toolbar to handle new buttons size
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1145 wx.CallAfter(self.toolbarsizer.Layout)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1146
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1147 def reset(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1148 self.log(_("Reset."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1149 dlg = wx.MessageDialog(self, _("Are you sure you want to reset the printer?"), _("Reset?"), wx.YES | wx.NO)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1150 if dlg.ShowModal() == wx.ID_YES:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1151 self.p.reset()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1152 self.sethotendgui(0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1153 self.setbedgui(0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1154 self.p.printing = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1155 wx.CallAfter(self.printbtn.SetLabel, _("Print"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1156 if self.paused:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1157 self.p.paused = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1158 wx.CallAfter(self.pausebtn.SetLabel, _("Pause"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1159 self.paused = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1160 wx.CallAfter(self.toolbarsizer.Layout)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1161 dlg.Destroy()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1162
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1163 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1164 # Print/upload handling
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1165 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1166
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1167 def on_startprint(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1168 wx.CallAfter(self.pausebtn.SetLabel, _("Pause"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1169 wx.CallAfter(self.pausebtn.Enable)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1170 wx.CallAfter(self.printbtn.SetLabel, _("Restart"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1171 wx.CallAfter(self.toolbarsizer.Layout)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1172
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1173 def printfile(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1174 self.extra_print_time = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1175 if self.paused:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1176 self.p.paused = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1177 self.paused = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1178 if self.sdprinting:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1179 self.on_startprint()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1180 self.p.send_now("M26 S0")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1181 self.p.send_now("M24")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1182 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1183
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1184 if not self.fgcode:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1185 wx.CallAfter(self.statusbar.SetStatusText, _("No file loaded. Please use load first."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1186 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1187 if not self.p.online:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1188 wx.CallAfter(self.statusbar.SetStatusText, _("Not connected to printer."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1189 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1190 self.sdprinting = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1191 self.on_startprint()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1192 self.p.startprint(self.fgcode)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1193
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1194 def sdprintfile(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1195 self.extra_print_time = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1196 self.on_startprint()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1197 threading.Thread(target = self.getfiles).start()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1198
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1199 def upload(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1200 if not self.fgcode:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1201 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1202 if not self.p.online:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1203 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1204 dlg = wx.TextEntryDialog(self, ("Enter a target filename in 8.3 format:"), _("Pick SD filename"), dosify(self.filename))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1205 if dlg.ShowModal() == wx.ID_OK:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1206 self.p.send_now("M21")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1207 self.p.send_now("M28 " + str(dlg.GetValue()))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1208 self.recvlisteners.append(self.uploadtrigger)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1209 dlg.Destroy()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1210
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1211 def uploadtrigger(self, l):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1212 if "Writing to file" in l:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1213 self.uploading = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1214 self.p.startprint(self.fgcode)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1215 self.p.endcb = self.endupload
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1216 self.recvlisteners.remove(self.uploadtrigger)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1217 elif "open failed, File" in l:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1218 self.recvlisteners.remove(self.uploadtrigger)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1219
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1220 def endupload(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1221 self.p.send_now("M29 ")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1222 wx.CallAfter(self.statusbar.SetStatusText, _("File upload complete"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1223 time.sleep(0.5)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1224 self.p.clear = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1225 self.uploading = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1226
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1227 def pause(self, event = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1228 if not self.paused:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1229 self.log(_("Print paused at: %s") % format_time(time.time()))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1230 if self.sdprinting:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1231 self.p.send_now("M25")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1232 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1233 if not self.p.printing:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1234 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1235 self.p.pause()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1236 self.p.runSmallScript(self.pauseScript)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1237 self.paused = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1238 # self.p.runSmallScript(self.pauseScript)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1239 self.extra_print_time += int(time.time() - self.starttime)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1240 wx.CallAfter(self.pausebtn.SetLabel, _("Resume"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1241 wx.CallAfter(self.toolbarsizer.Layout)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1242 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1243 self.log(_("Resuming."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1244 self.paused = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1245 if self.sdprinting:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1246 self.p.send_now("M24")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1247 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1248 self.p.resume()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1249 wx.CallAfter(self.pausebtn.SetLabel, _("Pause"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1250 wx.CallAfter(self.toolbarsizer.Layout)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1251
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1252 def recover(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1253 self.extra_print_time = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1254 if not self.p.online:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1255 wx.CallAfter(self.statusbar.SetStatusText, _("Not connected to printer."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1256 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1257 # Reset Z
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1258 self.p.send_now("G92 Z%f" % self.predisconnect_layer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1259 # Home X and Y
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1260 self.p.send_now("G28 X Y")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1261 self.on_startprint()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1262 self.p.startprint(self.predisconnect_mainqueue, self.p.queueindex)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1263
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1264 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1265 # File loading handling
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1266 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1267
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1268 def filesloaded(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1269 dlg = wx.SingleChoiceDialog(self, _("Select the file to print"), _("Pick SD file"), self.sdfiles)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1270 if dlg.ShowModal() == wx.ID_OK:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1271 target = dlg.GetStringSelection()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1272 if len(target):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1273 self.recvlisteners.append(self.waitforsdresponse)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1274 self.p.send_now("M23 " + target.lower())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1275 dlg.Destroy()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1276
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1277 def getfiles(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1278 if not self.p.online:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1279 self.sdfiles = []
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1280 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1281 self.sdlisting = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1282 self.sdfiles = []
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1283 self.recvlisteners.append(self.listfiles)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1284 self.p.send_now("M21")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1285 self.p.send_now("M20")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1286
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1287 def model_to_gcode_filename(self, filename):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1288 suffix = "_export.gcode"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1289 for ext in [".stl", ".obj"]:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1290 filename = filename.replace(ext, suffix)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1291 filename = filename.replace(ext.upper(), suffix)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1292 return filename
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1293
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1294 def slice_func(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1295 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1296 output_filename = self.model_to_gcode_filename(self.filename)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1297 pararray = prepare_command(self.settings.slicecommand,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1298 {"$s": self.filename, "$o": output_filename})
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1299 if self.settings.slic3rintegration:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1300 for cat, config in self.slic3r_configs.items():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1301 if config:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1302 fpath = os.path.join(self.slic3r_configpath, cat, config)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1303 pararray += ["--load", fpath]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1304 self.log(_("Running ") + " ".join(pararray))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1305 self.slicep = subprocess.Popen(pararray, stderr = subprocess.STDOUT, stdout = subprocess.PIPE)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1306 while True:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1307 o = self.slicep.stdout.read(1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1308 if o == '' and self.slicep.poll() is not None: break
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1309 sys.stdout.write(o)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1310 self.slicep.wait()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1311 self.stopsf = 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1312 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1313 self.logError(_("Failed to execute slicing software: ")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1314 + "\n" + traceback.format_exc())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1315 self.stopsf = 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1316
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1317 def slice_monitor(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1318 while not self.stopsf:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1319 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1320 wx.CallAfter(self.statusbar.SetStatusText, _("Slicing...")) # +self.cout.getvalue().split("\n")[-1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1321 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1322 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1323 time.sleep(0.1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1324 fn = self.filename
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1325 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1326 self.load_gcode_async(self.model_to_gcode_filename(self.filename))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1327 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1328 self.filename = fn
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1329 self.slicing = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1330 self.slicep = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1331
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1332 def slice(self, filename):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1333 wx.CallAfter(self.loadbtn.SetLabel, _("Cancel"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1334 wx.CallAfter(self.toolbarsizer.Layout)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1335 self.log(_("Slicing ") + filename)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1336 self.cout = StringIO.StringIO()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1337 self.filename = filename
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1338 self.stopsf = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1339 self.slicing = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1340 threading.Thread(target = self.slice_func).start()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1341 threading.Thread(target = self.slice_monitor).start()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1342
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1343 def cmdline_filename_callback(self, filename):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1344 # Do nothing when processing a filename from command line, as we'll
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1345 # handle it when everything has been prepared
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1346 self.filename = filename
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1347
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1348 def do_load(self, l):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1349 if hasattr(self, 'slicing'):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1350 self.loadfile(None, l)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1351 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1352 self._do_load(l)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1353
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1354 def load_recent_file(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1355 fileid = event.GetId() - wx.ID_FILE1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1356 path = self.filehistory.GetHistoryFile(fileid)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1357 self.loadfile(None, filename = path)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1358
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1359 def loadfile(self, event, filename = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1360 if self.slicing and self.slicep is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1361 self.slicep.terminate()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1362 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1363 basedir = self.settings.last_file_path
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1364 if not os.path.exists(basedir):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1365 basedir = "."
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1366 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1367 basedir = os.path.split(self.filename)[0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1368 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1369 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1370 dlg = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1371 if filename is None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1372 dlg = wx.FileDialog(self, _("Open file to print"), basedir, style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
16
36d478bde840 Implemented svg, png and hpgl compilers to pronterface
mbayer
parents: 15
diff changeset
1373 # add image files to GCODE file list
36d478bde840 Implemented svg, png and hpgl compilers to pronterface
mbayer
parents: 15
diff changeset
1374 dlg.SetWildcard(_("GCODE and Image files|*.gcode;*.gco;*.g;*.png;*.svg;*.hpgl;*.plt|OBJ, STL, and GCODE files (*.gcode;*.gco;*.g;*.stl;*.STL;*.obj;*.OBJ)|*.gcode;*.gco;*.g;*.stl;*.STL;*.obj;*.OBJ|GCODE files (*.gcode;*.gco;*.g)|*.gcode;*.gco;*.g|OBJ, STL files (*.stl;*.STL;*.obj;*.OBJ)|*.stl;*.STL;*.obj;*.OBJ|All Files (*.*)|*.*"))
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1375 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1376 dlg.SetFilterIndex(self.settings.last_file_filter)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1377 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1378 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1379 if filename or dlg.ShowModal() == wx.ID_OK:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1380 if filename:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1381 name = filename
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1382 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1383 name = dlg.GetPath()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1384 self.set("last_file_filter", dlg.GetFilterIndex())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1385 dlg.Destroy()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1386 if not os.path.exists(name):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1387 self.statusbar.SetStatusText(_("File not found!"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1388 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1389 path = os.path.split(name)[0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1390 if path != self.settings.last_file_path:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1391 self.set("last_file_path", path)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1392 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1393 abspath = os.path.abspath(name)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1394 recent_files = []
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1395 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1396 recent_files = json.loads(self.settings.recentfiles)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1397 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1398 self.logError(_("Failed to load recent files list:") +
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1399 "\n" + traceback.format_exc())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1400 if abspath in recent_files:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1401 recent_files.remove(abspath)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1402 recent_files.insert(0, abspath)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1403 if len(recent_files) > 5:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1404 recent_files = recent_files[:5]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1405 self.set("recentfiles", json.dumps(recent_files))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1406 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1407 self.logError(_("Could not update recent files list:") +
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1408 "\n" + traceback.format_exc())
19
234037fbca4b Bugfixing, Added M400 magic
mbayer
parents: 16
diff changeset
1409
20
03b34402d405 Code cleanup
mbayer
parents: 19
diff changeset
1410 # reload the library local so we dont have to restart the whole app when making code changes
03b34402d405 Code cleanup
mbayer
parents: 19
diff changeset
1411 reload(laser)
19
234037fbca4b Bugfixing, Added M400 magic
mbayer
parents: 16
diff changeset
1412
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1413 if name.lower().endswith(".stl") or name.lower().endswith(".obj"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1414 self.slice(name)
16
36d478bde840 Implemented svg, png and hpgl compilers to pronterface
mbayer
parents: 15
diff changeset
1415 elif name.lower().endswith(".png") or name.lower().endswith(".jpg") or name.lower().endswith(".gif"):
36d478bde840 Implemented svg, png and hpgl compilers to pronterface
mbayer
parents: 15
diff changeset
1416 # Generate GCODE from IMAGE
20
03b34402d405 Code cleanup
mbayer
parents: 19
diff changeset
1417 lc = laser.Lasercutter(pronterwindow = self)
16
36d478bde840 Implemented svg, png and hpgl compilers to pronterface
mbayer
parents: 15
diff changeset
1418 lc.image2gcode(name)
36d478bde840 Implemented svg, png and hpgl compilers to pronterface
mbayer
parents: 15
diff changeset
1419 elif name.lower().endswith(".svg"):
36d478bde840 Implemented svg, png and hpgl compilers to pronterface
mbayer
parents: 15
diff changeset
1420 # Generate GCODE from SVG
20
03b34402d405 Code cleanup
mbayer
parents: 19
diff changeset
1421 lc = laser.Lasercutter(pronterwindow = self)
16
36d478bde840 Implemented svg, png and hpgl compilers to pronterface
mbayer
parents: 15
diff changeset
1422 lc.svg2gcode(name)
36d478bde840 Implemented svg, png and hpgl compilers to pronterface
mbayer
parents: 15
diff changeset
1423 elif name.lower().endswith(".hpgl") or name.lower().endswith(".plt"):
36d478bde840 Implemented svg, png and hpgl compilers to pronterface
mbayer
parents: 15
diff changeset
1424 # Generate GCODE from HPGL
20
03b34402d405 Code cleanup
mbayer
parents: 19
diff changeset
1425 lc = laser.Lasercutter(pronterwindow = self)
16
36d478bde840 Implemented svg, png and hpgl compilers to pronterface
mbayer
parents: 15
diff changeset
1426 lc.hpgl2gcode(name)
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1427 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1428 self.load_gcode_async(name)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1429 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1430 dlg.Destroy()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1431
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1432 def load_gcode_async(self, filename):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1433 self.filename = filename
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1434 gcode = self.pre_gcode_load()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1435 self.log(_("Loading file: %s") % filename)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1436 threading.Thread(target = self.load_gcode_async_thread, args = (gcode,)).start()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1437
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1438 def load_gcode_async_thread(self, gcode):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1439 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1440 self.load_gcode(self.filename,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1441 layer_callback = self.layer_ready_cb,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1442 gcode = gcode)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1443 except PronterfaceQuitException:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1444 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1445 wx.CallAfter(self.post_gcode_load)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1446
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1447 def layer_ready_cb(self, gcode, layer):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1448 global pronterface_quitting
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1449 if pronterface_quitting:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1450 raise PronterfaceQuitException
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1451 if not self.settings.refreshwhenloading:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1452 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1453 self.viz_last_layer = layer
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1454 if time.time() - self.viz_last_yield > 1.0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1455 time.sleep(0.2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1456 self.loading_gcode_message = _("Loading %s: %d layers loaded (%d lines)") % (self.filename, layer + 1, len(gcode))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1457 self.viz_last_yield = time.time()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1458 wx.CallAfter(self.statusbar.SetStatusText, self.loading_gcode_message)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1459
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1460 def start_viz_thread(self, gcode = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1461 threading.Thread(target = self.loadviz, args = (gcode,)).start()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1462
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1463 def pre_gcode_load(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1464 self.loading_gcode = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1465 self.loading_gcode_message = _("Loading %s...") % self.filename
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1466 if self.settings.mainviz == "None":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1467 gcode = gcoder.LightGCode(deferred = True)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1468 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1469 gcode = gcoder.GCode(deferred = True)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1470 self.viz_last_yield = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1471 self.viz_last_layer = -1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1472 self.start_viz_thread(gcode)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1473 return gcode
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1474
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1475 def post_gcode_load(self, print_stats = True):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1476 # Must be called in wx.CallAfter for safety
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1477 self.loading_gcode = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1478 self.SetTitle(_(u"Pronterface - %s") % self.filename)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1479 message = _("Loaded %s, %d lines") % (self.filename, len(self.fgcode),)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1480 self.log(message)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1481 self.statusbar.SetStatusText(message)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1482 self.savebtn.Enable(True)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1483 self.loadbtn.SetLabel(_("Load File"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1484 self.printbtn.SetLabel(_("Print"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1485 self.pausebtn.SetLabel(_("Pause"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1486 self.pausebtn.Disable()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1487 self.recoverbtn.Disable()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1488 if self.p.online:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1489 self.printbtn.Enable()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1490 self.toolbarsizer.Layout()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1491 self.viz_last_layer = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1492 if print_stats:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1493 self.output_gcode_stats()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1494
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1495 def output_gcode_stats(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1496 gcode = self.fgcode
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1497 self.log(_("%.2fmm of filament used in this print") % gcode.filament_length)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1498 if(len(gcode.filament_length_multi)>1):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1499 for i in enumerate(gcode.filament_length_multi):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1500 print "Extruder %d: %0.02fmm" % (i[0],i[1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1501 self.log(_("The print goes:"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1502 self.log(_("- from %.2f mm to %.2f mm in X and is %.2f mm wide") % (gcode.xmin, gcode.xmax, gcode.width))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1503 self.log(_("- from %.2f mm to %.2f mm in Y and is %.2f mm deep") % (gcode.ymin, gcode.ymax, gcode.depth))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1504 self.log(_("- from %.2f mm to %.2f mm in Z and is %.2f mm high") % (gcode.zmin, gcode.zmax, gcode.height))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1505 self.log(_("Estimated duration: %d layers, %s") % gcode.estimate_duration())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1506
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1507 def loadviz(self, gcode = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1508 self.gviz.clear()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1509 self.gwindow.p.clear()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1510 if gcode is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1511 generator = self.gviz.addfile_perlayer(gcode, True)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1512 next_layer = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1513 # Progressive loading of visualization
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1514 # We load layers up to the last one which has been processed in GCoder
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1515 # (self.viz_last_layer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1516 # Once the GCode has been entirely loaded, this variable becomes None,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1517 # indicating that we can do the last generator call to finish the
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1518 # loading of the visualization, which will itself return None.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1519 # During preloading we verify that the layer we added is the one we
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1520 # expected through the assert call.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1521 while True:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1522 global pronterface_quitting
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1523 if pronterface_quitting:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1524 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1525 max_layer = self.viz_last_layer
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1526 if max_layer is None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1527 break
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1528 while next_layer <= max_layer:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1529 assert(generator.next() == next_layer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1530 next_layer += 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1531 time.sleep(0.1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1532 generator_output = generator.next()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1533 while generator_output is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1534 assert(generator_output in (None, next_layer))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1535 next_layer += 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1536 generator_output = generator.next()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1537 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1538 # If GCode is not being loaded asynchroneously, it is already
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1539 # loaded, so let's make visualization sequentially
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1540 gcode = self.fgcode
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1541 self.gviz.addfile(gcode)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1542 wx.CallAfter(self.gviz.Refresh)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1543 # Load external window sequentially now that everything is ready.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1544 # We can't really do any better as the 3D viewer might clone the
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1545 # finalized model from the main visualization
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1546 self.gwindow.p.addfile(gcode)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1547
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1548 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1549 # File saving handling
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1550 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1551
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1552 def savefile(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1553 basedir = self.settings.last_file_path
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1554 if not os.path.exists(basedir):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1555 basedir = "."
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1556 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1557 basedir = os.path.split(self.filename)[0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1558 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1559 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1560 dlg = wx.FileDialog(self, _("Save as"), basedir, style = wx.FD_SAVE)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1561 dlg.SetWildcard(_("GCODE files (*.gcode;*.gco;*.g)|*.gcode;*.gco;*.g|All Files (*.*)|*.*"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1562 if dlg.ShowModal() == wx.ID_OK:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1563 name = dlg.GetPath()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1564 open(name, "w").write("\n".join((line.raw for line in self.fgcode)))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1565 self.log(_("G-Code succesfully saved to %s") % name)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1566 dlg.Destroy()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1567
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1568 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1569 # Printcore callbacks
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1570 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1571
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1572 def process_host_command(self, command):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1573 """Override host command handling"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1574 command = command.lstrip()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1575 if command.startswith(";@pause"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1576 self.pause(None)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1577 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1578 pronsole.pronsole.process_host_command(self, command)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1579
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1580 def startcb(self, resuming = False):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1581 """Callback on print start"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1582 pronsole.pronsole.startcb(self, resuming)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1583 if self.settings.lockbox and self.settings.lockonstart:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1584 wx.CallAfter(self.lock, force = True)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1585
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1586 def endcb(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1587 """Callback on print end/pause"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1588 pronsole.pronsole.endcb(self)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1589 if self.p.queueindex == 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1590 self.p.runSmallScript(self.endScript)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1591 wx.CallAfter(self.pausebtn.Disable)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1592 wx.CallAfter(self.printbtn.SetLabel, _("Print"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1593 wx.CallAfter(self.toolbarsizer.Layout)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1594
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1595 def online(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1596 """Callback when printer goes online"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1597 self.log(_("Printer is now online."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1598 wx.CallAfter(self.online_gui)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1599
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1600 def online_gui(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1601 """Callback when printer goes online (graphical bits)"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1602 self.connectbtn.SetLabel(_("Disconnect"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1603 self.connectbtn.SetToolTip(wx.ToolTip("Disconnect from the printer"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1604 self.connectbtn.Bind(wx.EVT_BUTTON, self.disconnect)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1605
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1606 if hasattr(self, "extrudersel"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1607 self.do_tool(self.extrudersel.GetValue())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1608
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1609 self.gui_set_connected()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1610
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1611 if self.filename:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1612 self.printbtn.Enable()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1613
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1614 wx.CallAfter(self.toolbarsizer.Layout)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1615
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1616 def sentcb(self, line, gline):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1617 """Callback when a printer gcode has been sent"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1618 if not gline:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1619 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1620 elif gline.command in ["M104", "M109"]:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1621 gline_s = gcoder.S(gline)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1622 if gline_s is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1623 temp = gline_s
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1624 if self.display_gauges: wx.CallAfter(self.hottgauge.SetTarget, temp)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1625 if self.display_graph: wx.CallAfter(self.graph.SetExtruder0TargetTemperature, temp)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1626 elif gline.command in ["M140", "M190"]:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1627 gline_s = gcoder.S(gline)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1628 if gline_s is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1629 temp = gline_s
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1630 if self.display_gauges: wx.CallAfter(self.bedtgauge.SetTarget, temp)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1631 if self.display_graph: wx.CallAfter(self.graph.SetBedTargetTemperature, temp)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1632 elif gline.command in ["M106"]:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1633 gline_s=gcoder.S(gline)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1634 fanpow=255
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1635 if gline_s is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1636 fanpow=gline_s
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1637 if self.display_graph: wx.CallAfter(self.graph.SetFanPower, fanpow)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1638 elif gline.command in ["M107"]:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1639 if self.display_graph: wx.CallAfter(self.graph.SetFanPower, 0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1640 elif gline.command.startswith("T"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1641 tool = gline.command[1:]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1642 if hasattr(self, "extrudersel"): wx.CallAfter(self.extrudersel.SetValue, tool)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1643 if gline.is_move:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1644 self.sentglines.put_nowait(gline)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1645
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1646 def is_excluded_move(self, gline):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1647 """Check whether the given moves ends at a position specified as
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1648 excluded in the part excluder"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1649 if not gline.is_move or not self.excluder or not self.excluder.rectangles:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1650 return False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1651 for (x0, y0, x1, y1) in self.excluder.rectangles:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1652 if x0 <= gline.current_x <= x1 and y0 <= gline.current_y <= y1:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1653 return True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1654 return False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1655
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1656 def preprintsendcb(self, gline, next_gline):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1657 """Callback when a printer gcode is about to be sent. We use it to
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1658 exclude moves defined by the part excluder tool"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1659 if not self.is_excluded_move(gline):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1660 return gline
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1661 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1662 if gline.z is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1663 if gline.relative:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1664 if self.excluder_z_abs is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1665 self.excluder_z_abs += gline.z
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1666 elif self.excluder_z_rel is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1667 self.excluder_z_rel += gline.z
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1668 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1669 self.excluder_z_rel = gline.z
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1670 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1671 self.excluder_z_rel = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1672 self.excluder_z_abs = gline.z
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1673 if gline.e is not None and not gline.relative_e:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1674 self.excluder_e = gline.e
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1675 # If next move won't be excluded, push the changes we have to do
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1676 if next_gline is not None and not self.is_excluded_move(next_gline):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1677 if self.excluder_e is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1678 self.p.send_now("G92 E%.5f" % self.excluder_e)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1679 self.excluder_e = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1680 if self.excluder_z_abs is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1681 if gline.relative:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1682 self.p.send_now("G90")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1683 self.p.send_now("G1 Z%.5f" % self.excluder_z_abs)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1684 self.excluder_z_abs = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1685 if gline.relative:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1686 self.p.send_now("G91")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1687 if self.excluder_z_rel is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1688 if not gline.relative:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1689 self.p.send_now("G91")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1690 self.p.send_now("G1 Z%.5f" % self.excluder_z_rel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1691 self.excluder_z_rel = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1692 if not gline.relative:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1693 self.p.send_now("G90")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1694 return None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1695
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1696 def printsentcb(self, gline):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1697 """Callback when a print gcode has been sent"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1698 if gline.is_move:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1699 if hasattr(self.gwindow, "set_current_gline"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1700 wx.CallAfter(self.gwindow.set_current_gline, gline)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1701 if hasattr(self.gviz, "set_current_gline"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1702 wx.CallAfter(self.gviz.set_current_gline, gline)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1703
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1704 def layer_change_cb(self, newlayer):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1705 """Callback when the printed layer changed"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1706 pronsole.pronsole.layer_change_cb(self, newlayer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1707 if self.settings.mainviz != "3D" or self.settings.trackcurrentlayer3d:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1708 wx.CallAfter(self.gviz.setlayer, newlayer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1709
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1710 def update_tempdisplay(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1711 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1712 temps = parse_temperature_report(self.tempreadings)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1713 if "T0" in temps and temps["T0"][0]:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1714 hotend_temp = float(temps["T0"][0])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1715 elif "T" in temps and temps["T"][0]:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1716 hotend_temp = float(temps["T"][0])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1717 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1718 hotend_temp = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1719 if hotend_temp is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1720 if self.display_graph: wx.CallAfter(self.graph.SetExtruder0Temperature, hotend_temp)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1721 if self.display_gauges: wx.CallAfter(self.hottgauge.SetValue, hotend_temp)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1722 setpoint = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1723 if "T0" in temps and temps["T0"][1]: setpoint = float(temps["T0"][1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1724 elif temps["T"][1]: setpoint = float(temps["T"][1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1725 if setpoint is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1726 if self.display_graph: wx.CallAfter(self.graph.SetExtruder0TargetTemperature, setpoint)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1727 if self.display_gauges: wx.CallAfter(self.hottgauge.SetTarget, setpoint)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1728 if "T1" in temps:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1729 hotend_temp = float(temps["T1"][0])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1730 if self.display_graph: wx.CallAfter(self.graph.SetExtruder1Temperature, hotend_temp)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1731 setpoint = temps["T1"][1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1732 if setpoint and self.display_graph:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1733 wx.CallAfter(self.graph.SetExtruder1TargetTemperature, float(setpoint))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1734 bed_temp = float(temps["B"][0]) if "B" in temps and temps["B"][0] else None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1735 if bed_temp is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1736 if self.display_graph: wx.CallAfter(self.graph.SetBedTemperature, bed_temp)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1737 if self.display_gauges: wx.CallAfter(self.bedtgauge.SetValue, bed_temp)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1738 setpoint = temps["B"][1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1739 if setpoint:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1740 setpoint = float(setpoint)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1741 if self.display_graph: wx.CallAfter(self.graph.SetBedTargetTemperature, setpoint)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1742 if self.display_gauges: wx.CallAfter(self.bedtgauge.SetTarget, setpoint)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1743 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1744 self.logError(traceback.format_exc())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1745
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1746 def update_pos(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1747 bits = gcoder.m114_exp.findall(self.posreport)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1748 x = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1749 y = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1750 z = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1751 for bit in bits:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1752 if not bit[0]: continue
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1753 if x is None and bit[0] == "X":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1754 x = float(bit[1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1755 elif y is None and bit[0] == "Y":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1756 y = float(bit[1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1757 elif z is None and bit[0] == "Z":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1758 z = float(bit[1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1759 if x is not None: self.current_pos[0] = x
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1760 if y is not None: self.current_pos[1] = y
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1761 if z is not None: self.current_pos[2] = z
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1762
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1763 def recvcb_actions(self, l):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1764 if l.startswith("!!"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1765 if not self.paused:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1766 wx.CallAfter(self.pause)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1767 msg = l.split(" ", 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1768 if len(msg) > 1 and not self.p.loud:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1769 wx.CallAfter(self.addtexttolog, msg[1] + "\n")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1770 return True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1771 elif l.startswith("//"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1772 command = l.split(" ", 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1773 if len(command) > 1:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1774 command = command[1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1775 command = command.split(":")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1776 if len(command) == 2 and command[0] == "action":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1777 command = command[1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1778 self.log(_("Received command %s") % command)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1779 if command == "pause":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1780 if not self.paused:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1781 wx.CallAfter(self.pause)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1782 return True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1783 elif command == "resume":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1784 if self.paused:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1785 wx.CallAfter(self.pause)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1786 return True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1787 elif command == "disconnect":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1788 wx.CallAfter(self.disconnect)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1789 return True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1790 return False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1791
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1792 def recvcb(self, l):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1793 l = l.rstrip()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1794 if not self.recvcb_actions(l):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1795 report_type = self.recvcb_report(l)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1796 isreport = report_type != REPORT_NONE
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1797 if report_type & REPORT_POS:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1798 self.update_pos()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1799 elif report_type & REPORT_TEMP:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1800 wx.CallAfter(self.tempdisp.SetLabel, self.tempreadings.strip().replace("ok ", ""))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1801 self.update_tempdisplay()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1802 if not self.p.loud and (l not in ["ok", "wait"] and (not isreport or report_type & REPORT_MANUAL)):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1803 wx.CallAfter(self.addtexttolog, l + "\n")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1804 for listener in self.recvlisteners:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1805 listener(l)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1806
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1807 def listfiles(self, line, ignored = False):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1808 if "Begin file list" in line:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1809 self.sdlisting = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1810 elif "End file list" in line:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1811 self.sdlisting = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1812 self.recvlisteners.remove(self.listfiles)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1813 wx.CallAfter(self.filesloaded)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1814 elif self.sdlisting:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1815 self.sdfiles.append(line.strip().lower())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1816
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1817 def waitforsdresponse(self, l):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1818 if "file.open failed" in l:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1819 wx.CallAfter(self.statusbar.SetStatusText, _("Opening file failed."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1820 self.recvlisteners.remove(self.waitforsdresponse)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1821 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1822 if "File opened" in l:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1823 wx.CallAfter(self.statusbar.SetStatusText, l)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1824 if "File selected" in l:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1825 wx.CallAfter(self.statusbar.SetStatusText, _("Starting print"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1826 self.sdprinting = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1827 self.p.send_now("M24")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1828 self.startcb()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1829 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1830 if "Done printing file" in l:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1831 wx.CallAfter(self.statusbar.SetStatusText, l)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1832 self.sdprinting = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1833 self.recvlisteners.remove(self.waitforsdresponse)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1834 self.endcb()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1835 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1836 if "SD printing byte" in l:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1837 # M27 handler
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1838 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1839 resp = l.split()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1840 vals = resp[-1].split("/")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1841 self.percentdone = 100.0 * int(vals[0]) / int(vals[1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1842 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1843 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1844
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1845 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1846 # Custom buttons handling
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1847 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1848
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1849 def cbuttons_reload(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1850 allcbs = getattr(self, "custombuttons_widgets", [])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1851 for button in allcbs:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1852 self.cbuttonssizer.Detach(button)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1853 button.Destroy()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1854 self.custombuttons_widgets = []
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1855 custombuttons = self.custombuttons[:] + [None]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1856 for i, btndef in enumerate(custombuttons):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1857 if btndef is None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1858 if i == len(custombuttons) - 1:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1859 self.newbuttonbutton = b = wx.Button(self.centerpanel, -1, "+", size = (19, 18), style = wx.BU_EXACTFIT)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1860 b.SetForegroundColour("#4444ff")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1861 b.SetToolTip(wx.ToolTip(_("click to add new custom button")))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1862 b.Bind(wx.EVT_BUTTON, self.cbutton_edit)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1863 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1864 b = wx.StaticText(self.panel, -1, "")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1865 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1866 b = wx.Button(self.centerpanel, -1, btndef.label, style = wx.BU_EXACTFIT)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1867 b.SetToolTip(wx.ToolTip(_("Execute command: ") + btndef.command))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1868 if btndef.background:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1869 b.SetBackgroundColour(btndef.background)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1870 rr, gg, bb = b.GetBackgroundColour().Get()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1871 if 0.3 * rr + 0.59 * gg + 0.11 * bb < 60:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1872 b.SetForegroundColour("#ffffff")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1873 b.custombutton = i
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1874 b.properties = btndef
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1875 if btndef is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1876 b.Bind(wx.EVT_BUTTON, self.process_button)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1877 b.Bind(wx.EVT_MOUSE_EVENTS, self.editbutton)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1878 self.custombuttons_widgets.append(b)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1879 if type(self.cbuttonssizer) == wx.GridBagSizer:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1880 self.cbuttonssizer.Add(b, pos = (i // 4, i % 4), flag = wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1881 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1882 self.cbuttonssizer.Add(b, flag = wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1883 self.centerpanel.Layout()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1884 self.centerpanel.GetContainingSizer().Layout()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1885
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1886 def help_button(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1887 self.log(_('Defines custom button. Usage: button <num> "title" [/c "colour"] command'))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1888
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1889 def do_button(self, argstr):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1890 def nextarg(rest):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1891 rest = rest.lstrip()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1892 if rest.startswith('"'):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1893 return rest[1:].split('"', 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1894 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1895 return rest.split(None, 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1896 # try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1897 num, argstr = nextarg(argstr)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1898 num = int(num)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1899 title, argstr = nextarg(argstr)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1900 colour = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1901 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1902 c1, c2 = nextarg(argstr)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1903 if c1 == "/c":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1904 colour, argstr = nextarg(c2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1905 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1906 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1907 command = argstr.strip()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1908 if num < 0 or num >= 64:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1909 self.log(_("Custom button number should be between 0 and 63"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1910 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1911 while num >= len(self.custombuttons):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1912 self.custombuttons.append(None)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1913 self.custombuttons[num] = SpecialButton(title, command)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1914 if colour is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1915 self.custombuttons[num].background = colour
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1916 if not self.processing_rc:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1917 self.cbuttons_reload()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1918
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1919 def cbutton_save(self, n, bdef, new_n = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1920 if new_n is None: new_n = n
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1921 if bdef is None or bdef == "":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1922 self.save_in_rc(("button %d" % n), '')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1923 elif bdef.background:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1924 colour = bdef.background
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1925 if type(colour) not in (str, unicode):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1926 if type(colour) == tuple and tuple(map(type, colour)) == (int, int, int):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1927 colour = map(lambda x: x % 256, colour)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1928 colour = wx.Colour(*colour).GetAsString(wx.C2S_NAME | wx.C2S_HTML_SYNTAX)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1929 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1930 colour = wx.Colour(colour).GetAsString(wx.C2S_NAME | wx.C2S_HTML_SYNTAX)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1931 self.save_in_rc(("button %d" % n), 'button %d "%s" /c "%s" %s' % (new_n, bdef.label, colour, bdef.command))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1932 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1933 self.save_in_rc(("button %d" % n), 'button %d "%s" %s' % (new_n, bdef.label, bdef.command))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1934
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1935 def cbutton_edit(self, e, button = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1936 bedit = ButtonEdit(self)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1937 if button is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1938 n = button.custombutton
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1939 bedit.name.SetValue(button.properties.label)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1940 bedit.command.SetValue(button.properties.command)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1941 if button.properties.background:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1942 colour = button.properties.background
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1943 if type(colour) not in (str, unicode):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1944 if type(colour) == tuple and tuple(map(type, colour)) == (int, int, int):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1945 colour = map(lambda x: x % 256, colour)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1946 colour = wx.Colour(*colour).GetAsString(wx.C2S_NAME | wx.C2S_HTML_SYNTAX)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1947 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1948 colour = wx.Colour(colour).GetAsString(wx.C2S_NAME | wx.C2S_HTML_SYNTAX)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1949 bedit.color.SetValue(colour)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1950 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1951 n = len(self.custombuttons)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1952 while n > 0 and self.custombuttons[n - 1] is None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1953 n -= 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1954 if bedit.ShowModal() == wx.ID_OK:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1955 if n == len(self.custombuttons):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1956 self.custombuttons.append(None)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1957 self.custombuttons[n] = SpecialButton(bedit.name.GetValue().strip(), bedit.command.GetValue().strip(), custom = True)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1958 if bedit.color.GetValue().strip() != "":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1959 self.custombuttons[n].background = bedit.color.GetValue()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1960 self.cbutton_save(n, self.custombuttons[n])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1961 wx.CallAfter(bedit.Destroy)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1962 wx.CallAfter(self.cbuttons_reload)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1963
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1964 def cbutton_remove(self, e, button):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1965 n = button.custombutton
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1966 self.cbutton_save(n, None)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1967 del self.custombuttons[n]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1968 for i in range(n, len(self.custombuttons)):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1969 self.cbutton_save(i, self.custombuttons[i])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1970 wx.CallAfter(self.cbuttons_reload)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1971
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1972 def cbutton_order(self, e, button, dir):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1973 n = button.custombutton
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1974 if dir < 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1975 n = n - 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1976 if n + 1 >= len(self.custombuttons):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1977 self.custombuttons.append(None) # pad
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1978 # swap
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1979 self.custombuttons[n], self.custombuttons[n + 1] = self.custombuttons[n + 1], self.custombuttons[n]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1980 self.cbutton_save(n, self.custombuttons[n])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1981 self.cbutton_save(n + 1, self.custombuttons[n + 1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1982 wx.CallAfter(self.cbuttons_reload)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1983
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1984 def editbutton(self, e):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1985 if e.IsCommandEvent() or e.ButtonUp(wx.MOUSE_BTN_RIGHT):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1986 if e.IsCommandEvent():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1987 pos = (0, 0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1988 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1989 pos = e.GetPosition()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1990 popupmenu = wx.Menu()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1991 obj = e.GetEventObject()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1992 if hasattr(obj, "custombutton"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1993 item = popupmenu.Append(-1, _("Edit custom button '%s'") % e.GetEventObject().GetLabelText())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1994 self.Bind(wx.EVT_MENU, lambda e, button = e.GetEventObject(): self.cbutton_edit(e, button), item)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1995 item = popupmenu.Append(-1, _("Move left <<"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1996 self.Bind(wx.EVT_MENU, lambda e, button = e.GetEventObject(): self.cbutton_order(e, button, -1), item)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1997 if obj.custombutton == 0: item.Enable(False)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1998 item = popupmenu.Append(-1, _("Move right >>"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1999 self.Bind(wx.EVT_MENU, lambda e, button = e.GetEventObject(): self.cbutton_order(e, button, 1), item)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2000 if obj.custombutton == 63: item.Enable(False)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2001 pos = self.panel.ScreenToClient(e.GetEventObject().ClientToScreen(pos))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2002 item = popupmenu.Append(-1, _("Remove custom button '%s'") % e.GetEventObject().GetLabelText())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2003 self.Bind(wx.EVT_MENU, lambda e, button = e.GetEventObject(): self.cbutton_remove(e, button), item)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2004 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2005 item = popupmenu.Append(-1, _("Add custom button"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2006 self.Bind(wx.EVT_MENU, self.cbutton_edit, item)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2007 self.panel.PopupMenu(popupmenu, pos)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2008 elif e.Dragging() and e.ButtonIsDown(wx.MOUSE_BTN_LEFT):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2009 obj = e.GetEventObject()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2010 scrpos = obj.ClientToScreen(e.GetPosition())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2011 if not hasattr(self, "dragpos"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2012 self.dragpos = scrpos
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2013 e.Skip()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2014 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2015 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2016 dx, dy = self.dragpos[0] - scrpos[0], self.dragpos[1] - scrpos[1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2017 if dx * dx + dy * dy < 5 * 5: # threshold to detect dragging for jittery mice
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2018 e.Skip()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2019 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2020 if not hasattr(self, "dragging"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2021 # init dragging of the custom button
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2022 if hasattr(obj, "custombutton") and obj.properties is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2023 for b in self.custombuttons_widgets:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2024 if b.properties is None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2025 b.Enable()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2026 b.SetLabel("")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2027 b.SetFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2028 b.SetForegroundColour("black")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2029 b.SetSize(obj.GetSize())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2030 if self.toolbarsizer.GetItem(b) is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2031 self.toolbarsizer.SetItemMinSize(b, obj.GetSize())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2032 self.mainsizer.Layout()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2033 self.dragging = wx.Button(self.panel, -1, obj.GetLabel(), style = wx.BU_EXACTFIT)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2034 self.dragging.SetBackgroundColour(obj.GetBackgroundColour())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2035 self.dragging.SetForegroundColour(obj.GetForegroundColour())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2036 self.dragging.sourcebutton = obj
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2037 self.dragging.Raise()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2038 self.dragging.Disable()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2039 self.dragging.SetPosition(self.panel.ScreenToClient(scrpos))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2040 self.last_drag_dest = obj
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2041 self.dragging.label = obj.s_label = obj.GetLabel()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2042 self.dragging.bgc = obj.s_bgc = obj.GetBackgroundColour()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2043 self.dragging.fgc = obj.s_fgc = obj.GetForegroundColour()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2044 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2045 # dragging in progress
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2046 self.dragging.SetPosition(self.panel.ScreenToClient(scrpos))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2047 wx.CallAfter(self.dragging.Refresh)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2048 dst = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2049 src = self.dragging.sourcebutton
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2050 drg = self.dragging
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2051 for b in self.custombuttons_widgets:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2052 if b.GetScreenRect().Contains(scrpos):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2053 dst = b
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2054 break
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2055 if dst is not self.last_drag_dest:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2056 if self.last_drag_dest is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2057 self.last_drag_dest.SetBackgroundColour(self.last_drag_dest.s_bgc)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2058 self.last_drag_dest.SetForegroundColour(self.last_drag_dest.s_fgc)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2059 self.last_drag_dest.SetLabel(self.last_drag_dest.s_label)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2060 if dst is not None and dst is not src:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2061 dst.s_bgc = dst.GetBackgroundColour()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2062 dst.s_fgc = dst.GetForegroundColour()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2063 dst.s_label = dst.GetLabel()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2064 src.SetBackgroundColour(dst.GetBackgroundColour())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2065 src.SetForegroundColour(dst.GetForegroundColour())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2066 src.SetLabel(dst.GetLabel())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2067 dst.SetBackgroundColour(drg.bgc)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2068 dst.SetForegroundColour(drg.fgc)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2069 dst.SetLabel(drg.label)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2070 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2071 src.SetBackgroundColour(drg.bgc)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2072 src.SetForegroundColour(drg.fgc)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2073 src.SetLabel(drg.label)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2074 self.last_drag_dest = dst
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2075 elif hasattr(self, "dragging") and not e.ButtonIsDown(wx.MOUSE_BTN_LEFT):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2076 # dragging finished
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2077 obj = e.GetEventObject()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2078 scrpos = obj.ClientToScreen(e.GetPosition())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2079 dst = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2080 src = self.dragging.sourcebutton
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2081 drg = self.dragging
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2082 for b in self.custombuttons_widgets:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2083 if b.GetScreenRect().Contains(scrpos):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2084 dst = b
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2085 break
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2086 if dst is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2087 src_i = src.custombutton
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2088 dst_i = dst.custombutton
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2089 self.custombuttons[src_i], self.custombuttons[dst_i] = self.custombuttons[dst_i], self.custombuttons[src_i]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2090 self.cbutton_save(src_i, self.custombuttons[src_i])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2091 self.cbutton_save(dst_i, self.custombuttons[dst_i])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2092 while self.custombuttons[-1] is None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2093 del self.custombuttons[-1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2094 wx.CallAfter(self.dragging.Destroy)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2095 del self.dragging
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2096 wx.CallAfter(self.cbuttons_reload)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2097 del self.last_drag_dest
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2098 del self.dragpos
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2099 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2100 e.Skip()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2101
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2102 def process_button(self, e):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2103 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2104 if hasattr(e.GetEventObject(), "custombutton"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2105 if wx.GetKeyState(wx.WXK_CONTROL) or wx.GetKeyState(wx.WXK_ALT):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2106 return self.editbutton(e)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2107 self.cur_button = e.GetEventObject().custombutton
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2108 command = e.GetEventObject().properties.command
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2109 command = self.precmd(command)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2110 self.onecmd(command)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2111 self.cur_button = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2112 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2113 self.log(_("Failed to handle button"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2114 self.cur_button = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2115 raise
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2116
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2117 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2118 # Macros handling
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2119 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2120
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2121 def start_macro(self, macro_name, old_macro_definition = ""):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2122 if not self.processing_rc:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2123 def cb(definition):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2124 if len(definition.strip()) == 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2125 if old_macro_definition != "":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2126 dialog = wx.MessageDialog(self, _("Do you want to erase the macro?"), style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2127 if dialog.ShowModal() == wx.ID_YES:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2128 self.delete_macro(macro_name)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2129 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2130 self.log(_("Cancelled."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2131 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2132 self.cur_macro_name = macro_name
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2133 self.cur_macro_def = definition
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2134 self.end_macro()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2135 MacroEditor(macro_name, old_macro_definition, cb)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2136 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2137 pronsole.pronsole.start_macro(self, macro_name, old_macro_definition)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2138
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2139 def end_macro(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2140 pronsole.pronsole.end_macro(self)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2141 self.update_macros_menu()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2142
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2143 def delete_macro(self, macro_name):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2144 pronsole.pronsole.delete_macro(self, macro_name)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2145 self.update_macros_menu()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2146
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2147 def new_macro(self, e = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2148 dialog = wx.Dialog(self, -1, _("Enter macro name"), size = (260, 85))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2149 panel = wx.Panel(dialog, -1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2150 vbox = wx.BoxSizer(wx.VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2151 wx.StaticText(panel, -1, _("Macro name:"), (8, 14))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2152 dialog.namectrl = wx.TextCtrl(panel, -1, '', (110, 8), size = (130, 24), style = wx.TE_PROCESS_ENTER)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2153 hbox = wx.BoxSizer(wx.HORIZONTAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2154 okb = wx.Button(dialog, wx.ID_OK, _("Ok"), size = (60, 24))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2155 dialog.Bind(wx.EVT_TEXT_ENTER, lambda e: dialog.EndModal(wx.ID_OK), dialog.namectrl)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2156 hbox.Add(okb)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2157 hbox.Add(wx.Button(dialog, wx.ID_CANCEL, _("Cancel"), size = (60, 24)))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2158 vbox.Add(panel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2159 vbox.Add(hbox, 1, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2160 dialog.SetSizer(vbox)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2161 dialog.Centre()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2162 macro = ""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2163 if dialog.ShowModal() == wx.ID_OK:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2164 macro = dialog.namectrl.GetValue()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2165 if macro != "":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2166 wx.CallAfter(self.edit_macro, macro)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2167 dialog.Destroy()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2168 return macro
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2169
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2170 def edit_macro(self, macro):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2171 if macro == "": return self.new_macro()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2172 if macro in self.macros:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2173 old_def = self.macros[macro]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2174 elif len([c for c in macro.encode("ascii", "replace") if not c.isalnum() and c != "_"]):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2175 self.log(_("Macro name may contain only ASCII alphanumeric symbols and underscores"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2176 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2177 elif hasattr(self.__class__, "do_" + macro):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2178 self.log(_("Name '%s' is being used by built-in command") % macro)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2179 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2180 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2181 old_def = ""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2182 self.start_macro(macro, old_def)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2183 return macro
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2184
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2185 def update_macros_menu(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2186 if not hasattr(self, "macros_menu"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2187 return # too early, menu not yet built
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2188 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2189 while True:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2190 item = self.macros_menu.FindItemByPosition(1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2191 if item is None: break
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2192 self.macros_menu.DeleteItem(item)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2193 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2194 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2195 for macro in self.macros.keys():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2196 self.Bind(wx.EVT_MENU, lambda x, m = macro: self.start_macro(m, self.macros[m]), self.macros_menu.Append(-1, macro))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2197
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2198 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2199 # Slic3r integration
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2200 # --------------------------------------------------------------
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2201
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2202 def load_slic3r_configs(self, menus):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2203 """List Slic3r configurations and create menu"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2204 # Hack to get correct path for Slic3r config
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2205 orig_appname = self.app.GetAppName()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2206 self.app.SetAppName("Slic3r")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2207 configpath = wx.StandardPaths.Get().GetUserDataDir()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2208 self.app.SetAppName(orig_appname)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2209 self.slic3r_configpath = configpath
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2210 configfile = os.path.join(configpath, "slic3r.ini")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2211 config = self.read_slic3r_config(configfile)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2212 self.slic3r_configs = {}
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2213 for cat in menus:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2214 menu = menus[cat]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2215 pattern = os.path.join(configpath, cat, "*.ini")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2216 files = sorted(glob.glob(pattern))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2217 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2218 preset = config.get("presets", cat)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2219 self.slic3r_configs[cat] = preset
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2220 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2221 preset = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2222 self.slic3r_configs[cat] = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2223 for f in files:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2224 name = os.path.splitext(os.path.basename(f))[0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2225 item = menu.Append(-1, name, f, wx.ITEM_RADIO)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2226 item.Check(os.path.basename(f) == preset)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2227 self.Bind(wx.EVT_MENU,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2228 lambda event, cat = cat, f = f:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2229 self.set_slic3r_config(configfile, cat, f), item)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2230
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2231 def read_slic3r_config(self, configfile, parser = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2232 """Helper to read a Slic3r configuration file"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2233 import ConfigParser
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2234 parser = ConfigParser.RawConfigParser()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2235
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2236 class add_header(object):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2237 def __init__(self, f):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2238 self.f = f
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2239 self.header = '[dummy]'
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2240
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2241 def readline(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2242 if self.header:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2243 try: return self.header
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2244 finally: self.header = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2245 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2246 return self.f.readline()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2247 parser.readfp(add_header(open(configfile)), configfile)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2248 return parser
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2249
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2250 def set_slic3r_config(self, configfile, cat, file):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2251 """Set new preset for a given category"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2252 self.slic3r_configs[cat] = file
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2253 if self.settings.slic3rupdate:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2254 config = self.read_slic3r_config(configfile)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2255 config.set("presets", cat, os.path.basename(file))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2256 f = StringIO.StringIO()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2257 config.write(f)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2258 data = f.getvalue()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2259 f.close()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2260 data = data.replace("[dummy]\n", "")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2261 with open(configfile, "w") as f:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2262 f.write(data)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2263
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2264 class PronterApp(wx.App):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2265
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2266 mainwindow = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2267
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2268 def __init__(self, *args, **kwargs):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2269 super(PronterApp, self).__init__(*args, **kwargs)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2270 self.SetAppName("Pronterface")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2271 self.mainwindow = PronterWindow(self)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2272 self.mainwindow.Show()

mercurial