diff --git a/cards/passport_application.py b/cards/passport_application.py index 9e65c2b..7108e06 100644 --- a/cards/passport_application.py +++ b/cards/passport_application.py @@ -466,7 +466,7 @@ class FAC: for index, face in enumerate(self.faces): face.store(basename="%s_%02i" % (basename, index)) - def get_data(self): + def get_images(self): return [face.get_data() for face in self.faces] # Note: Probably all of the code in this class is wrong. I'm just guessing from examples and parts of specifications I didn't fully read --Henryk @@ -945,6 +945,12 @@ class Passport(object): def parse_DG2(self, contents): self.dg2_cbeff = CBEFF.from_data(contents) + def parse_DG5(self, contents): + self.dg5_tlv = TLV_utils.unpack(contents) + + def parse_DG7(self, contents): + self.dg7_tlv = TLV_utils.unpack(contents) + def calculate_check_digit(data, digit=None, field=None): """Calculate a check digit. If digit is not None then it will be compared to the calculated check digit and a PassportParseError will be raised on a mismatch. Optional argument field diff --git a/gui/__init__.py b/gui/__init__.py index 6e328d9..396108c 100644 --- a/gui/__init__.py +++ b/gui/__init__.py @@ -1,5 +1,5 @@ import gtk,gtk.glade,gobject -import os, time +import os, time, TLV_utils class Converter: SUPPORTS = ["jp2"] @@ -31,6 +31,8 @@ class PassportGUI: "on_exit_clicked": self.exit_clicked, "on_main_delete_event": self.exit_clicked, "on_main_destroy": gtk.main_quit, + "on_next_image_clicked": self.next_image, + "on_prev_image_clicked": self.prev_image, } self.main_window_xml.signal_autoconnect(signals) @@ -102,7 +104,15 @@ class PassportGUI: data = [] if hasattr(passport, "dg2_cbeff") and passport.dg2_cbeff is not None: for biometric in passport.dg2_cbeff.biometrics: - data = data + [(a,b,"Encoded Face") for (a,b) in biometric.get_data()] + data = data + [(a,b,"Encoded Face") for (a,b) in biometric.get_images()] + + for dg, tag, type in ( ("dg5", 0x5F40, "Displayed Portrait"), ("dg7", 0x5F43, "Displayed Signature or Usual Mark") ): + if hasattr(passport, "%s_tlv" % dg): + structure = getattr(passport, "%s_tlv" % dg) + if structure is not None: + hits = TLV_utils.tlv_find_tag(structure, tag) + for t,l,v in hits: + data.append( ("jpg",v,type) ) self._set_images(data) @@ -121,14 +131,17 @@ class PassportGUI: self.update_image_shown() - def update_image_shown(self): + def update_image_shown(self, add=0): + self.now_showing = self.now_showing + add + if self.now_showing >= len(self.images): self.now_showing = len(self.images)-1 + if self.now_showing < 0: + self.now_showing = 0 if len(self.images) > 0: pixbuf, description = self.images[self.now_showing] else: - self.now_showing = 0 pixbuf, description = None, "No image loaded" label = self.main_window_xml.get_widget("image_label") @@ -142,3 +155,12 @@ class PassportGUI: if pixbuf is not None: self.main_window_xml.get_widget("image").set_from_pixbuf(pixbuf) + + self.main_window_xml.get_widget("prev_image").set_property("sensitive", self.now_showing > 0) + self.main_window_xml.get_widget("next_image").set_property("sensitive", self.now_showing < len(self.images)-1) + + def next_image(self, widget): + self.update_image_shown(+1) + + def prev_image(self, widget): + self.update_image_shown(-1) diff --git a/gui/passport/passport.glade b/gui/passport/passport.glade index d6bc2e8..97acc77 100644 --- a/gui/passport/passport.glade +++ b/gui/passport/passport.glade @@ -322,12 +322,13 @@ Optional Data - + True False True GTK_RELIEF_NORMAL True + @@ -352,12 +353,13 @@ Optional Data - + True False True GTK_RELIEF_NORMAL True +