Пример #1
0
    def install(self, filePath):
        """Install dictionary"""

        extention = os.path.splitext(filePath)[1][1:]
        succeeded = False

        try:
            if extention.lower() in dicttype.PLUGIN.getFileExtentions():
                try:
                    directory, dtype = installPlugin(filePath)
                    if directory:
                        if dtype.lower() == 'plugin':
                            dictionary = newplugin._loadDictionaryPlugin(
                                directory)
                        else:
                            dictionary = plaindict._loadPlainDictionary(
                                directory)
                        self.mainWin.addDictionary(dictionary)
                        succeeded = True

                except Exception as e:
                    errorwin.showErrorMessage(_("Installation failed"),
                                              e.args[0] or '')
                    self.mainWin.SetStatusText(_("Installation failed"))
                    return

            else:
                try:
                    directory = installPlainDictionary(filePath)
                    if directory:
                        dictionary = plaindict._loadPlainDictionary(directory)
                        self.mainWin.addDictionary(dictionary)
                        succeeded = True
                except Exception as e:
                    traceback.print_exc()
                    errorwin.showErrorMessage(_("Installation Error"),
                                              e.args[0] or '')
                    self.mainWin.SetStatusText(_("Error: Installation failed"))
                    return
        except:
            # Can this happen?
            self.mainWin.SetStatusText(_("Error: Installation failed"))
            traceback.print_exc()

        if succeeded:
            title = _("Dictionary installed")
            msg = _("Dictionary successfully installed. You can choose it " \
                    "from \"Dictionaries\" menu now.")
            errorwin.showInfoMessage(title, msg)
Пример #2
0
    def setAvailDicts(self, addons):
        """Clear the list of available dictionaries and set
       new items"""

        self.availableList.DeleteAllItems()

        names = addons.keys()
        names.sort()
        names.reverse()

        for name in names:
            addon = addons.get(name)

            index = self.availableList.InsertStringItem(0, addon.getName())
            self.availableList.SetStringItem(index, 1,
                                             str(addon.getSize()) + " KB")
            self.availableList.SetItemData(index, index + 1)

        if names:
            self.availableList.SetColumnWidth(0, wx.LIST_AUTOSIZE)
        else:
            title = _("List updated")
            msg = _("All your dictionaries are up to date.")
            errorwin.showInfoMessage(title, msg)
Пример #3
0
   def setAvailDicts(self, addons):
       """Clear the list of available dictionaries and set
       new items"""

       self.availableList.DeleteAllItems()

       names = addons.keys()
       names.sort()
       names.reverse()

       for name in names:
           addon = addons.get(name)

           index = self.availableList.InsertStringItem(0, addon.getName())
           self.availableList.SetStringItem(index, 1,
                                            str(addon.getSize())+" KB")
           self.availableList.SetItemData(index, index+1)

       if names:
           self.availableList.SetColumnWidth(0, wx.LIST_AUTOSIZE)
       else:
           title = _("List updated")
           msg = _("All your dictionaries are up to date.")
           errorwin.showInfoMessage(title, msg)
Пример #4
0
                except Exception, e:
                    traceback.print_exc()
                    errorwin.showErrorMessage(_("Installation Error"),
                                              e.args[0] or '')
                    self.mainWin.SetStatusText(_("Error: Installation failed"))
                    return
        except:
            # Can this happen?
            self.mainWin.SetStatusText(_("Error: Installation failed"))
            traceback.print_exc()

        if succeeded:
            title = _("Dictionary installed")
            msg = _("Dictionary successfully installed. You can choose it " \
                    "from \"Dictionaries\" menu now.")
            errorwin.showInfoMessage(title, msg)


def installPlainDictionary(filePath):
    """Install plain dictionary and return directory path"""

    if not os.path.exists(filePath):
        raise Exception, _("File %s does not exist") % filePath

    if not os.path.isfile(filePath):
        raise Exception, _("%s is not a file") % filePath

    util.makeDirectories()

    fileName = os.path.basename(filePath)
    dictionaryName = os.path.splitext(fileName)[0]
