| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: ascii -*- |
| 3 |
# $Id: bCNC.py,v 1.6 2014/10/15 15:04:48 bnv Exp bnv $ |
| 4 |
# |
| 5 |
# Author: [email protected] |
| 6 |
# Date: 24-Aug-2014 |
| 7 |
|
| 8 |
from __future__ import absolute_import |
| 9 |
from __future__ import print_function |
| 10 |
import sys |
| 11 |
|
| 12 |
__version__ = "0.9.14-dev" |
| 13 |
__date__ = "8 Jan 2019" |
| 14 |
__author__ = "Vasilis Vlachoudis" |
| 15 |
__email__ = "[email protected]" |
| 16 |
__platform_fingerprint__ = "(%s py%s.%s.%s)"%(sys.platform, sys.version_info.major, sys.version_info.minor, sys.version_info.micro) |
| 17 |
|
| 18 |
import os |
| 19 |
import time |
| 20 |
import getopt |
| 21 |
import socket |
| 22 |
import traceback |
| 23 |
import threading |
| 24 |
|
| 25 |
from datetime import datetime |
| 26 |
|
| 27 |
try: |
| 28 |
import serial |
| 29 |
except: |
| 30 |
serial = None |
| 31 |
|
| 32 |
try: |
| 33 |
import Tkinter |
| 34 |
from Queue import * |
| 35 |
from Tkinter import * |
| 36 |
import tkMessageBox |
| 37 |
except ImportError: |
| 38 |
import tkinter |
| 39 |
from queue import * |
| 40 |
from tkinter import * |
| 41 |
import tkinter.messagebox as tkMessageBox |
| 42 |
PRGPATH=os.path.abspath(os.path.dirname(__file__)) |
| 43 |
sys.path.append(PRGPATH) |
| 44 |
sys.path.append(os.path.join(PRGPATH, 'lib')) |
| 45 |
sys.path.append(os.path.join(PRGPATH, 'plugins')) |
| 46 |
sys.path.append(os.path.join(PRGPATH, 'controllers')) |
| 47 |
|
| 48 |
# Load configuration before anything else |
| 49 |
# and if needed replace the translate function _() |
| 50 |
# before any string is initialized |
| 51 |
import Utils |
| 52 |
Utils.loadConfiguration() |
| 53 |
|
| 54 |
import rexx |
| 55 |
import tkExtra |
| 56 |
import Updates |
| 57 |
import bFileDialog |
| 58 |
import tkDialogs |
| 59 |
|
| 60 |
from CNC import WAIT, CNC, GCode |
| 61 |
import Ribbon |
| 62 |
import Pendant |
| 63 |
from Sender import Sender, NOT_CONNECTED, STATECOLOR, STATECOLORDEF |
| 64 |
|
| 65 |
import CNCCanvas |
| 66 |
import webbrowser |
| 67 |
|
| 68 |
from CNCRibbon import Page |
| 69 |
from ToolsPage import Tools, ToolsPage |
| 70 |
from FilePage import FilePage |
| 71 |
from ControlPage import ControlPage |
| 72 |
from TerminalPage import TerminalPage |
| 73 |
from ProbePage import ProbePage |
| 74 |
from EditorPage import EditorPage |
| 75 |
|
| 76 |
_openserial = True # override ini parameters |
| 77 |
_device = None |
| 78 |
_baud = None |
| 79 |
|
| 80 |
MONITOR_AFTER = 200 # ms |
| 81 |
DRAW_AFTER = 300 # ms |
| 82 |
|
| 83 |
RX_BUFFER_SIZE = 128 |
| 84 |
|
| 85 |
MAX_HISTORY = 500 |
| 86 |
|
| 87 |
#ZERO = ["G28", "G30", "G92"] |
| 88 |
|
| 89 |
FILETYPES = [ (_("All accepted"), ("*.ngc","*.cnc","*.nc", "*.tap", "*.gcode", "*.dxf", "*.probe", "*.orient", "*.stl", "*.svg")), |
| 90 |
(_("G-Code"),("*.ngc","*.cnc","*.nc", "*.tap", "*.gcode")), |
| 91 |
(_("G-Code clean"),("*.txt")), |
| 92 |
("DXF", "*.dxf"), |
| 93 |
("SVG", "*.svg"), |
| 94 |
(_("Probe"), ("*.probe", "*.xyz")), |
| 95 |
(_("Orient"), "*.orient"), |
| 96 |
("STL", "*.stl"), |
| 97 |
(_("All"), "*")] |
| 98 |
|
| 99 |
geometry = None |
| 100 |
|
| 101 |
#============================================================================== |
| 102 |
# Main Application window |
| 103 |
#============================================================================== |
| 104 |
class Application(Toplevel,Sender): |
| 105 |
def __init__(self, master, **kw): |
| 106 |
Toplevel.__init__(self, master, **kw) |
| 107 |
Sender.__init__(self) |
| 108 |
|
| 109 |
if sys.platform == "win32": |
| 110 |
self.iconbitmap("%s\\bCNC.ico"%(Utils.prgpath)) |
| 111 |
else: |
| 112 |
self.iconbitmap("@%s/share/bcnc/bCNC.xbm"%(sys.prefix)) |
| 113 |
self.title("%s %s %s"%(Utils.__prg__, __version__, __platform_fingerprint__)) |
| 114 |
self.widgets = [] |
| 115 |
|
| 116 |
# Global variables |
| 117 |
self.tools = Tools(self.gcode) |
| 118 |
self.controller = None |
| 119 |
self.loadConfig() |
| 120 |
# --- Ribbon --- |
| 121 |
self.ribbon = Ribbon.TabRibbonFrame(self) |
| 122 |
self.ribbon.pack(side=TOP, fill=X) |
| 123 |
|
| 124 |
# Main frame |
| 125 |
self.paned = PanedWindow(self, orient=HORIZONTAL) |
| 126 |
self.paned.pack(fill=BOTH, expand=YES) |
| 127 |
|
| 128 |
# Status bar |
| 129 |
frame = Frame(self) |
| 130 |
frame.pack(side=BOTTOM, fill=X) |
| 131 |
self.statusbar = tkExtra.ProgressBar(frame, height=20, relief=SUNKEN) |
| 132 |
self.statusbar.pack(side=LEFT, fill=X, expand=YES) |
| 133 |
self.statusbar.configText(fill="DarkBlue", justify=LEFT, anchor=W) |
| 134 |
|
| 135 |
self.statusz = Label(frame, foreground="DarkRed", relief=SUNKEN, anchor=W, width=10) |
| 136 |
self.statusz.pack(side=RIGHT) |
| 137 |
self.statusy = Label(frame, foreground="DarkRed", relief=SUNKEN, anchor=W, width=10) |
| 138 |
self.statusy.pack(side=RIGHT) |
| 139 |
self.statusx = Label(frame, foreground="DarkRed", relief=SUNKEN, anchor=W, width=10) |
| 140 |
self.statusx.pack(side=RIGHT) |
| 141 |
|
| 142 |
# Buffer bar |
| 143 |
self.bufferbar = tkExtra.ProgressBar(frame, height=20, width=40, relief=SUNKEN) |
| 144 |
self.bufferbar.pack(side=RIGHT, expand=NO) |
| 145 |
self.bufferbar.setLimits(0, 100) |
| 146 |
tkExtra.Balloon.set(self.bufferbar,_("Controller buffer fill")) |
| 147 |
|
| 148 |
# --- Left side --- |
| 149 |
frame = Frame(self.paned) |
| 150 |
self.paned.add(frame) #, minsize=340) |
| 151 |
|
| 152 |
pageframe = Frame(frame) |
| 153 |
pageframe.pack(side=TOP, expand=YES, fill=BOTH) |
| 154 |
self.ribbon.setPageFrame(pageframe) |
| 155 |
|
| 156 |
# Command bar |
| 157 |
f = Frame(frame) |
| 158 |
f.pack(side=BOTTOM, fill=X) |
| 159 |
self.cmdlabel = Label(f, text=_("Command:")) |
| 160 |
self.cmdlabel.pack(side=LEFT) |
| 161 |
self.command = Entry(f, relief=SUNKEN, background="White")#!!! |
| 162 |
self.command.pack(side=RIGHT, fill=X, expand=YES) |
| 163 |
self.command.bind("<Return>", self.cmdExecute) |
| 164 |
self.command.bind("<Up>", self.commandHistoryUp) |
| 165 |
self.command.bind("<Down>", self.commandHistoryDown) |
| 166 |
self.command.bind("<FocusIn>", self.commandFocusIn) |
| 167 |
self.command.bind("<FocusOut>", self.commandFocusOut) |
| 168 |
self.command.bind("<Key>", self.commandKey) |
| 169 |
self.command.bind("<Control-Key-z>", self.undo) |
| 170 |
self.command.bind("<Control-Key-Z>", self.redo) |
| 171 |
self.command.bind("<Control-Key-y>", self.redo) |
| 172 |
tkExtra.Balloon.set(self.command, |
| 173 |
_("MDI Command line: Accept g-code commands or macro " \ |
| 174 |
"commands (RESET/HOME...) or editor commands " \ |
| 175 |
"(move,inkscape, round...) [Space or Ctrl-Space]")) |
| 176 |
self.widgets.append(self.command) |
| 177 |
|
| 178 |
# --- Right side --- |
| 179 |
frame = Frame(self.paned) |
| 180 |
self.paned.add(frame) |
| 181 |
|
| 182 |
# --- Canvas --- |
| 183 |
self.canvasFrame = CNCCanvas.CanvasFrame(frame, self) |
| 184 |
self.canvasFrame.pack(side=TOP, fill=BOTH, expand=YES) |
| 185 |
#self.paned.add(self.canvasFrame) |
| 186 |
# XXX FIXME do I need the self.canvas? |
| 187 |
self.canvas = self.canvasFrame.canvas |
| 188 |
|
| 189 |
# fist create Pages |
| 190 |
self.pages = {} |
| 191 |
for cls in ( ControlPage, |
| 192 |
EditorPage, |
| 193 |
FilePage, |
| 194 |
ProbePage, |
| 195 |
TerminalPage, |
| 196 |
ToolsPage): |
| 197 |
page = cls(self.ribbon, self) |
| 198 |
self.pages[page.name] = page |
| 199 |
|
| 200 |
# then add their properties (in separate loop) |
| 201 |
errors = [] |
| 202 |
for name,page in self.pages.items(): |
| 203 |
for n in Utils.getStr(Utils.__prg__,"%s.ribbon"%(page.name)).split(): |
| 204 |
try: |
| 205 |
page.addRibbonGroup(n) |
| 206 |
except KeyError: |
| 207 |
errors.append(n) |
| 208 |
|
| 209 |
for n in Utils.getStr(Utils.__prg__,"%s.page"%(page.name)).split(): |
| 210 |
last = n[-1] |
| 211 |
if (n=="abcDRO" or n=="abcControl") and CNC.enable6axisopt == False: |
| 212 |
sys.stdout.write("Not Loading 6 axis displays\n") |
| 213 |
|
| 214 |
|
| 215 |
else: |
| 216 |
try: |
| 217 |
if last == "*": |
| 218 |
page.addPageFrame(n[:-1],fill=BOTH,expand=TRUE) |
| 219 |
else: |
| 220 |
page.addPageFrame(n) |
| 221 |
except KeyError: |
| 222 |
errors.append(n) |
| 223 |
|
| 224 |
if errors: |
| 225 |
tkMessageBox.showwarning("bCNC configuration", |
| 226 |
"The following pages \"%s\" are found in your " \ |
| 227 |
"${HOME}/.bCNC initialization " \ |
| 228 |
"file, which are either spelled wrongly or " \ |
| 229 |
"no longer exist in bCNC"%(" ".join(errors)),parent=self) |
| 230 |
|
| 231 |
# remember the editor list widget |
| 232 |
self.dro = Page.frames["DRO"] |
| 233 |
self.abcdro = Page.frames["abcDRO"] |
| 234 |
self.gstate = Page.frames["State"] |
| 235 |
self.control = Page.frames["Control"] |
| 236 |
self.abccontrol=Page.frames["abcControl"] |
| 237 |
self.editor = Page.frames["Editor"].editor |
| 238 |
self.terminal = Page.frames["Terminal"].terminal |
| 239 |
self.buffer = Page.frames["Terminal"].buffer |
| 240 |
|
| 241 |
|
| 242 |
# XXX FIXME Do we need it or I can takes from Page every time? |
| 243 |
self.autolevel = Page.frames["Probe:Autolevel"] |
| 244 |
|
| 245 |
# Left side |
| 246 |
for name in Utils.getStr(Utils.__prg__,"ribbon").split(): |
| 247 |
last = name[-1] |
| 248 |
if last == '>': |
| 249 |
name = name[:-1] |
| 250 |
side = RIGHT |
| 251 |
else: |
| 252 |
side = LEFT |
| 253 |
self.ribbon.addPage(self.pages[name],side) |
| 254 |
|
| 255 |
# Restore last page |
| 256 |
self.pages["Probe"].tabChange() # Select "Probe:Probe" tab to show the dialogs! |
| 257 |
self.ribbon.changePage(Utils.getStr(Utils.__prg__,"page", "File")) |
| 258 |
|
| 259 |
probe = Page.frames["Probe:Probe"] |
| 260 |
tkExtra.bindEventData(self, "<<OrientSelect>>", lambda e,f=probe: f.selectMarker(int(e.data))) |
| 261 |
tkExtra.bindEventData(self, '<<OrientChange>>', lambda e,s=self: s.canvas.orientChange(int(e.data))) |
| 262 |
self.bind('<<OrientUpdate>>', probe.orientUpdate) |
| 263 |
|
| 264 |
# Global bindings |
| 265 |
self.bind('<<Undo>>', self.undo) |
| 266 |
self.bind('<<Redo>>', self.redo) |
| 267 |
self.bind('<<Copy>>', self.copy) |
| 268 |
self.bind('<<Cut>>', self.cut) |
| 269 |
self.bind('<<Paste>>', self.paste) |
| 270 |
|
| 271 |
self.bind('<<Connect>>', self.openClose) |
| 272 |
|
| 273 |
self.bind('<<New>>', self.newFile) |
| 274 |
self.bind('<<Open>>', self.loadDialog) |
| 275 |
self.bind('<<Import>>', lambda x,s=self: s.importFile()) |
| 276 |
self.bind('<<Save>>', self.saveAll) |
| 277 |
self.bind('<<SaveAs>>', self.saveDialog) |
| 278 |
self.bind('<<Reload>>', self.reload) |
| 279 |
|
| 280 |
self.bind('<<Recent0>>', self._loadRecent0) |
| 281 |
self.bind('<<Recent1>>', self._loadRecent1) |
| 282 |
self.bind('<<Recent2>>', self._loadRecent2) |
| 283 |
self.bind('<<Recent3>>', self._loadRecent3) |
| 284 |
self.bind('<<Recent4>>', self._loadRecent4) |
| 285 |
self.bind('<<Recent5>>', self._loadRecent5) |
| 286 |
self.bind('<<Recent6>>', self._loadRecent6) |
| 287 |
self.bind('<<Recent7>>', self._loadRecent7) |
| 288 |
self.bind('<<Recent8>>', self._loadRecent8) |
| 289 |
self.bind('<<Recent9>>', self._loadRecent9) |
| 290 |
|
| 291 |
self.bind('<<TerminalClear>>', Page.frames["Terminal"].clear) |
| 292 |
self.bind('<<AlarmClear>>', self.alarmClear) |
| 293 |
self.bind('<<Help>>', self.help) |
| 294 |
# Do not send the event otherwise it will skip the feedHold/resume |
| 295 |
self.bind('<<FeedHold>>', lambda e,s=self: s.feedHold()) |
| 296 |
self.bind('<<Resume>>', lambda e,s=self: s.resume()) |
| 297 |
self.bind('<<Run>>', lambda e,s=self: s.run()) |
| 298 |
self.bind('<<Stop>>', self.stopRun) |
| 299 |
self.bind('<<Pause>>', self.pause) |
| 300 |
# self.bind('<<TabAdded>>', self.tabAdded) |
| 301 |
|
| 302 |
tkExtra.bindEventData(self, "<<Status>>", self.updateStatus) |
| 303 |
tkExtra.bindEventData(self, "<<Coords>>", self.updateCanvasCoords) |
| 304 |
|
| 305 |
# Editor bindings |
| 306 |
self.bind("<<Add>>", self.editor.insertItem) |
| 307 |
self.bind("<<AddBlock>>", self.editor.insertBlock) |
| 308 |
self.bind("<<AddLine>>", self.editor.insertLine) |
| 309 |
self.bind("<<Clone>>", self.editor.clone) |
| 310 |
self.canvas.bind("<Control-Key-Prior>", self.editor.orderUp) |
| 311 |
self.canvas.bind("<Control-Key-Next>", self.editor.orderDown) |
| 312 |
self.canvas.bind('<Control-Key-d>', self.editor.clone) |
| 313 |
self.canvas.bind('<Control-Key-c>', self.copy) |
| 314 |
self.canvas.bind('<Control-Key-x>', self.cut) |
| 315 |
self.canvas.bind('<Control-Key-v>', self.paste) |
| 316 |
self.bind("<<Delete>>", self.editor.deleteBlock) |
| 317 |
self.canvas.bind("<Delete>", self.editor.deleteBlock) |
| 318 |
self.canvas.bind("<BackSpace>", self.editor.deleteBlock) |
| 319 |
try: |
| 320 |
self.canvas.bind("<KP_Delete>", self.editor.deleteBlock) |
| 321 |
except: |
| 322 |
pass |
| 323 |
self.bind('<<Invert>>', self.editor.invertBlocks) |
| 324 |
self.bind('<<Expand>>', self.editor.toggleExpand) |
| 325 |
self.bind('<<EnableToggle>>', self.editor.toggleEnable) |
| 326 |
self.bind('<<Enable>>', self.editor.enable) |
| 327 |
self.bind('<<Disable>>', self.editor.disable) |
| 328 |
self.bind('<<ChangeColor>>', self.editor.changeColor) |
| 329 |
self.bind('<<Comment>>', self.editor.commentRow) |
| 330 |
self.bind('<<Join>>', self.editor.joinBlocks) |
| 331 |
self.bind('<<Split>>', self.editor.splitBlocks) |
| 332 |
|
| 333 |
# Canvas X-bindings |
| 334 |
self.bind("<<ViewChange>>", self.viewChange) |
| 335 |
self.bind("<<AddMarker>>", self.canvas.setActionAddMarker) |
| 336 |
self.bind('<<MoveGantry>>', self.canvas.setActionGantry) |
| 337 |
self.bind('<<SetWPOS>>', self.canvas.setActionWPOS) |
| 338 |
|
| 339 |
frame = Page.frames["Probe:Tool"] |
| 340 |
self.bind('<<ToolCalibrate>>', frame.calibrate) |
| 341 |
self.bind('<<ToolChange>>', frame.change) |
| 342 |
|
| 343 |
self.bind('<<AutolevelMargins>>',self.autolevel.getMargins) |
| 344 |
self.bind('<<AutolevelZero>>', self.autolevel.setZero) |
| 345 |
self.bind('<<AutolevelClear>>', self.autolevel.clear) |
| 346 |
self.bind('<<AutolevelScan>>', self.autolevel.scan) |
| 347 |
self.bind('<<AutolevelScanMargins>>', self.autolevel.scanMargins) |
| 348 |
|
| 349 |
self.bind('<<CameraOn>>', self.canvas.cameraOn) |
| 350 |
self.bind('<<CameraOff>>', self.canvas.cameraOff) |
| 351 |
|
| 352 |
self.bind('<<CanvasFocus>>', self.canvasFocus) |
| 353 |
self.bind('<<Draw>>', self.draw) |
| 354 |
self.bind('<<DrawProbe>>', lambda e,c=self.canvasFrame:c.drawProbe(True)) |
| 355 |
self.bind('<<DrawOrient>>', self.canvas.drawOrient) |
| 356 |
|
| 357 |
self.bind("<<ListboxSelect>>", self.selectionChange) |
| 358 |
self.bind("<<Modified>>", self.drawAfter) |
| 359 |
|
| 360 |
self.bind('<Control-Key-a>', self.selectAll) |
| 361 |
self.bind('<Control-Key-A>', self.unselectAll) |
| 362 |
self.bind('<Escape>', self.unselectAll) |
| 363 |
self.bind('<Control-Key-i>', self.selectInvert) |
| 364 |
|
| 365 |
self.bind('<<SelectAll>>', self.selectAll) |
| 366 |
self.bind('<<SelectNone>>', self.unselectAll) |
| 367 |
self.bind('<<SelectInvert>>', self.selectInvert) |
| 368 |
self.bind('<<SelectLayer>>', self.selectLayer) |
| 369 |
|
| 370 |
# self.bind('<Control-Key-f>', self.find) |
| 371 |
# self.bind('<Control-Key-g>', self.findNext) |
| 372 |
# self.bind('<Control-Key-h>', self.replace) |
| 373 |
self.bind('<Control-Key-e>', self.editor.toggleExpand) |
| 374 |
self.bind('<Control-Key-n>', self.showInfo) |
| 375 |
self.bind('<<ShowInfo>>', self.showInfo) |
| 376 |
self.bind('<Control-Key-l>', self.editor.toggleEnable) |
| 377 |
self.bind('<Control-Key-q>', self.quit) |
| 378 |
self.bind('<Control-Key-o>', self.loadDialog) |
| 379 |
self.bind('<Control-Key-r>', self.drawAfter) |
| 380 |
self.bind("<Control-Key-s>", self.saveAll) |
| 381 |
self.bind('<Control-Key-y>', self.redo) |
| 382 |
self.bind('<Control-Key-z>', self.undo) |
| 383 |
self.bind('<Control-Key-Z>', self.redo) |
| 384 |
self.canvas.bind('<Key-space>', self.commandFocus) |
| 385 |
self.bind('<Control-Key-space>',self.commandFocus) |
| 386 |
self.bind('<<CommandFocus>>', self.commandFocus) |
| 387 |
|
| 388 |
tools = self.pages["CAM"] |
| 389 |
self.bind('<<ToolAdd>>', tools.add) |
| 390 |
self.bind('<<ToolDelete>>', tools.delete) |
| 391 |
self.bind('<<ToolClone>>', tools.clone) |
| 392 |
self.bind('<<ToolRename>>', tools.rename) |
| 393 |
|
| 394 |
self.bind('<Prior>', self.control.moveZup) |
| 395 |
self.bind('<Next>', self.control.moveZdown) |
| 396 |
|
| 397 |
if self._swapKeyboard == 1: |
| 398 |
self.bind('<Right>', self.control.moveYup) |
| 399 |
self.bind('<Left>', self.control.moveYdown) |
| 400 |
self.bind('<Up>', self.control.moveXdown) |
| 401 |
self.bind('<Down>', self.control.moveXup) |
| 402 |
self.bind('.', self.abccontrol.moveAup) |
| 403 |
self.bind(',', self.abccontrol.moveAdown) |
| 404 |
elif self._swapKeyboard == -1: |
| 405 |
self.bind('<Right>', self.control.moveYdown) |
| 406 |
self.bind('<Left>', self.control.moveYup) |
| 407 |
self.bind('<Up>', self.control.moveXup) |
| 408 |
self.bind('<Down>', self.control.moveXdown) |
| 409 |
self.bind(',', self.abccontrol.moveAup) |
| 410 |
self.bind('.', self.abccontrol.moveAdown) |
| 411 |
else: |
| 412 |
self.bind('<Right>', self.control.moveXup) |
| 413 |
self.bind('<Left>', self.control.moveXdown) |
| 414 |
self.bind('<Up>', self.control.moveYup) |
| 415 |
self.bind('<Down>', self.control.moveYdown) |
| 416 |
self.bind('.', self.abccontrol.moveAup) |
| 417 |
self.bind(',', self.abccontrol.moveAdown) |
| 418 |
|
| 419 |
try: |
| 420 |
self.bind('<KP_Prior>', self.control.moveZup) |
| 421 |
self.bind('<KP_Next>', self.control.moveZdown) |
| 422 |
|
| 423 |
if self._swapKeyboard==1: |
| 424 |
self.bind('<KP_Right>', self.control.moveYup) |
| 425 |
self.bind('<KP_Left>', self.control.moveYdown) |
| 426 |
self.bind('<KP_Up>', self.control.moveXdown) |
| 427 |
self.bind('<KP_Down>', self.control.moveXup) |
| 428 |
elif self._swapKeyboard==-1: |
| 429 |
self.bind('<KP_Right>', self.control.moveYdown) |
| 430 |
self.bind('<KP_Left>', self.control.moveYup) |
| 431 |
self.bind('<KP_Up>', self.control.moveXup) |
| 432 |
self.bind('<KP_Down>', self.control.moveXdown) |
| 433 |
else: |
| 434 |
self.bind('<KP_Right>', self.control.moveXup) |
| 435 |
self.bind('<KP_Left>', self.control.moveXdown) |
| 436 |
self.bind('<KP_Up>', self.control.moveYup) |
| 437 |
self.bind('<KP_Down>', self.control.moveYdown) |
| 438 |
except TclError: |
| 439 |
pass |
| 440 |
|
| 441 |
self.bind('<Key-plus>', self.control.incStep) |
| 442 |
self.bind('<Key-equal>', self.control.incStep) |
| 443 |
self.bind('<KP_Add>', self.control.incStep) |
| 444 |
self.bind('<Key-minus>', self.control.decStep) |
| 445 |
self.bind('<Key-underscore>', self.control.decStep) |
| 446 |
self.bind('<KP_Subtract>', self.control.decStep) |
| 447 |
|
| 448 |
self.bind('<Key-asterisk>', self.control.mulStep) |
| 449 |
self.bind('<KP_Multiply>', self.control.mulStep) |
| 450 |
self.bind('<Key-slash>', self.control.divStep) |
| 451 |
self.bind('<KP_Divide>', self.control.divStep) |
| 452 |
|
| 453 |
self.bind('<Key-1>', self.control.setStep1) |
| 454 |
self.bind('<Key-2>', self.control.setStep2) |
| 455 |
self.bind('<Key-3>', self.control.setStep3) |
| 456 |
|
| 457 |
self.bind('<Key-exclam>', self.feedHold) |
| 458 |
self.bind('<Key-asciitilde>', self.resume) |
| 459 |
|
| 460 |
for x in self.widgets: |
| 461 |
if isinstance(x,Entry): |
| 462 |
x.bind("<Escape>", self.canvasFocus) |
| 463 |
|
| 464 |
self.bind('<FocusIn>', self.focusIn) |
| 465 |
self.protocol("WM_DELETE_WINDOW", self.quit) |
| 466 |
|
| 467 |
self.canvas.focus_set() |
| 468 |
|
| 469 |
# Fill basic global variables |
| 470 |
CNC.vars["state"] = NOT_CONNECTED |
| 471 |
CNC.vars["color"] = STATECOLOR[NOT_CONNECTED] |
| 472 |
self._pendantFileUploaded = None |
| 473 |
self._drawAfter = None # after handle for modification |
| 474 |
self._inFocus = False |
| 475 |
self._insertCount = 0 # END - insertCount lines where ok was applied to for $xxx commands |
| 476 |
self._selectI = 0 |
| 477 |
self.monitorSerial() |
| 478 |
self.canvasFrame.toggleDrawFlag() |
| 479 |
|
| 480 |
self.paned.sash_place(0, Utils.getInt(Utils.__prg__, "sash", 340), 0) |
| 481 |
|
| 482 |
# Auto start pendant and serial |
| 483 |
if Utils.getBool("Connection","pendant"): |
| 484 |
self.startPendant(False) |
| 485 |
|
| 486 |
if _openserial and Utils.getBool("Connection","openserial"): |
| 487 |
self.openClose() |
| 488 |
|
| 489 |
# Filedialog Load history |
| 490 |
for i in range(Utils._maxRecent): |
| 491 |
filename = Utils.getRecent(i) |
| 492 |
if filename is None: break |
| 493 |
bFileDialog.append2History(os.path.dirname(filename)) |
| 494 |
|
| 495 |
#----------------------------------------------------------------------- |
| 496 |
def setStatus(self, msg, force_update=False): |
| 497 |
self.statusbar.configText(text=msg, fill="DarkBlue") |
| 498 |
if force_update: |
| 499 |
self.statusbar.update_idletasks() |
| 500 |
self.bufferbar.update_idletasks() |
| 501 |
#----------------------------------------------------------------------- |
| 502 |
# Set a status message from an event |
| 503 |
#----------------------------------------------------------------------- |
| 504 |
def updateStatus(self, event): |
| 505 |
self.setStatus(_(event.data)) |
| 506 |
|
| 507 |
#----------------------------------------------------------------------- |
| 508 |
# Show popup dialog asking for value entry, usefull in g-code scripts |
| 509 |
#----------------------------------------------------------------------- |
| 510 |
def entry(self, message="Enter value", title="", input="", type_="str", from_=None, to_=None): |
| 511 |
d = tkDialogs.InputDialog(self, title, message, input, type_, from_, to_) |
| 512 |
v = d.show() |
| 513 |
|
| 514 |
if isinstance(v, basestring): |
| 515 |
v = v.strip() |
| 516 |
print("entered "+str(type(v))+": "+str(v)) |
| 517 |
return v |
| 518 |
|
| 519 |
#----------------------------------------------------------------------- |
| 520 |
# Update canvas coordinates |
| 521 |
#----------------------------------------------------------------------- |
| 522 |
def updateCanvasCoords(self, event): |
| 523 |
x,y,z = event.data.split() |
| 524 |
self.statusx["text"] = "X: "+x |
| 525 |
self.statusy["text"] = "Y: "+y |
| 526 |
self.statusz["text"] = "Z: "+z |
| 527 |
|
| 528 |
#---------------------------------------------------------------------- |
| 529 |
# Accept the user key if not editing any text |
| 530 |
#---------------------------------------------------------------------- |
| 531 |
def acceptKey(self, skipRun=False): |
| 532 |
if not skipRun and self.running: return False |
| 533 |
focus = self.focus_get() |
| 534 |
if isinstance(focus, Entry) or \ |
| 535 |
isinstance(focus, Spinbox) or \ |
| 536 |
isinstance(focus, Listbox) or \ |
| 537 |
isinstance(focus, Text): return False |
| 538 |
return True |
| 539 |
|
| 540 |
#----------------------------------------------------------------------- |
| 541 |
def quit(self, event=None): |
| 542 |
if self.running and self._quit<1: |
| 543 |
tkMessageBox.showinfo(_("Running"), |
| 544 |
_("CNC is currently running, please stop it before."), |
| 545 |
parent=self) |
| 546 |
self._quit += 1 |
| 547 |
return |
| 548 |
del self.widgets[:] |
| 549 |
|
| 550 |
if self.fileModified(): |
| 551 |
return |
| 552 |
|
| 553 |
self.canvas.cameraOff() |
| 554 |
Sender.quit(self) |
| 555 |
self.saveConfig() |
| 556 |
self.destroy() |
| 557 |
if Utils.errors and Utils._errorReport: |
| 558 |
Utils.ReportDialog.sendErrorReport() |
| 559 |
tk.destroy() |
| 560 |
|
| 561 |
# --------------------------------------------------------------------- |
| 562 |
def configWidgets(self, var, value): |
| 563 |
for w in self.widgets: |
| 564 |
if isinstance(w,tuple): |
| 565 |
try: |
| 566 |
w[0].entryconfig(w[1], state=value) |
| 567 |
except TclError: |
| 568 |
pass |
| 569 |
elif isinstance(w,tkExtra.Combobox): |
| 570 |
w.configure(state=value) |
| 571 |
else: |
| 572 |
w[var] = value |
| 573 |
|
| 574 |
# --------------------------------------------------------------------- |
| 575 |
def busy(self): |
| 576 |
try: |
| 577 |
self.config(cursor="watch") |
| 578 |
self.update_idletasks() |
| 579 |
except TclError: |
| 580 |
pass |
| 581 |
|
| 582 |
# ---------------------------------------------------------------------- |
| 583 |
def notBusy(self): |
| 584 |
try: |
| 585 |
self.config(cursor="") |
| 586 |
except TclError: |
| 587 |
pass |
| 588 |
|
| 589 |
# --------------------------------------------------------------------- |
| 590 |
def enable(self): |
| 591 |
self.configWidgets("state",NORMAL) |
| 592 |
self.statusbar.clear() |
| 593 |
self.statusbar.config(background="LightGray") |
| 594 |
self.bufferbar.clear() |
| 595 |
self.bufferbar.config(background="LightGray") |
| 596 |
self.bufferbar.setText("") |
| 597 |
|
| 598 |
# --------------------------------------------------------------------- |
| 599 |
def disable(self): |
| 600 |
self.configWidgets("state",DISABLED) |
| 601 |
|
| 602 |
# ---------------------------------------------------------------------- |
| 603 |
# Check for updates |
| 604 |
# ---------------------------------------------------------------------- |
| 605 |
def checkUpdates(self): |
| 606 |
# Find bCNC version |
| 607 |
Updates.CheckUpdateDialog(self, __version__) |
| 608 |
|
| 609 |
#----------------------------------------------------------------------- |
| 610 |
def loadShortcuts(self): |
| 611 |
for name, value in Utils.config.items("Shortcut"): |
| 612 |
# Convert to uppercase |
| 613 |
key = name.title() |
| 614 |
self.unbind("<%s>"%(key)) # unbind any possible old value |
| 615 |
if value: |
| 616 |
self.bind("<%s>"%(key), lambda e,s=self,c=value : s.execute(c)) |
| 617 |
|
| 618 |
#----------------------------------------------------------------------- |
| 619 |
def showUserFile(self): |
| 620 |
webbrowser.open(Utils.iniUser) |
| 621 |
#os.startfile(Utils.iniUser) |
| 622 |
|
| 623 |
#----------------------------------------------------------------------- |
| 624 |
def loadConfig(self): |
| 625 |
global geometry |
| 626 |
|
| 627 |
if geometry is None: |
| 628 |
geometry = "%sx%s" % (Utils.getInt(Utils.__prg__, "width", 900), |
| 629 |
Utils.getInt(Utils.__prg__, "height", 650)) |
| 630 |
try: self.geometry(geometry) |
| 631 |
except: pass |
| 632 |
|
| 633 |
#restore windowsState |
| 634 |
try: |
| 635 |
self.wm_state(Utils.getStr(Utils.__prg__, "windowstate", "normal")) |
| 636 |
except: |
| 637 |
pass |
| 638 |
|
| 639 |
# read Tk fonts to initialize them |
| 640 |
font = Utils.getFont("TkDefaultFont") |
| 641 |
font = Utils.getFont("TkFixedFont") |
| 642 |
font = Utils.getFont("TkMenuFont") |
| 643 |
font = Utils.getFont("TkTextFont") |
| 644 |
|
| 645 |
self._swapKeyboard = Utils.getInt("Control", "swap", 0) |
| 646 |
|
| 647 |
self._onStart = Utils.getStr("Events", "onstart", "") |
| 648 |
self._onStop = Utils.getStr("Events", "onstop", "") |
| 649 |
|
| 650 |
tkExtra.Balloon.font = Utils.getFont("balloon", tkExtra.Balloon.font) |
| 651 |
|
| 652 |
Ribbon._FONT = Utils.getFont("ribbon.label", Ribbon._FONT) |
| 653 |
Ribbon._TABFONT = Utils.getFont("ribbon.tab", Ribbon._TABFONT) |
| 654 |
|
| 655 |
Ribbon._ACTIVE_COLOR = Utils.getStr("Color", "ribbon.active", Ribbon._ACTIVE_COLOR) |
| 656 |
Ribbon._LABEL_SELECT_COLOR = Utils.getStr("Color", "ribbon.select", Ribbon._LABEL_SELECT_COLOR) |
| 657 |
|
| 658 |
self.tools.loadConfig() |
| 659 |
Sender.loadConfig(self) |
| 660 |
self.loadShortcuts() |
| 661 |
|
| 662 |
#----------------------------------------------------------------------- |
| 663 |
def saveConfig(self): |
| 664 |
# Program |
| 665 |
Utils.setInt(Utils.__prg__, "width", str(self.winfo_width())) |
| 666 |
Utils.setInt(Utils.__prg__, "height", str(self.winfo_height())) |
| 667 |
#Utils.setInt(Utils.__prg__, "x", str(self.winfo_rootx())) |
| 668 |
#Utils.setInt(Utils.__prg__, "y", str(self.winfo_rooty())) |
| 669 |
Utils.setInt(Utils.__prg__, "sash", str(self.paned.sash_coord(0)[0])) |
| 670 |
|
| 671 |
#save windowState |
| 672 |
Utils.setStr(Utils.__prg__, "windowstate", str(self.wm_state())) |
| 673 |
Utils.setStr(Utils.__prg__, "page", str(self.ribbon.getActivePage().name)) |
| 674 |
|
| 675 |
# Connection |
| 676 |
Page.saveConfig() |
| 677 |
Sender.saveConfig(self) |
| 678 |
self.tools.saveConfig() |
| 679 |
self.canvasFrame.saveConfig() |
| 680 |
|
| 681 |
#----------------------------------------------------------------------- |
| 682 |
def loadHistory(self): |
| 683 |
try: |
| 684 |
f = open(Utils.hisFile,"r") |
| 685 |
except: |
| 686 |
return |
| 687 |
self.history = [x.strip() for x in f] |
| 688 |
self._historySearch = None |
| 689 |
f.close() |
| 690 |
|
| 691 |
#----------------------------------------------------------------------- |
| 692 |
def saveHistory(self): |
| 693 |
try: |
| 694 |
f = open(Utils.hisFile,"w") |
| 695 |
except: |
| 696 |
return |
| 697 |
f.write("\n".join(self.history)) |
| 698 |
f.close() |
| 699 |
|
| 700 |
#----------------------------------------------------------------------- |
| 701 |
def cut(self, event=None): |
| 702 |
focus = self.focus_get() |
| 703 |
if focus in (self.canvas, self.editor): |
| 704 |
self.editor.cut() |
| 705 |
return "break" |
| 706 |
|
| 707 |
#----------------------------------------------------------------------- |
| 708 |
def copy(self, event=None): |
| 709 |
focus = self.focus_get() |
| 710 |
if focus in (self.canvas, self.editor): |
| 711 |
self.editor.copy() |
| 712 |
return "break" |
| 713 |
|
| 714 |
#----------------------------------------------------------------------- |
| 715 |
def paste(self, event=None): |
| 716 |
focus = self.focus_get() |
| 717 |
if focus in (self.canvas, self.editor): |
| 718 |
self.editor.paste() |
| 719 |
return "break" |
| 720 |
|
| 721 |
#----------------------------------------------------------------------- |
| 722 |
def undo(self, event=None): |
| 723 |
if not self.running and self.gcode.canUndo(): |
| 724 |
self.gcode.undo(); |
| 725 |
self.editor.fill() |
| 726 |
self.drawAfter() |
| 727 |
return "break" |
| 728 |
|
| 729 |
#----------------------------------------------------------------------- |
| 730 |
def redo(self, event=None): |
| 731 |
if not self.running and self.gcode.canRedo(): |
| 732 |
self.gcode.redo(); |
| 733 |
self.editor.fill() |
| 734 |
self.drawAfter() |
| 735 |
return "break" |
| 736 |
|
| 737 |
#----------------------------------------------------------------------- |
| 738 |
def addUndo(self, undoinfo): |
| 739 |
self.gcode.addUndo(undoinfo) |
| 740 |
|
| 741 |
#----------------------------------------------------------------------- |
| 742 |
def about(self, event=None, timer=None): |
| 743 |
toplevel = Toplevel(self) |
| 744 |
toplevel.transient(self) |
| 745 |
toplevel.title(_("About %s v%s") % (Utils.__prg__,__version__)) |
| 746 |
if sys.platform == "win32": |
| 747 |
self.iconbitmap("bCNC.ico") |
| 748 |
else: |
| 749 |
self.iconbitmap("@%s/share/bcnc/bCNC.xbm"%(sys.prefix)) |
| 750 |
|
| 751 |
bg = "#707070" |
| 752 |
fg = "#ffffff" |
| 753 |
|
| 754 |
font1 = 'Helvetica -32 bold' |
| 755 |
font2 = 'Helvetica -12' |
| 756 |
font3 = 'Helvetica -10' |
| 757 |
|
| 758 |
frame = Frame(toplevel, borderwidth=2, |
| 759 |
relief=SUNKEN, background=bg) |
| 760 |
frame.pack(side=TOP, expand=TRUE, fill=BOTH, padx=5, pady=5) |
| 761 |
|
| 762 |
# ----- |
| 763 |
row = 0 |
| 764 |
l = Label(frame, image=Utils.icons["bCNC"], |
| 765 |
foreground=fg, background=bg, |
| 766 |
relief=RAISED, |
| 767 |
padx=0, pady=0) |
| 768 |
l.grid(row=row, column=0, columnspan=2, padx=5, pady=5) |
| 769 |
|
| 770 |
# ----- |
| 771 |
#row += 1 |
| 772 |
#l = Label(frame, text=Utils.__prg__, |
| 773 |
# foreground=fg, background=bg, |
| 774 |
# font=font1) |
| 775 |
#l.grid(row=row, column=0, columnspan=2, sticky=W, padx=10, pady=5) |
| 776 |
|
| 777 |
# ----- |
| 778 |
row += 1 |
| 779 |
l = Label(frame, text=\ |
| 780 |
_("bCNC/\tAn advanced fully featured\n" \ |
| 781 |
"\tg-code sender for GRBL."), |
| 782 |
font = font3, |
| 783 |
foreground=fg, background=bg, justify=LEFT) |
| 784 |
l.grid(row=row, column=0, columnspan=2, sticky=W, padx=10, pady=1) |
| 785 |
|
| 786 |
# ----- |
| 787 |
row += 1 |
| 788 |
f = Frame(frame, borderwidth=1, relief=SUNKEN, |
| 789 |
height=2, background=bg) |
| 790 |
f.grid(row=row, column=0, columnspan=2, sticky=EW, padx=5, pady=5) |
| 791 |
|
| 792 |
# ----- |
| 793 |
row += 1 |
| 794 |
l = Label(frame, text='www:', |
| 795 |
foreground=fg, background=bg, justify=LEFT, |
| 796 |
font=font2) |
| 797 |
l.grid(row=row, column=0, sticky=E, padx=10, pady=2) |
| 798 |
|
| 799 |
l = Label(frame, text=Utils.__www__, |
| 800 |
foreground=fg, background=bg, justify=LEFT, |
| 801 |
activeforeground="Blue", |
| 802 |
font=font2, cursor="hand1") |
| 803 |
l.grid(row=row, column=1, sticky=W, padx=2, pady=2) |
| 804 |
l.bind('<Button-1>', lambda e : webbrowser.open(Utils.__www__)) |
| 805 |
|
| 806 |
# ----- |
| 807 |
row += 1 |
| 808 |
l = Label(frame, text='email:', |
| 809 |
foreground=fg, background=bg, justify=LEFT, |
| 810 |
font=font2) |
| 811 |
l.grid(row=row, column=0, sticky=E, padx=10, pady=2) |
| 812 |
|
| 813 |
l = Label(frame, text=__email__, |
| 814 |
foreground=fg, background=bg, justify=LEFT, |
| 815 |
font=font2) |
| 816 |
l.grid(row=row, column=1, sticky=W, padx=2, pady=2) |
| 817 |
|
| 818 |
# ----- |
| 819 |
row += 1 |
| 820 |
l = Label(frame, text='author:', |
| 821 |
foreground=fg, background=bg, justify=LEFT, |
| 822 |
font=font2) |
| 823 |
l.grid(row=row, column=0, sticky=NE, padx=10, pady=2) |
| 824 |
|
| 825 |
l = Label(frame, text=__author__, |
| 826 |
foreground=fg, background=bg, justify=LEFT, |
| 827 |
font=font2) |
| 828 |
l.grid(row=row, column=1, sticky=NW, padx=2, pady=2) |
| 829 |
|
| 830 |
# ----- |
| 831 |
row += 1 |
| 832 |
l = Label(frame, text='contributors:', |
| 833 |
foreground=fg, background=bg, justify=LEFT, |
| 834 |
font=font2) |
| 835 |
l.grid(row=row, column=0, sticky=NE, padx=10, pady=2) |
| 836 |
|
| 837 |
l = Label(frame, text=Utils.__contribute__, |
| 838 |
foreground=fg, background=bg, justify=LEFT, |
| 839 |
font=font2) |
| 840 |
l.grid(row=row, column=1, sticky=NW, padx=2, pady=2) |
| 841 |
|
| 842 |
# ----- |
| 843 |
row += 1 |
| 844 |
l = Label(frame, text='translations:', |
| 845 |
foreground=fg, background=bg, justify=LEFT, |
| 846 |
font=font2) |
| 847 |
l.grid(row=row, column=0, sticky=NE, padx=10, pady=2) |
| 848 |
|
| 849 |
l = Label(frame, text=Utils.__translations__, |
| 850 |
foreground=fg, background=bg, justify=LEFT, |
| 851 |
font=font2) |
| 852 |
l.grid(row=row, column=1, sticky=NW, padx=2, pady=2) |
| 853 |
|
| 854 |
# ----- |
| 855 |
row += 1 |
| 856 |
l = Label(frame, text='credits:', |
| 857 |
foreground=fg, background=bg, justify=LEFT, |
| 858 |
font=font2) |
| 859 |
l.grid(row=row, column=0, sticky=NE, padx=10, pady=2) |
| 860 |
|
| 861 |
l = Label(frame, text=Utils.__credits__, |
| 862 |
foreground=fg, background=bg, justify=LEFT, |
| 863 |
font=font2) |
| 864 |
l.grid(row=row, column=1, sticky=NW, padx=2, pady=2) |
| 865 |
|
| 866 |
# ----- |
| 867 |
row += 1 |
| 868 |
l = Label(frame, text='version:', |
| 869 |
foreground=fg, background=bg, justify=LEFT, |
| 870 |
font=font2) |
| 871 |
l.grid(row=row, column=0, sticky=E, padx=10, pady=2) |
| 872 |
|
| 873 |
l = Label(frame, text=__version__, |
| 874 |
foreground=fg, background=bg, justify=LEFT, |
| 875 |
font=font2) |
| 876 |
l.grid(row=row, column=1, sticky=NW, padx=2, pady=2) |
| 877 |
|
| 878 |
# ----- |
| 879 |
row += 1 |
| 880 |
l = Label(frame, text='last change:', |
| 881 |
foreground=fg, background=bg, justify=LEFT, |
| 882 |
font=font2) |
| 883 |
l.grid(row=row, column=0, sticky=E, padx=10, pady=2) |
| 884 |
|
| 885 |
l = Label(frame, text=__date__, |
| 886 |
foreground=fg, background=bg, justify=LEFT, |
| 887 |
font=font2) |
| 888 |
l.grid(row=row, column=1, sticky=NW, padx=2, pady=2) |
| 889 |
|
| 890 |
closeFunc = lambda e=None,t=toplevel: t.destroy() |
| 891 |
b = Button(toplevel, text=_("Close"), command=closeFunc) |
| 892 |
b.pack(pady=5) |
| 893 |
frame.grid_columnconfigure(1, weight=1) |
| 894 |
|
| 895 |
toplevel.bind('<Escape>', closeFunc) |
| 896 |
toplevel.bind('<Return>', closeFunc) |
| 897 |
toplevel.bind('<KP_Enter>', closeFunc) |
| 898 |
|
| 899 |
#Center to the screen |
| 900 |
#toplevel.update_idletasks() |
| 901 |
#w = toplevel.winfo_screenwidth() |
| 902 |
#h = toplevel.winfo_screenheight() |
| 903 |
#size = tuple(int(_) for _ in toplevel.geometry().split('+')[0].split('x')) |
| 904 |
#x = w/2 - size[0]/2 |
| 905 |
#y = h/2 - size[1]/2 |
| 906 |
#toplevel.geometry("%dx%d+%d+%d" % (size + (x, y))) |
| 907 |
|
| 908 |
toplevel.deiconify() |
| 909 |
toplevel.wait_visibility() |
| 910 |
toplevel.resizable(False, False) |
| 911 |
|
| 912 |
try: toplevel.grab_set() |
| 913 |
except: pass |
| 914 |
b.focus_set() |
| 915 |
toplevel.lift() |
| 916 |
if timer: toplevel.after(timer, closeFunc) |
| 917 |
toplevel.wait_window() |
| 918 |
|
| 919 |
#----------------------------------------------------------------------- |
| 920 |
def alarmClear(self, event=None): |
| 921 |
self._alarm = False |
| 922 |
|
| 923 |
#----------------------------------------------------------------------- |
| 924 |
# Display information on selected blocks |
| 925 |
#----------------------------------------------------------------------- |
| 926 |
def showInfo(self, event=None): |
| 927 |
self.canvas.showInfo(self.editor.getSelectedBlocks()) |
| 928 |
return "break" |
| 929 |
|
| 930 |
#----------------------------------------------------------------------- |
| 931 |
# FIXME Very primitive |
| 932 |
#----------------------------------------------------------------------- |
| 933 |
def showStats(self, event=None): |
| 934 |
toplevel = Toplevel(self) |
| 935 |
toplevel.transient(self) |
| 936 |
toplevel.title(_("Statistics")) |
| 937 |
|
| 938 |
if CNC.inch: |
| 939 |
unit = "in" |
| 940 |
else: |
| 941 |
unit = "mm" |
| 942 |
|
| 943 |
# count enabled blocks |
| 944 |
e = 0 |
| 945 |
l = 0 |
| 946 |
r = 0 |
| 947 |
t = 0 |
| 948 |
for block in self.gcode.blocks: |
| 949 |
if block.enable: |
| 950 |
e += 1 |
| 951 |
l += block.length |
| 952 |
r += block.rapid |
| 953 |
t += block.time |
| 954 |
|
| 955 |
# =========== |
| 956 |
frame = LabelFrame(toplevel, text=_("Enabled GCode"), foreground="DarkRed") |
| 957 |
frame.pack(fill=BOTH) |
| 958 |
|
| 959 |
# --- |
| 960 |
row, col = 0,0 |
| 961 |
Label(frame, text=_("Margins X:")).grid(row=row, column=col, sticky=E) |
| 962 |
col += 1 |
| 963 |
Label(frame, text="%g .. %g [%g] %s" % \ |
| 964 |
(CNC.vars["xmin"], CNC.vars["xmax"], |
| 965 |
CNC.vars["xmax"] -CNC.vars["xmin"], |
| 966 |
unit), |
| 967 |
foreground="DarkBlue").grid(row=row, column=col, sticky=W) |
| 968 |
|
| 969 |
# --- |
| 970 |
row += 1 |
| 971 |
col = 0 |
| 972 |
Label(frame, text="... Y:").grid(row=row, column=col, sticky=E) |
| 973 |
col += 1 |
| 974 |
Label(frame, text="%g .. %g [%g] %s" % \ |
| 975 |
(CNC.vars["ymin"], CNC.vars["ymax"], |
| 976 |
CNC.vars["ymax"] -CNC.vars["ymin"], |
| 977 |
unit), |
| 978 |
foreground="DarkBlue").grid(row=row, column=col, sticky=W) |
| 979 |
|
| 980 |
# --- |
| 981 |
row += 1 |
| 982 |
col = 0 |
| 983 |
Label(frame, text="... Z:").grid(row=row, column=col, sticky=E) |
| 984 |
col += 1 |
| 985 |
Label(frame, text="%g .. %g [%g] %s" % \ |
| 986 |
(CNC.vars["zmin"], CNC.vars["zmax"], |
| 987 |
CNC.vars["zmax"] -CNC.vars["zmin"], |
| 988 |
unit), |
| 989 |
foreground="DarkBlue").grid(row=row, column=col, sticky=W) |
| 990 |
|
| 991 |
# --- |
| 992 |
row += 1 |
| 993 |
col = 0 |
| 994 |
Label(frame, text=_("# Blocks:")).grid(row=row, column=col, sticky=E) |
| 995 |
col += 1 |
| 996 |
Label(frame, text=str(e), |
| 997 |
foreground="DarkBlue").grid(row=row, column=col, sticky=W) |
| 998 |
|
| 999 |
# --- |
| 1000 |
row += 1 |
| 1001 |
col = 0 |
| 1002 |
Label(frame, text=_("Length:")).grid(row=row, column=col, sticky=E) |
| 1003 |
col += 1 |
| 1004 |
Label(frame, text="%g %s" % (l, unit), |
| 1005 |
foreground="DarkBlue").grid(row=row, column=col, sticky=W) |
| 1006 |
|
| 1007 |
# --- |
| 1008 |
row += 1 |
| 1009 |
col = 0 |
| 1010 |
Label(frame, text=_("Rapid:")).grid(row=row, column=col, sticky=E) |
| 1011 |
col += 1 |
| 1012 |
Label(frame, text="%g %s" % (r, unit), |
| 1013 |
foreground="DarkBlue").grid(row=row, column=col, sticky=W) |
| 1014 |
|
| 1015 |
# --- |
| 1016 |
row += 1 |
| 1017 |
col = 0 |
| 1018 |
Label(frame, text=_("Time:")).grid(row=row, column=col, sticky=E) |
| 1019 |
col += 1 |
| 1020 |
h,m = divmod(t, 60) # t in min |
| 1021 |
s = (m-int(m))*60 |
| 1022 |
Label(frame, text="%d:%02d:%02d s" % (int(h),int(m),int(s)), |
| 1023 |
foreground="DarkBlue").grid(row=row, column=col, sticky=W) |
| 1024 |
|
| 1025 |
frame.grid_columnconfigure(1, weight=1) |
| 1026 |
|
| 1027 |
|
| 1028 |
# =========== |
| 1029 |
frame = LabelFrame(toplevel, text=_("All GCode"), foreground="DarkRed") |
| 1030 |
frame.pack(fill=BOTH) |
| 1031 |
|
| 1032 |
# --- |
| 1033 |
row, col = 0,0 |
| 1034 |
Label(frame, text=_("Margins X:")).grid(row=row, column=col, sticky=E) |
| 1035 |
col += 1 |
| 1036 |
Label(frame, text="%g .. %g [%g] %s" % \ |
| 1037 |
(CNC.vars["axmin"], CNC.vars["axmax"], |
| 1038 |
CNC.vars["axmax"] -CNC.vars["axmin"], |
| 1039 |
unit), |
| 1040 |
foreground="DarkBlue").grid(row=row, column=col, sticky=W) |
| 1041 |
|
| 1042 |
# --- |
| 1043 |
row += 1 |
| 1044 |
col = 0 |
| 1045 |
Label(frame, text="... Y:").grid(row=row, column=col, sticky=E) |
| 1046 |
col += 1 |
| 1047 |
Label(frame, text="%g .. %g [%g] %s" % \ |
| 1048 |
(CNC.vars["aymin"], CNC.vars["aymax"], |
| 1049 |
CNC.vars["aymax"] -CNC.vars["aymin"], |
| 1050 |
unit), |
| 1051 |
foreground="DarkBlue").grid(row=row, column=col, sticky=W) |
| 1052 |
|
| 1053 |
# --- |
| 1054 |
row += 1 |
| 1055 |
col = 0 |
| 1056 |
Label(frame, text="... Z:").grid(row=row, column=col, sticky=E) |
| 1057 |
col += 1 |
| 1058 |
Label(frame, text="%g .. %g [%g] %s" % \ |
| 1059 |
(CNC.vars["azmin"], CNC.vars["azmax"], |
| 1060 |
CNC.vars["azmax"] -CNC.vars["azmin"], |
| 1061 |
unit), |
| 1062 |
foreground="DarkBlue").grid(row=row, column=col, sticky=W) |
| 1063 |
|
| 1064 |
# --- |
| 1065 |
row += 1 |
| 1066 |
col = 0 |
| 1067 |
Label(frame, text=_("# Blocks:")).grid(row=row, column=col, sticky=E) |
| 1068 |
col += 1 |
| 1069 |
Label(frame, text=str(len(self.gcode.blocks)), |
| 1070 |
foreground="DarkBlue").grid(row=row, column=col, sticky=W) |
| 1071 |
# --- |
| 1072 |
row += 1 |
| 1073 |
col = 0 |
| 1074 |
Label(frame, text=_("Length:")).grid(row=row, column=col, sticky=E) |
| 1075 |
col += 1 |
| 1076 |
Label(frame, text="%g %s" % (self.cnc.totalLength, unit), |
| 1077 |
foreground="DarkBlue").grid(row=row, column=col, sticky=W) |
| 1078 |
|
| 1079 |
# --- |
| 1080 |
row += 1 |
| 1081 |
col = 0 |
| 1082 |
Label(frame, text=_("Time:")).grid(row=row, column=col, sticky=E) |
| 1083 |
col += 1 |
| 1084 |
h,m = divmod(self.cnc.totalTime, 60) # t in min |
| 1085 |
s = (m-int(m))*60 |
| 1086 |
Label(frame, text="%d:%02d:%02d s" % (int(h),int(m),int(s)), |
| 1087 |
foreground="DarkBlue").grid(row=row, column=col, sticky=W) |
| 1088 |
|
| 1089 |
frame.grid_columnconfigure(1, weight=1) |
| 1090 |
|
| 1091 |
# =========== |
| 1092 |
frame = Frame(toplevel) |
| 1093 |
frame.pack(fill=X) |
| 1094 |
|
| 1095 |
closeFunc = lambda e=None,t=toplevel: t.destroy() |
| 1096 |
b = Button(frame, text=_("Close"), command=closeFunc) |
| 1097 |
b.pack(pady=5) |
| 1098 |
frame.grid_columnconfigure(1, weight=1) |
| 1099 |
|
| 1100 |
toplevel.bind("<Escape>", closeFunc) |
| 1101 |
toplevel.bind("<Return>", closeFunc) |
| 1102 |
toplevel.bind("<KP_Enter>", closeFunc) |
| 1103 |
|
| 1104 |
# ---- |
| 1105 |
toplevel.deiconify() |
| 1106 |
toplevel.wait_visibility() |
| 1107 |
toplevel.resizable(False, False) |
| 1108 |
|
| 1109 |
try: toplevel.grab_set() |
| 1110 |
except: pass |
| 1111 |
b.focus_set() |
| 1112 |
toplevel.lift() |
| 1113 |
toplevel.wait_window() |
| 1114 |
|
| 1115 |
#----------------------------------------------------------------------- |
| 1116 |
def reportDialog(self, event=None): |
| 1117 |
Utils.ReportDialog(self) |
| 1118 |
|
| 1119 |
#----------------------------------------------------------------------- |
| 1120 |
def viewChange(self, event=None): |
| 1121 |
if self.running: |
| 1122 |
self._selectI = 0 # last selection pointer in items |
| 1123 |
self.draw() |
| 1124 |
|
| 1125 |
# ---------------------------------------------------------------------- |
| 1126 |
def refresh(self, event=None): |
| 1127 |
self.editor.fill() |
| 1128 |
self.draw() |
| 1129 |
|
| 1130 |
# ---------------------------------------------------------------------- |
| 1131 |
def draw(self): |
| 1132 |
view = CNCCanvas.VIEWS.index(self.canvasFrame.view.get()) |
| 1133 |
self.canvas.draw(view) |
| 1134 |
self.selectionChange() |
| 1135 |
|
| 1136 |
# ---------------------------------------------------------------------- |
| 1137 |
# Redraw with a small delay |
| 1138 |
# ---------------------------------------------------------------------- |
| 1139 |
def drawAfter(self, event=None): |
| 1140 |
if self._drawAfter is not None: self.after_cancel(self._drawAfter) |
| 1141 |
self._drawAfter = self.after(DRAW_AFTER, self.draw) |
| 1142 |
return "break" |
| 1143 |
|
| 1144 |
#----------------------------------------------------------------------- |
| 1145 |
def canvasFocus(self, event=None): |
| 1146 |
self.canvas.focus_set() |
| 1147 |
return "break" |
| 1148 |
|
| 1149 |
#----------------------------------------------------------------------- |
| 1150 |
def selectAll(self, event=None): |
| 1151 |
focus = self.focus_get() |
| 1152 |
if focus in (self.canvas, self.editor): |
| 1153 |
self.editor.copy() |
| 1154 |
self.ribbon.changePage("Editor") |
| 1155 |
self.editor.selectAll() |
| 1156 |
self.selectionChange() |
| 1157 |
return "break" |
| 1158 |
|
| 1159 |
#----------------------------------------------------------------------- |
| 1160 |
def unselectAll(self, event=None): |
| 1161 |
focus = self.focus_get() |
| 1162 |
if focus in (self.canvas, self.editor): |
| 1163 |
self.ribbon.changePage("Editor") |
| 1164 |
self.editor.selectClear() |
| 1165 |
self.selectionChange() |
| 1166 |
return "break" |
| 1167 |
|
| 1168 |
#----------------------------------------------------------------------- |
| 1169 |
def selectInvert(self, event=None): |
| 1170 |
focus = self.focus_get() |
| 1171 |
if focus in (self.canvas, self.editor): |
| 1172 |
self.ribbon.changePage("Editor") |
| 1173 |
self.editor.selectInvert() |
| 1174 |
self.selectionChange() |
| 1175 |
return "break" |
| 1176 |
|
| 1177 |
#----------------------------------------------------------------------- |
| 1178 |
def selectLayer(self, event=None): |
| 1179 |
focus = self.focus_get() |
| 1180 |
if focus in (self.canvas, self.editor): |
| 1181 |
self.ribbon.changePage("Editor") |
| 1182 |
self.editor.selectLayer() |
| 1183 |
self.selectionChange() |
| 1184 |
return "break" |
| 1185 |
|
| 1186 |
#----------------------------------------------------------------------- |
| 1187 |
def find(self, event=None): |
| 1188 |
self.ribbon.changePage("Editor") |
| 1189 |
#### self.editor.findDialog() |
| 1190 |
# return "break" |
| 1191 |
# |
| 1192 |
# |
| 1193 |
|
| 1194 |
#----------------------------------------------------------------------- |
| 1195 |
def findNext(self, event=None): |
| 1196 |
self.ribbon.changePage("Editor") |
| 1197 |
#### self.editor.findNext() |
| 1198 |
# return "break" |
| 1199 |
# |
| 1200 |
# |
| 1201 |
|
| 1202 |
#----------------------------------------------------------------------- |
| 1203 |
def replace(self, event=None): |
| 1204 |
self.ribbon.changePage("Editor") |
| 1205 |
#### self.editor.replaceDialog() |
| 1206 |
# return "break" |
| 1207 |
|
| 1208 |
#----------------------------------------------------------------------- |
| 1209 |
def activeBlock(self): |
| 1210 |
return self.editor.activeBlock() |
| 1211 |
|
| 1212 |
#----------------------------------------------------------------------- |
| 1213 |
# Keyboard binding to <Return> |
| 1214 |
#----------------------------------------------------------------------- |
| 1215 |
def cmdExecute(self, event): |
| 1216 |
self.commandExecute() |
| 1217 |
|
| 1218 |
# ---------------------------------------------------------------------- |
| 1219 |
def insertCommand(self, cmd, execute=False): |
| 1220 |
self.command.delete(0,END) |
| 1221 |
self.command.insert(0,cmd) |
| 1222 |
if execute: self.commandExecute(False) |
| 1223 |
|
| 1224 |
#----------------------------------------------------------------------- |
| 1225 |
# Execute command from command line |
| 1226 |
#----------------------------------------------------------------------- |
| 1227 |
def commandExecute(self, addHistory=True): |
| 1228 |
self._historyPos = None |
| 1229 |
self._historySearch = None |
| 1230 |
|
| 1231 |
line = self.command.get().strip() |
| 1232 |
if not line: return |
| 1233 |
|
| 1234 |
if self._historyPos is not None: |
| 1235 |
if self.history[self._historyPos] != line: |
| 1236 |
self.history.append(line) |
| 1237 |
elif not self.history or self.history[-1] != line: |
| 1238 |
self.history.append(line) |
| 1239 |
|
| 1240 |
if len(self.history)>MAX_HISTORY: |
| 1241 |
self.history.pop(0) |
| 1242 |
self.command.delete(0,END) |
| 1243 |
self.execute(line) |
| 1244 |
|
| 1245 |
#----------------------------------------------------------------------- |
| 1246 |
# Execute a single command |
| 1247 |
#----------------------------------------------------------------------- |
| 1248 |
def execute(self, line): |
| 1249 |
#print |
| 1250 |
#print "<<<",line |
| 1251 |
try: |
| 1252 |
line = self.evaluate(line) |
| 1253 |
except: |
| 1254 |
tkMessageBox.showerror(_("Evaluation error"), |
| 1255 |
sys.exc_info()[1], parent=self) |
| 1256 |
return "break" |
| 1257 |
#print ">>>",line |
| 1258 |
|
| 1259 |
if line is None: return "break" |
| 1260 |
|
| 1261 |
if self.executeGcode(line): return "break" |
| 1262 |
|
| 1263 |
oline = line.strip() |
| 1264 |
line = oline.replace(","," ").split() |
| 1265 |
cmd = line[0].upper() |
| 1266 |
|
| 1267 |
# ABO*UT: About dialog |
| 1268 |
if rexx.abbrev("ABOUT",cmd,3): |
| 1269 |
self.about() |
| 1270 |
|
| 1271 |
elif rexx.abbrev("AUTOLEVEL",cmd,4): |
| 1272 |
self.executeOnSelection("AUTOLEVEL", True) |
| 1273 |
|
| 1274 |
# CAM*ERA: camera actions |
| 1275 |
elif rexx.abbrev("CAMERA",cmd,3): |
| 1276 |
# FIXME will make crazy the button state |
| 1277 |
if rexx.abbrev("SWITCH",line[1].upper(),1): |
| 1278 |
Page.groups["Probe:Camera"].switchCamera() |
| 1279 |
|
| 1280 |
elif rexx.abbrev("SPINDLE",line[1].upper(),2): |
| 1281 |
Page.frames["Probe:Camera"].registerSpindle() |
| 1282 |
|
| 1283 |
elif rexx.abbrev("CAMERA",line[1].upper(),1): |
| 1284 |
Page.frames["Probe:Camera"].registerCamera() |
| 1285 |
|
| 1286 |
# CLE*AR: clear terminal |
| 1287 |
elif rexx.abbrev("CLEAR",cmd,3) or cmd=="CLS": |
| 1288 |
self.ribbon.changePage("Terminal") |
| 1289 |
Page.frames["Terminal"].clear() |
| 1290 |
|
| 1291 |
# CLOSE: close path - join end with start with a line segment |
| 1292 |
elif rexx.abbrev("CLOSE",cmd,4): |
| 1293 |
self.executeOnSelection("CLOSE", True) |
| 1294 |
|
| 1295 |
# CONT*ROL: switch to control tab |
| 1296 |
elif rexx.abbrev("CONTROL",cmd,4): |
| 1297 |
self.ribbon.changePage("Control") |
| 1298 |
|
| 1299 |
# CUT [depth] [pass-per-depth] [z-surface] [feed] [feedz]: replicate selected blocks to cut-height |
| 1300 |
# default values are taken from the active material |
| 1301 |
elif cmd == "CUT": |
| 1302 |
try: depth = float(line[1]) |
| 1303 |
except: depth = None |
| 1304 |
|
| 1305 |
try: step = float(line[2]) |
| 1306 |
except: step = None |
| 1307 |
|
| 1308 |
try: surface = float(line[3]) |
| 1309 |
except: surface = None |
| 1310 |
|
| 1311 |
try: feed = float(line[4]) |
| 1312 |
except: feed = None |
| 1313 |
|
| 1314 |
try: feedz = float(line[5]) |
| 1315 |
except: feedz = None |
| 1316 |
self.executeOnSelection("CUT", True, depth, step, surface, feed, feedz) |
| 1317 |
|
| 1318 |
# DOWN: move downward in cutting order the selected blocks |
| 1319 |
# UP: move upwards in cutting order the selected blocks |
| 1320 |
elif cmd=="DOWN": |
| 1321 |
self.editor.orderDown() |
| 1322 |
elif cmd=="UP": |
| 1323 |
self.editor.orderUp() |
| 1324 |
|
| 1325 |
# DIR*ECTION |
| 1326 |
elif rexx.abbrev("DIRECTION", cmd, 3): |
| 1327 |
if rexx.abbrev("CLIMB", line[1].upper(), 2): |
| 1328 |
direction = -2 |
| 1329 |
elif rexx.abbrev("CONVENTIONAL", line[1].upper(), 2): |
| 1330 |
direction = 2 |
| 1331 |
elif rexx.abbrev("CW", line[1].upper(), 2): |
| 1332 |
direction = 1 |
| 1333 |
elif rexx.abbrev("CCW", line[1].upper(), 2): |
| 1334 |
direction = -1 |
| 1335 |
else: |
| 1336 |
tkMessageBox.showerror(_("Direction command error"), |
| 1337 |
_("Invalid direction %s specified"%(line[1])), |
| 1338 |
parent=self) |
| 1339 |
return "break" |
| 1340 |
self.executeOnSelection("DIRECTION", True, direction) |
| 1341 |
|
| 1342 |
# DRI*LL [depth] [peck]: perform drilling at all penetrations points |
| 1343 |
elif rexx.abbrev("DRILL",cmd,3): |
| 1344 |
try: h = float(line[1]) |
| 1345 |
except: h = None |
| 1346 |
|
| 1347 |
try: p = float(line[2]) |
| 1348 |
except: p = None |
| 1349 |
self.executeOnSelection("DRILL", True, h, p) |
| 1350 |
|
| 1351 |
# ECHO <msg>: echo message |
| 1352 |
elif cmd=="ECHO": |
| 1353 |
self.setStatus(oline[5:].strip()) |
| 1354 |
|
| 1355 |
# FEED on/off: append feed commands on every motion line for feed override testing |
| 1356 |
elif cmd=="FEED": |
| 1357 |
try: |
| 1358 |
CNC.appendFeed = (line[1].upper()=="ON") |
| 1359 |
except: |
| 1360 |
CNC.appendFeed = True |
| 1361 |
self.setStatus(CNC.appendFeed and \ |
| 1362 |
"Feed appending turned on" or \ |
| 1363 |
"Feed appending turned off") |
| 1364 |
|
| 1365 |
# INV*ERT: invert selected blocks |
| 1366 |
elif rexx.abbrev("INVERT",cmd,3): |
| 1367 |
self.editor.invertBlocks() |
| 1368 |
|
| 1369 |
# MSG|MESSAGE <msg>: echo message |
| 1370 |
elif cmd in ("MSG","MESSAGE"): |
| 1371 |
tkMessageBox.showinfo("Message",oline[oline.find(" ")+1:].strip(), parent=self) |
| 1372 |
|
| 1373 |
# FIL*TER: filter editor blocks with text |
| 1374 |
elif rexx.abbrev("FILTER",cmd,3) or cmd=="ALL": |
| 1375 |
try: |
| 1376 |
self.editor.filter = line[1] |
| 1377 |
except: |
| 1378 |
self.editor.filter = None |
| 1379 |
self.editor.fill() |
| 1380 |
|
| 1381 |
# ED*IT: edit current line or item |
| 1382 |
elif rexx.abbrev("EDIT",cmd,2): |
| 1383 |
self.edit() |
| 1384 |
|
| 1385 |
# IM*PORT <filename>: import filename with gcode or dxf at cursor location |
| 1386 |
# or at the end of the file |
| 1387 |
elif rexx.abbrev("IMPORT",cmd,2): |
| 1388 |
try: self.importFile(line[1]) |
| 1389 |
except: self.importFile() |
| 1390 |
|
| 1391 |
# INK*SCAPE: remove uneccessary Z motion as a result of inkscape gcodetools |
| 1392 |
elif rexx.abbrev("INKSCAPE",cmd,3): |
| 1393 |
if len(line)>1 and rexx.abbrev("ALL",line[1].upper()): |
| 1394 |
self.editor.selectAll() |
| 1395 |
self.executeOnSelection("INKSCAPE", True) |
| 1396 |
|
| 1397 |
# ISLAND set or toggle island tag |
| 1398 |
elif rexx.abbrev("ISLAND", cmd, 3): |
| 1399 |
if len(line) > 1: |
| 1400 |
if line[1].upper() == "1": |
| 1401 |
isl = True |
| 1402 |
else: |
| 1403 |
isl = False |
| 1404 |
else: |
| 1405 |
isl = None |
| 1406 |
self.executeOnSelection("ISLAND", True, isl) |
| 1407 |
|
| 1408 |
# ISO1: switch to ISO1 projection |
| 1409 |
elif cmd=="ISO1": |
| 1410 |
self.canvasFrame.viewISO1() |
| 1411 |
# ISO2: switch to ISO2 projection |
| 1412 |
elif cmd=="ISO2": |
| 1413 |
self.canvasFrame.viewISO2() |
| 1414 |
# ISO3: switch to ISO3 projection |
| 1415 |
elif cmd=="ISO3": |
| 1416 |
self.canvasFrame.viewISO3() |
| 1417 |
|
| 1418 |
# LO*AD [filename]: load filename containing g-code |
| 1419 |
elif rexx.abbrev("LOAD",cmd,2) and len(line)==1: |
| 1420 |
self.loadDialog() |
| 1421 |
|
| 1422 |
# MAT*ERIAL [name/height] [pass-per-depth] [feed]: set material from database or parameters |
| 1423 |
# elif rexx.abbrev("MATERIAL",cmd,3): |
| 1424 |
# tool = self.tools["Material"] |
| 1425 |
# # MAT*ERIAL [height] [pass-depth] [feed] |
| 1426 |
# try: self.height = float(line[1]) |
| 1427 |
# except: pass |
| 1428 |
# try: self.depth_pass = float(line[2]) |
| 1429 |
# except: pass |
| 1430 |
# try: self.feed = float(line[3]) |
| 1431 |
# except: pass |
| 1432 |
# self.setStatus(_("Height: %g Depth-per-pass: %g Feed: %g")%(self.height,self.depth_pass, self.feed)) |
| 1433 |
|
| 1434 |
# MIR*ROR [H*ORIZONTAL/V*ERTICAL]: mirror selected objects horizontally or vertically |
| 1435 |
elif rexx.abbrev("MIRROR",cmd,3): |
| 1436 |
if len(line)==1: return "break" |
| 1437 |
line1 = line[1].upper() |
| 1438 |
#if nothing is selected: |
| 1439 |
if not self.editor.curselection(): |
| 1440 |
self.editor.selectAll() |
| 1441 |
if rexx.abbrev("HORIZONTAL",line1): |
| 1442 |
self.executeOnSelection("MIRRORH", False) |
| 1443 |
elif rexx.abbrev("VERTICAL",line1): |
| 1444 |
self.executeOnSelection("MIRRORV", False) |
| 1445 |
|
| 1446 |
elif rexx.abbrev("ORDER",cmd,2): |
| 1447 |
if line[1].upper() == "UP": |
| 1448 |
self.editor.orderUp() |
| 1449 |
elif line[1].upper() == "DOWN": |
| 1450 |
self.editor.orderDown() |
| 1451 |
|
| 1452 |
# MO*VE [|CE*NTER|BL|BR|TL|TR|UP|DOWN|x] [[y [z]]]: |
| 1453 |
# move selected objects either by mouse or by coordinates |
| 1454 |
elif rexx.abbrev("MOVE",cmd,2): |
| 1455 |
if len(line)==1: |
| 1456 |
self.canvas.setActionMove() |
| 1457 |
return "break" |
| 1458 |
line1 = line[1].upper() |
| 1459 |
dz = 0.0 |
| 1460 |
if rexx.abbrev("CENTER",line1,2): |
| 1461 |
dx = -(CNC.vars["xmin"] + CNC.vars["xmax"])/2.0 |
| 1462 |
dy = -(CNC.vars["ymin"] + CNC.vars["ymax"])/2.0 |
| 1463 |
self.editor.selectAll() |
| 1464 |
elif line1=="BL": |
| 1465 |
dx = -CNC.vars["xmin"] |
| 1466 |
dy = -CNC.vars["ymin"] |
| 1467 |
self.editor.selectAll() |
| 1468 |
elif line1=="BC": |
| 1469 |
dx = -(CNC.vars["xmin"] + CNC.vars["xmax"])/2.0 |
| 1470 |
dy = -CNC.vars["ymin"] |
| 1471 |
self.editor.selectAll() |
| 1472 |
elif line1=="BR": |
| 1473 |
dx = -CNC.vars["xmax"] |
| 1474 |
dy = -CNC.vars["ymin"] |
| 1475 |
self.editor.selectAll() |
| 1476 |
elif line1=="TL": |
| 1477 |
dx = -CNC.vars["xmin"] |
| 1478 |
dy = -CNC.vars["ymax"] |
| 1479 |
self.editor.selectAll() |
| 1480 |
elif line1=="TC": |
| 1481 |
dx = -(CNC.vars["xmin"] + CNC.vars["xmax"])/2.0 |
| 1482 |
dy = -CNC.vars["ymax"] |
| 1483 |
self.editor.selectAll() |
| 1484 |
elif line1=="TR": |
| 1485 |
dx = -CNC.vars["xmax"] |
| 1486 |
dy = -CNC.vars["ymax"] |
| 1487 |
self.editor.selectAll() |
| 1488 |
elif line1=="LC": |
| 1489 |
dx = -CNC.vars["xmin"] |
| 1490 |
dy = -(CNC.vars["ymin"] + CNC.vars["ymax"])/2.0 |
| 1491 |
self.editor.selectAll() |
| 1492 |
elif line1=="RC": |
| 1493 |
dx = -CNC.vars["xmax"] |
| 1494 |
dy = -(CNC.vars["ymin"] + CNC.vars["ymax"])/2.0 |
| 1495 |
self.editor.selectAll() |
| 1496 |
elif line1 in ("UP","DOWN"): |
| 1497 |
dx = line1 |
| 1498 |
dy = dz = line1 |
| 1499 |
else: |
| 1500 |
try: dx = float(line[1]) |
| 1501 |
except: dx = 0.0 |
| 1502 |
try: dy = float(line[2]) |
| 1503 |
except: dy = 0.0 |
| 1504 |
try: dz = float(line[3]) |
| 1505 |
except: dz = 0.0 |
| 1506 |
self.executeOnSelection("MOVE", False, dx,dy,dz) |
| 1507 |
|
| 1508 |
# OPT*IMIZE: reorder selected blocks to minimize rapid motions |
| 1509 |
elif rexx.abbrev("OPTIMIZE",cmd,3): |
| 1510 |
if not self.editor.curselection(): |
| 1511 |
tkMessageBox.showinfo(_("Optimize"), |
| 1512 |
_("Please select the blocks of gcode you want to optimize."), |
| 1513 |
parent=self) |
| 1514 |
else: |
| 1515 |
self.executeOnSelection("OPTIMIZE", True) |
| 1516 |
|
| 1517 |
# OPT*IMIZE: reorder selected blocks to minimize rapid motions # FIXME comment for ORIENT not OPTIMIZE |
| 1518 |
elif rexx.abbrev("ORIENT",cmd,4): |
| 1519 |
if not self.editor.curselection(): |
| 1520 |
self.editor.selectAll() |
| 1521 |
self.executeOnSelection("ORIENT", False) |
| 1522 |
|
| 1523 |
# ORI*GIN x y z: move origin to x,y,z by moving all to -x -y -z |
| 1524 |
elif rexx.abbrev("ORIGIN",cmd,3): |
| 1525 |
try: dx = -float(line[1]) |
| 1526 |
except: dx = 0.0 |
| 1527 |
try: dy = -float(line[2]) |
| 1528 |
except: dy = 0.0 |
| 1529 |
try: dz = -float(line[3]) |
| 1530 |
except: dz = 0.0 |
| 1531 |
self.editor.selectAll() |
| 1532 |
self.executeOnSelection("MOVE", False, dx,dy,dz) |
| 1533 |
|
| 1534 |
# POC*KET: create pocket path |
| 1535 |
elif rexx.abbrev("POCKET",cmd,3): |
| 1536 |
self.pocket() |
| 1537 |
|
| 1538 |
# PROF*ILE [offset]: create profile path |
| 1539 |
elif rexx.abbrev("PROFILE",cmd,3): |
| 1540 |
if len(line)>1: |
| 1541 |
self.profile(line[1]) |
| 1542 |
else: |
| 1543 |
self.profile() |
| 1544 |
|
| 1545 |
# REV*ERSE: reverse path direction |
| 1546 |
elif rexx.abbrev("REVERSE", cmd, 3): |
| 1547 |
self.executeOnSelection("REVERSE", True) |
| 1548 |
|
| 1549 |
# ROT*ATE [CCW|CW|FLIP|ang] [x0 [y0]]: rotate selected blocks |
| 1550 |
# counter-clockwise(90) / clockwise(-90) / flip(180) |
| 1551 |
# 90deg or by a specific angle and a pivot point |
| 1552 |
elif rexx.abbrev("ROTATE",cmd,3): |
| 1553 |
line1 = line[1].upper() |
| 1554 |
x0 = y0 = 0.0 |
| 1555 |
if line1 == "CCW": |
| 1556 |
ang = 90.0 |
| 1557 |
#self.editor.selectAll() |
| 1558 |
elif line1 == "CW": |
| 1559 |
ang = -90.0 |
| 1560 |
#self.editor.selectAll() |
| 1561 |
elif line1=="FLIP": |
| 1562 |
ang = 180.0 |
| 1563 |
#self.editor.selectAll() |
| 1564 |
else: |
| 1565 |
try: ang = float(line[1]) |
| 1566 |
except: pass |
| 1567 |
try: x0 = float(line[2]) |
| 1568 |
except: pass |
| 1569 |
try: y0 = float(line[3]) |
| 1570 |
except: pass |
| 1571 |
self.executeOnSelection("ROTATE", False, ang,x0,y0) |
| 1572 |
|
| 1573 |
# ROU*ND [n]: round all digits to n fractional digits |
| 1574 |
elif rexx.abbrev("ROUND",cmd,3): |
| 1575 |
acc = None |
| 1576 |
if len(line)>1: |
| 1577 |
if rexx.abbrev("ALL",line[1].upper()): |
| 1578 |
self.editor.selectAll() |
| 1579 |
else: |
| 1580 |
try: |
| 1581 |
acc = int(line[1]) |
| 1582 |
except: |
| 1583 |
pass |
| 1584 |
self.executeOnSelection("ROUND", False, acc) |
| 1585 |
|
| 1586 |
# RU*LER: measure distances with mouse ruler |
| 1587 |
elif rexx.abbrev("RULER",cmd,2): |
| 1588 |
self.canvas.setActionRuler() |
| 1589 |
|
| 1590 |
# STAT*ISTICS: show statistics of current job |
| 1591 |
elif rexx.abbrev("STATISTICS",cmd,4): |
| 1592 |
self.showStats() |
| 1593 |
|
| 1594 |
# STEP [s]: set motion step size to s |
| 1595 |
elif cmd == "STEP": |
| 1596 |
try: |
| 1597 |
self.control.setStep(float(line[1])) |
| 1598 |
except: |
| 1599 |
pass |
| 1600 |
|
| 1601 |
# SPI*NDLE [ON|OFF|speed]: turn on/off spindle |
| 1602 |
elif rexx.abbrev("SPINDLE",cmd,3): |
| 1603 |
if len(line)>1: |
| 1604 |
if line[1].upper()=="OFF": |
| 1605 |
self.gstate.spindle.set(False) |
| 1606 |
elif line[1].upper()=="ON": |
| 1607 |
self.gstate.spindle.set(True) |
| 1608 |
else: |
| 1609 |
try: |
| 1610 |
rpm = int(line[1]) |
| 1611 |
if rpm==0: |
| 1612 |
self.gstate.spindleSpeed.set(0) |
| 1613 |
self.gstate.spindle.set(False) |
| 1614 |
else: |
| 1615 |
self.gstate.spindleSpeed.set(rpm) |
| 1616 |
self.gstate.spindle.set(True) |
| 1617 |
except: |
| 1618 |
pass |
| 1619 |
else: |
| 1620 |
# toggle spindle |
| 1621 |
self.gstate.spindle.set(not self.gstate.spindle.get()) |
| 1622 |
self.gstate.spindleControl() |
| 1623 |
|
| 1624 |
# STOP: stop current run |
| 1625 |
elif cmd == "STOP": |
| 1626 |
self.stopRun() |
| 1627 |
|
| 1628 |
# TAB*S [ntabs] [dtabs] [dx] [dy] [z]: create tabs on selected blocks |
| 1629 |
# default values are taken from the active tab |
| 1630 |
elif rexx.abbrev("TABS",cmd,3): |
| 1631 |
tabs = self.tools["TABS"] |
| 1632 |
try: ntabs = int(line[1]) |
| 1633 |
except: ntabs = int(tabs["ntabs"]) |
| 1634 |
try: dtabs = float(line[2]) |
| 1635 |
except: dtabs = tabs.fromMm("dtabs") |
| 1636 |
try: dx = float(line[3]) |
| 1637 |
except: dx = tabs.fromMm("dx") |
| 1638 |
try: dy = float(line[4]) |
| 1639 |
except: dy = tabs.fromMm("dy") |
| 1640 |
try: z = float(line[5]) |
| 1641 |
except: z = tabs.fromMm("z") |
| 1642 |
try: circular = bool(line[6]) |
| 1643 |
except: circular = True |
| 1644 |
self.executeOnSelection("TABS", True, ntabs, dtabs, dx, dy, z, circular) |
| 1645 |
|
| 1646 |
# TERM*INAL: switch to terminal tab |
| 1647 |
elif rexx.abbrev("TERMINAL",cmd,4): |
| 1648 |
self.ribbon.changePage("Terminal") |
| 1649 |
|
| 1650 |
# TOOL [diameter]: set diameter of cutting tool |
| 1651 |
elif cmd in ("BIT","TOOL","MILL"): |
| 1652 |
try: |
| 1653 |
diam = float(line[1]) |
| 1654 |
except: |
| 1655 |
tool = self.tools["EndMill"] |
| 1656 |
diam = self.tools.fromMm(tool["diameter"]) |
| 1657 |
self.setStatus(_("EndMill: %s %g")%(tool["name"], diam)) |
| 1658 |
|
| 1659 |
# TOOLS |
| 1660 |
elif cmd=="TOOLS": |
| 1661 |
self.ribbon.changePage("CAM") |
| 1662 |
|
| 1663 |
# UNL*OCK: unlock grbl |
| 1664 |
elif rexx.abbrev("UNLOCK",cmd,3): |
| 1665 |
self.unlock() |
| 1666 |
|
| 1667 |
# US*ER cmd: execute user command, cmd=number or name |
| 1668 |
elif rexx.abbrev("USER",cmd,2): |
| 1669 |
n = Utils.getInt("Buttons","n",6) |
| 1670 |
try: |
| 1671 |
idx = int(line[1]) |
| 1672 |
except: |
| 1673 |
try: |
| 1674 |
name = line[1].upper() |
| 1675 |
for i in range(n): |
| 1676 |
if name == Utils.getStr("Buttons","name.%d"%(i),"").upper(): |
| 1677 |
idx = i |
| 1678 |
break |
| 1679 |
except: |
| 1680 |
return "break" |
| 1681 |
if idx<0 or idx>=n: |
| 1682 |
self.setStatus(_("Invalid user command %s")%(line[1])) |
| 1683 |
return "break" |
| 1684 |
cmd = Utils.getStr("Buttons","command.%d"%(idx),"") |
| 1685 |
for line in cmd.splitlines(): |
| 1686 |
self.execute(line) |
| 1687 |
|
| 1688 |
# RR*APID: |
| 1689 |
elif rexx.abbrev("RRAPID",cmd,2): |
| 1690 |
Page.frames["Probe:Probe"].recordRapid() |
| 1691 |
|
| 1692 |
# RF*EED: |
| 1693 |
elif rexx.abbrev("RFEED",cmd,2): |
| 1694 |
Page.frames["Probe:Probe"].recordFeed() |
| 1695 |
|
| 1696 |
# RP*OINT: |
| 1697 |
elif rexx.abbrev("RPOINT",cmd,2): |
| 1698 |
Page.frames["Probe:Probe"].recordPoint() |
| 1699 |
|
| 1700 |
# RC*IRCLE: |
| 1701 |
elif rexx.abbrev("RCIRCLE",cmd,2): |
| 1702 |
Page.frames["Probe:Probe"].recordCircle() |
| 1703 |
|
| 1704 |
# RFI*NISH: |
| 1705 |
elif rexx.abbrev("RFINISH",cmd,3): |
| 1706 |
Page.frames["Probe:Probe"].recordFinishAll() |
| 1707 |
|
| 1708 |
# XY: switch to XY view |
| 1709 |
# YX: switch to XY view |
| 1710 |
elif cmd in ("XY","YX"): |
| 1711 |
self.canvasFrame.viewXY() |
| 1712 |
|
| 1713 |
# XZ: switch to XZ view |
| 1714 |
# ZX: switch to XZ view |
| 1715 |
elif cmd in ("XZ","ZX"): |
| 1716 |
self.canvasFrame.viewXZ() |
| 1717 |
|
| 1718 |
# YZ: switch to YZ view |
| 1719 |
# ZY: switch to YZ view |
| 1720 |
elif cmd in ("YZ","ZY"): |
| 1721 |
self.canvasFrame.viewYZ() |
| 1722 |
|
| 1723 |
else: |
| 1724 |
rc = self.executeCommand(oline) |
| 1725 |
if rc: |
| 1726 |
tkMessageBox.showerror(rc[0],rc[1], parent=self) |
| 1727 |
return "break" |
| 1728 |
|
| 1729 |
#----------------------------------------------------------------------- |
| 1730 |
# Execute a command over the selected lines |
| 1731 |
#----------------------------------------------------------------------- |
| 1732 |
def executeOnSelection(self, cmd, blocksonly, *args): |
| 1733 |
if blocksonly: |
| 1734 |
items = self.editor.getSelectedBlocks() |
| 1735 |
else: |
| 1736 |
items = self.editor.getCleanSelection() |
| 1737 |
if not items: |
| 1738 |
tkMessageBox.showwarning(_("Nothing to do"), |
| 1739 |
_("Operation %s requires some gcode to be selected")%(cmd), |
| 1740 |
parent=self) |
| 1741 |
return |
| 1742 |
|
| 1743 |
self.busy() |
| 1744 |
sel = None |
| 1745 |
undoinfo = None # all operations should return undo information |
| 1746 |
if cmd == "AUTOLEVEL": |
| 1747 |
sel = self.gcode.autolevel(items) |
| 1748 |
elif cmd == "CUT": |
| 1749 |
sel = self.gcode.cut(items, *args) |
| 1750 |
elif cmd == "CLOSE": |
| 1751 |
sel = self.gcode.close(items) |
| 1752 |
elif cmd == "DIRECTION": |
| 1753 |
sel = self.gcode.cutDirection(items, *args) |
| 1754 |
elif cmd == "DRILL": |
| 1755 |
sel = self.gcode.drill(items, *args) |
| 1756 |
elif cmd == "ORDER": |
| 1757 |
self.gcode.orderLines(items, *args) |
| 1758 |
elif cmd == "INKSCAPE": |
| 1759 |
self.gcode.inkscapeLines() |
| 1760 |
elif cmd == "ISLAND": |
| 1761 |
self.gcode.island(items, *args) |
| 1762 |
elif cmd == "MIRRORH": |
| 1763 |
self.gcode.mirrorHLines(items) |
| 1764 |
elif cmd == "MIRRORV": |
| 1765 |
self.gcode.mirrorVLines(items) |
| 1766 |
elif cmd == "MOVE": |
| 1767 |
self.gcode.moveLines(items, *args) |
| 1768 |
elif cmd == "OPTIMIZE": |
| 1769 |
self.gcode.optimize(items) |
| 1770 |
elif cmd == "ORIENT": |
| 1771 |
self.gcode.orientLines(items) |
| 1772 |
elif cmd == "REVERSE": |
| 1773 |
self.gcode.reverse(items, *args) |
| 1774 |
elif cmd == "ROUND": |
| 1775 |
self.gcode.roundLines(items, *args) |
| 1776 |
elif cmd == "ROTATE": |
| 1777 |
self.gcode.rotateLines(items, *args) |
| 1778 |
elif cmd == "TABS": |
| 1779 |
sel = self.gcode.createTabs(items, *args) |
| 1780 |
|
| 1781 |
# Fill listbox and update selection |
| 1782 |
self.editor.fill() |
| 1783 |
if sel is not None: |
| 1784 |
if isinstance(sel, str): |
| 1785 |
tkMessageBox.showerror(_("Operation error"), sel, parent=self) |
| 1786 |
else: |
| 1787 |
self.editor.select(sel,clear=True) |
| 1788 |
self.drawAfter() |
| 1789 |
self.notBusy() |
| 1790 |
self.setStatus("%s %s"%(cmd," ".join([str(a) for a in args if a is not None]))) |
| 1791 |
|
| 1792 |
#----------------------------------------------------------------------- |
| 1793 |
def profile(self, direction=None, offset=0.0, overcut=False, name=None, pocket=False): |
| 1794 |
tool = self.tools["EndMill"] |
| 1795 |
ofs = self.tools.fromMm(tool["diameter"])/2.0 |
| 1796 |
sign = 1.0 |
| 1797 |
|
| 1798 |
if direction is None: |
| 1799 |
pass |
| 1800 |
elif rexx.abbrev("INSIDE",direction.upper()): |
| 1801 |
sign = -1.0 |
| 1802 |
elif rexx.abbrev("OUTSIDE",direction.upper()): |
| 1803 |
sign = 1.0 |
| 1804 |
else: |
| 1805 |
try: |
| 1806 |
ofs = float(direction)/2.0 |
| 1807 |
except: |
| 1808 |
pass |
| 1809 |
|
| 1810 |
# additional offset |
| 1811 |
try: ofs += float(offset) |
| 1812 |
except: pass |
| 1813 |
|
| 1814 |
self.busy() |
| 1815 |
blocks = self.editor.getSelectedBlocks() |
| 1816 |
# on return we have the blocks with the new blocks to select |
| 1817 |
msg = self.gcode.profile(blocks, ofs*sign, overcut, name, pocket) |
| 1818 |
if msg: |
| 1819 |
tkMessageBox.showwarning("Open paths", |
| 1820 |
"WARNING: %s"%(msg), |
| 1821 |
parent=self) |
| 1822 |
self.editor.fill() |
| 1823 |
self.editor.selectBlocks(blocks) |
| 1824 |
self.draw() |
| 1825 |
self.notBusy() |
| 1826 |
self.setStatus(_("Profile block distance=%g")%(ofs*sign)) |
| 1827 |
|
| 1828 |
#----------------------------------------------------------------------- |
| 1829 |
def pocket(self, name=None): |
| 1830 |
tool = self.tools["EndMill"] |
| 1831 |
diameter = self.tools.fromMm(tool["diameter"]) |
| 1832 |
try: |
| 1833 |
stepover = tool["stepover"] / 100.0 |
| 1834 |
except TypeError: |
| 1835 |
stepover = 0. |
| 1836 |
|
| 1837 |
self.busy() |
| 1838 |
blocks = self.editor.getSelectedBlocks() |
| 1839 |
# on return we have the blocks with the new blocks to select |
| 1840 |
msg = self.gcode.pocket(blocks, diameter, stepover, name) |
| 1841 |
if msg: |
| 1842 |
tkMessageBox.showwarning(_("Open paths"), |
| 1843 |
_("WARNING: %s")%(msg), |
| 1844 |
parent=self) |
| 1845 |
self.editor.fill() |
| 1846 |
self.editor.selectBlocks(blocks) |
| 1847 |
self.draw() |
| 1848 |
self.notBusy() |
| 1849 |
# self.setStatus(_("Pocket block distance=%g")%(ofs*sign)) |
| 1850 |
|
| 1851 |
#----------------------------------------------------------------------- |
| 1852 |
def trochprofile_bcnc(self, cutDiam=0.0, direction=None, offset=0.0, overcut=False,adaptative=False, adaptedRadius=0.0, tooldiameter=0.0,\ |
| 1853 |
targetDepth=0.0,depthIncrement=0.0, tabsnumber=0.0, tabsWidth=0.0, tabsHeight=0.0): |
| 1854 |
# tool = self.tools["EndMill"] |
| 1855 |
# ofs = self.tools.fromMm(tool["diameter"])/2.0 |
| 1856 |
adaptedRadius = float(adaptedRadius) |
| 1857 |
ofs = float(cutDiam)/2.0 |
| 1858 |
sign = 1.0 |
| 1859 |
|
| 1860 |
if direction is None: |
| 1861 |
pass |
| 1862 |
elif rexx.abbrev("INSIDE",direction.upper()): |
| 1863 |
sign = -1.0 |
| 1864 |
elif rexx.abbrev("OUTSIDE",direction.upper()): |
| 1865 |
sign = 1.0 |
| 1866 |
elif rexx.abbrev("ON",direction.upper()): |
| 1867 |
ofs = 0 |
| 1868 |
else: |
| 1869 |
try: |
| 1870 |
ofs = float(direction)/2.0 |
| 1871 |
except: |
| 1872 |
pass |
| 1873 |
|
| 1874 |
# additional offset |
| 1875 |
try: ofs += float(offset) |
| 1876 |
except: pass |
| 1877 |
|
| 1878 |
self.busy() |
| 1879 |
blocks = self.editor.getSelectedBlocks() |
| 1880 |
# on return we have the blocks with the new blocks to select |
| 1881 |
msg = self.gcode.trochprofile_cnc(blocks, ofs*sign, overcut, adaptative, adaptedRadius, cutDiam, tooldiameter,\ |
| 1882 |
targetDepth, depthIncrement, tabsnumber, tabsWidth, tabsHeight) |
| 1883 |
if msg: |
| 1884 |
tkMessageBox.showwarning("Open paths", |
| 1885 |
"WARNING: %s"%(msg), |
| 1886 |
parent=self) |
| 1887 |
msg2 = adaptative |
| 1888 |
if msg2: |
| 1889 |
tkMessageBox.showwarning("Adaptative", |
| 1890 |
"WARNING: Adaptive route generated, but Trocoidal still does not implement it. Use will give wrong results in the corners!", |
| 1891 |
parent=self) |
| 1892 |
|
| 1893 |
self.editor.fill() |
| 1894 |
self.editor.selectBlocks(blocks) |
| 1895 |
self.draw() |
| 1896 |
self.notBusy() |
| 1897 |
self.setStatus(_("Profile block distance=%g")%(ofs*sign)) |
| 1898 |
#----------------------------------------------------------------------- |
| 1899 |
def edit(self, event=None): |
| 1900 |
page = self.ribbon.getActivePage() |
| 1901 |
if page.name == "Editor": |
| 1902 |
self.editor.edit() |
| 1903 |
elif page.name == "CAM": |
| 1904 |
page.edit() |
| 1905 |
|
| 1906 |
#----------------------------------------------------------------------- |
| 1907 |
def commandFocus(self, event=None): |
| 1908 |
self.command.focus_set() |
| 1909 |
|
| 1910 |
#----------------------------------------------------------------------- |
| 1911 |
def commandFocusIn(self, event=None): |
| 1912 |
self.cmdlabel["foreground"] = "Blue" |
| 1913 |
|
| 1914 |
#----------------------------------------------------------------------- |
| 1915 |
def commandFocusOut(self, event=None): |
| 1916 |
self.cmdlabel["foreground"] = "Black" |
| 1917 |
|
| 1918 |
#----------------------------------------------------------------------- |
| 1919 |
# FIXME why it is not called? |
| 1920 |
#----------------------------------------------------------------------- |
| 1921 |
def commandKey(self, event): |
| 1922 |
if event.char or event.keysym in ("BackSpace"): |
| 1923 |
self._historyPos = None |
| 1924 |
self._historySearch = None |
| 1925 |
|
| 1926 |
#----------------------------------------------------------------------- |
| 1927 |
def commandHistoryUp(self, event=None): |
| 1928 |
if self._historyPos is None: |
| 1929 |
s = self.command.get() |
| 1930 |
if self.history: |
| 1931 |
self._historyPos = len(self.history)-1 |
| 1932 |
else: |
| 1933 |
self._historySearch = None |
| 1934 |
return |
| 1935 |
if s and self._historySearch is None: |
| 1936 |
self._historySearch = s.strip().upper() |
| 1937 |
else: |
| 1938 |
self._historyPos = max(0, self._historyPos-1) |
| 1939 |
|
| 1940 |
if self._historySearch: |
| 1941 |
for i in range(self._historyPos,-1,-1): |
| 1942 |
h = self.history[i] |
| 1943 |
if h.upper().startswith(self._historySearch): |
| 1944 |
self._historyPos = i |
| 1945 |
break |
| 1946 |
|
| 1947 |
self.command.delete(0,END) |
| 1948 |
self.command.insert(0,self.history[self._historyPos]) |
| 1949 |
|
| 1950 |
#----------------------------------------------------------------------- |
| 1951 |
def commandHistoryDown(self, event=None): |
| 1952 |
if self._historyPos is None: |
| 1953 |
self._historySearch = None |
| 1954 |
return |
| 1955 |
else: |
| 1956 |
self._historyPos += 1 |
| 1957 |
if self._historyPos >= len(self.history): |
| 1958 |
self._historyPos = None |
| 1959 |
self._historySearch = None |
| 1960 |
|
| 1961 |
if self._historySearch: |
| 1962 |
for i in range(self._historyPos,len(self.history)): |
| 1963 |
h = self.history[i] |
| 1964 |
if h.upper().startswith(self._historySearch): |
| 1965 |
self._historyPos = i |
| 1966 |
break |
| 1967 |
|
| 1968 |
self.command.delete(0,END) |
| 1969 |
if self._historyPos is not None: |
| 1970 |
self.command.insert(0,self.history[self._historyPos]) |
| 1971 |
|
| 1972 |
#----------------------------------------------------------------------- |
| 1973 |
def select(self, items, double, clear, toggle=True): |
| 1974 |
self.editor.select(items, double, clear, toggle) |
| 1975 |
self.selectionChange() |
| 1976 |
|
| 1977 |
# ---------------------------------------------------------------------- |
| 1978 |
# Selection has changed highlight the canvas |
| 1979 |
# ---------------------------------------------------------------------- |
| 1980 |
def selectionChange(self, event=None): |
| 1981 |
items = self.editor.getSelection() |
| 1982 |
self.canvas.clearSelection() |
| 1983 |
if not items: return |
| 1984 |
self.canvas.select(items) |
| 1985 |
self.canvas.activeMarker(self.editor.getActive()) |
| 1986 |
|
| 1987 |
#----------------------------------------------------------------------- |
| 1988 |
# Create a new file |
| 1989 |
#----------------------------------------------------------------------- |
| 1990 |
def newFile(self, event=None): |
| 1991 |
if self.running: return |
| 1992 |
if self.fileModified(): return |
| 1993 |
self.gcode.init() |
| 1994 |
self.gcode.headerFooter() |
| 1995 |
self.editor.fill() |
| 1996 |
self.draw() |
| 1997 |
self.title("%s %s %s"%(Utils.__prg__,__version__,__platform_fingerprint__)) |
| 1998 |
|
| 1999 |
#----------------------------------------------------------------------- |
| 2000 |
# load dialog |
| 2001 |
#----------------------------------------------------------------------- |
| 2002 |
def loadDialog(self, event=None): |
| 2003 |
if self.running: return |
| 2004 |
filename = bFileDialog.askopenfilename(master=self, |
| 2005 |
title=_("Open file"), |
| 2006 |
initialfile=os.path.join( |
| 2007 |
Utils.getUtf("File", "dir"), |
| 2008 |
Utils.getUtf("File", "file")), |
| 2009 |
filetypes=FILETYPES) |
| 2010 |
if filename: self.load(filename) |
| 2011 |
return "break" |
| 2012 |
|
| 2013 |
#----------------------------------------------------------------------- |
| 2014 |
# save dialog |
| 2015 |
#----------------------------------------------------------------------- |
| 2016 |
def saveDialog(self, event=None): |
| 2017 |
if self.running: return |
| 2018 |
fn, ext = os.path.splitext(Utils.getUtf("File", "file")) |
| 2019 |
if ext in (".dxf", ".DXF"): ext = ".ngc" |
| 2020 |
filename = bFileDialog.asksaveasfilename(master=self, |
| 2021 |
title=_("Save file"), |
| 2022 |
initialfile=os.path.join(Utils.getUtf("File", "dir"), fn+ext), |
| 2023 |
filetypes=FILETYPES) |
| 2024 |
if filename: self.save(filename) |
| 2025 |
return "break" |
| 2026 |
|
| 2027 |
#----------------------------------------------------------------------- |
| 2028 |
def fileModified(self): |
| 2029 |
if self.gcode.isModified(): |
| 2030 |
ans = tkMessageBox.askquestion(_("File modified"), |
| 2031 |
_("Gcode was modified do you want to save it first?"), |
| 2032 |
type = tkMessageBox.YESNOCANCEL, |
| 2033 |
parent=self) |
| 2034 |
if ans==tkMessageBox.CANCEL: |
| 2035 |
return True |
| 2036 |
if ans==tkMessageBox.YES or ans==True: |
| 2037 |
self.saveAll() |
| 2038 |
|
| 2039 |
if not self.gcode.probe.isEmpty() and not self.gcode.probe.saved: |
| 2040 |
ans = tkMessageBox.askquestion(_("Probe File modified"), |
| 2041 |
_("Probe was modified do you want to save it first?"), |
| 2042 |
type = tkMessageBox.YESNOCANCEL, |
| 2043 |
parent=self) |
| 2044 |
if ans==tkMessageBox.CANCEL: |
| 2045 |
return True |
| 2046 |
if ans==tkMessageBox.YES or ans==True: |
| 2047 |
if self.gcode.probe.filename == "": |
| 2048 |
self.saveDialog() |
| 2049 |
else: |
| 2050 |
self.gcode.probe.save() |
| 2051 |
return False |
| 2052 |
|
| 2053 |
#----------------------------------------------------------------------- |
| 2054 |
# Load a file into editor |
| 2055 |
#----------------------------------------------------------------------- |
| 2056 |
def load(self, filename, autoloaded = False): |
| 2057 |
fn,ext = os.path.splitext(filename) |
| 2058 |
if ext==".probe": |
| 2059 |
pass |
| 2060 |
else: |
| 2061 |
if self.fileModified(): return |
| 2062 |
|
| 2063 |
if not self.gcode.probe.isEmpty(): |
| 2064 |
ans = tkMessageBox.askquestion(_("Existing Autolevel"), |
| 2065 |
_("Autolevel/probe information already exists.\nDelete it?"), |
| 2066 |
parent=self) |
| 2067 |
if ans==tkMessageBox.YES or ans==True: |
| 2068 |
self.gcode.probe.init() |
| 2069 |
|
| 2070 |
self.setStatus(_("Loading: %s ...")%(filename), True) |
| 2071 |
Sender.load(self,filename) |
| 2072 |
|
| 2073 |
if ext==".probe": |
| 2074 |
self.autolevel.setValues() |
| 2075 |
self.event_generate("<<DrawProbe>>") |
| 2076 |
|
| 2077 |
elif ext==".orient": |
| 2078 |
self.event_generate("<<DrawOrient>>") |
| 2079 |
self.event_generate("<<OrientSelect>>",data=0) |
| 2080 |
self.event_generate("<<OrientUpdate>>") |
| 2081 |
|
| 2082 |
else: |
| 2083 |
self.editor.selectClear() |
| 2084 |
self.editor.fill() |
| 2085 |
self.canvas.reset() |
| 2086 |
self.draw() |
| 2087 |
self.canvas.fit2Screen() |
| 2088 |
Page.frames["CAM"].populate() |
| 2089 |
|
| 2090 |
if autoloaded: |
| 2091 |
self.setStatus(_("'%s' reloaded at '%s'")%(filename,str(datetime.now()))) |
| 2092 |
else: |
| 2093 |
self.setStatus(_("'%s' loaded")%(filename)) |
| 2094 |
self.title("%s %s: %s %s"%(Utils.__prg__,__version__,self.gcode.filename,__platform_fingerprint__)) |
| 2095 |
|
| 2096 |
#----------------------------------------------------------------------- |
| 2097 |
def save(self, filename): |
| 2098 |
Sender.save(self, filename) |
| 2099 |
self.setStatus(_("'%s' saved")%(filename)) |
| 2100 |
self.title("%s %s: %s %s"%(Utils.__prg__,__version__,self.gcode.filename,__platform_fingerprint__)) |
| 2101 |
|
| 2102 |
#----------------------------------------------------------------------- |
| 2103 |
def saveAll(self, event=None): |
| 2104 |
if self.gcode.filename: |
| 2105 |
Sender.saveAll(self) |
| 2106 |
else: |
| 2107 |
self.saveDialog() |
| 2108 |
return "break" |
| 2109 |
|
| 2110 |
#----------------------------------------------------------------------- |
| 2111 |
def reload(self, event=None): |
| 2112 |
self.load(self.gcode.filename) |
| 2113 |
|
| 2114 |
#----------------------------------------------------------------------- |
| 2115 |
def importFile(self, filename=None): |
| 2116 |
if filename is None: |
| 2117 |
filename = bFileDialog.askopenfilename(master=self, |
| 2118 |
title=_("Import Gcode/DXF file"), |
| 2119 |
initialfile=os.path.join( |
| 2120 |
Utils.getUtf("File", "dir"), |
| 2121 |
Utils.getUtf("File", "file")), |
| 2122 |
filetypes=[(_("G-Code"),("*.ngc","*.nc", "*.gcode")), |
| 2123 |
("DXF", "*.dxf"), |
| 2124 |
("All","*")]) |
| 2125 |
if filename: |
| 2126 |
fn,ext = os.path.splitext(filename) |
| 2127 |
ext = ext.lower() |
| 2128 |
gcode = GCode() |
| 2129 |
if ext == ".dxf": |
| 2130 |
gcode.importDXF(filename) |
| 2131 |
elif ext == ".svg": |
| 2132 |
gcode.importSVG(filename) |
| 2133 |
else: |
| 2134 |
gcode.load(filename) |
| 2135 |
sel = self.editor.getSelectedBlocks() |
| 2136 |
if not sel: |
| 2137 |
pos = None |
| 2138 |
else: |
| 2139 |
pos = sel[-1] |
| 2140 |
self.addUndo(self.gcode.insBlocksUndo(pos, gcode.blocks)) |
| 2141 |
del gcode |
| 2142 |
self.editor.fill() |
| 2143 |
self.draw() |
| 2144 |
self.canvas.fit2Screen() |
| 2145 |
|
| 2146 |
#----------------------------------------------------------------------- |
| 2147 |
def focusIn(self, event): |
| 2148 |
if self._inFocus: return |
| 2149 |
# FocusIn is generated for all sub-windows, handle only the main window |
| 2150 |
if self is not event.widget: return |
| 2151 |
self._inFocus = True |
| 2152 |
if self.gcode.checkFile(): |
| 2153 |
if self.gcode.isModified(): |
| 2154 |
ans = tkMessageBox.askquestion(_("Warning"), |
| 2155 |
_("Gcode file %s was changed since editing started\n" \ |
| 2156 |
"Reload new version?")%(self.gcode.filename), |
| 2157 |
parent=self) |
| 2158 |
if ans==tkMessageBox.YES or ans==True: |
| 2159 |
self.gcode.resetModified() |
| 2160 |
self.load(self.gcode.filename) |
| 2161 |
else: |
| 2162 |
self.load(self.gcode.filename, True) |
| 2163 |
self._inFocus = False |
| 2164 |
self.gcode.syncFileTime() |
| 2165 |
|
| 2166 |
#----------------------------------------------------------------------- |
| 2167 |
def openClose(self, event=None): |
| 2168 |
serialPage = Page.frames["Serial"] |
| 2169 |
if self.serial is not None: |
| 2170 |
self.close() |
| 2171 |
serialPage.connectBtn.config(text=_("Open"), |
| 2172 |
background="Salmon", |
| 2173 |
activebackground="Salmon") |
| 2174 |
else: |
| 2175 |
serialPage = Page.frames["Serial"] |
| 2176 |
device = _device or serialPage.portCombo.get() #.split("\t")[0] |
| 2177 |
baudrate = _baud or serialPage.baudCombo.get() |
| 2178 |
if self.open(device, baudrate): |
| 2179 |
serialPage.connectBtn.config(text=_("Close"), |
| 2180 |
background="LightGreen", |
| 2181 |
activebackground="LightGreen") |
| 2182 |
self.enable() |
| 2183 |
|
| 2184 |
#----------------------------------------------------------------------- |
| 2185 |
def open(self, device, baudrate): |
| 2186 |
try: |
| 2187 |
return Sender.open(self, device, baudrate) |
| 2188 |
except: |
| 2189 |
self.serial = None |
| 2190 |
self.thread = None |
| 2191 |
tkMessageBox.showerror(_("Error opening serial"), |
| 2192 |
sys.exc_info()[1], |
| 2193 |
parent=self) |
| 2194 |
return False |
| 2195 |
|
| 2196 |
#----------------------------------------------------------------------- |
| 2197 |
def close(self): |
| 2198 |
Sender.close(self) |
| 2199 |
try: |
| 2200 |
self.dro.updateState() |
| 2201 |
except TclError: |
| 2202 |
pass |
| 2203 |
|
| 2204 |
#----------------------------------------------------------------------- |
| 2205 |
# An entry function should be called periodically during compiling |
| 2206 |
# to check if the Pause or Stop buttons are pressed |
| 2207 |
# @return true if the compile has to abort |
| 2208 |
#----------------------------------------------------------------------- |
| 2209 |
def checkStop(self): |
| 2210 |
try: |
| 2211 |
self.update() # very tricky function of Tk |
| 2212 |
except TclError: |
| 2213 |
pass |
| 2214 |
return self._stop |
| 2215 |
|
| 2216 |
#----------------------------------------------------------------------- |
| 2217 |
# Send enabled gcode file to the CNC machine |
| 2218 |
#----------------------------------------------------------------------- |
| 2219 |
def run(self, lines=None): |
| 2220 |
self.cleanAfter = True #Clean when this operation stops |
| 2221 |
print("Will clean after this operation") |
| 2222 |
|
| 2223 |
if self.serial is None and not CNC.developer: |
| 2224 |
tkMessageBox.showerror(_("Serial Error"), |
| 2225 |
_("Serial is not connected"), |
| 2226 |
parent=self) |
| 2227 |
return |
| 2228 |
if self.running: |
| 2229 |
if self._pause: |
| 2230 |
self.resume() |
| 2231 |
return |
| 2232 |
tkMessageBox.showerror(_("Already running"), |
| 2233 |
_("Please stop before"), |
| 2234 |
parent=self) |
| 2235 |
return |
| 2236 |
|
| 2237 |
self.editor.selectClear() |
| 2238 |
self.selectionChange() |
| 2239 |
CNC.vars["errline"] = "" |
| 2240 |
|
| 2241 |
# the buffer of the machine should be empty? |
| 2242 |
self.initRun() |
| 2243 |
self.canvas.clearSelection() |
| 2244 |
self._runLines = sys.maxsize # temporary WARNING this value is used |
| 2245 |
# by Sender._serialIO to check if we |
| 2246 |
# are still sending or we finished |
| 2247 |
self._gcount = 0 # count executed lines |
| 2248 |
self._selectI = 0 # last selection pointer in items |
| 2249 |
self._paths = None # temporary |
| 2250 |
CNC.vars["running"] = True # enable running status |
| 2251 |
CNC.vars["_OvChanged"] = True # force a feed change if any |
| 2252 |
if self._onStart: |
| 2253 |
try: |
| 2254 |
os.system(self._onStart) |
| 2255 |
except: |
| 2256 |
pass |
| 2257 |
|
| 2258 |
if lines is None: |
| 2259 |
#if not self.gcode.probe.isEmpty() and not self.gcode.probe.zeroed: |
| 2260 |
# tkMessageBox.showerror(_("Probe is not zeroed"), |
| 2261 |
# _("Please ZERO any location of the probe before starting a run"), |
| 2262 |
# parent=self) |
| 2263 |
# return |
| 2264 |
self.statusbar.setLimits(0, 9999) |
| 2265 |
self.statusbar.setProgress(0,0) |
| 2266 |
|
| 2267 |
#class MyQueue: |
| 2268 |
# def put(self,line): |
| 2269 |
# print ">>>",line |
| 2270 |
#self._paths = self.gcode.compile(MyQueue(), self.checkStop) |
| 2271 |
#return |
| 2272 |
|
| 2273 |
self._paths = self.gcode.compile(self.queue, self.checkStop) |
| 2274 |
if self._paths is None: |
| 2275 |
self.emptyQueue() |
| 2276 |
self.purgeController() |
| 2277 |
return |
| 2278 |
elif not self._paths: |
| 2279 |
self.runEnded() |
| 2280 |
tkMessageBox.showerror(_("Empty gcode"), |
| 2281 |
_("Not gcode file was loaded"), |
| 2282 |
parent=self) |
| 2283 |
return |
| 2284 |
|
| 2285 |
# reset colors |
| 2286 |
before = time.time() |
| 2287 |
for ij in self._paths: # Slow loop |
| 2288 |
if not ij: continue |
| 2289 |
path = self.gcode[ij[0]].path(ij[1]) |
| 2290 |
if path: |
| 2291 |
color = self.canvas.itemcget(path, "fill") |
| 2292 |
if color != CNCCanvas.ENABLE_COLOR: |
| 2293 |
self.canvas.itemconfig( |
| 2294 |
path, |
| 2295 |
width=1, |
| 2296 |
fill=CNCCanvas.ENABLE_COLOR) |
| 2297 |
# Force a periodic update since this loop can take time |
| 2298 |
if time.time() - before > 0.25: |
| 2299 |
self.update() |
| 2300 |
before = time.time() |
| 2301 |
|
| 2302 |
# the buffer of the machine should be empty? |
| 2303 |
self._runLines = len(self._paths) + 1 # plus the wait |
| 2304 |
else: |
| 2305 |
n = 1 # including one wait command |
| 2306 |
for line in CNC.compile(lines): |
| 2307 |
if line is not None: |
| 2308 |
if isinstance(line,str): |
| 2309 |
self.queue.put(line+"\n") |
| 2310 |
else: |
| 2311 |
self.queue.put(line) |
| 2312 |
n += 1 |
| 2313 |
self._runLines = n # set it at the end to be sure that all lines are queued |
| 2314 |
self.queue.put((WAIT,)) # wait at the end to become idle |
| 2315 |
|
| 2316 |
self.setStatus(_("Running...")) |
| 2317 |
self.statusbar.setLimits(0, self._runLines) |
| 2318 |
self.statusbar.configText(fill="White") |
| 2319 |
self.statusbar.config(background="DarkGray") |
| 2320 |
|
| 2321 |
self.bufferbar.configText(fill="White") |
| 2322 |
self.bufferbar.config(background="DarkGray") |
| 2323 |
self.bufferbar.setText("") |
| 2324 |
|
| 2325 |
#----------------------------------------------------------------------- |
| 2326 |
# Start the web pendant |
| 2327 |
#----------------------------------------------------------------------- |
| 2328 |
def startPendant(self, showInfo=True): |
| 2329 |
started=Pendant.start(self) |
| 2330 |
if showInfo: |
| 2331 |
hostName="http://%s:%d"%(socket.gethostname(),Pendant.port) |
| 2332 |
if started: |
| 2333 |
tkMessageBox.showinfo(_("Pendant"), |
| 2334 |
_("Pendant started:\n")+hostName, |
| 2335 |
parent=self) |
| 2336 |
else: |
| 2337 |
dr=tkMessageBox.askquestion(_("Pendant"), |
| 2338 |
_("Pendant already started:\n") \ |
| 2339 |
+ hostName + \ |
| 2340 |
_("\nWould you like open it locally?"), |
| 2341 |
parent=self) |
| 2342 |
if dr=="yes": |
| 2343 |
webbrowser.open(hostName,new=2) |
| 2344 |
|
| 2345 |
#----------------------------------------------------------------------- |
| 2346 |
# Stop the web pendant |
| 2347 |
#----------------------------------------------------------------------- |
| 2348 |
def stopPendant(self): |
| 2349 |
if Pendant.stop(): |
| 2350 |
tkMessageBox.showinfo(_("Pendant"),_("Pendant stopped"), parent=self) |
| 2351 |
|
| 2352 |
#----------------------------------------------------------------------- |
| 2353 |
# Inner loop to catch any generic exception |
| 2354 |
#----------------------------------------------------------------------- |
| 2355 |
def _monitorSerial(self): |
| 2356 |
# Check serial output |
| 2357 |
t = time.time() |
| 2358 |
|
| 2359 |
# dump in the terminal what ever you can in less than 0.1s |
| 2360 |
inserted = False |
| 2361 |
while self.log.qsize()>0 and time.time()-t<0.1: |
| 2362 |
try: |
| 2363 |
msg, line = self.log.get_nowait() |
| 2364 |
line = str(line).rstrip("\n") |
| 2365 |
inserted = True |
| 2366 |
#print "<<<",msg,line,"\n" in line |
| 2367 |
|
| 2368 |
if msg == Sender.MSG_BUFFER: |
| 2369 |
self.buffer.insert(END, line) |
| 2370 |
|
| 2371 |
elif msg == Sender.MSG_SEND: |
| 2372 |
self.terminal.insert(END, line) |
| 2373 |
self.terminal.itemconfig(END, foreground="Blue") |
| 2374 |
|
| 2375 |
elif msg == Sender.MSG_RECEIVE: |
| 2376 |
self.terminal.insert(END, line) |
| 2377 |
if self._insertCount: |
| 2378 |
# when counting is started, then continue |
| 2379 |
self._insertCount += 1 |
| 2380 |
elif line and line[0] in ("[","$"): |
| 2381 |
# start the counting on the first line received |
| 2382 |
# starting with $ or [ |
| 2383 |
self._insertCount = 1 |
| 2384 |
|
| 2385 |
elif msg == Sender.MSG_OK: |
| 2386 |
if self.terminal.size()>0: |
| 2387 |
if self._insertCount: |
| 2388 |
pos = self.terminal.size()-self._insertCount |
| 2389 |
self._insertCount = 0 |
| 2390 |
else: |
| 2391 |
pos = END |
| 2392 |
self.terminal.insert(pos, self.buffer.get(0)) |
| 2393 |
self.terminal.itemconfig(pos, foreground="Blue") |
| 2394 |
self.buffer.delete(0) |
| 2395 |
self.terminal.insert(END, line) |
| 2396 |
|
| 2397 |
elif msg == Sender.MSG_ERROR: |
| 2398 |
if self.terminal.size()>0: |
| 2399 |
if self._insertCount: |
| 2400 |
pos = self.terminal.size()-self._insertCount |
| 2401 |
self._insertCount = 0 |
| 2402 |
else: |
| 2403 |
pos = END |
| 2404 |
self.terminal.insert(pos, self.buffer.get(0)) |
| 2405 |
self.terminal.itemconfig(pos, foreground="Blue") |
| 2406 |
self.buffer.delete(0) |
| 2407 |
self.terminal.insert(END, line) |
| 2408 |
self.terminal.itemconfig(END, foreground="Red") |
| 2409 |
|
| 2410 |
elif msg == Sender.MSG_RUNEND: |
| 2411 |
self.terminal.insert(END, line) |
| 2412 |
self.terminal.itemconfig(END, foreground="Magenta") |
| 2413 |
self.setStatus(line) |
| 2414 |
self.enable() |
| 2415 |
|
| 2416 |
elif msg == Sender.MSG_CLEAR: |
| 2417 |
self.buffer.delete(0,END) |
| 2418 |
|
| 2419 |
else: |
| 2420 |
# Unknown? |
| 2421 |
self.buffer.insert(END, line) |
| 2422 |
self.terminal.itemconfig(END, foreground="Magenta") |
| 2423 |
|
| 2424 |
if self.terminal.size() > 1000: |
| 2425 |
self.terminal.delete(0,500) |
| 2426 |
except Empty: |
| 2427 |
break |
| 2428 |
|
| 2429 |
if inserted: self.terminal.see(END) |
| 2430 |
|
| 2431 |
# Check pendant |
| 2432 |
try: |
| 2433 |
cmd = self.pendant.get_nowait() |
| 2434 |
self.execute(cmd) |
| 2435 |
except Empty: |
| 2436 |
pass |
| 2437 |
|
| 2438 |
# Load file from pendant |
| 2439 |
if self._pendantFileUploaded!=None: |
| 2440 |
self.load(self._pendantFileUploaded) |
| 2441 |
self._pendantFileUploaded=None |
| 2442 |
|
| 2443 |
# Update position if needed |
| 2444 |
if self._posUpdate: |
| 2445 |
state = CNC.vars["state"] |
| 2446 |
#print Sender.ERROR_CODES[state] |
| 2447 |
try: |
| 2448 |
CNC.vars["color"] = STATECOLOR[state] |
| 2449 |
except KeyError: |
| 2450 |
if self._alarm: |
| 2451 |
CNC.vars["color"] = STATECOLOR["Alarm"] |
| 2452 |
else: |
| 2453 |
CNC.vars["color"] = STATECOLORDEF |
| 2454 |
self._pause = ("Hold" in state) |
| 2455 |
self.dro.updateState() |
| 2456 |
self.dro.updateCoords() |
| 2457 |
self.canvas.gantry(CNC.vars["wx"], |
| 2458 |
CNC.vars["wy"], |
| 2459 |
CNC.vars["wz"], |
| 2460 |
CNC.vars["mx"], |
| 2461 |
CNC.vars["my"], |
| 2462 |
CNC.vars["mz"]) |
| 2463 |
if state=="Run": |
| 2464 |
self.gstate.updateFeed() |
| 2465 |
#self.xxx.updateSpindle() |
| 2466 |
self._posUpdate = False |
| 2467 |
|
| 2468 |
# Update status string |
| 2469 |
if self._gUpdate: |
| 2470 |
self.gstate.updateG() |
| 2471 |
self._gUpdate = False |
| 2472 |
|
| 2473 |
# Update probe and draw point |
| 2474 |
if self._probeUpdate: |
| 2475 |
Page.frames["Probe:Probe"].updateProbe() |
| 2476 |
Page.frames["ProbeCommon"].updateTlo() |
| 2477 |
self.canvas.drawProbe() |
| 2478 |
self._probeUpdate = False |
| 2479 |
|
| 2480 |
# Update any possible variable? |
| 2481 |
if self._update: |
| 2482 |
if self._update == "toolheight": |
| 2483 |
Page.frames["Probe:Tool"].updateTool() |
| 2484 |
elif self._update == "TLO": |
| 2485 |
Page.frames["ProbeCommon"].updateTlo() |
| 2486 |
self._update = None |
| 2487 |
|
| 2488 |
if self.running: |
| 2489 |
self.statusbar.setProgress(self._runLines-self.queue.qsize(), |
| 2490 |
self._gcount) |
| 2491 |
CNC.vars["msg"] = self.statusbar.msg |
| 2492 |
self.bufferbar.setProgress(Sender.getBufferFill(self)) |
| 2493 |
self.bufferbar.setText("%i%%"%Sender.getBufferFill(self)) |
| 2494 |
|
| 2495 |
if self._selectI>=0 and self._paths: |
| 2496 |
while self._selectI <= self._gcount and self._selectI<len(self._paths): |
| 2497 |
if self._paths[self._selectI]: |
| 2498 |
i,j = self._paths[self._selectI] |
| 2499 |
path = self.gcode[i].path(j) |
| 2500 |
if path: |
| 2501 |
self.canvas.itemconfig(path, |
| 2502 |
width=2, |
| 2503 |
fill=CNCCanvas.PROCESS_COLOR) |
| 2504 |
self._selectI += 1 |
| 2505 |
|
| 2506 |
if self._gcount >= self._runLines: |
| 2507 |
self.runEnded() |
| 2508 |
|
| 2509 |
#----------------------------------------------------------------------- |
| 2510 |
# "thread" timed function looking for messages in the serial thread |
| 2511 |
# and reporting back in the terminal |
| 2512 |
#----------------------------------------------------------------------- |
| 2513 |
def monitorSerial(self): |
| 2514 |
try: |
| 2515 |
self._monitorSerial() |
| 2516 |
except: |
| 2517 |
typ, val, tb = sys.exc_info() |
| 2518 |
traceback.print_exception(typ, val, tb) |
| 2519 |
self.after(MONITOR_AFTER, self.monitorSerial) |
| 2520 |
|
| 2521 |
#----------------------------------------------------------------------- |
| 2522 |
def get(self, section, item): |
| 2523 |
return Utils.config.get(section, item) |
| 2524 |
|
| 2525 |
#----------------------------------------------------------------------- |
| 2526 |
def set(self, section, item, value): |
| 2527 |
return Utils.config.set(section, item, value) |
| 2528 |
|
| 2529 |
|
| 2530 |
#------------------------------------------------------------------------------ |
| 2531 |
def usage(rc): |
| 2532 |
sys.stdout.write("%s V%s [%s] %s\n"%(Utils.__prg__, __version__, __date__, __platform_fingerprint__)) |
| 2533 |
sys.stdout.write("%s <%s>\n\n"%(__author__, __email__)) |
| 2534 |
sys.stdout.write("Usage: [options] [filename...]\n\n") |
| 2535 |
sys.stdout.write("Options:\n") |
| 2536 |
sys.stdout.write("\t-b # | --baud #\t\tSet the baud rate\n") |
| 2537 |
sys.stdout.write("\t-d\t\t\tEnable developer features\n") |
| 2538 |
sys.stdout.write("\t-D\t\t\tDisable developer features\n") |
| 2539 |
sys.stdout.write("\t-f | --fullscreen\tEnable fullscreen mode\n") |
| 2540 |
sys.stdout.write("\t-g #\t\t\tSet the default geometry\n") |
| 2541 |
sys.stdout.write("\t-h | -? | --help\tThis help page\n") |
| 2542 |
sys.stdout.write("\t-i # | --ini #\t\tAlternative ini file for testing\n") |
| 2543 |
sys.stdout.write("\t-l | --list\t\tList all recently opened files\n") |
| 2544 |
sys.stdout.write("\t-p # | --pendant #\tOpen pendant to specified port\n") |
| 2545 |
sys.stdout.write("\t-P\t\t\tDo not start pendant\n") |
| 2546 |
sys.stdout.write("\t-r | --recent\t\tLoad the most recent file opened\n") |
| 2547 |
sys.stdout.write("\t-R #\t\t\tLoad the recent file matching the argument\n") |
| 2548 |
sys.stdout.write("\t-s # | --serial #\tOpen serial port specified\n") |
| 2549 |
sys.stdout.write("\t-S\t\t\tDo not open serial port\n") |
| 2550 |
sys.stdout.write("\t--run\t\t\tDirectly run the file once loaded\n") |
| 2551 |
sys.stdout.write("\n") |
| 2552 |
sys.exit(rc) |
| 2553 |
|
| 2554 |
#------------------------------------------------------------------------------ |
| 2555 |
tk = None |
| 2556 |
application = None |
| 2557 |
|
| 2558 |
|
| 2559 |
def main(args=None): |
| 2560 |
global tk |
| 2561 |
global application |
| 2562 |
|
| 2563 |
#if sys.version_info[0] != 2: |
| 2564 |
sys.stdout.write("="*80+"\n") |
| 2565 |
sys.stdout.write("WARNING: bCNC has been recently ported to support both python v2.x and v3.x\n") |
| 2566 |
sys.stdout.write("Most things seem to work reasonably well in both python versions.\n") |
| 2567 |
sys.stdout.write("Please report any issues to: https://github.com/vlachoudis/bCNC/issues\n") |
| 2568 |
sys.stdout.write("="*80+"\n") |
| 2569 |
#sys.exit(0) |
| 2570 |
|
| 2571 |
tk = Tk() |
| 2572 |
tk.withdraw() |
| 2573 |
#if sys.version_info[0] != 2: |
| 2574 |
# tkMessageBox.showwarning("bCNC: Unsupported Python version", "Only Python 2 is currently supported by bCNC.\nContinue at your own risk!\nPlease report any issues to\nhttps://github.com/vlachoudis/bCNC/issues") |
| 2575 |
|
| 2576 |
try: |
| 2577 |
Tkinter.CallWrapper = Utils.CallWrapper |
| 2578 |
except: |
| 2579 |
tkinter.CallWrapper = Utils.CallWrapper |
| 2580 |
|
| 2581 |
tkExtra.bindClasses(tk) |
| 2582 |
Utils.loadIcons() |
| 2583 |
|
| 2584 |
# Parse arguments |
| 2585 |
try: |
| 2586 |
optlist, args = getopt.getopt(sys.argv[1:], |
| 2587 |
'?b:dDfhi:g:rlpPSs:', |
| 2588 |
['help', 'ini=', 'fullscreen', 'recent', 'list','pendant=','serial=','baud=','run']) |
| 2589 |
except getopt.GetoptError: |
| 2590 |
usage(1) |
| 2591 |
|
| 2592 |
recent = None |
| 2593 |
run = False |
| 2594 |
fullscreen = False |
| 2595 |
for opt, val in optlist: |
| 2596 |
if opt in ("-h", "-?", "--help"): |
| 2597 |
usage(0) |
| 2598 |
elif opt in ("-i", "--ini"): |
| 2599 |
Utils.iniUser = val |
| 2600 |
Utils.loadConfiguration() |
| 2601 |
elif opt == "-d": |
| 2602 |
CNC.developer = True |
| 2603 |
elif opt == "-D": |
| 2604 |
CNC.developer = False |
| 2605 |
elif opt == "-g": |
| 2606 |
geometry = val |
| 2607 |
elif opt in ("-r", "-R", "--recent", "-l", "--list"): |
| 2608 |
if opt in ("-r","--recent"): |
| 2609 |
r = 0 |
| 2610 |
elif opt in ("--list","-l"): |
| 2611 |
r = -1 |
| 2612 |
else: |
| 2613 |
try: |
| 2614 |
r = int(val)-1 |
| 2615 |
except: |
| 2616 |
# Scan in names |
| 2617 |
for r in range(Utils._maxRecent): |
| 2618 |
filename = Utils.getRecent(r) |
| 2619 |
if filename is None: break |
| 2620 |
fn, ext = os.path.splitext(os.path.basename(filename)) |
| 2621 |
if fn == val: |
| 2622 |
break |
| 2623 |
else: |
| 2624 |
r = 0 |
| 2625 |
if r<0: |
| 2626 |
# display list of recent files |
| 2627 |
maxlen = 10 |
| 2628 |
for i in range(Utils._maxRecent): |
| 2629 |
try: filename = Utils.getRecent(i) |
| 2630 |
except: continue |
| 2631 |
maxlen = max(maxlen, len(os.path.basename(filename))) |
| 2632 |
|
| 2633 |
sys.stdout.write("Recent files:\n") |
| 2634 |
for i in range(Utils._maxRecent): |
| 2635 |
filename = Utils.getRecent(i) |
| 2636 |
if filename is None: break |
| 2637 |
d = os.path.dirname(filename) |
| 2638 |
fn = os.path.basename(filename) |
| 2639 |
sys.stdout.write(" %2d: %-*s %s\n"%(i+1,maxlen,fn,d)) |
| 2640 |
|
| 2641 |
try: |
| 2642 |
sys.stdout.write("Select one: ") |
| 2643 |
r = int(sys.stdin.readline())-1 |
| 2644 |
except: |
| 2645 |
pass |
| 2646 |
try: recent = Utils.getRecent(r) |
| 2647 |
except: pass |
| 2648 |
|
| 2649 |
elif opt in ("-f", "--fullscreen"): |
| 2650 |
fullscreen = True |
| 2651 |
|
| 2652 |
elif opt == "-S": |
| 2653 |
_openserial = False |
| 2654 |
|
| 2655 |
elif opt in ("-s", "--serial"): |
| 2656 |
_openserial = True |
| 2657 |
_device = val |
| 2658 |
|
| 2659 |
elif opt in ("-b", "--baud"): |
| 2660 |
_baud = val |
| 2661 |
|
| 2662 |
elif opt == "-p": |
| 2663 |
pass #startPendant() |
| 2664 |
|
| 2665 |
elif opt == "-P": |
| 2666 |
pass #stopPendant() |
| 2667 |
|
| 2668 |
elif opt == "--pendant": |
| 2669 |
pass #startPendant on port |
| 2670 |
|
| 2671 |
elif opt == "--run": |
| 2672 |
run = True |
| 2673 |
|
| 2674 |
palette = {"background": tk.cget("background")} |
| 2675 |
|
| 2676 |
color_count = 0 |
| 2677 |
custom_color_count = 0 |
| 2678 |
for color_name in ("background", "foreground", "activeBackground", "activeForeground", "disabledForeground", \ |
| 2679 |
"highlightBackground", "highlightColor", "selectBackground", "selectForeground"): |
| 2680 |
color2 = Utils.getStr("Color", "global." + color_name.lower(), None) |
| 2681 |
color_count += 1 |
| 2682 |
if (color2 is not None) and (color2.strip() != ""): |
| 2683 |
palette[color_name] = color2.strip() |
| 2684 |
custom_color_count += 1 |
| 2685 |
|
| 2686 |
if color_count == 0: |
| 2687 |
tkExtra.GLOBAL_CONTROL_BACKGROUND = color2 |
| 2688 |
elif color_count == 1: |
| 2689 |
tkExtra.GLOBAL_FONT_COLOR = color2 |
| 2690 |
|
| 2691 |
if custom_color_count > 0: |
| 2692 |
print("Changing palette") |
| 2693 |
tk.tk_setPalette(**palette) |
| 2694 |
|
| 2695 |
# Start application |
| 2696 |
application = Application(tk) |
| 2697 |
|
| 2698 |
if fullscreen: application.attributes("-fullscreen", True) |
| 2699 |
|
| 2700 |
# Parse remaining arguments except files |
| 2701 |
if recent: args.append(recent) |
| 2702 |
for fn in args: |
| 2703 |
application.load(fn) |
| 2704 |
|
| 2705 |
if serial is None: |
| 2706 |
tkMessageBox.showerror(_("python serial missing"), |
| 2707 |
_("ERROR: Please install the python pyserial module\n" \ |
| 2708 |
"Windows:\n\tC:\\PythonXX\\Scripts\\easy_install pyserial\n" \ |
| 2709 |
"Mac:\tpip install pyserial\n" \ |
| 2710 |
"Linux:\tsudo apt-get install python-serial\n" \ |
| 2711 |
"\tor yum install python-serial\n" \ |
| 2712 |
"\tor dnf install python-pyserial"), |
| 2713 |
parent=application) |
| 2714 |
if Updates.need2Check(): application.checkUpdates() |
| 2715 |
|
| 2716 |
if run: |
| 2717 |
application.run() |
| 2718 |
|
| 2719 |
try: |
| 2720 |
tk.mainloop() |
| 2721 |
except KeyboardInterrupt: |
| 2722 |
application.quit() |
| 2723 |
|
| 2724 |
application.close() |
| 2725 |
Utils.saveConfiguration() |
| 2726 |
|
| 2727 |
|
| 2728 |
if __name__ == "__main__": |
| 2729 |
main() |
| 2730 |
|
| 2731 |
|
| 2732 |
#vim:ts=8:sw=8:sts=8:noet |