itkdb-gtk 0.10.9.dev3__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.

itkdb_gtk/UploadTest.py CHANGED
@@ -9,7 +9,6 @@ try:
9
9
  import itkdb_gtk
10
10
 
11
11
  except ImportError:
12
- from pathlib import Path
13
12
  cwd = Path(__file__).parent.parent
14
13
  sys.path.append(cwd.as_posix())
15
14
 
@@ -78,7 +77,7 @@ def check_data(data):
78
77
  class UploadTest(dbGtkUtils.ITkDBWindow):
79
78
  """Collects information to upload a test and its attachments."""
80
79
 
81
- def __init__(self, session, payload=None, attachment=None, help=None):
80
+ def __init__(self, session, payload=None, attachment=None, help_link=None):
82
81
  """Initialization.
83
82
 
84
83
  Args:
@@ -93,6 +92,7 @@ class UploadTest(dbGtkUtils.ITkDBWindow):
93
92
  self.attachments = []
94
93
  self.comments = []
95
94
  self.defects = []
95
+ self.currentStage = None
96
96
  if attachment is not None:
97
97
  if isinstance(attachment, ITkDButils.Attachment):
98
98
  if attachment.path is not None:
@@ -107,7 +107,7 @@ class UploadTest(dbGtkUtils.ITkDBWindow):
107
107
 
108
108
  global gtk_runs
109
109
  if gtk_runs:
110
- super().__init__(session=session, title="Upload Test", gtk_runs=gtk_runs, help=help)
110
+ super().__init__(session=session, title="Upload Test", gtk_runs=gtk_runs, help_link=help_link)
111
111
  self.init_window()
112
112
 
113
113
  def init_window(self):
@@ -211,14 +211,15 @@ class UploadTest(dbGtkUtils.ITkDBWindow):
211
211
  ifile = Path(self.payload).expanduser().resolve().as_posix()
212
212
  self.testF.set_filename(ifile)
213
213
  self.on_test_file(self.testF)
214
- self.write_message("Loaded {}".format(the_path.name))
214
+ self.write_message("Loaded {}\n".format(the_path.name))
215
215
 
216
216
  else:
217
217
  print("Input file does not exists: {}".format(self.payload))
218
218
 
219
219
  except TypeError:
220
220
  self.load_payload(self.payload)
221
- self.write_message("Loaded memory payload.")
221
+ self.write_message("Loaded memory payload.\n")
222
+ self.testF.set_sensitive(False)
222
223
 
223
224
  if len(self.attachments) > 0:
224
225
  self.btn_attch.set_label("Attachments ({})".format(len(self.attachments)))
@@ -293,7 +294,7 @@ class UploadTest(dbGtkUtils.ITkDBWindow):
293
294
  self.objStage.set_active(indx)
294
295
 
295
296
  except Exception:
296
- self.write_message("Something went wring with the stages")
297
+ self.write_message("Something went wrong with the stages\n")
297
298
 
298
299
 
299
300
  def on_test_file(self, fdlg):
@@ -303,7 +304,7 @@ class UploadTest(dbGtkUtils.ITkDBWindow):
303
304
 
304
305
  # The file exists by definition
305
306
  try:
306
- self.data = json.loads(open(fnam).read())
307
+ self.data = json.loads(open(fnam, encoding="UTF-8").read())
307
308
  errors, missing = check_data(self.data)
308
309
  self.complete_missing(missing, errors)
309
310
  self.set_stages()
@@ -326,7 +327,7 @@ class UploadTest(dbGtkUtils.ITkDBWindow):
326
327
  self.write_message("Setting Institution to {}\n".format(self.data["institution"]))
327
328
 
328
329
  else:
329
- dbGtkUtils.complain("Invalid JSON data".format('\n'.join(errors)))
330
+ dbGtkUtils.complain("Invalid JSON data\n{}".format('\n'.join(errors)))
330
331
 
331
332
  self.find_attachments()
332
333
  self.find_comments()
@@ -366,7 +367,7 @@ class UploadTest(dbGtkUtils.ITkDBWindow):
366
367
  else:
367
368
  the_path = Path(A["path"]).expanduser().resolve()
368
369
 
369
- self.attachments.append(ITkDButils.Attachment(the_path, A["title"], A["description"]))
370
+ self.attachments.append(ITkDButils.Attachment(path=the_path, title=A["title"], desc=A["description"]))
370
371
 
371
372
  if len(self.attachments) > 0:
372
373
  self.btn_attch.set_label("Attachments ({})".format(len(self.attachments)))
@@ -444,19 +445,20 @@ class UploadTest(dbGtkUtils.ITkDBWindow):
444
445
  self.data["comments"] = self.comments
445
446
  self.data["defects"] = self.defects
446
447
 
447
- rc = ITkDButils.upload_test(self.session, self.data, self.attachments)
448
+ rc = ITkDButils.upload_test(self.session, self.data, self.attachments, check_runNumber=True)
448
449
  if rc:
449
450
  ipos = rc.find("The following details may help:")
450
451
  msg = rc[ipos:]
451
452
  dbGtkUtils.complain("Failed uploading test", msg)
452
453
 
453
454
  else:
454
- self.write_message("Upload successfull")
455
+ self.write_message("Upload successfull\n")
455
456
  dbGtkUtils.ask_for_confirmation("Upload successfull", "")
456
457
 
457
458
 
458
459
  def main():
459
460
  """Main entry."""
461
+ HELP_LINK="https://itkdb-gtk.docs.cern.ch/uploadSingleTest.html"
460
462
  parser = argparse.ArgumentParser()
461
463
 
462
464
  parser.add_argument("--test-file", help="Name of json file with test data")
@@ -482,9 +484,10 @@ def main():
482
484
  # Start GUI
483
485
  UpT = UploadTest(client,
484
486
  payload=args.test_file,
485
- attachment=ITkDButils.Attachment(args.attachment,
486
- args.attach_title,
487
- args.attach_desc))
487
+ help_link=HELP_LINK,
488
+ attachment=ITkDButils.Attachment(path=args.attachment,
489
+ title=args.attach_title,
490
+ desc=args.attach_desc))
488
491
 
489
492
  if gtk_runs:
490
493
  UpT.present()
@@ -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()