printrun-src/printrun/gui/__init__.py

Sat, 23 Sep 2017 10:27:49 +0200

author
mdd
date
Sat, 23 Sep 2017 10:27:49 +0200
changeset 34
654a41b13258
parent 15
0bbb006204fc
child 46
cce0af6351f0
permissions
-rw-r--r--

Added more default options
Code cleanup

15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1 # This file is part of the Printrun suite.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
3 # Printrun is free software: you can redistribute it and/or modify
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
4 # it under the terms of the GNU General Public License as published by
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
5 # the Free Software Foundation, either version 3 of the License, or
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
6 # (at your option) any later version.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
7 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
8 # Printrun is distributed in the hope that it will be useful,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
11 # GNU General Public License for more details.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
12 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
13 # You should have received a copy of the GNU General Public License
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
14 # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
16 import logging
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
17
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
18 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
19 import wx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
20 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
21 logging.error(_("WX is not installed. This program requires WX to run."))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
22 raise
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
23
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
24 from printrun.utils import install_locale
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
25 install_locale('pronterface')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
26
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
27 from .controls import ControlsSizer, add_extra_controls
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
28 from .viz import VizPane
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
29 from .log import LogPane
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
30 from .toolbar import MainToolbar
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
31
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
32 class ToggleablePane(wx.BoxSizer):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
33
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
34 def __init__(self, root, label, parentpanel, parentsizers):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
35 super(ToggleablePane, self).__init__(wx.HORIZONTAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
36 if not parentpanel: parentpanel = root.panel
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
37 self.root = root
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
38 self.visible = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
39 self.parentpanel = parentpanel
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
40 self.parentsizers = parentsizers
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
41 self.panepanel = root.newPanel(parentpanel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
42 self.button = wx.Button(parentpanel, -1, label, size = (22, 18), style = wx.BU_EXACTFIT)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
43 self.button.Bind(wx.EVT_BUTTON, self.toggle)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
44
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
45 def toggle(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
46 if self.visible:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
47 self.Hide(self.panepanel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
48 self.on_hide()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
49 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
50 self.Show(self.panepanel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
51 self.on_show()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
52 self.visible = not self.visible
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
53 self.button.SetLabel(">" if self.button.GetLabel() == "<" else "<")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
54
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
55 class LeftPaneToggleable(ToggleablePane):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
56 def __init__(self, root, parentpanel, parentsizers):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
57 super(LeftPaneToggleable, self).__init__(root, "<", parentpanel, parentsizers)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
58 self.Add(self.panepanel, 0, wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
59 self.Add(self.button, 0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
60
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
61 def set_sizer(self, sizer):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
62 self.panepanel.SetSizer(sizer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
63
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
64 def on_show(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
65 for sizer in self.parentsizers:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
66 sizer.Layout()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
67
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
68 def on_hide(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
69 for sizer in self.parentsizers:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
70 # Expand right splitterwindow
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
71 if isinstance(sizer, wx.SplitterWindow):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
72 if sizer.shrinked:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
73 button_width = self.button.GetSize()[0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
74 sizer.SetSashPosition(sizer.GetSize()[0] - button_width)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
75 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
76 sizer.Layout()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
77
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
78 class LogPaneToggleable(ToggleablePane):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
79 def __init__(self, root, parentpanel, parentsizers):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
80 super(LogPaneToggleable, self).__init__(root, ">", parentpanel, parentsizers)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
81 self.Add(self.button, 0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
82 pane = LogPane(root, self.panepanel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
83 self.panepanel.SetSizer(pane)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
84 self.Add(self.panepanel, 1, wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
85 self.splitter = self.parentpanel.GetParent()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
86
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
87 def on_show(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
88 self.splitter.shrinked = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
89 self.splitter.SetSashPosition(self.splitter.GetSize()[0] - self.orig_width)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
90 self.splitter.SetMinimumPaneSize(self.orig_min_size)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
91 self.splitter.SetSashGravity(self.orig_gravity)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
92 if hasattr(self.splitter, "SetSashSize"): self.splitter.SetSashSize(self.orig_sash_size)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
93 if hasattr(self.splitter, "SetSashInvisible"): self.splitter.SetSashInvisible(False)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
94 for sizer in self.parentsizers:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
95 sizer.Layout()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
96
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
97 def on_hide(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
98 self.splitter.shrinked = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
99 self.orig_width = self.splitter.GetSize()[0] - self.splitter.GetSashPosition()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
100 button_width = self.button.GetSize()[0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
101 self.orig_min_size = self.splitter.GetMinimumPaneSize()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
102 self.orig_gravity = self.splitter.GetSashGravity()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
103 self.splitter.SetMinimumPaneSize(button_width)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
104 self.splitter.SetSashGravity(1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
105 self.splitter.SetSashPosition(self.splitter.GetSize()[0] - button_width)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
106 if hasattr(self.splitter, "SetSashSize"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
107 self.orig_sash_size = self.splitter.GetSashSize()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
108 self.splitter.SetSashSize(0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
109 if hasattr(self.splitter, "SetSashInvisible"): self.splitter.SetSashInvisible(True)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
110 for sizer in self.parentsizers:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
111 sizer.Layout()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
112
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
113 class MainWindow(wx.Frame):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
114
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
115 def __init__(self, *args, **kwargs):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
116 super(MainWindow, self).__init__(*args, **kwargs)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
117 # this list will contain all controls that should be only enabled
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
118 # when we're connected to a printer
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
119 self.panel = wx.Panel(self, -1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
120 self.reset_ui()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
121 self.statefulControls = []
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
122
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
123 def reset_ui(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
124 self.panels = []
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
125 self.printerControls = []
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
126
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
127 def newPanel(self, parent, add_to_list = True):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
128 panel = wx.Panel(parent)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
129 self.registerPanel(panel, add_to_list)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
130 return panel
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
131
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
132 def registerPanel(self, panel, add_to_list = True):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
133 panel.SetBackgroundColour(self.bgcolor)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
134 if add_to_list: self.panels.append(panel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
135
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
136 def createTabbedGui(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
137 self.notesizer = wx.BoxSizer(wx.VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
138 self.notebook = wx.Notebook(self.panel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
139 self.notebook.SetBackgroundColour(self.bgcolor)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
140 page1panel = self.newPanel(self.notebook)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
141 page2panel = self.newPanel(self.notebook)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
142 self.mainsizer_page1 = wx.BoxSizer(wx.VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
143 page1panel1 = self.newPanel(page1panel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
144 page1panel2 = self.newPanel(page1panel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
145 self.toolbarsizer = MainToolbar(self, page1panel1, use_wrapsizer = True)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
146 page1panel1.SetSizer(self.toolbarsizer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
147 self.mainsizer_page1.Add(page1panel1, 0, wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
148 self.lowersizer = wx.BoxSizer(wx.HORIZONTAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
149 page1panel2.SetSizer(self.lowersizer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
150 leftsizer = wx.BoxSizer(wx.VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
151 controls_sizer = ControlsSizer(self, page1panel2, True)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
152 leftsizer.Add(controls_sizer, 1, wx.ALIGN_CENTER)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
153 rightsizer = wx.BoxSizer(wx.VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
154 extracontrols = wx.GridBagSizer()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
155 add_extra_controls(extracontrols, self, page1panel2, controls_sizer.extra_buttons)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
156 rightsizer.AddStretchSpacer()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
157 rightsizer.Add(extracontrols, 0, wx.ALIGN_CENTER)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
158 self.lowersizer.Add(leftsizer, 0, wx.ALIGN_CENTER | wx.RIGHT, border = 10)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
159 self.lowersizer.Add(rightsizer, 1, wx.ALIGN_CENTER)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
160 self.mainsizer_page1.Add(page1panel2, 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
161 self.mainsizer = wx.BoxSizer(wx.HORIZONTAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
162 self.splitterwindow = wx.SplitterWindow(page2panel, style = wx.SP_3D)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
163 page2sizer1 = wx.BoxSizer(wx.HORIZONTAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
164 page2panel1 = self.newPanel(self.splitterwindow)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
165 page2sizer2 = wx.BoxSizer(wx.HORIZONTAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
166 page2panel2 = self.newPanel(self.splitterwindow)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
167 vizpane = VizPane(self, page2panel1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
168 page2sizer1.Add(vizpane, 1, wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
169 page2sizer2.Add(LogPane(self, page2panel2), 1, wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
170 page2panel1.SetSizer(page2sizer1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
171 page2panel2.SetSizer(page2sizer2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
172 self.splitterwindow.SetMinimumPaneSize(1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
173 self.splitterwindow.SetSashGravity(0.5)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
174 self.splitterwindow.SplitVertically(page2panel1, page2panel2,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
175 self.settings.last_sash_position)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
176 self.mainsizer.Add(self.splitterwindow, 1, wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
177 page1panel.SetSizer(self.mainsizer_page1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
178 page2panel.SetSizer(self.mainsizer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
179 self.notesizer.Add(self.notebook, 1, wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
180 self.notebook.AddPage(page1panel, _("Commands"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
181 self.notebook.AddPage(page2panel, _("Status"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
182 if self.settings.uimode == _("Tabbed with platers"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
183 from printrun.stlplater import StlPlaterPanel
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
184 from printrun.gcodeplater import GcodePlaterPanel
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
185 page3panel = StlPlaterPanel(parent = self.notebook,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
186 callback = self.platecb,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
187 build_dimensions = self.build_dimensions_list,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
188 circular_platform = self.settings.circular_bed,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
189 simarrange_path = self.settings.simarrange_path,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
190 antialias_samples = int(self.settings.antialias3dsamples))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
191 page4panel = GcodePlaterPanel(parent = self.notebook,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
192 callback = self.platecb,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
193 build_dimensions = self.build_dimensions_list,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
194 circular_platform = self.settings.circular_bed,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
195 antialias_samples = int(self.settings.antialias3dsamples))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
196 self.registerPanel(page3panel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
197 self.registerPanel(page4panel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
198 self.notebook.AddPage(page3panel, _("Plater"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
199 self.notebook.AddPage(page4panel, _("G-Code Plater"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
200 self.panel.SetSizer(self.notesizer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
201 self.panel.Bind(wx.EVT_MOUSE_EVENTS, self.editbutton)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
202 self.Bind(wx.EVT_CLOSE, self.kill)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
203
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
204 # Custom buttons
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
205 if wx.VERSION > (2, 9): self.cbuttonssizer = wx.WrapSizer(wx.HORIZONTAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
206 else: self.cbuttonssizer = wx.GridBagSizer()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
207 self.cbuttonssizer = wx.GridBagSizer()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
208 self.centerpanel = self.newPanel(page1panel2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
209 self.centerpanel.SetSizer(self.cbuttonssizer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
210 rightsizer.Add(self.centerpanel, 0, wx.ALIGN_CENTER)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
211 rightsizer.AddStretchSpacer()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
212
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
213 self.panel.SetSizerAndFit(self.notesizer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
214
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
215 self.cbuttons_reload()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
216 minsize = self.lowersizer.GetMinSize() # lower pane
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
217 minsize[1] = self.notebook.GetSize()[1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
218 self.SetMinSize(self.ClientToWindowSize(minsize)) # client to window
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
219 self.Fit()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
220
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
221 def createGui(self, compact = False, mini = False):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
222 self.mainsizer = wx.BoxSizer(wx.VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
223 self.lowersizer = wx.BoxSizer(wx.HORIZONTAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
224 upperpanel = self.newPanel(self.panel, False)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
225 self.toolbarsizer = MainToolbar(self, upperpanel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
226 lowerpanel = self.newPanel(self.panel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
227 upperpanel.SetSizer(self.toolbarsizer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
228 lowerpanel.SetSizer(self.lowersizer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
229 leftpanel = self.newPanel(lowerpanel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
230 left_pane = LeftPaneToggleable(self, leftpanel, [self.lowersizer])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
231 leftpanel.SetSizer(left_pane)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
232 left_real_panel = left_pane.panepanel
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
233 controls_panel = self.newPanel(left_real_panel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
234 controls_sizer = ControlsSizer(self, controls_panel, mini_mode = mini)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
235 controls_panel.SetSizer(controls_sizer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
236 left_sizer = wx.BoxSizer(wx.VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
237 left_sizer.Add(controls_panel, 1, wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
238 left_pane.set_sizer(left_sizer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
239 self.lowersizer.Add(leftpanel, 0, wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
240 if not compact: # Use a splitterwindow to group viz and log
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
241 rightpanel = self.newPanel(lowerpanel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
242 rightsizer = wx.BoxSizer(wx.VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
243 rightpanel.SetSizer(rightsizer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
244 self.splitterwindow = wx.SplitterWindow(rightpanel, style = wx.SP_3D)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
245 self.splitterwindow.SetMinimumPaneSize(150)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
246 self.splitterwindow.SetSashGravity(0.8)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
247 rightsizer.Add(self.splitterwindow, 1, wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
248 vizpanel = self.newPanel(self.splitterwindow)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
249 logpanel = self.newPanel(self.splitterwindow)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
250 self.splitterwindow.SplitVertically(vizpanel, logpanel,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
251 self.settings.last_sash_position)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
252 self.splitterwindow.shrinked = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
253 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
254 vizpanel = self.newPanel(lowerpanel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
255 logpanel = self.newPanel(left_real_panel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
256 viz_pane = VizPane(self, vizpanel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
257 # Custom buttons
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
258 if wx.VERSION > (2, 9): self.cbuttonssizer = wx.WrapSizer(wx.HORIZONTAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
259 else: self.cbuttonssizer = wx.GridBagSizer()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
260 self.centerpanel = self.newPanel(vizpanel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
261 self.centerpanel.SetSizer(self.cbuttonssizer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
262 viz_pane.Add(self.centerpanel, 0, flag = wx.ALIGN_CENTER)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
263 vizpanel.SetSizer(viz_pane)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
264 if compact:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
265 log_pane = LogPane(self, logpanel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
266 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
267 log_pane = LogPaneToggleable(self, logpanel, [self.lowersizer])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
268 left_pane.parentsizers.append(self.splitterwindow)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
269 logpanel.SetSizer(log_pane)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
270 if not compact:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
271 self.lowersizer.Add(rightpanel, 1, wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
272 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
273 left_sizer.Add(logpanel, 1, wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
274 self.lowersizer.Add(vizpanel, 1, wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
275 self.mainsizer.Add(upperpanel, 0, wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
276 self.mainsizer.Add(lowerpanel, 1, wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
277 self.panel.SetSizer(self.mainsizer)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
278 self.panel.Bind(wx.EVT_MOUSE_EVENTS, self.editbutton)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
279 self.Bind(wx.EVT_CLOSE, self.kill)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
280
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
281 self.mainsizer.Layout()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
282 # This prevents resizing below a reasonnable value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
283 # We sum the lowersizer (left pane / viz / log) min size
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
284 # the toolbar height and the statusbar/menubar sizes
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
285 minsize = [0, 0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
286 minsize[0] = self.lowersizer.GetMinSize()[0] # lower pane
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
287 minsize[1] = max(viz_pane.GetMinSize()[1], controls_sizer.GetMinSize()[1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
288 minsize[1] += self.toolbarsizer.GetMinSize()[1] # toolbar height
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
289 displaysize = wx.DisplaySize()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
290 minsize[0] = min(minsize[0], displaysize[0])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
291 minsize[1] = min(minsize[1], displaysize[1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
292 self.SetMinSize(self.ClientToWindowSize(minsize)) # client to window
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
293
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
294 self.cbuttons_reload()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
295
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
296 def gui_set_connected(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
297 self.xyb.enable()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
298 self.zb.enable()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
299 for control in self.printerControls:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
300 control.Enable()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
301
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
302 def gui_set_disconnected(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
303 self.printbtn.Disable()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
304 self.pausebtn.Disable()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
305 self.recoverbtn.Disable()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
306 for control in self.printerControls:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
307 control.Disable()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
308 self.xyb.disable()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
309 self.zb.disable()

mercurial