itkdb-gtk 0.0.14__py3-none-any.whl → 0.0.16__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.

@@ -4,12 +4,14 @@ import pathlib
4
4
  import sys
5
5
 
6
6
  try:
7
- import dbGtkUtils
8
- import ITkDBlogin
9
- import ITkDButils
10
- except ModuleNotFoundError:
11
- from itkdb_gtk import dbGtkUtils, ITkDBlogin, ITkDButils
12
-
7
+ import itkdb_gtk
8
+
9
+ except ImportError:
10
+ from pathlib import Path
11
+ cwd = Path(sys.argv[0]).parent.parent
12
+ sys.path.append(cwd.as_posix())
13
+
14
+ from itkdb_gtk import dbGtkUtils, ITkDBlogin, ITkDButils
13
15
  import gi
14
16
  import serial
15
17
 
@@ -125,8 +127,7 @@ class ReceiveShipments(dbGtkUtils.ITkDBWindow):
125
127
  paned.add1(tree_view)
126
128
 
127
129
  # The text view
128
- frame = self.create_text_view()
129
- paned.add2(frame)
130
+ paned.add2(self.message_panel.frame)
130
131
 
131
132
  self.show_all()
132
133
 
itkdb_gtk/GlueWeight.py CHANGED
@@ -7,11 +7,14 @@ from copy import deepcopy
7
7
  from pathlib import Path
8
8
 
9
9
  try:
10
- import dbGtkUtils
11
- import ITkDBlogin
12
- import ITkDButils
13
- except ModuleNotFoundError:
14
- from itkdb_gtk import dbGtkUtils, ITkDBlogin, ITkDButils
10
+ import itkdb_gtk
11
+
12
+ except ImportError:
13
+ from pathlib import Path
14
+ cwd = Path(sys.argv[0]).parent.parent
15
+ sys.path.append(cwd.as_posix())
16
+
17
+ from itkdb_gtk import dbGtkUtils, ITkDBlogin, ITkDButils
15
18
 
16
19
  import gi
17
20
  gi.require_version("Gtk", "3.0")
@@ -4,14 +4,16 @@ import json
4
4
  import sys
5
5
 
6
6
  try:
7
- import dbGtkUtils
8
- import ITkDBlogin
9
- import ITkDButils
10
- except ModuleNotFoundError:
11
- from itkdb_gtk import dbGtkUtils, ITkDBlogin, ITkDButils
7
+ import itkdb_gtk
8
+
9
+ except ImportError:
10
+ from pathlib import Path
11
+ cwd = Path(sys.argv[0]).parent.parent
12
+ sys.path.append(cwd.as_posix())
12
13
 
13
- import gi
14
+ from itkdb_gtk import dbGtkUtils, ITkDBlogin, ITkDButils
14
15
 
16
+ import gi
15
17
  gi.require_version("Gtk", "3.0")
16
18
  from gi.repository import Gtk, Gio
17
19
 
@@ -99,10 +101,10 @@ class GroundingTest(dbGtkUtils.ITkDBWindow):
99
101
  # Create the Notebook pages
100
102
  self.create_test_box("Visual Inspection", "VISUAL_INSPECTION")
101
103
  self.create_test_box("Grounding", "GROUNDING_CHECK")
104
+ self.create_test_box("Pipe bending", "BENDING120")
102
105
 
103
106
  # The text view
104
- frame = self.create_text_view()
105
- self.mainBox.pack_end(frame, True, True, 5)
107
+ self.mainBox.pack_end(self.message_panel.frame, True, True, 5)
106
108
 
107
109
  self.show_all()
108
110
 
itkdb_gtk/ITkDBlogin.py CHANGED
@@ -92,6 +92,7 @@ class ITkDBlogin(Gtk.Dialog):
92
92
 
93
93
  if gtk_runs:
94
94
  self.create_window()
95
+ self.present()
95
96
  self.run()
96
97
 
97
98
  else:
itkdb_gtk/ITkDButils.py CHANGED
@@ -235,9 +235,13 @@ def set_object_stage(client, SN, stage):
235
235
  def get_DB_component(client, SN):
236
236
  """Get ta component by its serial number."""
237
237
  global db_response
238
- db_response = client.get('getComponent', json={'component': SN})
239
- return db_response
238
+ try:
239
+ db_response = client.get('getComponent', json={'component': SN})
240
+ return db_response
240
241
 
242
+ except Exception as e:
243
+ db_response = str(e)
244
+ return None
241
245
 
242
246
  def upload_test(client, data, attachments=None):
