]>
Commit | Line | Data |
---|---|---|
1 | import gi | |
2 | gi.require_version("Gtk", "3.0") | |
3 | from gi.repository import Gtk | |
4 | ||
5 | class NewlensDialog(Gtk.Dialog): | |
6 | def __init__(self, builder, db, path = None): | |
7 | from notebook import Notebook | |
8 | from textview import Textview | |
9 | ||
10 | self.path = path | |
11 | self.builder = builder | |
12 | self.notebook = Notebook(self.builder, db) | |
13 | Gtk.Dialog.__init__(self, parent=None) | |
14 | self.set_title("New [{maker}] Lens".format(maker = self.notebook.getCurrentPageLabel())) | |
15 | self.set_default_size(400, 200) | |
16 | if path is not None: | |
17 | self.add_button("_Delete", Gtk.ResponseType.DELETE_EVENT) | |
18 | self.add_button("_Update", Gtk.ResponseType.APPLY) | |
19 | btn = self.add_button("_Close", Gtk.ResponseType.CLOSE) | |
20 | else: | |
21 | self.add_button("_OK", Gtk.ResponseType.OK) | |
22 | btn = self.add_button("_Cancel", Gtk.ResponseType.CANCEL) | |
23 | ||
24 | self.connect("response", self.on_response) | |
25 | ||
26 | box = self.get_content_area() | |
27 | snLabel = Gtk.Label(label="Serial No") | |
28 | self.snEntry = Gtk.Entry() | |
29 | self.snEntry.set_placeholder_text("Serial No") | |
30 | self.snEntry.set_tooltip_text("Enter serial no of the lens") | |
31 | box.add(snLabel) | |
32 | box.add(self.snEntry) | |
33 | descLabel = Gtk.Label(label="Lens description") | |
34 | self.descEntry = Gtk.Entry() | |
35 | self.descEntry.set_placeholder_text("Lens description") | |
36 | self.descEntry.set_tooltip_text("Enter description of the lens") | |
37 | box.add(descLabel) | |
38 | box.add(self.descEntry) | |
39 | noteLabel = Gtk.Label(label="Notes") | |
40 | self.textview = Textview() | |
41 | box.add(noteLabel) | |
42 | box.add(self.textview.getScrolledWindow()) | |
43 | self.show_all() | |
44 | btn.grab_focus() | |
45 | ||
46 | def on_response(self, dialog, response): | |
47 | if response == Gtk.ResponseType.OK: | |
48 | sn = int(self.snEntry.get_text()) | |
49 | desc = self.descEntry.get_text() | |
50 | notes = self.textview.getText() | |
51 | page = self.notebook.getCurrentPageLabel() | |
52 | self.notebook.addRow(page, (sn, desc, notes)) | |
53 | elif response == Gtk.ResponseType.CANCEL: | |
54 | pass | |
55 | elif response == Gtk.ResponseType.APPLY: | |
56 | sn = int(self.snEntry.get_text()) | |
57 | desc = self.descEntry.get_text() | |
58 | notes = self.textview.getText() | |
59 | model = self.path[0] | |
60 | iter = model.get_iter(self.path[1]) | |
61 | id = model.get_value(iter, 3) | |
62 | self.notebook.updateRow(self.path, (sn, desc, notes, id)) | |
63 | elif response == Gtk.ResponseType.DELETE_EVENT: | |
64 | model = self.path[0] | |
65 | iter = model.get_iter(self.path[1]) | |
66 | id = model.get_value(iter, 3) | |
67 | self.notebook.deleteRow(self.path, id) | |
68 | elif response == Gtk.ResponseType.CLOSE: | |
69 | pass | |
70 | else: | |
71 | pass | |
72 | dialog.destroy() | |
73 | ||
74 | def setText(self, data): | |
75 | self.snEntry.set_text(str(data[0])) | |
76 | self.descEntry.set_text(data[1]) | |
77 | self.textview.setText(data[2]) |