forked from vlachoudis/bCNC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FilePage.py
312 lines (273 loc) · 9.99 KB
/
FilePage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# -*- coding: ascii -*-
# $Id$
#
# Author: [email protected]
# Date: 18-Jun-2015
__author__ = "Vasilis Vlachoudis"
__email__ = "[email protected]"
import os
try:
from Tkinter import *
import ConfigParser
except ImportError:
from tkinter import *
import configparser as ConfigParser
import tkExtra
import Utils
import Ribbon
import CNCRibbon
try:
from serial.tools.list_ports import comports
except:
from Utils import comports
BAUDS = [2400, 4800, 9600, 19200, 38400, 57600, 115200]
#===============================================================================
# Recent Menu button
#===============================================================================
class _RecentMenuButton(Ribbon.MenuButton):
#----------------------------------------------------------------------
def createMenu(self):
menu = Menu(self, tearoff=0, activebackground=Ribbon._ACTIVE_COLOR)
for i in range(Utils._maxRecent):
filename = Utils.getRecent(i)
if filename is None: break
fn = os.path.basename(filename)
menu.add_command(label="%d %s"%(i+1, fn),
compound=LEFT,
image=Utils.icons["new"],
command=lambda s=self,i=i: s.event_generate("<<Recent%d>>"%(i)))
if i==0: # no entry
self.event_generate("<<Open>>")
return None
return menu
#===============================================================================
# File Group
#===============================================================================
class FileGroup(CNCRibbon.ButtonGroup):
def __init__(self, master, app):
CNCRibbon.ButtonGroup.__init__(self, master, N_("File"), app)
self.grid3rows()
# ---
col,row=0,0
b = Ribbon.LabelButton(self.frame, self, "<<New>>",
image=Utils.icons["new32"],
text=_("New"),
compound=TOP,
background=Ribbon._BACKGROUND)
b.grid(row=row, column=col, rowspan=3, padx=0, pady=0, sticky=NSEW)
tkExtra.Balloon.set(b, _("New gcode/dxf file"))
self.addWidget(b)
# ---
col,row=1,0
b = Ribbon.LabelButton(self.frame, self, "<<Open>>",
image=Utils.icons["open32"],
background=Ribbon._BACKGROUND)
b.grid(row=row, column=col, rowspan=2, padx=0, pady=0, sticky=NSEW)
tkExtra.Balloon.set(b, _("Open existing gcode/dxf file [Ctrl-O]"))
self.addWidget(b)
col,row=1,2
b = _RecentMenuButton(self.frame, None,
text=_("Open"),
image=Utils.icons["triangle_down"],
compound=RIGHT,
background=Ribbon._BACKGROUND)
b.grid(row=row, column=col, padx=0, pady=0, sticky=NSEW)
tkExtra.Balloon.set(b, _("Open recent file"))
self.addWidget(b)
# ---
col,row=2,0
b = Ribbon.LabelButton(self.frame, self, "<<Save>>",
image=Utils.icons["save32"],
command=app.save,
background=Ribbon._BACKGROUND)
b.grid(row=row, column=col, rowspan=2, padx=0, pady=0, sticky=NSEW)
tkExtra.Balloon.set(b, _("Save gcode/dxf file [Ctrl-S]"))
self.addWidget(b)
col,row=2,2
b = Ribbon.LabelButton(self.frame, self, "<<SaveAs>>",
text=_("Save"),
image=Utils.icons["triangle_down"],
compound=RIGHT,
background=Ribbon._BACKGROUND)
b.grid(row=row, column=col, padx=0, pady=0, sticky=NSEW)
tkExtra.Balloon.set(b, _("Save gcode/dxf AS"))
self.addWidget(b)
#===============================================================================
# Options Group
#===============================================================================
class OptionsGroup(CNCRibbon.ButtonGroup):
def __init__(self, master, app):
CNCRibbon.ButtonGroup.__init__(self, master, N_("Options"), app)
self.grid3rows()
# # ---
# col,row=0,0
# b = Ribbon.LabelButton(self.frame, #self.page, "<<Config>>",
# text=_("Config"),
# image=Utils.icons["config32"],
## command=self.app.preferences,
# state=DISABLED,
# compound=TOP,
# anchor=W,
# background=Ribbon._BACKGROUND)
# b.grid(row=row, column=col, rowspan=3, padx=0, pady=0, sticky=NS)
# tkExtra.Balloon.set(b, _("Open configuration dialog"))
# ===
col,row=1,0
b = Ribbon.LabelButton(self.frame,
text=_("Report"),
image=Utils.icons["debug"],
compound=LEFT,
command=Utils.ReportDialog.sendErrorReport,
anchor=W,
background=Ribbon._BACKGROUND)
b.grid(row=row, column=col, padx=0, pady=0, sticky=EW)
tkExtra.Balloon.set(b, _("Send Error Report"))
# ---
col,row=1,1
b = Ribbon.LabelButton(self.frame,
text=_("Updates"),
image=Utils.icons["global"],
compound=LEFT,
command=self.app.checkUpdates,
anchor=W,
background=Ribbon._BACKGROUND)
b.grid(row=row, column=col, padx=0, pady=0, sticky=EW)
tkExtra.Balloon.set(b, _("Check Updates"))
col,row=1,2
b = Ribbon.LabelButton(self.frame,
text=_("About"),
image=Utils.icons["about"],
compound=LEFT,
command=self.app.about,
anchor=W,
background=Ribbon._BACKGROUND)
b.grid(row=row, column=col, padx=0, pady=0, sticky=EW)
tkExtra.Balloon.set(b, _("About the program"))
#===============================================================================
# Pendant Group
#===============================================================================
class PendantGroup(CNCRibbon.ButtonGroup):
def __init__(self, master, app):
CNCRibbon.ButtonGroup.__init__(self, master, N_("Pendant"), app)
self.grid3rows()
col,row=0,0
b = Ribbon.LabelButton(self.frame,
text=_("Start"),
image=Utils.icons["start"],
compound=LEFT,
anchor=W,
command=app.startPendant,
background=Ribbon._BACKGROUND)
b.grid(row=row, column=col, padx=0, pady=0, sticky=NSEW)
tkExtra.Balloon.set(b, _("Start pendant"))
row += 1
b = Ribbon.LabelButton(self.frame,
text=_("Stop"),
image=Utils.icons["stop"],
compound=LEFT,
anchor=W,
command=app.stopPendant,
background=Ribbon._BACKGROUND)
b.grid(row=row, column=col, padx=0, pady=0, sticky=NSEW)
tkExtra.Balloon.set(b, _("Stop pendant"))
#===============================================================================
# Close Group
#===============================================================================
class CloseGroup(CNCRibbon.ButtonGroup):
def __init__(self, master, app):
CNCRibbon.ButtonGroup.__init__(self, master, N_("Close"), app)
# ---
b = Ribbon.LabelButton(self.frame,
text=_("Exit"),
image=Utils.icons["exit32"],
compound=TOP,
command=app.quit,
anchor=W,
background=Ribbon._BACKGROUND)
b.pack(fill=BOTH, expand=YES)
tkExtra.Balloon.set(b, _("Close program [Ctrl-Q]"))
#===============================================================================
# Serial Frame
#===============================================================================
class SerialFrame(CNCRibbon.PageLabelFrame):
def __init__(self, master, app):
CNCRibbon.PageLabelFrame.__init__(self, master, "Serial", app)
self.autostart = BooleanVar()
# ---
col,row=0,0
b = Label(self, text=_("Port:"), background=Ribbon._BACKGROUND)
b.grid(row=row,column=col,sticky=E)
self.addWidget(b)
self.portCombo = tkExtra.Combobox(self, False, background="White", width=16)
self.portCombo.grid(row=row, column=col+1, sticky=EW)
tkExtra.Balloon.set(self.portCombo, _("Select (or manual enter) port to connect"))
# sys.stdout.write(comports())
devices = sorted([x[0] for x in comports()])
self.portCombo.fill(devices)
self.portCombo.set(Utils.getStr("Connection","port"))
self.addWidget(self.portCombo)
# ---
row += 1
b = Label(self, text=_("Baud:"), background=Ribbon._BACKGROUND)
b.grid(row=row,column=col,sticky=E)
self.baudCombo = tkExtra.Combobox(self, True, background="White")
self.baudCombo.grid(row=row, column=col+1, sticky=EW)
tkExtra.Balloon.set(self.baudCombo, _("Select connection baud rate"))
self.baudCombo.fill(BAUDS)
self.baudCombo.set(Utils.getStr("Connection","baud","115200"))
self.addWidget(self.baudCombo)
# ---
row += 1
b = Label(self, text=_("Controller:"), background=Ribbon._BACKGROUND)
b.grid(row=row,column=col,sticky=E)
self.ctrlCombo = tkExtra.Combobox(self, True,
background="White",
command=self.ctrlChange)
self.ctrlCombo.grid(row=row, column=col+1, sticky=EW)
tkExtra.Balloon.set(self.ctrlCombo, _("Select controller board"))
self.ctrlCombo.fill(sorted(Utils.CONTROLLER.keys()))
self.ctrlCombo.set(Utils.controllerName(app.controller))
self.addWidget(self.ctrlCombo)
# ---
row += 1
b= Checkbutton(self, text=_("Connect on startup"),
variable=self.autostart)
b.grid(row=row, column=col, columnspan=2, sticky=W)
tkExtra.Balloon.set(b, _("Connect to serial on startup of the program"))
self.autostart.set(Utils.getBool("Connection","openserial"))
self.addWidget(b)
# ---
col += 2
row = 0
self.connectBtn = Ribbon.LabelButton(self,
image=Utils.icons["serial32"],
text=_("Open"),
compound=TOP,
command=lambda s=self : s.event_generate("<<Connect>>"),
background=Ribbon._BACKGROUND)
self.connectBtn.grid(row=row, column=col, rowspan=3, padx=0, pady=0, sticky=NSEW)
tkExtra.Balloon.set(self.connectBtn, _("Open/Close serial port"))
self.grid_columnconfigure(1, weight=1)
#-----------------------------------------------------------------------
def ctrlChange(self):
self.app.controller = Utils.CONTROLLER.get(self.ctrlCombo.get(), 0)
#-----------------------------------------------------------------------
def saveConfig(self):
# Connection
Utils.setStr("Connection", "controller", Utils.controllerName(self.app.controller))
Utils.setStr("Connection", "port", self.portCombo.get())
Utils.setStr("Connection", "baud", self.baudCombo.get())
Utils.setBool("Connection", "openserial", self.autostart.get())
#===============================================================================
# File Page
#===============================================================================
class FilePage(CNCRibbon.Page):
__doc__ = _("File I/O and configuration")
_name_ = N_("File")
_icon_ = "new"
#----------------------------------------------------------------------
# Add a widget in the widgets list to enable disable during the run
#----------------------------------------------------------------------
def register(self):
self._register((FileGroup, PendantGroup, OptionsGroup, CloseGroup),
(SerialFrame,))