243
247
  """Upload a test to the DB.
@@ -7,11 +7,14 @@ import pathlib
7
7
  import sys
8
8
 
9
9
  try:
10
- import dbGtkUtils
11
- import ITkDBlogin
12
- import ITkDButils
13
- except ModuleNotFoundError:
14
- from itkdb_gtk import dbGtkUtils, ITkDBlogin, ITkDButils
10
+ import itkdb_gtk
11
+
12
+ except ImportError:
13
+ from pathlib import Path
14
+ cwd = Path(sys.argv[0]).parent.parent
15
+ sys.path.append(cwd.as_posix())
16
+
17
+ from itkdb_gtk import dbGtkUtils, ITkDBlogin, ITkDButils
15
18
 
16
19
  import gi
17
20
  import serial
@@ -125,8 +128,7 @@ class SendShipments(dbGtkUtils.ITkDBWindow):
125
128
  paned.add1(tree_view)
126
129
 
127
130
  # The text view
128
- frame = self.create_text_view()
129
- paned.add2(frame)
131
+ paned.add2(self.message_panel.frame)
130
132
 
131
133
  self.show_all()
132
134
 
@@ -1,9 +1,15 @@
1
+ import sys
1
2
  from pathlib import Path
3
+
2
4
  try:
3
- import dbGtkUtils
4
- import ITkDButils
5
- except ModuleNotFoundError:
6
- from itkdb_gtk import dbGtkUtils, ITkDButils
5
+ import itkdb_gtk
6
+
7
+ except ImportError:
8
+ from pathlib import Path
9
+ cwd = Path(sys.argv[0]).parent.parent
10
+ sys.path.append(cwd.as_posix())
11
+
12
+ from itkdb_gtk import dbGtkUtils, ITkDButils
7
13
 
8
14
  import gi
9
15
  gi.require_version("Gtk", "3.0")
@@ -83,6 +89,8 @@ class ShowAttachments(Gtk.Dialog):
83
89
  """Creates the tree vew with the attachments."""
84
90
  model = Gtk.ListStore(str, str, str, str)
85
91
  self.tree = Gtk.TreeView(model=model)
92
+ self.tree.connect("button-press-event", self.button_pressed)
93
+
86
94
  scrolled = Gtk.ScrolledWindow()
87
95
  scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
88
96
  scrolled.add(self.tree)
@@ -102,6 +110,122 @@ class ShowAttachments(Gtk.Dialog):
102
110
 
103
111
  return scrolled
104
112
 
113
+ def button_pressed(self, tree, event):
114
+ """Button clicked on top of attachment."""
115
+ # double click shows attachments
116
+ it = None
117
+ model = self.tree.get_model()
118
+ if event.button == 1 and event.type == Gdk.EventType.DOUBLE_BUTTON_PRESS:
119
+ select = self.tree.get_selection()
120
+ model, it = select.get_selected()
121
+ if not it:
122
+ return
123
+
124
+ self.edit_attachment(model, it)
125
+ return
126
+
127
+ if event.button != 3:
128
+ return
129
+
130
+ # Create popup menu
131
+ select = self.tree.get_selection()
132
+ model, it = select.get_selected()
133
+ values = None
134
+ if it:
135
+ values = model[it]
136
+
137
+ else:
138
+ P = tree.get_path_at_pos(event.x, event.y)
139
+ if P:
140
+ it = model.get_iter(P[0])
141
+ values = model[it]
142
+
143
+ if not values:
144
+ return
145
+
146
+ if not it:
147
+ P = self.tree.get_path_at_pos(event.x, event.y)
148
+ if P:
149
+ it = model.get_iter(P[0])
150
+
151
+ if not it:
152
+ return
153
+
154
+ menu = Gtk.Menu()
155
+ item_edit = Gtk.MenuItem(label="Edit")
156
+ item_edit.connect("activate", self.on_edit_attachment, (model, it))
157
+ menu.append(item_edit)
158
+
159
+ item_show = Gtk.MenuItem(label="Show file")
160
+ item_show.connect("activate", self.on_show_file, (model, it))
161
+ menu.append(item_show)
162
+
163
+ menu.show_all()
164
+ menu.popup_at_pointer(event)
165
+
166
+ def edit_attachment(self, model, it):
167
+ """Edit attachment at current row."""
168
+ values = model[it]
169
+ dlg = add_attachment_dialog()
170
+ dlg.fC.set_filename(values[3])
171
+ dlg.att_title.set_text(values[1])
172
+ dlg.att_desc.set_text(values[2])
173
+ rc = dlg.run()
174
+ if rc == Gtk.ResponseType.OK:
175
+ path = Path(dlg.fC.get_filename())
176
+ title = dlg.att_title.get_text()
177
+ desc = dlg.att_desc.get_text()
178
+ model.set_value(it, 0, path.name)
179
+ model.set_value(it, 1, title)
180
+ model.set_value(it, 2, desc)
181
+ model.set_value(it, 3, path.as_posix())
182
+
183
+ dlg.hide()
184
+ dlg.destroy()
185
+
186
+ def on_edit_attachment(self, item, data):
187
+ """Test JSon."""
188
+ model, it = data
189
+ self.edit_attachment(model, it)
190
+
191
+
192
+ def on_show_file(self, item, data):
193
+ """Test JSon."""
194
+ model, it = data
195
+ values = model[it]
196
+ sss = None
197
+ try:
198
+ with open(values[3], "tr", encoding="utf-8") as f:
199
+ sss = f.read()
200
+
201
+ except UnicodeDecodeError:
202
+ dbGtkUtils.complain("Error showing file", "File is not a text file")
203
+ return
204
+
205
+
206
+ dlg = Gtk.Dialog(title="Add Attachment",
207
+ transient_for=self,
208
+ flags=0)
209
+ dlg.add_buttons(Gtk.STOCK_OK, Gtk.ResponseType.OK)
210
+ dlg.set_size_request(300, 200)
211
+ area = dlg.get_content_area()
212
+ box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
213
+ area.add(box)
214
+
215
+ scrolledwindow = Gtk.ScrolledWindow()
216
+ box.pack_start(scrolledwindow, False, True, 0)
217
+
218
+ scrolledwindow.set_hexpand(True)
219
+ scrolledwindow.set_vexpand(True)
220
+ textview = Gtk.TextView()
221
+ textview.get_buffer().set_text(sss)
222
+ scrolledwindow.add(textview)
223
+ dlg.show_all()
224
+ dlg.run()
225
+ dlg.hide()
226
+ dlg.destroy()
227
+
228
+
105
229
  def add_attachment(self, *args):
106
230
  """Add Attachment button clicked."""
107
231
  dlg = add_attachment_dialog()
@@ -123,15 +247,19 @@ class ShowAttachments(Gtk.Dialog):
123
247
  def remove_attachment(self, *args):
124
248
  """Remove selected attachment."""
125
249
  select = self.tree.get_selection()
126
- model, iter = select.get_selected()
127
- if iter:
128
- values = model[iter]
250
+ model, it = select.get_selected()
251
+ if it:
252
+ values = model[it]
129
253
  for a in self.attachments:
130
254
  if a.path == values[3]:
131
255
  rc = dbGtkUtils.ask_for_confirmation("Remove this attachment ?",
132
256
  "{} - {}\n{}".format(a.title, a.desc, values[0]))
133
257
  if rc:
134
258
  self.attachments.remove(a)
135
- model.remove(iter)
259
+ model.remove(it)
136
260
 
137
261
  break
262
+
263
+ if __name__ == "__main__":
264
+ SA = ShowAttachments("Test Attachments", None)
265
+ SA.run()
itkdb_gtk/ShowComments.py CHANGED
@@ -1,7 +1,16 @@
1
+ #!/usr/bin/env python3
2
+ """Shows comments."""
3
+
1
4
  try:
2
- import dbGtkUtils
3
- except ModuleNotFoundError:
4
- from itkdb_gtk import dbGtkUtils
5
+ import itkdb_gtk
6
+
7
+ except ImportError:
8
+ import sys
9
+ from pathlib import Path
10
+ cwd = Path(sys.argv[0]).parent.parent
11
+ sys.path.append(cwd.as_posix())
12
+
13
+ from itkdb_gtk import dbGtkUtils
5
14
 
6
15
  import gi
7
16
  gi.require_version("Gtk", "3.0")
itkdb_gtk/ShowDefects.py CHANGED
@@ -1,7 +1,14 @@
1
+
1
2
  try:
2
- import dbGtkUtils
3
- except ModuleNotFoundError:
4
- from itkdb_gtk import dbGtkUtils
3
+ import itkdb_gtk
4
+
5
+ except ImportError:
6
+ import sys
7
+ from pathlib import Path
8
+ cwd = Path(sys.argv[0]).parent.parent
9
+ sys.path.append(cwd.as_posix())
10
+
11
+ from itkdb_gtk import dbGtkUtils
5
12
 
6
13
  import gi
7
14
  gi.require_version("Gtk", "3.0")
@@ -10,10 +17,15 @@ from gi.repository import Gtk, Gio, Gdk
10
17
 
11
18
  class ShowDefects(Gtk.Dialog):
12
19
  """Edit defects"""
13
- def __init__(self, title, defects=[], parent=None):
20
+
21
+ def __init__(self, title, defects=None, parent=None):
14
22
  """Initialization."""
15
23
  super().__init__(title=title, transient_for=parent)
16
- self.defects = [C for C in defects]
24
+ if defects:
25
+ self.defects = [C for C in defects]
26
+ else:
27
+ self.defects = []
28
+
17
29
  self.init_window()
18
30
 
19
31
  def init_window(self):