printrun-src/printrun/spoolmanager/spoolmanager_gui.py

Wed, 20 Jan 2021 10:15:13 +0100

author
mdd
date
Wed, 20 Jan 2021 10:15:13 +0100
changeset 46
cce0af6351f0
permissions
-rw-r--r--

updated and added new files for printrun

46
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
1 # This file is part of the Printrun suite.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
2 #
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
3 # Printrun is free software: you can redistribute it and/or modify
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
4 # it under the terms of the GNU General Public License as published by
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
5 # the Free Software Foundation, either version 3 of the License, or
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
6 # (at your option) any later version.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
7 #
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
8 # Printrun is distributed in the hope that it will be useful,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
11 # GNU General Public License for more details.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
12 #
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
13 # You should have received a copy of the GNU General Public License
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
14 # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
15 #
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
16 # Copyright 2017 Rock Storm <rockstorm@gmx.com>
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
17
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
18 import wx
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
19 from . import spoolmanager
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
20
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
21 class SpoolManagerMainWindow(wx.Frame):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
22 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
23 Front-end for the Spool Manager.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
24
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
25 Main window which displays the currently loaded spools and the list of
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
26 recorded ones with buttons to add, load, edit or delete them.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
27 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
28
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
29 def __init__(self, parent, spool_manager):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
30 wx.Frame.__init__(self, parent,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
31 title = "Spool Manager",
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
32 style = wx.DEFAULT_FRAME_STYLE | wx.FRAME_FLOAT_ON_PARENT)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
33
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
34 self.statusbar = self.CreateStatusBar()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
35
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
36 self.SetIcon(parent.GetIcon())
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
37
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
38 # Initiate the back-end
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
39 self.spool_manager = spool_manager
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
40 self.spool_manager.refresh()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
41
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
42 # Generate the dialogs showing the current spools
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
43 self.current_spools_dialog = CurrentSpoolDialog(self,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
44 self.spool_manager)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
45
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
46 # Generate the list of recorded spools
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
47 self.spool_list = SpoolListView(self, self.spool_manager)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
48
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
49 # Generate the buttons
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
50 self.new_button = wx.Button(self, wx.ID_ADD)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
51 self.new_button.SetToolTip("Add a new spool")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
52 self.edit_button = wx.Button(self, wx.ID_EDIT)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
53 self.edit_button.SetToolTip("Edit the selected spool")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
54 self.delete_button = wx.Button(self, wx.ID_DELETE)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
55 self.delete_button.SetToolTip("Delete the selected spool")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
56
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
57 # "Program" the buttons
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
58 self.new_button.Bind(wx.EVT_BUTTON, self.onClickAdd)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
59 self.edit_button.Bind(wx.EVT_BUTTON, self.onClickEdit)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
60 self.delete_button.Bind(wx.EVT_BUTTON, self.onClickDelete)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
61
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
62 # Layout
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
63 ## Group the buttons
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
64 self.button_sizer = wx.BoxSizer(wx.VERTICAL)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
65 self.button_sizer.Add(self.new_button, 1,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
66 wx.FIXED_MINSIZE | wx.ALIGN_CENTER)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
67 self.button_sizer.Add(self.edit_button, 1,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
68 wx.FIXED_MINSIZE | wx.ALIGN_CENTER)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
69 self.button_sizer.Add(self.delete_button, 1,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
70 wx.FIXED_MINSIZE | wx.ALIGN_CENTER)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
71
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
72 ## Group the buttons with the spool list
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
73 self.list_sizer = wx.BoxSizer(wx.HORIZONTAL)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
74 self.list_sizer.Add(self.spool_list, 1, wx.EXPAND)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
75 self.list_sizer.Add(self.button_sizer, 0, wx.ALIGN_CENTER)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
76
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
77 ## Layout the whole thing
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
78 self.full_sizer = wx.BoxSizer(wx.VERTICAL)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
79 self.full_sizer.Add(self.current_spools_dialog, 0, wx.EXPAND)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
80 self.full_sizer.Add(self.list_sizer, 1, wx.ALL | wx.EXPAND, 10)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
81
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
82 self.SetSizerAndFit(self.full_sizer)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
83
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
84 def onClickAdd(self, event):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
85 """Open the window for customizing the new spool."""
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
86 SpoolManagerAddWindow(self).Show(True)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
87
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
88 def onClickLoad(self, event, extruder):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
89 """Load the selected spool to the correspondent extruder."""
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
90
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
91 # Check whether there is a spool selected
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
92 spool_index = self.spool_list.GetFirstSelected()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
93 if spool_index == -1 :
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
94 self.statusbar.SetStatusText(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
95 "Could not load the spool. No spool selected.")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
96 return 0
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
97 else:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
98 spool_name = self.spool_list.GetItemText(spool_index)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
99 self.statusbar.SetStatusText("")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
100
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
101 # If selected spool is already loaded, do nothing
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
102 spool_extruder = self.spool_manager.isLoaded(spool_name)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
103 if spool_extruder > -1:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
104 self.statusbar.SetStatusText(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
105 "Spool '%s' is already loaded for Extruder %d." %
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
106 (spool_name, spool_extruder))
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
107 return 0
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
108
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
109 # Load the selected spool and refresh the current spools dialog
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
110 self.spool_manager.load(spool_name, extruder)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
111 self.current_spools_dialog.refreshDialog(self.spool_manager)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
112 self.statusbar.SetStatusText(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
113 "Loaded spool '%s' for Extruder %d." % (spool_name, extruder))
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
114
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
115 def onClickUnload(self, event, extruder):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
116 """Unload the spool from the correspondent extruder."""
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
117
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
118 spool_name = self.spool_manager.getSpoolName(extruder)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
119 if spool_name != None:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
120 self.spool_manager.unload(extruder)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
121 self.current_spools_dialog.refreshDialog(self.spool_manager)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
122 self.statusbar.SetStatusText(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
123 "Unloaded spool from Extruder %d." % extruder)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
124 else:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
125 self.statusbar.SetStatusText(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
126 "There is no spool loaded for Extruder %d." % extruder)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
127
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
128 def onClickEdit(self, event):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
129 """Open the window for editing the data of the selected spool."""
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
130
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
131 # Check whether there is a spool selected
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
132 spool_index = self.spool_list.GetFirstSelected()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
133 if spool_index == -1 :
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
134 self.statusbar.SetStatusText(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
135 "Could not edit the spool. No spool selected.")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
136 return 0
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
137
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
138 # Open the edit window
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
139 spool_name = self.spool_list.GetItemText(spool_index)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
140 spool_length = self.spool_list.GetItemText(spool_index, 1)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
141 SpoolManagerEditWindow(self, spool_name, spool_length).Show(True)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
142 self.statusbar.SetStatusText("")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
143
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
144 def onClickDelete(self, event):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
145 """Delete the selected spool."""
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
146
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
147 # Get the selected spool
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
148 spool_index = self.spool_list.GetFirstSelected()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
149 if spool_index == -1 :
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
150 self.statusbar.SetStatusText(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
151 "Could not delete the spool. No spool selected.")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
152 return 0
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
153 else:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
154 spool_name = self.spool_list.GetItemText(spool_index)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
155 self.statusbar.SetStatusText("")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
156
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
157 # Ask confirmation for deleting
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
158 delete_dialog = wx.MessageDialog(self,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
159 message = "Are you sure you want to delete the '%s' spool" %
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
160 spool_name,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
161 caption = "Delete Spool",
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
162 style = wx.YES_NO | wx.ICON_EXCLAMATION)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
163
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
164 if delete_dialog.ShowModal() == wx.ID_YES:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
165 # Remove spool
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
166 self.spool_manager.remove(spool_name)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
167 self.spool_list.refreshList(self.spool_manager)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
168 self.current_spools_dialog.refreshDialog(self.spool_manager)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
169 self.statusbar.SetStatusText(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
170 "Deleted spool '%s'." % spool_name)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
171
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
172
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
173 class SpoolListView(wx.ListView):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
174 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
175 Custom wxListView object which visualizes the list of available spools.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
176 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
177
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
178 def __init__(self, parent, spool_manager):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
179 wx.ListView.__init__(self, parent,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
180 style = wx.LC_REPORT | wx.LC_SINGLE_SEL)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
181 self.InsertColumn(0, "Spool", width = wx.LIST_AUTOSIZE_USEHEADER)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
182 self.InsertColumn(1, "Filament", width = wx.LIST_AUTOSIZE_USEHEADER)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
183 self.populateList(spool_manager)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
184
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
185 # "Program" the layout
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
186 self.Bind(wx.EVT_SIZE, self.onResizeList)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
187
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
188 def populateList(self, spool_manager):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
189 """Get the list of recorded spools from the Spool Manager."""
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
190 spool_list = spool_manager.getSpoolList()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
191 for i in range(len(spool_list)):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
192 self.Append(spool_list[i])
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
193
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
194 def refreshList(self, spool_manager):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
195 """Refresh the list by re-reading the Spool Manager list."""
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
196 self.DeleteAllItems()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
197 self.populateList(spool_manager)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
198
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
199 def onResizeList(self, event):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
200 list_size = self.GetSize()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
201 self.SetColumnWidth(1, -2)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
202 filament_column_width = self.GetColumnWidth(1)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
203 self.SetColumnWidth(col = 0,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
204 width = list_size.width - filament_column_width)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
205 event.Skip()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
206
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
207
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
208 class CurrentSpoolDialog(wx.Panel):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
209 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
210 Custom wxStaticText object to display the currently loaded spools and
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
211 their remaining filament.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
212 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
213
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
214 def __init__(self, parent, spool_manager):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
215 wx.Panel.__init__(self, parent)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
216 self.parent = parent
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
217 self.extruders = spool_manager.getExtruderCount()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
218
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
219 full_sizer = wx.BoxSizer(wx.VERTICAL)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
220
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
221 # Calculate the minimum size needed to properly display the
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
222 # extruder information
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
223 min_size = self.GetTextExtent(" Remaining filament: 0000000.00")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
224
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
225 # Generate a dialog for every extruder
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
226 self.extruder_dialog = []
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
227 load_button = []
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
228 unload_button = []
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
229 button_sizer = []
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
230 dialog_sizer = []
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
231 for i in range(self.extruders):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
232 # Generate the dialog with the spool information
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
233 self.extruder_dialog.append(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
234 wx.StaticText(self, style = wx.ST_ELLIPSIZE_END))
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
235 self.extruder_dialog[i].SetMinSize(wx.Size(min_size.width, -1))
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
236
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
237 # Generate the "load" and "unload" buttons
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
238 load_button.append(wx.Button(self, label = "Load"))
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
239 load_button[i].SetToolTip(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
240 "Load selected spool for Extruder %d" % i)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
241 unload_button.append(wx.Button(self, label = "Unload"))
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
242 unload_button[i].SetToolTip(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
243 "Unload the spool for Extruder %d" % i)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
244
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
245 # "Program" the buttons
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
246 load_button[i].Bind(wx.EVT_BUTTON,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
247 lambda event, extruder=i: parent.onClickLoad(event, extruder))
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
248 unload_button[i].Bind(wx.EVT_BUTTON,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
249 lambda event, extruder=i: parent.onClickUnload(event, extruder))
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
250
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
251 # Layout
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
252 button_sizer.append(wx.BoxSizer(wx.VERTICAL))
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
253 button_sizer[i].Add(load_button[i], 0,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
254 wx.FIXED_MINSIZE | wx.ALIGN_CENTER)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
255 button_sizer[i].Add(unload_button[i], 0,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
256 wx.FIXED_MINSIZE | wx.ALIGN_CENTER)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
257
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
258 dialog_sizer.append(wx.BoxSizer(wx.HORIZONTAL))
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
259 dialog_sizer[i].Add(self.extruder_dialog[i], 1, wx.ALIGN_CENTER)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
260 dialog_sizer[i].AddSpacer(10)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
261 dialog_sizer[i].Add(button_sizer[i], 0, wx.EXPAND)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
262
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
263 full_sizer.Add(dialog_sizer[i], 0, wx.ALL | wx.EXPAND, 10)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
264
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
265 self.refreshDialog(spool_manager)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
266
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
267 self.SetSizerAndFit(full_sizer)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
268
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
269
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
270 def refreshDialog(self, spool_manager):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
271 """Retrieve the current spools from the Spool Manager."""
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
272
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
273 for i in range(self.extruders):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
274 spool_name = spool_manager.getSpoolName(i)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
275 spool_filament = spool_manager.getRemainingFilament(i)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
276 label = ("Spool for Extruder %d:\n" % i +
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
277 " Name: %s\n" % spool_name +
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
278 " Remaining filament: %.2f" % spool_filament)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
279 self.extruder_dialog[i].SetLabelText(label)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
280
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
281
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
282 # ---------------------------------------------------------------------------
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
283 def checkOverwrite(parent, spool_name):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
284 """Ask the user whether or not to overwrite the existing spool."""
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
285
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
286 overwrite_dialog = wx.MessageDialog(parent,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
287 message = "A spool with the name '%s'' already exists." %
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
288 spool_name +
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
289 "Do you wish to overwrite it?",
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
290 caption = "Overwrite",
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
291 style = wx.YES_NO | wx.ICON_EXCLAMATION)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
292
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
293 if overwrite_dialog.ShowModal() == wx.ID_YES:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
294 return True
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
295 else:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
296 return False
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
297
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
298 def getFloat(parent, number):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
299 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
300 Check whether the input number is a float. Either return the number or
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
301 return False.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
302 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
303 try:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
304 return float(number)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
305 except ValueError:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
306 parent.statusbar.SetStatusText("Unrecognized number: %s" % number)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
307 return False
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
308
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
309
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
310 # ---------------------------------------------------------------------------
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
311 class SpoolManagerAddWindow(wx.Frame):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
312 """Window for adding spools."""
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
313
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
314 def __init__(self, parent):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
315
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
316 wx.Frame.__init__(self, parent,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
317 title = "Add Spool",
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
318 style = wx.DEFAULT_FRAME_STYLE | wx.FRAME_FLOAT_ON_PARENT)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
319
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
320 self.statusbar = self.CreateStatusBar()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
321
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
322 self.parent = parent
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
323
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
324 self.SetIcon(parent.GetIcon())
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
325
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
326 # Generate the dialogs
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
327 self.name_dialog = LabeledTextCtrl(self,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
328 "Name", "Default Spool", "")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
329 self.diameter_dialog = LabeledTextCtrl(self,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
330 "Diameter", "1.75", "mm")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
331 self.diameter_dialog.SetToolTip(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
332 "Typically, either 1.75 mm or 2.85 mm (a.k.a '3')")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
333 self.weight_dialog = LabeledTextCtrl(self,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
334 "Weight", "1", "Kg")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
335 self.density_dialog = LabeledTextCtrl(self,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
336 "Density", "1.25", "g/cm^3")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
337 self.density_dialog.SetToolTip(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
338 "Typical densities are 1.25 g/cm^3 for PLA and 1.08 g/cm^3 for" +
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
339 " ABS")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
340 self.length_dialog = LabeledTextCtrl(self,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
341 "Length", "332601.35", "mm")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
342
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
343 # "Program" the dialogs
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
344 self.diameter_dialog.Bind(wx.EVT_TEXT, self.calculateLength)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
345 self.weight_dialog.Bind(wx.EVT_TEXT, self.calculateLength)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
346 self.density_dialog.Bind(wx.EVT_TEXT, self.calculateLength)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
347 self.length_dialog.Bind(wx.EVT_TEXT, self.calculateWeight)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
348
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
349 # Generate the bottom buttons
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
350 self.add_button = wx.Button(self, wx.ID_ADD)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
351 self.cancel_button = wx.Button(self, wx.ID_CANCEL)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
352
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
353 # "Program" the bottom buttons
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
354 self.add_button.Bind(wx.EVT_BUTTON, self.onClickAdd)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
355 self.cancel_button.Bind(wx.EVT_BUTTON, self.onClickCancel)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
356
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
357 # Layout
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
358 ## Group the bottom buttons
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
359 self.bottom_buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
360 self.bottom_buttons_sizer.Add(self.add_button, 0, wx.FIXED_MINSIZE)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
361 self.bottom_buttons_sizer.Add(self.cancel_button, 0, wx.FIXED_MINSIZE)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
362
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
363 ## Group the whole window
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
364 self.full_sizer = wx.BoxSizer(wx.VERTICAL)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
365 self.full_sizer.Add(self.name_dialog, 0,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
366 wx.TOP | wx.BOTTOM | wx.EXPAND, 10)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
367 self.full_sizer.Add(self.diameter_dialog, 0, wx.EXPAND)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
368 self.full_sizer.Add(self.weight_dialog, 0, wx.EXPAND)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
369 self.full_sizer.Add(self.density_dialog, 0, wx.EXPAND)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
370 self.full_sizer.Add(self.length_dialog, 0, wx.EXPAND)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
371 self.full_sizer.Add(self.bottom_buttons_sizer, 0,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
372 wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 10)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
373
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
374 self.SetSizerAndFit(self.full_sizer)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
375
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
376 # Don't allow this window to be resized in height
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
377 add_window_size = self.GetSize()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
378 self.SetMaxSize((-1, add_window_size.height))
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
379
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
380 def onClickAdd(self, event):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
381 """Add the new spool and close the window."""
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
382
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
383 spool_name = self.name_dialog.field.GetValue()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
384 spool_length = getFloat(self, self.length_dialog.field.GetValue())
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
385
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
386 # Check whether the length is actually a number
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
387 if not spool_length:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
388 self.statusbar.SetStatusText(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
389 "ERROR: Unrecognized length: %s." %
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
390 self.length_dialog.field.GetValue())
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
391 return -1
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
392
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
393 # The remaining filament should always be a positive number
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
394 if not spool_length > 0:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
395 self.statusbar.SetStatusText(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
396 "ERROR: Length is zero or negative: %.2f." % spool_length)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
397 return -1
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
398
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
399 # Check whether the name is already used. If it is used, prompt the
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
400 # user before overwriting it
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
401 if self.parent.spool_manager.isListed(spool_name):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
402 if checkOverwrite(self, spool_name):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
403 # Remove the "will be overwritten" spool
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
404 self.parent.spool_manager.remove(spool_name)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
405 else:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
406 return 0
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
407
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
408 # Add the new spool
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
409 self.parent.spool_manager.add(spool_name, spool_length)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
410 self.parent.spool_list.refreshList(self.parent.spool_manager)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
411 self.parent.current_spools_dialog.refreshDialog(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
412 self.parent.spool_manager)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
413 self.parent.statusbar.SetStatusText(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
414 "Added new spool '%s'" % spool_name +
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
415 " with %.2f mm of remaining filament." % spool_length)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
416
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
417 self.Close(True)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
418
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
419 def onClickCancel(self, event):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
420 """Do nothing and close the window."""
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
421 self.Close(True)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
422 self.parent.statusbar.SetStatusText("")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
423
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
424 def calculateLength(self, event):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
425 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
426 Calculate the length of the filament given the mass, diameter and
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
427 density of the filament. Set the 'Length' field to this quantity.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
428 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
429
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
430 mass = getFloat(self, self.weight_dialog.field.GetValue())
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
431 diameter = getFloat(self, self.diameter_dialog.field.GetValue())
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
432 density = getFloat(self, self.density_dialog.field.GetValue())
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
433 if mass and diameter and density:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
434 pi = 3.14159265359
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
435 length = 4e6 * mass / pi / diameter**2 / density
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
436 self.length_dialog.field.ChangeValue("%.2f" % length)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
437 self.statusbar.SetStatusText("")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
438 else:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
439 self.length_dialog.field.ChangeValue("---")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
440
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
441 def calculateWeight(self, event):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
442 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
443 Calculate the weight of the filament given the length, diameter and
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
444 density of the filament. Set the 'Weight' field to this value.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
445 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
446
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
447 length = getFloat(self, self.length_dialog.field.GetValue())
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
448 diameter = getFloat(self, self.diameter_dialog.field.GetValue())
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
449 density = getFloat(self, self.density_dialog.field.GetValue())
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
450 if length and diameter and density:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
451 pi = 3.14159265359
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
452 mass = length * pi * diameter**2 * density / 4e6
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
453 self.weight_dialog.field.ChangeValue("%.2f" % mass)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
454 self.statusbar.SetStatusText("")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
455 else:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
456 self.weight_dialog.field.ChangeValue("---")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
457
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
458
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
459 class LabeledTextCtrl(wx.Panel):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
460 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
461 Group together a wxTextCtrl with a preceding and a subsequent wxStaticText.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
462 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
463
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
464 def __init__(self, parent, preceding_text, field_value, subsequent_text):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
465 wx.Panel.__init__(self, parent)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
466 self.pretext = wx.StaticText(self, label = preceding_text,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
467 style = wx.ALIGN_RIGHT)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
468 self.field = wx.TextCtrl(self, value = field_value)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
469 self.subtext = wx.StaticText(self, label = subsequent_text)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
470
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
471 # Layout the panel
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
472 self.sizer = wx.BoxSizer(wx.HORIZONTAL)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
473 self.sizer.Add(self.pretext, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 10)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
474 self.sizer.SetItemMinSize(self.pretext, (80, -1))
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
475 self.sizer.Add(self.field, 1, wx.EXPAND)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
476 self.sizer.Add(self.subtext, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 10)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
477 self.sizer.SetItemMinSize(self.subtext, (50, -1))
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
478
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
479 self.SetSizerAndFit(self.sizer)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
480
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
481
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
482 # ---------------------------------------------------------------------------
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
483 class SpoolManagerEditWindow(wx.Frame):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
484 """Window for editing the name or the length of a spool."""
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
485
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
486 def __init__(self, parent, spool_name, spool_length):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
487
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
488 wx.Frame.__init__(self, parent,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
489 title = "Edit Spool",
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
490 style = wx.DEFAULT_FRAME_STYLE | wx.FRAME_FLOAT_ON_PARENT)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
491
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
492 self.statusbar = self.CreateStatusBar()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
493
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
494 self.parent = parent
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
495
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
496 self.SetIcon(parent.GetIcon())
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
497
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
498 self.old_spool_name = spool_name
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
499 self.old_spool_length = getFloat(self, spool_length)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
500
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
501 # Set how many millimeters will the buttons add or subtract
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
502 self.quantities = [-100.0, -50.0, -10.0, 10.0, 50.0, 100.0]
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
503
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
504 # Generate the name field
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
505 self.name_field = LabeledTextCtrl(self,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
506 "Name", self.old_spool_name, "")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
507
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
508 # Generate the length field and buttons
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
509 self.length_title = wx.StaticText(self, label = "Remaining filament:")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
510 self.minus3_button = wx.Button(self,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
511 label = str(self.quantities[0]), style = wx.BU_EXACTFIT)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
512 self.minus2_button = wx.Button(self,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
513 label = str(self.quantities[1]), style = wx.BU_EXACTFIT)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
514 self.minus1_button = wx.Button(self,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
515 label = str(self.quantities[2]), style = wx.BU_EXACTFIT)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
516 self.length_field = wx.TextCtrl(self,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
517 value = str(self.old_spool_length))
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
518 self.plus1_button = wx.Button(self,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
519 label = "+" + str(self.quantities[3]), style = wx.BU_EXACTFIT)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
520 self.plus2_button = wx.Button(self,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
521 label = "+" + str(self.quantities[4]), style = wx.BU_EXACTFIT)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
522 self.plus3_button = wx.Button(self,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
523 label = "+" + str(self.quantities[5]), style = wx.BU_EXACTFIT)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
524
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
525 # "Program" the length buttons
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
526 self.minus3_button.Bind(wx.EVT_BUTTON, self.changeLength)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
527 self.minus2_button.Bind(wx.EVT_BUTTON, self.changeLength)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
528 self.minus1_button.Bind(wx.EVT_BUTTON, self.changeLength)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
529 self.plus1_button.Bind(wx.EVT_BUTTON, self.changeLength)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
530 self.plus2_button.Bind(wx.EVT_BUTTON, self.changeLength)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
531 self.plus3_button.Bind(wx.EVT_BUTTON, self.changeLength)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
532
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
533 # Generate the bottom buttons
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
534 self.save_button = wx.Button(self, wx.ID_SAVE)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
535 self.cancel_button = wx.Button(self, wx.ID_CANCEL)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
536
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
537 # "Program" the bottom buttons
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
538 self.save_button.Bind(wx.EVT_BUTTON, self.onClickSave)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
539 self.cancel_button.Bind(wx.EVT_BUTTON, self.onClickCancel)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
540
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
541 # Layout
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
542 ## Group the length field and its correspondent buttons
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
543 self.length_sizer = wx.BoxSizer(wx.HORIZONTAL)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
544 self.length_sizer.Add(self.minus3_button, 0,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
545 wx.FIXED_MINSIZE | wx.ALIGN_CENTER)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
546 self.length_sizer.Add(self.minus2_button, 0,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
547 wx.FIXED_MINSIZE | wx.ALIGN_CENTER)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
548 self.length_sizer.Add(self.minus1_button, 0,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
549 wx.FIXED_MINSIZE | wx.ALIGN_CENTER)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
550 self.length_sizer.Add(self.length_field, 1, wx.EXPAND)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
551 self.length_sizer.Add(self.plus1_button, 0,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
552 wx.FIXED_MINSIZE | wx.ALIGN_CENTER)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
553 self.length_sizer.Add(self.plus2_button, 0,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
554 wx.FIXED_MINSIZE | wx.ALIGN_CENTER)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
555 self.length_sizer.Add(self.plus3_button, 0,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
556 wx.FIXED_MINSIZE | wx.ALIGN_CENTER)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
557
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
558 ## Group the bottom buttons
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
559 self.bottom_buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
560 self.bottom_buttons_sizer.Add(self.save_button, 0, wx.EXPAND)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
561 self.bottom_buttons_sizer.Add(self.cancel_button, 0, wx.EXPAND)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
562
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
563 ## Lay out the whole window
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
564 self.full_sizer = wx.BoxSizer(wx.VERTICAL)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
565 self.full_sizer.Add(self.name_field, 0, wx.EXPAND)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
566 self.full_sizer.AddSpacer(10)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
567 self.full_sizer.Add(self.length_title, 0,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
568 wx.LEFT | wx.RIGHT | wx.EXPAND, 10)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
569 self.full_sizer.Add(self.length_sizer, 0,
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
570 wx.LEFT | wx.RIGHT | wx.EXPAND, 10)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
571 self.full_sizer.AddSpacer(10)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
572 self.full_sizer.Add(self.bottom_buttons_sizer, 0, wx.ALIGN_CENTER)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
573
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
574 self.SetSizerAndFit(self.full_sizer)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
575
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
576 # Don't allow this window to be resized in height
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
577 edit_window_size = self.GetSize()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
578 self.SetMaxSize((-1, edit_window_size.height))
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
579
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
580 def changeLength(self, event):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
581 new_length = getFloat(self, self.length_field.GetValue())
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
582 if new_length:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
583 new_length = new_length + float(event.GetEventObject().GetLabel())
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
584 self.length_field.ChangeValue("%.2f" % new_length)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
585 self.statusbar.SetStatusText("")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
586
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
587 def onClickSave(self, event):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
588
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
589 new_spool_name = self.name_field.field.GetValue()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
590 new_spool_length = getFloat(self, self.length_field.GetValue())
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
591
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
592 # Check whether the length is actually a number
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
593 if not new_spool_length:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
594 self.statusbar.SetStatusText(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
595 "ERROR: Unrecognized length: %s." %
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
596 self.length_field.GetValue())
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
597 return -1
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
598
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
599 if not new_spool_length > 0:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
600 self.statusbar.SetStatusText(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
601 "ERROR: Length is zero or negative: %.2f." % new_spool_length)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
602 return -1
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
603
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
604 # Check whether the "old" spool was loaded
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
605 new_spool_extruder = self.parent.spool_manager.isLoaded(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
606 self.old_spool_name)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
607
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
608 # Check whether the name has changed
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
609 if new_spool_name == self.old_spool_name:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
610 # Remove only the "old" spool
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
611 self.parent.spool_manager.remove(self.old_spool_name)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
612 else:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
613 # Check whether the new name is already used
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
614 if self.parent.spool_manager.isListed(new_spool_name):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
615 if checkOverwrite(self, new_spool_name):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
616 # Remove the "old" and the "will be overwritten" spools
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
617 self.parent.spool_manager.remove(self.old_spool_name)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
618 self.parent.spool_manager.remove(new_spool_name)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
619 else:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
620 return 0
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
621 else:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
622 # Remove only the "old" spool
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
623 self.parent.spool_manager.remove(self.old_spool_name)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
624
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
625 # Add "new" or edited spool
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
626 self.parent.spool_manager.add(new_spool_name, new_spool_length)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
627 self.parent.spool_manager.load(new_spool_name, new_spool_extruder)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
628 self.parent.spool_list.refreshList(self.parent.spool_manager)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
629 self.parent.current_spools_dialog.refreshDialog(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
630 self.parent.spool_manager)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
631 self.parent.statusbar.SetStatusText(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
632 "Edited spool '%s'" % new_spool_name +
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
633 " with %.2f mm of remaining filament." % new_spool_length)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
634
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
635 self.Close(True)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
636
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
637 def onClickCancel(self, event):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
638 self.Close(True)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
639 self.parent.statusbar.SetStatusText("")

mercurial