forked from vlachoudis/bCNC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CNCRibbon.py
163 lines (138 loc) · 5.75 KB
/
CNCRibbon.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
# -*- coding: ascii -*-
# $Id$
#
# Author: vvlachoudis@gmail.com
# Date: 18-Jun-2015
__author__ = "Vasilis Vlachoudis"
__email__ = "vvlachoudis@gmail.com"
try:
from Tkinter import *
except ImportError:
from tkinter import *
import Ribbon
import tkExtra
#===============================================================================
# Link to main app
#===============================================================================
class _LinkApp:
def __init__(self, app):
self.app = app
#----------------------------------------------------------------------
# Add a widget in the widgets list to enable disable during the run
#----------------------------------------------------------------------
def addWidget(self, widget):
self.app.widgets.append(widget)
#----------------------------------------------------------------------
# Send a command to Grbl
#----------------------------------------------------------------------
def sendGCode(self, cmd):
self.app.sendGCode(cmd)
#----------------------------------------------------------------------
# Accept the user key if not editing any text
#----------------------------------------------------------------------
def acceptKey(self, skipRun=False):
return self.app.acceptKey(skipRun)
#----------------------------------------------------------------------
def saveConfig(self):
pass
#----------------------------------------------------------------------
def loadConfig(self):
pass
#===============================================================================
# Button Group, a group of widgets that will be placed in the ribbon
#===============================================================================
class ButtonGroup(Ribbon.LabelGroup, _LinkApp):
def __init__(self, master, name, app):
Ribbon.LabelGroup.__init__(self, master, name)
_LinkApp.__init__(self, app)
if ":" in name:
self.label["text"] = name.split(":")[1]
#===============================================================================
# Button Group, a group of widgets that will be placed in the ribbon
#===============================================================================
class ButtonMenuGroup(Ribbon.MenuGroup, _LinkApp):
def __init__(self, master, name, app, menulist=None):
Ribbon.MenuGroup.__init__(self, master, name, menulist)
_LinkApp.__init__(self, app)
#===============================================================================
# Page, Frame
#===============================================================================
class PageFrame(Frame, _LinkApp):
def __init__(self, master, name, app):
Frame.__init__(self, master)
_LinkApp.__init__(self, app)
self.name = name
#===============================================================================
# Page, LabelFrame
#===============================================================================
class PageLabelFrame(LabelFrame, _LinkApp):
def __init__(self, master, name, app):
LabelFrame.__init__(self, master, text=name, foreground="DarkBlue")
_LinkApp.__init__(self, app)
self.name = name
#===============================================================================
# Page, ExLabelFrame
#===============================================================================
class PageExLabelFrame(tkExtra.ExLabelFrame, _LinkApp):
def __init__(self, master, name, app):
tkExtra.ExLabelFrame.__init__(self, master, text=name, foreground="DarkBlue")
_LinkApp.__init__(self, app)
self.name = name
#===============================================================================
# CNC Page interface between the basic Page class and the bCNC class
#===============================================================================
class Page(Ribbon.Page):
groups = {}
frames = {}
def __init__(self, master, app, **kw):
self.app = app
Ribbon.Page.__init__(self, master, **kw)
self.register()
#----------------------------------------------------------------------
# Should be overridden with the groups and frames to register
#----------------------------------------------------------------------
def register(self):
pass
#----------------------------------------------------------------------
# Register groups
#----------------------------------------------------------------------
def _register(self, groups, frames):
if groups:
for g in groups:
w = g(self.master._ribbonFrame, self.app)
Page.groups[w.name] = w
if frames:
for f in frames:
w = f(self.master._pageFrame, self.app)
Page.frames[w.name] = w
#----------------------------------------------------------------------
# Add a widget in the widgets list to enable disable during the run
#----------------------------------------------------------------------
def addWidget(self, widget):
self.app.widgets.append(widget)
#----------------------------------------------------------------------
# Send a command to Grbl
#----------------------------------------------------------------------
def sendGCode(self, cmd):
self.app.sendGCode(cmd)
#----------------------------------------------------------------------
def addRibbonGroup(self, name, **args):
if not args: args = {"side":LEFT, "fill":BOTH}
self.ribbons.append((Page.groups[name], args))
#----------------------------------------------------------------------
def addPageFrame(self, name, **args):
if not args: args = {"side":TOP, "fill":BOTH}
if isinstance(name,str):
self.frames.append((Page.frames[name], args))
else:
self.frames.append((name, args))
#----------------------------------------------------------------------
@staticmethod
def saveConfig():
for frame in Page.frames.values():
frame.saveConfig()
#----------------------------------------------------------------------
@staticmethod
def loadConfig():
for frame in Page.frames.values():
frame.loadConfig()