Esempio n. 1
0
    def load_file(self, filename=None):
        if filename is None:
            filename = self.select_file()
        if filename is None:
            return True

        self.filename = None

        try:
            f = file(filename, "r")
        except IOError:
            gmGuiHelpers.gm_show_error(_("Cannot access xDT file\n\n" " [%s]"), _("loading xDT file"))
            return False
        f.close()

        encoding = gmXdtObjects.determine_xdt_encoding(filename=filename)
        if encoding is None:
            encoding = "utf8"
            gmDispatcher.send(signal="statustext", msg=_("Encoding missing in xDT file. Assuming [%s].") % encoding)
            _log.warning("xDT file [%s] does not define an encoding, assuming [%s]" % (filename, encoding))

        try:
            xdt_file = io.open(filename, mode="rt", encoding=encoding, errors="replace")
        except IOError:
            gmGuiHelpers.gm_show_error(_("Cannot access xDT file\n\n" " [%s]"), _("loading xDT file"))
            return False

            # parse and display file
        self._LCTRL_xdt.DeleteAllItems()

        self._LCTRL_xdt.InsertStringItem(index=0, label=_("name of xDT file"))
        self._LCTRL_xdt.SetStringItem(index=0, col=1, label=filename)

        idx = 1
        for line in xdt_file:
            line = line.replace("\015", "")
            line = line.replace("\012", "")
            length, field, content = line[:3], line[3:7], line[7:]

            try:
                left = gmXdtMappings.xdt_id_map[field]
            except KeyError:
                left = field

            try:
                right = gmXdtMappings.xdt_map_of_content_maps[field][content]
            except KeyError:
                right = content

            self._LCTRL_xdt.InsertStringItem(index=idx, label=left)
            self._LCTRL_xdt.SetStringItem(index=idx, col=1, label=right)
            self._LCTRL_xdt.SetStringItem(index=idx, col=2, label=field)
            self._LCTRL_xdt.SetStringItem(index=idx, col=3, label=content)
            idx += 1

        xdt_file.close()

        self._LCTRL_xdt.SetColumnWidth(0, wx.LIST_AUTOSIZE)
        self._LCTRL_xdt.SetColumnWidth(1, wx.LIST_AUTOSIZE)

        self._LCTRL_xdt.SetFocus()
        self._LCTRL_xdt.SetItemState(
            item=0,
            state=wx.LIST_STATE_SELECTED | wx.LIST_STATE_FOCUSED,
            stateMask=wx.LIST_STATE_SELECTED | wx.LIST_STATE_FOCUSED,
        )

        self.filename = filename
Esempio n. 2
0
    def load_file(self, filename=None):
        if filename is None:
            filename = self.select_file()
        if filename is None:
            return True

        self.filename = None

        try:
            f = file(filename, 'r')
        except IOError:
            gmGuiHelpers.gm_show_error(_('Cannot access xDT file\n\n'
                                         ' [%s]'), _('loading xDT file'))
            return False
        f.close()

        encoding = gmXdtObjects.determine_xdt_encoding(filename=filename)
        if encoding is None:
            encoding = 'utf8'
            gmDispatcher.send(
                signal='statustext',
                msg=_('Encoding missing in xDT file. Assuming [%s].') %
                encoding)
            _log.warning(
                'xDT file [%s] does not define an encoding, assuming [%s]' %
                (filename, encoding))

        try:
            xdt_file = io.open(filename,
                               mode='rt',
                               encoding=encoding,
                               errors='replace')
        except IOError:
            gmGuiHelpers.gm_show_error(_('Cannot access xDT file\n\n'
                                         ' [%s]'), _('loading xDT file'))
            return False

        # parse and display file
        self._LCTRL_xdt.DeleteAllItems()

        self._LCTRL_xdt.InsertStringItem(index=0, label=_('name of xDT file'))
        self._LCTRL_xdt.SetStringItem(index=0, col=1, label=filename)

        idx = 1
        for line in xdt_file:
            line = line.replace('\015', '')
            line = line.replace('\012', '')
            length, field, content = line[:3], line[3:7], line[7:]

            try:
                left = gmXdtMappings.xdt_id_map[field]
            except KeyError:
                left = field

            try:
                right = gmXdtMappings.xdt_map_of_content_maps[field][content]
            except KeyError:
                right = content

            self._LCTRL_xdt.InsertStringItem(index=idx, label=left)
            self._LCTRL_xdt.SetStringItem(index=idx, col=1, label=right)
            self._LCTRL_xdt.SetStringItem(index=idx, col=2, label=field)
            self._LCTRL_xdt.SetStringItem(index=idx, col=3, label=content)
            idx += 1

        xdt_file.close()

        self._LCTRL_xdt.SetColumnWidth(0, wx.LIST_AUTOSIZE)
        self._LCTRL_xdt.SetColumnWidth(1, wx.LIST_AUTOSIZE)

        self._LCTRL_xdt.SetFocus()
        self._LCTRL_xdt.SetItemState(
            item=0,
            state=wx.LIST_STATE_SELECTED | wx.LIST_STATE_FOCUSED,
            stateMask=wx.LIST_STATE_SELECTED | wx.LIST_STATE_FOCUSED)

        self.filename = filename