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.

@@ -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,10 @@ 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"
27
24
 
28
25
  class TestJson(GObject.Object):
29
26
  """To store test JSOn."""
@@ -40,15 +37,19 @@ class TestJson(GObject.Object):
40
37
 
41
38
  class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
42
39
  """PB/Hybryd panel visual inspection GUI."""
43
- SN, PASSED, F_NAME, F_PATH, TEST_J, ALL = range(6)
40
+ SN, ORDER, PASSED, N_FILES, F_LIST, TEST_J, ALL = range(7)
41
+ F_DEFECT, F_NAME, F_PATH = range(3)
44
42
 
45
- def __init__(self, session, title="PanelVisualInspection", help=HELP_LINK):
46
- super().__init__(title="ITkDB Dashboard",
43
+ def __init__(self, session, title="PanelVisualInspection", help_link=None):
44
+ super().__init__(title=title,
47
45
  session=session,
48
46
  show_search="Find object with given SN.",
49
- help=help)
47
+ help_link=help_link)
48
+
49
+ self.institute = self.pdb_user["institutions"][0]["code"]
50
+ self.global_image = None
51
+ self.global_link = None
50
52
 
51
- self.institute = "IFIC"
52
53
  # action button in header
53
54
  button = Gtk.Button()
54
55
  icon = Gio.ThemedIcon(name="document-send-symbolic")
@@ -62,11 +63,14 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
62
63
  self.mainBox.pack_start(grid, False, False, 5)
63
64
 
64
65
  irow = 0
65
- receiver = self.create_institute_combo()
66
+ receiver = self.create_institute_combo(only_user=True)
66
67
  receiver.connect("changed", self.on_institute)
67
68
  receiver.set_tooltip_text("Select the Institute making the test.")
68
69
  dbGtkUtils.set_combo_iter(receiver, self.institute)
69
- grid.attach(Gtk.Label(label="Institute"), 0, irow, 1, 1)
70
+
71
+ lbl = Gtk.Label(label="Institute")
72
+ lbl.set_xalign(0)
73
+ grid.attach(lbl, 0, irow, 1, 1)
70
74
  grid.attach(receiver, 1, irow, 1, 1)
71
75
 
72
76
  irow += 1
@@ -86,12 +90,22 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
86
90
  lbl = Gtk.Label(label="Date")
87
91
  lbl.set_xalign(0)
88
92
  grid.attach(lbl, 0, irow, 1, 1)
89
-
93
+
90
94
  self.date = dbGtkUtils.TextEntry(small=True)
91
95
  grid.attach(self.date.widget, 1, irow, 1, 1)
92
96
  self.date.entry.set_text(ITkDButils.get_db_date())
93
97
  self.date.connect("text_changed", self.new_date)
94
98
 
99
+ irow += 1
100
+ self.fC = Gtk.FileChooserButton()
101
+ self.fC.connect("file-set", self.on_global_image)
102
+
103
+ lbl = Gtk.Label(label="Global Image")
104
+ lbl.set_xalign(0)
105
+ grid.attach(lbl, 0, irow, 1, 1)
106
+ grid.attach(self.fC, 1, irow, 1, 1)
107
+
108
+
95
109
  # Paned object
96
110
  paned = Gtk.Paned(orientation=Gtk.Orientation.VERTICAL)
97
111
  paned.set_size_request(-1, 200)
@@ -109,6 +123,17 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
109
123
 
110
124
  dbGtkUtils.setup_scanner(self.get_qrcode)
111
125
 
126
+ def on_global_image(self, *args):
127
+ """We choose the global image."""
128
+ fnam = self.fC.get_filename()
129
+ if fnam is None or not Path(fnam).exists():
130
+ dbGtkUtils.complain("Could not find image", fnam, parent=self)
131
+ return
132
+
133
+ self.global_image = Path(fnam).expanduser().resolve()
134
+
135
+
136
+
112
137
  def on_institute(self, combo):
113
138
  """A new recipient has been chosen."""
114
139
  name = self.get_institute_from_combo(combo)
@@ -121,10 +146,13 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
121
146
  if d is not None:
122
147
  self.date.set_text(d)
123
148
 
124
-
125
149
  def create_model(self):
126
150
  """Create tree view model."""
127
- return Gtk.ListStore(str, bool, str, str, TestJson)
151
+ return Gtk.ListStore(str, int, bool, int, Gtk.ListStore, TestJson)
152
+
153
+ def create_file_model(self):
154
+ """Create model for file list"""
155
+ return Gtk.ListStore(str, str, str)
128
156
 
129
157
  def create_tree_view(self, size=150):
130
158
  """Create the TreeView with the children."""
