itkdb-gtk 0.10.9.dev3__py3-none-any.whl → 0.10.10.dev1__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.

@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env python3
2
2
  """PB/Hybrid panel Visual inspection GUI.."""
3
- import json
4
3
  import sys
5
4
  import copy
6
5
  from pathlib import Path
@@ -18,12 +17,11 @@ from itkdb_gtk.ShowDefects import ShowDefects
18
17
  from itkdb_gtk.UploadTest import create_json_data_editor
19
18
 
20
19
 
21
-
22
20
  import gi
23
21
  gi.require_version("Gtk", "3.0")
24
22
  from gi.repository import Gtk, Gdk, Gio, GObject
25
23
 
26
- HELP_LINK="https://itkdb-gtk.docs.cern.ch"
24
+ HELP_LINK="https://itkdb-gtk.docs.cern.ch/panelVisualInspection.html"
27
25
 
28
26
  class TestJson(GObject.Object):
29
27
  """To store test JSOn."""
@@ -40,15 +38,19 @@ class TestJson(GObject.Object):
40
38
 
41
39
  class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
42
40
  """PB/Hybryd panel visual inspection GUI."""
43
- SN, PASSED, F_NAME, F_PATH, TEST_J, ALL = range(6)
41
+ SN, ORDER, PASSED, N_FILES, F_LIST, TEST_J, ALL = range(7)
42
+ F_DEFECT, F_NAME, F_PATH = range(3)
44
43
 
45
- def __init__(self, session, title="PanelVisualInspection", help=HELP_LINK):
46
- super().__init__(title="ITkDB Dashboard",
44
+ def __init__(self, session, title="PanelVisualInspection", help_link=HELP_LINK):
45
+ super().__init__(title=title,
47
46
  session=session,
48
47
  show_search="Find object with given SN.",
49
- help=help)
48
+ help_link=help_link)
49
+
50
+ self.institute = self.pdb_user["institutions"][0]["code"]
51
+ self.global_image = None
52
+ self.global_link = None
50
53
 
51
- self.institute = "IFIC"
52
54
  # action button in header
53
55
  button = Gtk.Button()
54
56
  icon = Gio.ThemedIcon(name="document-send-symbolic")
@@ -66,7 +68,10 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
66
68
  receiver.connect("changed", self.on_institute)
67
69
  receiver.set_tooltip_text("Select the Institute making the test.")
68
70
  dbGtkUtils.set_combo_iter(receiver, self.institute)
69
- grid.attach(Gtk.Label(label="Institute"), 0, irow, 1, 1)
71
+
72
+ lbl = Gtk.Label(label="Institute")
73
+ lbl.set_xalign(0)
74
+ grid.attach(lbl, 0, irow, 1, 1)
70
75
  grid.attach(receiver, 1, irow, 1, 1)
71
76
 
72
77
  irow += 1
@@ -86,12 +91,22 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
86
91
  lbl = Gtk.Label(label="Date")
87
92
  lbl.set_xalign(0)
88
93
  grid.attach(lbl, 0, irow, 1, 1)
89
-
94
+
90
95
  self.date = dbGtkUtils.TextEntry(small=True)
91
96
  grid.attach(self.date.widget, 1, irow, 1, 1)
92
97
  self.date.entry.set_text(ITkDButils.get_db_date())
93
98
  self.date.connect("text_changed", self.new_date)
94
99
 
100
+ irow += 1
101
+ self.fC = Gtk.FileChooserButton()
102
+ self.fC.connect("file-set", self.on_global_image)
103
+
104
+ lbl = Gtk.Label(label="Global Image")
105
+ lbl.set_xalign(0)
106
+ grid.attach(lbl, 0, irow, 1, 1)
107
+ grid.attach(self.fC, 1, irow, 1, 1)
108
+
109
+
95
110
  # Paned object
96
111
  paned = Gtk.Paned(orientation=Gtk.Orientation.VERTICAL)
97
112
  paned.set_size_request(-1, 200)
@@ -109,6 +124,17 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
109
124
 
110
125
  dbGtkUtils.setup_scanner(self.get_qrcode)
111
126
 
