itkdb-gtk 0.10.9.dev4__py3-none-any.whl → 0.10.10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of itkdb-gtk might be problematic. Click here for more details.

@@ -0,0 +1,299 @@
1
+ #!/usr/bin/env python3
2
+ """Module Visual inspection GUI."""
3
+ import sys
4
+ import re
5
+ from pathlib import Path
6
+
7
+ try:
8
+ import itkdb_gtk
9
+
10
+ except ImportError:
11
+ cwd = Path(__file__).parent.parent
12
+ sys.path.append(cwd.as_posix())
13
+
14
+ from itkdb_gtk import dbGtkUtils, ITkDBlogin, ITkDButils
15
+ from itkdb_gtk.ShowComments import ShowComments
16
+ from itkdb_gtk.ShowDefects import ShowDefects
17
+ from itkdb_gtk.ShowAttachments import ShowAttachments
18
+ from itkdb_gtk.UploadTest import UploadTest
19
+
20
+ import gi
21
+ gi.require_version("Gtk", "3.0")
22
+ from gi.repository import Gtk, Gio
23
+
24
+
25
+ module_type = re.compile("20USE(M[0-5]{1}|[345]{1}[LR]{1})[0-9]{7}")
26
+ sensor_type = re.compile("20USES[0-5]{1}[0-9]{7}")
27
+
28
+
29
+ class ModuleVisualInspection(dbGtkUtils.ITkDBWindow):
30
+ """Module/Sensor Visual Inspection."""
31
+
32
+ def __init__(self, session, title="Visual Inspection", help_link=None):
33
+ super().__init__(title=title,
34
+ session=session,
35
+ show_search="Find object with given SN.",
36
+ help_link=help_link)
37
+
38
+ self.institute = self.pdb_user["institutions"][0]["code"]
39
+ self.global_image = None
40
+ self.global_link = None
41
+ self.data = None
42
+ self.currentStage = None
43
+ self.attachments = []
44
+ self.comments = []
45
+ self.defects = []
46
+
47
+ # action button in header
48
+ button = Gtk.Button()
49
+ icon = Gio.ThemedIcon(name="document-send-symbolic")
50
+ image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON)
51
+ button.add(image)
52
+ button.set_tooltip_text("Click to upload the test.")
53
+ button.connect("clicked", self.upload_test)
54
+ self.hb.pack_end(button)
55
+
56
+ grid = Gtk.Grid(column_spacing=10, row_spacing=5)
57
+ self.mainBox.pack_start(grid, False, False, 5)
58
+
59
+ irow = 0
60
+ receiver = self.create_institute_combo(only_user=True)
61
+ receiver.connect("changed", self.on_institute)
62
+ receiver.set_tooltip_text("Select the Institute making the test.")
63
+ dbGtkUtils.set_combo_iter(receiver, self.institute)
64
+
65
+ lbl = Gtk.Label(label="Institute")
66
+ lbl.set_xalign(0)
67
+ grid.attach(lbl, 0, irow, 1, 1)
68
+ grid.attach(receiver, 1, irow, 1, 1)
69
+
70
+ self.obj_type = None
71
+ self.obj_type_label = Gtk.Label()
72
+ self.obj_type_label.set_xalign(0)
73
+ grid.attach(self.obj_type_label, 2, irow, 1, 1)
74
+
75
+ irow += 1
76
+ lbl = Gtk.Label(label="Serial Number")
77
+ lbl.set_xalign(0)
78
+ grid.attach(lbl, 0, irow, 1, 1)
79
+
80
+ self.SN = dbGtkUtils.TextEntry(small=True)
81
+ self.SN.connect("text_changed", self.SN_ready)
82
+ self.SN.widget.set_tooltip_text("Enter SN of module.")
83
+ grid.attach(self.SN.widget, 1, irow, 1, 1)
84
+
85
+
86
+ self.passed = Gtk.Switch()
87
+ self.passed.props.halign = Gtk.Align.START
88
+ self.passed.set_active(True)
89
+ lbl = Gtk.Label(label="Passed")
90
+ lbl.set_xalign(0)
91
+ grid.attach(lbl, 2, irow, 1, 1)
92
+ grid.attach(self.passed, 3, irow, 1, 1)
93
+
94
+
95
+ irow += 1
96
+ lbl = Gtk.Label(label="Date")
97
+ lbl.set_xalign(0)
98
+ grid.attach(lbl, 0, irow, 1, 1)
99
+
100
+ self.date = dbGtkUtils.TextEntry(small=True)
101
+ grid.attach(self.date.widget, 1, irow, 1, 1)
102
+ self.date.entry.set_text(ITkDButils.get_db_date())
103
+ self.date.connect("text_changed", self.new_date)
104
+
105
+ self.problems = Gtk.Switch()
106
+ self.problems.props.halign = Gtk.Align.START
107
+ self.problems.set_active(False)
108
+ lbl = Gtk.Label(label="Problems")
109
+ lbl.set_xalign(0)
110
+ grid.attach(lbl, 2, irow, 1, 1)
111
+ grid.attach(self.problems, 3, irow, 1, 1)
112
+
113
+ irow +=1
114
+ self.reception = Gtk.Switch()
115
+ self.reception.props.halign = Gtk.Align.START
116
+ self.reception.set_active(False)
117
+ lbl = Gtk.Label(label="Reception VI")
118
+ lbl.set_xalign(0)
119
+ grid.attach(lbl, 0, irow, 1, 1)
120
+ grid.attach(self.reception, 1, irow, 1, 1)
121
+
122
+ irow +=1
123
+ lbl = Gtk.Label()
124
+ grid.attach(lbl, 0, irow, 1, 1)
125
+
126
+ # The "Add attachment" button.
127
+ box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
128
+ self.mainBox.pack_start(box, False, False, 0)
129
+ self.btn_attch = dbGtkUtils.add_button_to_container(box, "Attachments",
130
+ "Click to edit attachments.",
131
+ self.edit_attachments)
132
+
133
+ self.btn_comments = dbGtkUtils.add_button_to_container(box, "Comments",
134
+ "Click to edit comments.",
135
+ self.edit_comments)
136
+
137
+ self.btn_defects = dbGtkUtils.add_button_to_container(box, "Defects",
138
+ "Click to edit defects.",
139
+ self.edit_defects)
140
+
141
+ self.mainBox.pack_start(self.message_panel.frame, True, True, 5)
142
+ self.write_message("Module Visual Inspection\n")
143
+ self.show_all()
144
+
145
+ dbGtkUtils.setup_scanner(self.get_qrcode)
146
+
147
+ def on_institute(self, combo):
148
+ """A new recipient has been chosen."""
149
+ name = self.get_institute_from_combo(combo)
150
+ if name:
151
+ self.institute = name
152
+
153
+ def new_date(self, entry, value):
154
+ """new date given at input."""
155
+ d = dbGtkUtils.parse_date_as_string(value)
156
+ if d is not None:
157
+ self.date.set_text(d)
158
+
159
+ def SN_ready(self, *args):
160
+ """SN is ready in the TextEnttry."""
161
+ SN = self.SN.get_text()
162
+ # GEt children.
163
+ module = ITkDButils.get_DB_component(self.session, SN)
164
+ if module is None:
165
+ self.write_message(ITkDButils.get_db_response())
166
+ return
167
+
168
+ SN = module["serialNumber"]
169
+ if module_type.match(SN):
170
+ self.obj_type_label.set_markup("<b><big>Module</big></b>")
171
+ self.obj_type = "MODULE"
172
+ elif sensor_type.match(SN):
173
+ self.obj_type_label.set_text("<b><big>Sensor</big></b>")
174
+ self.obj_type = "SENSOR"
175
+ else:
176
+ self.obj_type_label.set_text("Invalid SN")
177
+ self.obj_type = None
178
+ dbGtkUtils.complain("Invalid SN", "Not a module nor a sensor.")
179
+
180
+ self.reception.set_sensitive(True)
181
+ self.reception.set_active(False)
182
+ self.currentStage = module["currentStage"]["code"]
183
+ if self.obj_type == "MODULE" and self.currentStage in ["AT_LOADING_SITE", "STITCH_BONDING"]:
184
+ self.reception.set_active(True)
185
+ self.reception.set_sensitive(False)
186
+
187
+ args[0].set_text(SN)
188
+
189
+
190
+ def edit_attachments(self, *args):
191
+ """Edit test attachmetns."""
192
+ SA = ShowAttachments("Test Attachments", self.session, self.attachments, parent=self)
193
+ response = SA.run()
194
+ if response == Gtk.ResponseType.OK:
195
+ self.attachments = SA.attachments
196
+
197
+ SA.hide()
198
+ SA.destroy()
199
+
200
+ if len(self.attachments) > 0:
201
+ self.btn_attch.set_label("Attachments ({})".format(len(self.attachments)))
202
+
203
+ def edit_comments(self, *args):
204
+ """Edit test comments."""
205
+ SC = ShowComments("Test Comments", self.comments, self)
206
+ rc = SC.run()
207
+ if rc == Gtk.ResponseType.OK:
208
+ self.comments = SC.comments
209
+
210
+ SC.hide()
211
+ SC.destroy()
212
+
213
+ if len(self.comments) > 0:
214
+ self.btn_comments.set_label("Comments ({})".format(len(self.comments)))
215
+
216
+ def edit_defects(self, *args):
217
+ """Edit test defects."""
218
+ SD = ShowDefects("Test Defects", self.defects, self)
219
+ rc = SD.run()
220
+ if rc == Gtk.ResponseType.OK:
221
+ self.defects = SD.defects
222
+
223
+ SD.hide()
224
+ SD.destroy()
225
+
226
+ if len(self.defects) > 0:
227
+ self.btn_defects.set_label("Defects ({})".format(len(self.defects)))
228
+
229
+ def upload_test(self, *args):
230
+ """Upload the test."""
231
+ SN = self.SN.get_text()
232
+ if len(SN) == 0 or self.obj_type is None:
233
+ dbGtkUtils.complain("Invalid Serial Number", SN)
234
+ return
235
+
236
+ defaults = {
237
+ "component": SN,
238
+ "institution": self.institute,
239
+ "passed": self.passed.get_active(),
240
+ "problems": self.problems.get_active(),
241
+ "runNumber": "1",
242
+ "date": self.date.get_text()
243
+ }
244
+
245
+ test_type = "VISUAL_INSPECTION"
246
+ if self.obj_type == "SENSOR":
247
+ test_type = "VIS_INSP_RES_MOD_V2"
248
+
249
+ else:
250
+ if self.reception.get_active():
251
+ test_type = "VISUAL_INSPECTION_RECEPTION"
252
+
253
+
254
+ self.data = ITkDButils.get_test_skeleton(self.session,
255
+ self.obj_type,
256
+ test_type,
257
+ defaults)
258
+
259
+ self.data["comments"] = self.comments
260
+ self.data["defects"] = self.defects
261
+ uploadW = UploadTest(self.session, self.data, self.attachments)
262
+
263
+
264
+
265
+ def get_qrcode(self, fd, state, reader):
266
+ """Read SN from scanner."""
267
+ txt = dbGtkUtils.scanner_get_line(reader)
268
+ self.write_message("SN: {}\n".format(txt))
269
+ self.SN_ready(txt, self.SN.widget)
270
+
271
+
272
+ def main():
273
+ """Main entry."""
274
+ HELP_LINK="https://itkdb-gtk.docs.cern.ch/moduleVisualInspection.html"
275
+
276
+ # DB login
277
+ dlg = ITkDBlogin.ITkDBlogin()
278
+ client = dlg.get_client()
279
+ if client is None:
280
+ print("Could not connect to DB with provided credentials.")
281
+ dlg.die()
282
+ sys.exit()
283
+
284
+ client.user_gui = dlg
285
+
286
+ gTest = ModuleVisualInspection(client, help_link=HELP_LINK)
287
+
288
+ gTest.present()
289
+ gTest.connect("destroy", Gtk.main_quit)
290
+ try:
291
+ Gtk.main()
292
+
293
+ except KeyboardInterrupt:
294
+ print("Arrrgggg!!!")
295
+
296
+ dlg.die()
297
+
298
+ if __name__ == "__main__":
299
+ main()