@@ -141,12 +169,16 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
141
169
  column = Gtk.TreeViewColumn("SN", renderer, text=PanelVisualInspection.SN)
142
170
  self.tree.append_column(column)
143
171
 
172
+ renderer = Gtk.CellRendererText()
173
+ column = Gtk.TreeViewColumn("position", renderer, text=PanelVisualInspection.ORDER)
174
+ self.tree.append_column(column)
175
+
144
176
  renderer = Gtk.CellRendererToggle()
145
177
  renderer.set_property("activatable", True)
146
178
  renderer.set_property("radio", True)
147
179
  renderer.set_padding(5, 0)
148
180
 
149
- x, y = renderer.get_alignment()
181
+ _, y = renderer.get_alignment()
150
182
  renderer.set_alignment(0, y)
151
183
  # renderer.set_property("inconsistent", True)
152
184
  renderer.connect("toggled", self.btn_toggled)
@@ -154,12 +186,10 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
154
186
  column = Gtk.TreeViewColumn("Passed", renderer, active=PanelVisualInspection.PASSED)
155
187
  self.tree.append_column(column)
156
188
 
157
-
158
189
  renderer = Gtk.CellRendererText()
159
- column = Gtk.TreeViewColumn("Image", renderer, text=PanelVisualInspection.F_NAME)
190
+ column = Gtk.TreeViewColumn("N. Images", renderer, text=PanelVisualInspection.N_FILES)
160
191
  self.tree.append_column(column)
161
192
 
162
-
163
193
  return scrolled
164
194
 
165
195
  def btn_toggled(self, renderer, path, *args):
@@ -169,110 +199,208 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
169
199
  model[path][PanelVisualInspection.PASSED] = val
170
200
 
171
201
 
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
-
202
+ def get_iter_at_position(self, tree, event):
203
+ """Get the model and iterator at position."""
182
204
  # Create popup menu
183
- select = self.tree.get_selection()
184
- model, iter = select.get_selected()
205
+ select = tree.get_selection()
206
+ model, lv_iter = select.get_selected()
185
207
  values = None
186
- if iter:
187
- values = model[iter]
208
+ if lv_iter:
209
+ values = model[lv_iter]
188
210
 
189
- if not iter:
211
+ else:
190
212
  P = tree.get_path_at_pos(event.x, event.y)
191
213
  if P:
192
- print(P[0].to_string())
193
- iter = model.get_iter(P[0])
194
- values = model[iter]
214
+ lv_iter = model.get_iter(P[0])
215
+ values = model[lv_iter]
216
+
217
+ return model, lv_iter, values
195
218
 
219
+
220
+ def button_pressed(self, tree, event):
221
+ """Button pressed on tree view."""
222
+ # Create popup menu
223
+ model, lv_iter, values = self.get_iter_at_position(tree, event)
196
224
  if not values:
197
225
  return
198
226
 
227
+ # double click shows attachments
228
+ if event.button == 1 and event.type == Gdk.EventType.DOUBLE_BUTTON_PRESS:
229
+ #self.write_message("This is a double click.\n")
230
+ self.on_upload_image(None, (model, lv_iter, values))
231
+ return
232
+
233
+ if event.button != 3:
234
+ return
235
+
199
236
  menu = Gtk.Menu()
200
237
 
201
238
  item_show = Gtk.MenuItem(label="Upload Image")
202
- item_show.connect("activate", self.on_upload_image, (model, iter, values))
239
+ item_show.connect("activate", self.on_upload_image, (model, lv_iter, values))
203
240
  menu.append(item_show)
204
241
 
205
242
  item_show_json = Gtk.MenuItem(label="Show JSOn")
206
- item_show_json.connect("activate", self.on_show_json, (model, iter, values))
243
+ item_show_json.connect("activate", self.on_show_json, (model, lv_iter, values))
207
244
  menu.append(item_show_json)
208
245
 
209
246
  item_show_com = Gtk.MenuItem(label="Edit Comments")
210
- item_show_com.connect("activate", self.on_show_comments, (model, iter, values))
247
+ item_show_com.connect("activate", self.on_show_comments, (model, lv_iter, values))
211
248
  menu.append(item_show_com)
212
249
 
213
250
  item_show_def = Gtk.MenuItem(label="Edit Defects")
214
- item_show_def.connect("activate", self.on_show_defects, (model, iter, values))
251
+ item_show_def.connect("activate", self.on_show_defects, (model, lv_iter, values))
215
252
  menu.append(item_show_def)
216
253
 
217
254
  menu.show_all()
218
255
  menu.popup_at_pointer(event)
219
256
 
220
257
  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