127
+ def on_global_image(self, *args):
128
+ """We choose the global image."""
129
+ fnam = self.fC.get_filename()
130
+ if fnam is None or not Path(fnam).exists():
131
+ dbGtkUtils.complain("Could not find image", fnam, parent=self)
132
+ return
133
+
134
+ self.global_image = Path(fnam).expanduser().resolve()
135
+
136
+
137
+
112
138
  def on_institute(self, combo):
113
139
  """A new recipient has been chosen."""
114
140
  name = self.get_institute_from_combo(combo)
@@ -121,10 +147,13 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
121
147
  if d is not None:
122
148
  self.date.set_text(d)
123
149
 
124
-
125
150
  def create_model(self):
126
151
  """Create tree view model."""
127
- return Gtk.ListStore(str, bool, str, str, TestJson)
152
+ return Gtk.ListStore(str, int, bool, int, Gtk.ListStore, TestJson)
153
+
154
+ def create_file_model(self):
155
+ """Create model for file list"""
156
+ return Gtk.ListStore(str, str, str)
128
157
 
129
158
  def create_tree_view(self, size=150):
130
159
  """Create the TreeView with the children."""
@@ -141,12 +170,16 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
141
170
  column = Gtk.TreeViewColumn("SN", renderer, text=PanelVisualInspection.SN)
142
171
  self.tree.append_column(column)
143
172
 
173
+ renderer = Gtk.CellRendererText()
174
+ column = Gtk.TreeViewColumn("position", renderer, text=PanelVisualInspection.ORDER)
175
+ self.tree.append_column(column)
176
+
144
177
  renderer = Gtk.CellRendererToggle()
145
178
  renderer.set_property("activatable", True)
146
179
  renderer.set_property("radio", True)
147
180
  renderer.set_padding(5, 0)
148
181
 
149
- x, y = renderer.get_alignment()
182
+ _, y = renderer.get_alignment()
150
183
  renderer.set_alignment(0, y)
151
184
  # renderer.set_property("inconsistent", True)
152
185
  renderer.connect("toggled", self.btn_toggled)
@@ -154,12 +187,10 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
154
187
  column = Gtk.TreeViewColumn("Passed", renderer, active=PanelVisualInspection.PASSED)
155
188
  self.tree.append_column(column)
156
189
 
157
-
158
190
  renderer = Gtk.CellRendererText()
159
- column = Gtk.TreeViewColumn("Image", renderer, text=PanelVisualInspection.F_NAME)
191
+ column = Gtk.TreeViewColumn("N. Images", renderer, text=PanelVisualInspection.N_FILES)
160
192
  self.tree.append_column(column)
161
193
 
162
-
163
194
  return scrolled
164
195
 
165
196
  def btn_toggled(self, renderer, path, *args):
@@ -169,110 +200,208 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
169
200
  model[path][PanelVisualInspection.PASSED] = val
170
201
 
171
202
 
172
- def button_pressed(self, tree, event):
173
- """Button pressed on tree view."""
174
- # double click shows attachments
175
- if event.button == 1 and event.type == Gdk.EventType.DOUBLE_BUTTON_PRESS:
176
- self.write_message("This is a double click.\n")
177
- return
178
-
179
- if event.button != 3:
180
- return
181
-
203
+ def get_iter_at_position(self, tree, event):
204
+ """Get the model and iterator at position."""
182
205
  # Create popup menu
183
- select = self.tree.get_selection()
184
- model, iter = select.get_selected()
206
+ select = tree.get_selection()
207
+ model, lv_iter = select.get_selected()
185
208
  values = None
186
- if iter:
187
- values = model[iter]
209
+ if lv_iter:
210
+ values = model[lv_iter]
188
211
 
189
- if not iter:
212
+ else:
190
213
  P = tree.get_path_at_pos(event.x, event.y)
191
214
  if P:
192
- print(P[0].to_string())
193
- iter = model.get_iter(P[0])
194
- values = model[iter]
215
+ lv_iter = model.get_iter(P[0])
216
+ values = model[lv_iter]
217
+
218
+ return model, lv_iter, values
195
219
 
220
+
221
+ def button_pressed(self, tree, event):
222
+ """Button pressed on tree view."""
223
+ # Create popup menu
224
+ model, lv_iter, values = self.get_iter_at_position(tree, event)
196
225
  if not values:
197
226
  return
198
227
 