Пример #5
0
    def loadDictionary(self, dictInstance):
        """Prepares main window for using dictionary"""

        if not dictInstance:
            systemLog(ERROR, "loadDictionary: dictInstance is False")
            return

        #
        # Check licence agreement
        #
        licence = dictInstance.getLicence()

        if licence \
               and not self.app.agreements.getAccepted(dictInstance.getPath()):
            if not miscwin.showLicenceAgreement(None, licence):
                from lib.gui import errorwin
                title = _("Licence Agreement Rejected")
                msg = _("You cannot use dictionary \"%s\" without accepting "\
                        "licence agreement") % dictInstance.getName()
                errorwin.showErrorMessage(title, msg)
                return
            else:
                self.app.agreements.addAgreement(dictInstance.getPath())

        self.onCloseDict(None)
        self.activeDictionary = dictInstance

        if dictInstance.getType() in dicttype.indexableTypes:
            if plaindict.indexShouldBeMade(dictInstance):
                # Notify about indexing
                from lib.gui import errorwin
                title = _("Dictionary Index")
                msg = _("This is the first time you use this dictionary or it " \
                        "has been changed on disk since last indexing. " \
                        "Indexing is used to make search more efficient. " \
                        "The dictionary will be indexed now. It can take a few " \
                        "or more seconds.\n\n" \
                        "Press OK to continue...")
                errorwin.showInfoMessage(title, msg)

                # Make index
                try:
                    wx.BeginBusyCursor()
                    plaindict.makeIndex(dictInstance,
                                        self.app.config.get('encoding'))
                    wx.EndBusyCursor()
                except Exception as e:
                    wx.EndBusyCursor()
                    traceback.print_exc()
                    title = _("Index Creation Error")
                    msg = _("Error occured while indexing file. " \
                            "This may be because of currently selected " \
                            "character encoding %s is not correct for this " \
                            "dictionary. Try selecting " \
                            "another encoding from View > Character Encoding " \
                            "menu") % self.app.config.get('encoding')

                    from lib.gui import errorwin
                    errorwin.showErrorMessage(title, msg)
                    return

            # Load index
            try:
                wx.BeginBusyCursor()
                index = plaindict.loadIndex(dictInstance)
                self.activeDictionary.setIndex(index)
                wx.EndBusyCursor()
            except Exception as e:
                wx.EndBusyCursor()
                traceback.print_exc()
                title = _("Error")
                msg = _("Unable to load dictionary index table. "
                        "Got error: %s") % e
                from lib.gui import errorwin
                errorwin.showErrorMessage(title, msg)
                return

        wx.BeginBusyCursor()
        self.activeDictionary.start()
        self.checkIfNeedsList()
        self.SetTitle(titleTemplate % dictInstance.getName())
        self.SetStatusText(enc.toWX(_("Dictionary \"%s\" loaded") \
                                      % dictInstance.getName()))

        self.entry.SetFocus()

        try:
            self.checkEncMenuItem(self.activeDictionary.getEncoding())
        except Exception as e:
            systemLog(ERROR, "Unable to select encoding menu item: %s" % e)

        wx.EndBusyCursor()
Пример #6
0
                except Exception, e:
                    traceback.print_exc()
                    errorwin.showErrorMessage(_("Installation Error"),
                                              e.args[0] or '')
                    self.mainWin.SetStatusText(_("Error: Installation failed"))
                    return
        except:
            # Can this happen?
            self.mainWin.SetStatusText(_("Error: Installation failed"))
            traceback.print_exc()

        if succeeded:
            title = _("Dictionary installed")
            msg = _("Dictionary successfully installed. You can choose it " \
                    "from \"Dictionaries\" menu now.")
            errorwin.showInfoMessage(title, msg)



def installPlainDictionary(filePath):
    """Install plain dictionary and return directory path"""

    if not os.path.exists(filePath):
        raise Exception, _("File %s does not exist") % filePath

    if not os.path.isfile(filePath):
        raise Exception, _("%s is not a file") % filePath

    util.makeDirectories()

    fileName = os.path.basename(filePath)