258
+ """Add defects with images.."""
228
259
 
229
- if len(ifiles) > 1:
230
- dbGtkUtils.complain("More than one file selected","Choosing first.")
260
+ model, lv_iter, val = data
231
261
 
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)
262
+ irow = 0
263
+ tree = Gtk.TreeView(model=val[self.F_LIST])
264
+ tree.connect("button-press-event", self.on_file_pressed)
236
265
 
266
+ btn = Gtk.Button(label="Add image")
267
+ btn.set_tooltip_text("Click to add a new image.")
268
+ btn.connect("clicked", self.on_add_image, val[PanelVisualInspection.F_LIST])
237
269
 
238
- self.write_message("Upload image\n")
270
+ scrolled = Gtk.ScrolledWindow()
271
+ scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
272
+ scrolled.add(tree)
273
+ scrolled.set_size_request(-1, 150)
239
274
 
275
+ renderer = Gtk.CellRendererText()
276
+ column = Gtk.TreeViewColumn("Description", renderer, text=PanelVisualInspection.F_DEFECT)
277
+ tree.append_column(column)
278
+
279
+ renderer = Gtk.CellRendererText()
280
+ column = Gtk.TreeViewColumn("File", renderer, text=PanelVisualInspection.F_NAME)
281
+ tree.append_column(column)
282
+
283
+ dlg = Gtk.Dialog(title="Add Image")
284
+ dlg.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
285
+ Gtk.STOCK_OK, Gtk.ResponseType.OK)
286
+ box = dlg.get_content_area()
287
+ box.add(btn)
288
+ box.add(scrolled)
289
+ dlg.show_all()
290
+ rc = dlg.run()
291
+ if rc == Gtk.ResponseType.OK:
292
+ f_model = tree.get_model()
293
+ n_files = f_model.iter_n_children()
294
+ model.set_value(lv_iter, PanelVisualInspection.F_LIST, f_model)
295
+ model.set_value(lv_iter, PanelVisualInspection.N_FILES, n_files)
296
+
297
+ dlg.hide()
298
+ dlg.destroy()
299
+
300
+ self.write_message("Defects added\n")
301
+
302
+ def on_file_pressed(self, tree, event):
303
+ """Called when right button clicked in add image dialog.
304
+
305
+ Opens a pop-up menu to delete the selected entry."""
306
+ # double click shows attachments
307
+ if event.button == 1 and event.type == Gdk.EventType.DOUBLE_BUTTON_PRESS:
308
+ self.write_message("This is a double click.\n")
309
+ return
310
+
311
+
312
+ if event.button != 3:
313
+ return
314
+
315
+ model, lv_iter, values = self.get_iter_at_position(tree, event)
316
+ if not values:
317
+ return
318
+ menu = Gtk.Menu()
319
+
320
+ item_show = Gtk.MenuItem(label="Delete")
321
+ item_show.connect("activate", self.on_delete_image, (model, lv_iter, values))
322
+ menu.append(item_show)
323
+
324
+ menu.show_all()
325
+ menu.popup_at_pointer(event)
326
+
327
+ def on_delete_image(self, item, data):
328
+ """Delete a defect and image"""
329
+ model, lv_iter, _ = data
330
+ model.remove(lv_iter)
331
+
332
+ def on_add_image(self, btn, model):
333
+ """Adds a new image."""
334
+ dlg = Gtk.Dialog(title="Add Image")
335
+
336
+ dlg.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
337
+ Gtk.STOCK_OK, Gtk.ResponseType.OK)
338
+ box = dlg.get_content_area()
339
+ grid = Gtk.Grid(column_spacing=5, row_spacing=1)
340
+ box.add(grid)
341
+
342
+ irow = 0
343
+ lbl = Gtk.Label(label="Description")
344
+ lbl.set_xalign(0)
345
+ grid.attach(lbl, 0, irow, 1, 1)
346
+
347
+ desc = Gtk.Entry()
348
+ grid.attach(desc, 1, irow, 1, 1)
349
+
350
+ irow += 1
351
+ lbl = Gtk.Label(label="Image")
352
+ lbl.set_xalign(0)
353
+ grid.attach(lbl, 0, irow, 1, 1)
354
+
355
+ fC = Gtk.FileChooserButton()
356
+ grid.attach(fC, 1, irow, 1, 1)
357
+
358
+ dlg.show_all()
359
+
360
+ rc = dlg.run()
361
+ if rc == Gtk.ResponseType.OK:
362
+ D = desc.get_text()
363
+ P = Path(fC.get_filename()).expanduser().resolve()
364
+ model.append([D, P.name, P.as_posix()])
365
+
366
+ dlg.hide()
367
+ dlg.destroy()
240
368
 