228
+ # double click shows attachments
229
+ if event.button == 1 and event.type == Gdk.EventType.DOUBLE_BUTTON_PRESS:
230
+ #self.write_message("This is a double click.\n")
231
+ self.on_upload_image(None, (model, lv_iter, values))
232
+ return
233
+
234
+ if event.button != 3:
235
+ return
236
+
199
237
  menu = Gtk.Menu()
200
238
 
201
239
  item_show = Gtk.MenuItem(label="Upload Image")
202
- item_show.connect("activate", self.on_upload_image, (model, iter, values))
240
+ item_show.connect("activate", self.on_upload_image, (model, lv_iter, values))
203
241
  menu.append(item_show)
204
242
 
205
243
  item_show_json = Gtk.MenuItem(label="Show JSOn")
206
- item_show_json.connect("activate", self.on_show_json, (model, iter, values))
244
+ item_show_json.connect("activate", self.on_show_json, (model, lv_iter, values))
207
245
  menu.append(item_show_json)
208
246
 
209
247
  item_show_com = Gtk.MenuItem(label="Edit Comments")
210
- item_show_com.connect("activate", self.on_show_comments, (model, iter, values))
248
+ item_show_com.connect("activate", self.on_show_comments, (model, lv_iter, values))
211
249
  menu.append(item_show_com)
212
250
 
213
251
  item_show_def = Gtk.MenuItem(label="Edit Defects")
214
- item_show_def.connect("activate", self.on_show_defects, (model, iter, values))
252
+ item_show_def.connect("activate", self.on_show_defects, (model, lv_iter, values))
215
253
  menu.append(item_show_def)
216
254
 
217
255
  menu.show_all()
218
256
  menu.popup_at_pointer(event)
219
257
 
220
258
  def on_upload_image(self, item, data):
221
- """Choose file."""
222
- fdlg = Gtk.FileChooserNative(action=Gtk.FileChooserAction.OPEN, accept_label="Select")
223
- response = fdlg.run()
224
- if response == Gtk.ResponseType.ACCEPT:
225
- ifiles = [ipath for ipath in fdlg.get_filenames()]
226
- if len(ifiles)<1:
227
- return
259
+ """Add defects with images.."""
260
+
261
+ model, lv_iter, val = data
262
+
263
+ irow = 0
264
+ tree = Gtk.TreeView(model=val[self.F_LIST])
265
+ tree.connect("button-press-event", self.on_file_pressed)
228
266
 
229
- if len(ifiles) > 1:
230
- dbGtkUtils.complain("More than one file selected","Choosing first.")
267
+ btn = Gtk.Button(label="Add image")
268
+ btn.set_tooltip_text("Click to add a new image.")
269
+ btn.connect("clicked", self.on_add_image, val[PanelVisualInspection.F_LIST])
231
270
 
232
- fnam = ifiles[0]
233
- model, iter, val = data
234
- model.set_value(iter, PanelVisualInspection.F_PATH, fnam)
235
- model.set_value(iter, PanelVisualInspection.F_NAME, Path(fnam).name)
271
+ scrolled = Gtk.ScrolledWindow()
272
+ scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
273
+ scrolled.add(tree)
274
+ scrolled.set_size_request(-1, 150)
275
+
276
+ renderer = Gtk.CellRendererText()
277
+ column = Gtk.TreeViewColumn("Description", renderer, text=PanelVisualInspection.F_DEFECT)
278
+ tree.append_column(column)
279
+
280
+ renderer = Gtk.CellRendererText()
281
+ column = Gtk.TreeViewColumn("File", renderer, text=PanelVisualInspection.F_NAME)
282
+ tree.append_column(column)
283
+
284
+ dlg = Gtk.Dialog(title="Add Image")
285
+ dlg.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
286
+ Gtk.STOCK_OK, Gtk.ResponseType.OK)
287
+ box = dlg.get_content_area()
288
+ box.add(btn)
289
+ box.add(scrolled)
290
+ dlg.show_all()
291
+ rc = dlg.run()
292
+ if rc == Gtk.ResponseType.OK:
293
+ f_model = tree.get_model()
294
+ n_files = f_model.iter_n_children()
295
+ model.set_value(lv_iter, PanelVisualInspection.F_LIST, f_model)
296
+ model.set_value(lv_iter, PanelVisualInspection.N_FILES, n_files)
297
+
298
+ dlg.hide()
299
+ dlg.destroy()
300
+
301
+ self.write_message("Defects added\n")
302
+
303
+ def on_file_pressed(self, tree, event):
304
+ """Called when right button clicked in add image dialog.
236
305
 
306
+ Opens a pop-up menu to delete the selected entry."""
307
+ # double click shows attachments
308
+ if event.button == 1 and event.type == Gdk.EventType.DOUBLE_BUTTON_PRESS:
309
+ self.write_message("This is a double click.\n")
310
+ return
237
311
 
