X-Git-Url: http://git.datanom.net/lensdatabase.git/blobdiff_plain/365c79d46c3804dd4b3f796bd2fcd4e3ddf1186b..29f0e748a8cd062a091bc4cca710fa91f720c11c:/newlensdialog.py?ds=sidebyside diff --git a/newlensdialog.py b/newlensdialog.py new file mode 100644 index 0000000..e5b654e --- /dev/null +++ b/newlensdialog.py @@ -0,0 +1,77 @@ +import gi +gi.require_version("Gtk", "3.0") +from gi.repository import Gtk + +class NewlensDialog(Gtk.Dialog): + def __init__(self, builder, db, path = None): + from notebook import Notebook + from textview import Textview + + self.path = path + self.builder = builder + self.notebook = Notebook(self.builder, db) + Gtk.Dialog.__init__(self, parent=None) + self.set_title("New [{maker}] Lens".format(maker = self.notebook.getCurrentPageLabel())) + self.set_default_size(400, 200) + if path is not None: + self.add_button("_Delete", Gtk.ResponseType.DELETE_EVENT) + self.add_button("_Update", Gtk.ResponseType.APPLY) + btn = self.add_button("_Close", Gtk.ResponseType.CLOSE) + else: + self.add_button("_OK", Gtk.ResponseType.OK) + btn = self.add_button("_Cancel", Gtk.ResponseType.CANCEL) + + self.connect("response", self.on_response) + + box = self.get_content_area() + snLabel = Gtk.Label(label="Serial No") + self.snEntry = Gtk.Entry() + self.snEntry.set_placeholder_text("Serial No") + self.snEntry.set_tooltip_text("Enter serial no of the lens") + box.add(snLabel) + box.add(self.snEntry) + descLabel = Gtk.Label(label="Lens description") + self.descEntry = Gtk.Entry() + self.descEntry.set_placeholder_text("Lens description") + self.descEntry.set_tooltip_text("Enter description of the lens") + box.add(descLabel) + box.add(self.descEntry) + noteLabel = Gtk.Label(label="Notes") + self.textview = Textview() + box.add(noteLabel) + box.add(self.textview.getScrolledWindow()) + self.show_all() + btn.grab_focus() + + def on_response(self, dialog, response): + if response == Gtk.ResponseType.OK: + sn = int(self.snEntry.get_text()) + desc = self.descEntry.get_text() + notes = self.textview.getText() + page = self.notebook.getCurrentPageLabel() + self.notebook.addRow(page, (sn, desc, notes)) + elif response == Gtk.ResponseType.CANCEL: + pass + elif response == Gtk.ResponseType.APPLY: + sn = int(self.snEntry.get_text()) + desc = self.descEntry.get_text() + notes = self.textview.getText() + model = self.path[0] + iter = model.get_iter(self.path[1]) + id = model.get_value(iter, 3) + self.notebook.updateRow(self.path, (sn, desc, notes, id)) + elif response == Gtk.ResponseType.DELETE_EVENT: + model = self.path[0] + iter = model.get_iter(self.path[1]) + id = model.get_value(iter, 3) + self.notebook.deleteRow(self.path, id) + elif response == Gtk.ResponseType.CLOSE: + pass + else: + pass + dialog.destroy() + + def setText(self, data): + self.snEntry.set_text(str(data[0])) + self.descEntry.set_text(data[1]) + self.textview.setText(data[2])