241
369
  def on_show_json(self, item, data):
242
370
  """Test JSon."""
243
- model, iter, val = data
371
+ model, lv_iter, val = data
244
372
  payload = val[PanelVisualInspection.TEST_J].js
245
373
  value, dlg = create_json_data_editor(payload)
246
374
  rc = dlg.run()
247
375
  if rc == Gtk.ResponseType.OK:
248
376
  payload = value.values
249
- model.set_value(iter, PanelVisualInspection.TEST_J, TestJson(payload))
377
+ model.set_value(lv_iter, PanelVisualInspection.TEST_J, TestJson(payload))
250
378
 
251
379
  dlg.hide()
252
380
  dlg.destroy()
253
381
 
254
382
  def on_show_comments(self, item, data):
255
383
  """Show comments"""
256
- model, iter, val = data
384
+ model, lv_iter, val = data
257
385
  js = val[PanelVisualInspection.TEST_J].js
258
386
  SC = ShowComments("Test Comments", js["comments"], self)
259
387
  rc = SC.run()
260
388
  if rc == Gtk.ResponseType.OK:
261
389
  js["comments"] = SC.comments
262
- model.set_value(iter, PanelVisualInspection.TEST_J, TestJson(js))
390
+ model.set_value(lv_iter, PanelVisualInspection.TEST_J, TestJson(js))
263
391
 
264
392
  SC.hide()
265
393
  SC.destroy()
266
394
 
267
395
  def on_show_defects(self, item, data):
268
396
  """Show comments"""
269
- model, iter, val = data
397
+ model, lv_iter, val = data
270
398
  js = val[PanelVisualInspection.TEST_J].js
271
399
  SD = ShowDefects("Test Defects", js["defects"], self)
272
400
  rc = SD.run()
273
401
  if rc == Gtk.ResponseType.OK:
274
402
  js["defects"] = SD.defects
275
- model.set_value(iter, PanelVisualInspection.TEST_J, TestJson(js))
403
+ model.set_value(lv_iter, PanelVisualInspection.TEST_J, TestJson(js))
276
404
 
277
405
  SD.hide()
278
406
  SD.destroy()
@@ -335,7 +463,17 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
335
463
  if child["component"] is not None:
336
464
  child_SN = child["component"]["serialNumber"]
337
465
  skltn["component"] = child_SN
338
- model.append([child_SN, True, "", "", TestJson(skltn)])
466
+ if is_PWB:
467
+ position = child["order"]
468
+ else:
469
+ position = -1
470
+ for P in child["properties"]:
471
+ if P["code"] == "HYBRID_POSITION":
472
+ if P["value"] is not None:
473
+ position = int(P["value"])
474
+ break
475
+
476
+ model.append([child_SN, position, True, 0, self.create_file_model(), TestJson(skltn)])
339
477
 
340
478
  self.tree.set_model(model)
341
479
 
@@ -345,29 +483,74 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
345
483
  SN = self.SN.get_text()
346
484
 
347
485
  model = self.tree.get_model()
348
- iter = model.get_iter_first()
486
+ lv_iter = model.get_iter_first()
349
487
  n_items = 0
350
- while iter:
351
- values = model[iter]
488
+ global_link = None
489
+ while lv_iter:
490
+ values = model[lv_iter]
352
491
  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
492
 
359
- rc = ITkDButils.upload_test(self.session, payload, attachments)
493
+ attachments = []
494
+ if global_link is None:
495
+ A = ITkDButils.Attachment(path=self.global_image, title="Global Image", desc="Image of whole panel")
496
+ attachments.append(A)
497
+
498
+ im_model = values[PanelVisualInspection.F_LIST]
499
+ im_iter = im_model.get_iter_first()
500
+ idef = 1
501
+ while im_iter:
502
+ defect, name, path = im_model[im_iter]
503
+ A = ITkDButils.Attachment(path=path, title="Defect {}".format(idef), desc=defect)
504
+ attachments.append(A)
505
+ idef += 1
506
+ im_iter = im_model.iter_next(im_iter)
507
+
508
+ rc = ITkDButils.upload_test(self.session, payload, attachments, check_runNumber=True)
360
509
  if rc:
361
510
  ipos = rc.find("The following details may help:")
362
511
  msg = rc[ipos:]
363
512
  dbGtkUtils.complain("Failed uploading test {}-{}".format(payload["component"], payload["testType"]), msg)
364
- self.write_message(msg)
513
+ self.write_message(msg+"\n")
365
514
 
366
515
  else:
367
516
  self.write_message("Upload {}-{} successfull\n".format(payload["component"], payload["testType"]))
