printrun-src/printrun/spoolmanager/spoolmanager.py

Wed, 20 Jan 2021 10:17:01 +0100

author
mdd
date
Wed, 20 Jan 2021 10:17:01 +0100
changeset 47
dcc64b767b64
parent 46
cce0af6351f0
permissions
-rw-r--r--

updated pronterface.py losing my own changes

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 # This module indirectly depends of pronsole and settings but it does not
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
19 # import them
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 SpoolManager():
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 Back-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 It is expected to be called from an object which has the contents of
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
26 settings.py and pronsole.py. This way the class is able to '_add' and
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
27 'set' settings.
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 This class basically handles a single variable called '_spool_list'. It is
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
30 a list of spool_items. A spool_item is in turn a list three elements: a
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
31 string, a float and an integer. Namely: the name of the spool, the
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
32 remaining length of filament and the extruder it is loaded to. E.g.:
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 spool_item = [string name, float length, int extruder]
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 _spool_list = [spool_item spool_1, ... , spool_item spool_n ]
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 '_spool_list' is somehow a Nx3 matrix where N is the number of recorded
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
39 spools. The first column contains the names of the spools, the second the
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
40 lengths of remaining filament and the third column contains which extruder
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
41 is the spool loaded for.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
42
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
43 The variable '_spool_list' is saved in the configuration file using a
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
44 setting with the same name: 'spool_list'. It is saved as a single string.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
45 It concatenates every item from the list and separates them by a comma and
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
46 a space. For instance, if the variable '_spool_list' was:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
47
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
48 _spool_list = [["spool_1", 100.0, 0], ["spool_2", 200.0, -1]]
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
49
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
50 The 'spool_list' setting will look like:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
51
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
52 "spool_1, 100.0, 0, spool_2, 200.0, -1"
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
53 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
54
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
55 def __init__(self, parent):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
56 self.parent = parent
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
57 self.refresh()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
58
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
59 def refresh(self):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
60 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
61 Read the configuration file and populate the list of recorded spools.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
62 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
63 self._spool_list = self._readSetting(self.parent.settings.spool_list)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
64
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
65 def add(self, spool_name, spool_length):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
66 """Add the given spool to the list of recorded spools."""
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
67 self._spool_list.append([spool_name, spool_length, -1])
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
68 self._save()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
69
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
70 def load(self, spool_name, extruder):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
71 """Set the extruder field of the given spool item."""
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
72
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
73 # If there was a spool already loaded for this extruder unload it
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
74 previous_spool = self._findByColumn(extruder, 2)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
75 if previous_spool != -1:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
76 self.unload(extruder)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
77
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
78 # Load the given spool
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
79 new_spool = self._findByColumn(spool_name, 0)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
80 self.remove(spool_name)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
81 self._spool_list.append([new_spool[0], new_spool[1], extruder])
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
82 self._save()
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 remove(self, spool_name):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
85 """Remove the given spool item from the list of recorded spools."""
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
86 spool_item = self._findByColumn(spool_name, 0)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
87 self._spool_list.remove(spool_item)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
88 self._save()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
89
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
90 def unload(self, extruder):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
91 """Set to -1 the extruder field of the spool item currently on."""
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
92
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
93 spool_item = self._findByColumn(extruder, 2)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
94 if spool_item != -1:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
95 self.remove(spool_item[0])
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
96 self._spool_list.append([spool_item[0], spool_item[1], -1])
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
97 self._save()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
98
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
99 def isLoaded(self, spool_name):
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 int isLoaded( string name )
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
102
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
103 Return the extruder that the given spool is loaded to. -1 if it is
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
104 not loaded for any extruder or None if the given name does not match
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
105 any known spool.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
106 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
107
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
108 spool_item = self._findByColumn(spool_name, 0)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
109 if spool_item != -1:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
110 return spool_item[2]
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
111 else:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
112 return None
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
113
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
114 def isListed(self, spool_name):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
115 """Return 'True' if the given spool is on the list."""
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
116
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
117 spool_item = self._findByColumn(spool_name, 0)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
118 if not spool_item == -1:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
119 return True
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
120 else:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
121 return False
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
122
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
123 def getSpoolName(self, extruder):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
124 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
125 string getSpoolName( int extruder )
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
126
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
127 Return the name of the spool loaded for the given extruder.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
128 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
129
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
130 spool_item = self._findByColumn(extruder, 2)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
131 if spool_item != -1:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
132 return spool_item[0]
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
133 else:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
134 return None
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
135
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
136 def getRemainingFilament(self, extruder):
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 float getRemainingFilament( int extruder )
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
139
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
140 Return the name of the spool loaded for the given extruder.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
141 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
142
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
143 spool_item = self._findByColumn(extruder, 2)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
144 if spool_item != -1:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
145 return spool_item[1]
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
146 else:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
147 return float("NaN")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
148
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
149 def editLength(self, increment, spool_name = None, extruder = -1):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
150 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
151 int editLength ( float increment, string spool_name, int extruder )
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
152
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
153 Add the given 'increment' amount to the length of filament of the
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
154 given spool. Spool can be specified either by name or by the extruder
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
155 it is loaded to.
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
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
158 if spool_name != None:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
159 spool_item = self._findByColumn(spool_name, 0)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
160 elif extruder != -1:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
161 spool_item = self._findByColumn(extruder, 2)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
162 else:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
163 return -1 # Not enough arguments
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
164
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
165 if spool_item == -1:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
166 return -2 # No spool found for the given name or extruder
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
167
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
168 length = spool_item[1] + increment
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
169 self.remove(spool_item[0])
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
170 self.add(spool_item[0], length)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
171 if spool_item[2] > -1:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
172 self.load(spool_item[0], spool_item[2])
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
173 self._save()
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 return 0
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 def getExtruderCount(self):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
178 """int getExtruderCount()"""
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
179 return self.parent.settings.extruders
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
180
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
181 def getSpoolCount(self):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
182 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
183 int getSpoolCount()
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 Return the number of currently recorded spools.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
186 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
187 return len(self._spool_list)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
188
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
189 def getSpoolList(self):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
190 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
191 [N][2] getSpoolList ()
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
192
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
193 Returns a list of the recorded spools. Returns a Nx2 matrix where N is
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
194 the number of recorded spools. The first column contains the names of
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
195 the spools and the second the lengths of remaining filament.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
196 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
197
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
198 slist = []
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
199 for i in range(self.getSpoolCount()):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
200 item = [self._spool_list[i][0], self._spool_list[i][1]]
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
201 slist.append(item)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
202 return slist
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
203
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
204 def _findByColumn(self, data, col = 0):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
205 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
206 Find which spool_item from the list contains certain data.
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 The 'col' argument specifies in which field from the spool_item to
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
209 look for. For instance, with the following list:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
210
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
211 _spool_list = [["spool_1", 100.0, 1],
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
212 ["spool_2", 200.0, 0],
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 .
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
215 .
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
216 ["spool_10", 1000.0, 0]]
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
217
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
218 A call like: _findByColumn("spool_2", 0)
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
219
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
220 Will produce: ["spool_2", 200.0, 0]
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
221
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
222 col = 0, would look into the "name's column"
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
223 col = 1, would look into the "length's column"
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
224 col = 2, would look into the "extruder's column"
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
225 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
226
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
227 for spool_item in self._spool_list:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
228 if data == spool_item[col]:
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
229 return spool_item
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
230
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
231 return -1
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
232
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
233 def _save(self):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
234 """Update the list of recorded spools in the configuration file."""
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
235 self._setSetting(self._spool_list, "spool_list")
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 def _setSetting(self, variable, setting):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
238 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
239 Write the given variable to the given setting of the configuration
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
240 file.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
241 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
242 n = 3 # number of fields in spool_item
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
243 string_list = []
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
244 for i in range(len(variable)):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
245 for j in range(n):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
246 string_list.append(str(variable[i][j]))
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
247 separator = ", "
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
248 self.parent.set(setting, separator.join(string_list))
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
249
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
250 def _readSetting(self, setting):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
251 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
252 Return the variable read.
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
253 """
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
254 n = 3 # number of fields in spool_item
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
255 string_list = setting.split(", ")
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
256 variable = []
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
257 for i in range(len(string_list)//n):
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
258 variable.append(
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
259 [string_list[n*i],
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
260 float(string_list[n*i+1]),
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
261 int(string_list[n*i+2])])
cce0af6351f0 updated and added new files for printrun
mdd
parents:
diff changeset
262 return variable

mercurial