238
- self.write_message("Upload image\n")
239
312
 
313
+ if event.button != 3:
314
+ return
315
+
316
+ model, lv_iter, values = self.get_iter_at_position(tree, event)
317
+ if not values:
318
+ return
319
+ menu = Gtk.Menu()
320
+
321
+ item_show = Gtk.MenuItem(label="Delete")
322
+ item_show.connect("activate", self.on_delete_image, (model, lv_iter, values))
323
+ menu.append(item_show)
324
+
325
+ menu.show_all()
326
+ menu.popup_at_pointer(event)
327
+
328
+ def on_delete_image(self, item, data):
329
+ """Delete a defect and image"""
330
+ model, lv_iter, _ = data
331
+ model.remove(lv_iter)
332
+
333
+ def on_add_image(self, btn, model):
334
+ """Adds a new image."""
335
+ dlg = Gtk.Dialog(title="Add Image")
336
+
337
+ dlg.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
338
+ Gtk.STOCK_OK, Gtk.ResponseType.OK)
339
+ box = dlg.get_content_area()
340
+ grid = Gtk.Grid(column_spacing=5, row_spacing=1)
341
+ box.add(grid)
342
+
343
+ irow = 0
344
+ lbl = Gtk.Label(label="Description")
345
+ lbl.set_xalign(0)
346
+ grid.attach(lbl, 0, irow, 1, 1)
347
+
348
+ desc = Gtk.Entry()
349
+ grid.attach(desc, 1, irow, 1, 1)
350
+
351
+ irow += 1
352
+ lbl = Gtk.Label(label="Image")
353
+ lbl.set_xalign(0)
354
+ grid.attach(lbl, 0, irow, 1, 1)
355
+
356
+ fC = Gtk.FileChooserButton()
357
+ grid.attach(fC, 1, irow, 1, 1)
358
+
359
+ dlg.show_all()
360
+
361
+ rc = dlg.run()
362
+ if rc == Gtk.ResponseType.OK:
363
+ D = desc.get_text()
364
+ P = Path(fC.get_filename()).expanduser().resolve()
365
+ model.append([D, P.name, P.as_posix()])
366
+
367
+ dlg.hide()
368
+ dlg.destroy()
240
369
 
241
370
  def on_show_json(self, item, data):
242
371
  """Test JSon."""
243
- model, iter, val = data
372
+ model, lv_iter, val = data
244
373
  payload = val[PanelVisualInspection.TEST_J].js
245
374
  value, dlg = create_json_data_editor(payload)
246
375
  rc = dlg.run()
247
376
  if rc == Gtk.ResponseType.OK:
248
377
  payload = value.values
249
- model.set_value(iter, PanelVisualInspection.TEST_J, TestJson(payload))
378
+ model.set_value(lv_iter, PanelVisualInspection.TEST_J, TestJson(payload))
250
379
 
251
380
  dlg.hide()
252
381
  dlg.destroy()
253
382
 
254
383
  def on_show_comments(self, item, data):
255
384
  """Show comments"""
256
- model, iter, val = data
385
+ model, lv_iter, val = data
257
386
  js = val[PanelVisualInspection.TEST_J].js
258
387
  SC = ShowComments("Test Comments", js["comments"], self)
259
388
  rc = SC.run()
260
389
  if rc == Gtk.ResponseType.OK:
261
390
  js["comments"] = SC.comments
262
- model.set_value(iter, PanelVisualInspection.TEST_J, TestJson(js))
391
+ model.set_value(lv_iter, PanelVisualInspection.TEST_J, TestJson(js))
263
392
 
264
393
  SC.hide()
265
394
  SC.destroy()
266
395
 
267
396
  def on_show_defects(self, item, data):
268
397
  """Show comments"""
269
- model, iter, val = data
398
+ model, lv_iter, val = data
270
399
  js = val[PanelVisualInspection.TEST_J].js