517
+ if global_link is None:
518
+ try:
519
+ global_link = ITkDButils.attachment_urls[self.global_image.name]
520
+ except KeyError:
521
+ pass
522
+
523
+ if payload["testType"] == "PICTURE":
524
+ rc = ITkDButils.set_test_run_parameter(self.session,
525
+ ITkDButils.uploaded_test_runs[0],
526
+ "COMMENT", "Picture of PW carrier")
527
+
528
+ rc = ITkDButils.set_test_run_parameter(self.session,
529
+ ITkDButils.uploaded_test_runs[0],
530
+ "LINK_TO_PICTURE", global_link)
531
+ if rc:
532
+ ipos = rc.find("The following details may help:")
533
+ msg = rc[ipos:]
534
+ dbGtkUtils.complain("Failed updating LINK_TO_PICTURE {}-{}".format(payload["component"],
535
+ payload["testType"]), msg)
536
+ self.write_message(msg+'\n')
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"],
546
+ payload["testType"]), msg)
547
+ self.write_message(msg+"\n")
548
+ else:
549
+ self.write_message("Image: {}\n".format(global_link))
550
+
368
551
 
369
552
  n_items += 1
370
- iter = model.iter_next(iter)
553
+ lv_iter = model.iter_next(lv_iter)
371
554
 
372
555
 
373
556
  def get_qrcode(self, fd, state, reader):
@@ -380,6 +563,8 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
380
563
  def main():
381
564
  """Main entry."""
382
565
  # DB login
566
+ HELP_LINK="https://itkdb-gtk.docs.cern.ch/panelVisualInspection.html"
567
+
383
568
  dlg = ITkDBlogin.ITkDBlogin()
384
569
  client = dlg.get_client()
385
570
  if client is None:
@@ -389,7 +574,7 @@ def main():
389
574
 
390
575
  client.user_gui = dlg
391
576
 
392
- gTest = PanelVisualInspection(client)
577
+ gTest = PanelVisualInspection(client, help_link=HELP_LINK)
393
578
 
394
579
  gTest.present()
395
580
  gTest.connect("destroy", Gtk.main_quit)
@@ -402,4 +587,4 @@ def main():
402
587
  dlg.die()
403
588
 
404
589
  if __name__ == "__main__":
405
- main()
590
+ 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,8 +83,8 @@ 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"
87
- inst = self.create_institute_combo()
86
+ self.institute = self.pdb_user["institutions"][0]["code"]
87
+ inst = self.create_institute_combo(only_user=True)
88
88
  inst.connect("changed", self.new_institute)
89
89
  inst.set_tooltip_text("Select the Institute.")
90
90
  grid.attach(inst, 1, 1, 1, 1)
@@ -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",
@@ -180,7 +187,7 @@ class PetalReceptionTests(dbGtkUtils.ITkDBWindow):
180
187
  self.dbObject = ITkDButils.get_DB_component(self.session, SN)
181
188
 
182
189
  except Exception as E:
183
- self.write_message(str(E))
190
+ self.write_message(str(E)+'\n')
184
191
  dbGtkUtils.complain("Could not find object in DB", str(E))
185
192
  self.dbObject = None
186
193
  return
@@ -191,7 +198,7 @@ class PetalReceptionTests(dbGtkUtils.ITkDBWindow):
191
198
  """Add a new defect."""
192
199
  page = self.notebook.get_nth_page(self.notebook.get_current_page())
193
200
  values = dbGtkUtils.get_a_list_of_values("Insert new defect", ("Type", "Description/v"))
194
- if len(values):
201
+ if len(values)>0:
195
202
  defect = {"name": values[0], "description": values[1]}
196
203
  page.dict_dialog.values["defects"].append(defect)
197
204
  page.dict_dialog.refresh()
@@ -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
 
@@ -273,6 +280,8 @@ class PetalReceptionTests(dbGtkUtils.ITkDBWindow):
273
280
  def main():
274
281
  """Main entry."""
275
282
  # DB login
283
+ HELP_LINK="https://itkdb-gtk.docs.cern.ch/petalReceptionTests.html"
284
+
276
285
  dlg = ITkDBlogin.ITkDBlogin()
277
286
  client = dlg.get_client()
278
287
  if client is None:
@@ -282,7 +291,7 @@ def main():
282
291
 
283
292
  client.user_gui = dlg
284
293
 
285
- gTest = PetalReceptionTests(client)
294
+ gTest = PetalReceptionTests(client, help_link=HELP_LINK)
286
295
 
287
296
  gTest.present()
288
297
  gTest.connect("destroy", Gtk.main_quit)