271
400
  SD = ShowDefects("Test Defects", js["defects"], self)
272
401
  rc = SD.run()
273
402
  if rc == Gtk.ResponseType.OK:
274
403
  js["defects"] = SD.defects
275
- model.set_value(iter, PanelVisualInspection.TEST_J, TestJson(js))
404
+ model.set_value(lv_iter, PanelVisualInspection.TEST_J, TestJson(js))
276
405
 
277
406
  SD.hide()
278
407
  SD.destroy()
@@ -335,7 +464,17 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
335
464
  if child["component"] is not None:
336
465
  child_SN = child["component"]["serialNumber"]
337
466
  skltn["component"] = child_SN
338
- model.append([child_SN, True, "", "", TestJson(skltn)])
467
+ if is_PWB:
468
+ position = child["order"]
469
+ else:
470
+ position = -1
471
+ for P in child["properties"]:
472
+ if P["code"] == "HYBRID_POSITION":
473
+ if P["value"] is not None:
474
+ position = int(P["value"])
475
+ break
476
+
477
+ model.append([child_SN, position, True, 0, self.create_file_model(), TestJson(skltn)])
339
478
 
340
479
  self.tree.set_model(model)
341
480
 
@@ -345,18 +484,29 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
345
484
  SN = self.SN.get_text()
346
485
 
347
486
  model = self.tree.get_model()
348
- iter = model.get_iter_first()
487
+ lv_iter = model.get_iter_first()
349
488
  n_items = 0
350
- while iter:
351
- values = model[iter]
489
+ global_link = None
490
+ while lv_iter:
491
+ values = model[lv_iter]
352
492
  payload = values[PanelVisualInspection.TEST_J].js
353
- ifile = values[PanelVisualInspection.F_PATH]
354
- if len(ifile)>0:
355
- attachments = [ITkDButils.Attachment(ifile, "Image", "Image")]
356
- else:
357
- attachments = []
358
493
 
359
- rc = ITkDButils.upload_test(self.session, payload, attachments)
494
+ attachments = []
495
+ if global_link is None:
496
+ A = ITkDButils.Attachment(path=self.global_image, title="Global Image", desc="Image of whole panel")
497
+ attachments.append(A)
498
+
499
+ im_model = values[PanelVisualInspection.F_LIST]
500
+ im_iter = im_model.get_iter_first()
501
+ idef = 1
502
+ while im_iter:
503
+ defect, name, path = im_model[im_iter]
504
+ A = ITkDButils.Attachment(path=path, title="Defect {}".format(idef), desc=defect)
505
+ attachments.append(A)
506
+ idef += 1
507
+ im_iter = im_model.iter_next(im_iter)
508
+
509
+ rc = ITkDButils.upload_test(self.session, payload, attachments, check_runNumber=True)
360
510
  if rc:
361
511
  ipos = rc.find("The following details may help:")
362
512
  msg = rc[ipos:]
@@ -365,9 +515,39 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
365
515
 
366
516
  else:
367
517
  self.write_message("Upload {}-{} successfull\n".format(payload["component"], payload["testType"]))
518
+ if global_link is None:
519
+ try:
520
+ global_link = ITkDButils.attachment_urls[self.global_image.name]
521
+ except KeyError:
522
+ pass
523
+
524
+ if payload["testType"] == "PICTURE":
525
+ rc = ITkDButils.set_test_run_parameter(self.session,
526
+ ITkDButils.uploaded_test_runs[0],
527
+ "COMMENT", "Picture of PW carrier")
528
+
529
+ rc = ITkDButils.set_test_run_parameter(self.session,
530
+ ITkDButils.uploaded_test_runs[0],
531
+ "LINK_TO_PICTURE", global_link)
532
+ if rc:
533
+ ipos = rc.find("The following details may help:")
534
+ msg = rc[ipos:]
535
+ dbGtkUtils.complain("Failed updating LINK_TO_PICTURE {}-{}".format(payload["component"], payload["testType"]), msg)
536
+ self.write_message(msg)
537
+
538
+ elif payload["testType"] == "VISUAL_INSPECTION_RECEPTION":
539
+ rc = ITkDButils.create_test_run_comment(self.session,
540
+ ITkDButils.uploaded_test_runs[0],
541
+ ["Link to global image:\n {}".format(global_link)])
542
+ if rc:
543
+ ipos = rc.find("The following details may help:")
544
+ msg = rc[ipos:]
545
+ dbGtkUtils.complain("Failed adding global link as comment: {}-{}".format(payload["component"], payload["testType"]), msg)
546
+ self.write_message(msg)
547
+
368
548
 
369
549
  n_items += 1
370
- iter = model.iter_next(iter)
550
+ lv_iter = model.iter_next(lv_iter)
371
551
 
372
552
 
373
553
  def get_qrcode(self, fd, state, reader):
@@ -402,4 +582,4 @@ def main():
402
582
  dlg.die()
403
583
 
404
584
  if __name__ == "__main__":
405
- main()
585
+ main()
@@ -38,12 +38,12 @@ def find_children(W):
38
38
  class PetalReceptionTests(dbGtkUtils.ITkDBWindow):
39
39
  """Petl Reception Test GUI."""
40
40
 
41
- def __init__(self, session, help=None):
41
+ def __init__(self, session, help_link=None):
42
42
  """Initialization."""
43
- super().__init__(title="ITkDB Dashboard",
43
+ super().__init__(title="Petal Reception Tests",
44
44
  session=session,
45
45
  show_search="Find object with given SN.",
46
- help=help)
46
+ help_link=help_link)
47
47
 
48
48
  # Members
49
49
  self.dbObject = None
@@ -83,7 +83,7 @@ class PetalReceptionTests(dbGtkUtils.ITkDBWindow):
83
83
  lbl.set_xalign(0)
84
84
  grid.attach(lbl, 0, 1, 1, 1)
85
85
 
86
- self.institute = "IFIC"
86
+ self.institute = self.pdb_user["institutions"][0]["code"]
87
87
  inst = self.create_institute_combo()
88
88
  inst.connect("changed", self.new_institute)
89
89
  inst.set_tooltip_text("Select the Institute.")
@@ -114,6 +114,10 @@ class PetalReceptionTests(dbGtkUtils.ITkDBWindow):
114
114
  # The text view
115
115
  self.mainBox.pack_end(self.message_panel.frame, True, True, 5)
116
116
 
117
+ # Set the default institute
118
+ dbGtkUtils.set_combo_iter(inst, self.institute)
119
+
120
+
117
121
  self.show_all()
118
122
 
119
123
  def on_SN_changed(self, entry, value):
@@ -139,7 +143,7 @@ class PetalReceptionTests(dbGtkUtils.ITkDBWindow):
139
143
  page.dict_dialog.factory_reset()
140
144
 
141
145
 
142
- def create_test_box(self, label, test_name, institute="IFIC"):
146
+ def create_test_box(self, label, test_name, institute=None):
143
147
  """Create and add to notebook a test dialog.
144
148
 
145
149
  Args:
@@ -148,6 +152,9 @@ class PetalReceptionTests(dbGtkUtils.ITkDBWindow):
148
152
  institute: The institute.
149
153
 
150
154
  """
155
+ if institute is None:
156
+ institute = self.institute
157
+
151
158
  defaults = {
152
159
  "institution": institute,
153
160
  "runNumber": "1",
@@ -226,11 +233,11 @@ class PetalReceptionTests(dbGtkUtils.ITkDBWindow):
226
233
  if fnam is not None and len(fnam)>0:
227
234
  P = Path(fnam).expanduser().resolve()
228
235
  if P.exists():
229
- A = ITkDButils.Attachment(P.as_posix(), P.name, "X-ray image")
236
+ A = ITkDButils.Attachment(path=P.as_posix(), title=P.name, desc="X-ray image")
230
237
  values["results"]["IMAGELINK"] = P.name
231
238
  attachments.append(A)
232
239
 
233
- rc = ITkDButils.upload_test(self.session, values, attachments=attachments)
240
+ rc = ITkDButils.upload_test(self.session, values, attachments=attachments, check_runNumber=True)
234
241
  if rc is not None:
235
242
  dbGtkUtils.complain("Could not upload test", rc)
236
243
 
itkdb_gtk/SensorUtils.py CHANGED
@@ -1,10 +1,8 @@
1
1
  #!/usr/bin/env python3
2
2
  """A collection of utilities for sensor data."""
3
- import io
4
3
  from pathlib import Path
5
- import numpy as np
6
4
  import warnings
7
- import tempfile
5
+ import numpy as np
8
6
  from itkdb_gtk import ITkDButils
9
7
 
10
8
  #
@@ -210,7 +208,7 @@ def LocateMicroDischarge(
210
208
  V_BDV_ind = V_BDV_ind[ind]
211
209
  if V_avg_BD.shape == (0,):
212
210
  return NO_BD_CONST
213
-
211
+
214
212
  return NO_BD_CONST
215
213
 
216
214
 
@@ -260,8 +258,12 @@ def sensor_data_to_json(session, mdata, mod_type, logger=None):
260
258
  passed = True
261
259
 
262
260
  # Find Current @ 500V
263
- indx = np.where(V == 500)[0]
264
- i_500 = I[indx][0] / area
261
+ try:
262
+ indx = np.where(V == 500)[0]
263
+ i_500 = I[indx][0] / area
264
+ except IndexError:
265
+ i_500 = 999
266
+
265
267
  if logger:
266
268
  logger.write_message("I @ 500V = {:.2f} nA/cm2\n".format(i_500))
267
269
 
@@ -296,7 +298,7 @@ def sensor_data_to_json(session, mdata, mod_type, logger=None):
296
298
  )
297
299
  if logger:
298
300
  logger.write_message("...{}. FAILED\n".format(txt))
299
-
301
+
300
302
  passed = False
301
303
  else:
302
304
  if MicroDischargeV == NO_BD_CONST:
@@ -388,7 +390,7 @@ def save_sensor_data(fnam, mdata, name=None):
388
390
  Args:
389
391
  fnam: file name or file object.
390
392
  mdata (dict): data as returned by :function:`read_sensor_file`
391
-
393
+
392
394
  """
393
395
  if hasattr(fnam, "write") and callable(fnam.write):
394
396
  data_out = fnam
@@ -396,17 +398,17 @@ def save_sensor_data(fnam, mdata, name=None):
396
398
  fnam = name
397
399
  else:
398
400
  fnam = build_file_name(mdata)
399
-
401
+
400
402
  else:
401
403
  data_out = open(fnam, 'w', encoding="utf-8")
402
404
  fnam = Path(fnam).name
403
-
405
+
404
406
  is_module = "Module_SN" in mdata
405
407
  if is_module:
406
408
  SN = mdata["Module_SN"]
407
409
  else:
408
410
  SN = mdata["Component"]
409
-
411
+
410
412
  if is_module:
411
413
  items = [
412
414
  "Type",
@@ -446,7 +448,7 @@ def save_sensor_data(fnam, mdata, name=None):
446
448
  "Humidity",
447
449
  "Comments",
448
450
  ]
449
-
451
+
450
452
  data_out.write("{}\n".format(fnam))
451
453
  for key in items:
452
454
  if key == "Module_SN" or key == "Component":
@@ -469,7 +471,7 @@ def save_sensor_data(fnam, mdata, name=None):
469
471
  V = np.abs(mdata["curve"]["V"])
470
472
  I = np.abs(mdata["curve"]["I"])
471
473
  S = np.abs(mdata["curve"]["S"])
472
-
474
+
473
475
  ndata = len(V)
474
476
  for i in range(ndata):
475
477
  data_out.write("{:10.2f}\t{:10.2f}\t{:10.2f}\n".format(V[i], I[i], S[i]))
@@ -487,4 +489,4 @@ def build_file_name(mdata):
487
489
  SN = mdata["Component"]
488
490
  fnam = "{}-W{}_IV_{}".format(mdata["Batch"], mdata["Wafer"], mdata["RunNumber"])
489
491
 
490
- return fnam
492
+ return fnam
@@ -232,7 +232,9 @@ class ShowAttachments(Gtk.Dialog):
232
232
  rc = dlg.run()
233
233
  if rc == Gtk.ResponseType.OK:
234
234
  path = Path(dlg.fC.get_filename())
235
- A = ITkDButils.Attachment(path, dlg.att_title.get_text().strip(), dlg.att_desc.get_text().strip())
235
+ A = ITkDButils.Attachment(path=path,
236
+ title=dlg.att_title.get_text().strip(),
237
+ desc=dlg.att_desc.get_text().strip())
236
238
  self.append_attachment_to_view(A)
237
239
  self.attachments.append(A)
238
240