Ejemplo n.º 1
0
 def __init__(self, abspath):
     self.__entries = []
     self.__dict17 = SimpleDictionary()  #WordDictionary(5, (u"", u""))
     self.__dictLin = SimpleDictionary()  #WordDictionary(5, (u"", u""))
     self.__dictDor = SimpleDictionary()  #WordDictionary(5, (u"", u""))
     self.__new = []
     self.__path = abspath
     if os.path.exists(abspath + os.sep + "hint.reg"):
         f = open(abspath + os.sep + "hint.reg")
         for line in f:
             if line == "\n" or line[0] == "#":
                 continue
             line = line[:-1]
             els = line.split(",")
             for i in range(0, len(els)):
                 els[i] = els[i].replace('\\;', ',').replace('\\\\', '\\')
             siglum = self.__computeSiglum(els)
             self.__entries.append((els[0], els[1], els[2], siglum))
             #c = Counter()
             if els[0] != '':
                 self.__dict17.addWord(ustr(els[0]), (els[0], siglum))
             if els[1] != '':
                 self.__dictLin.addWord(ustr(els[1]), (els[1], siglum))
             if els[2] != '':
                 self.__dictDor.addWord(ustr(els[2]), (els[2], siglum))
             #print c
         f.close()
Ejemplo n.º 2
0
 def incrementalAdd(self, hint):
     log.log("HintRegisterBrowser.incrementalAdd", [hint], 0)
     #c = Counter()
     if not self._initialized:
         log.log("HintRegisterBrowser.incrementalAdd return", [], 2)
         return
     if not self._smart:
         self.reinitialize()
         ind = self.__binaryFind(hint)
         RegisterBrowser._select(self, ind, veto=True)
         log.log("HintRegisterBrowser.incrementalAdd return", [], 3)
         return
     ind = self.__binaryFind(hint)
     if ind == len(self.__hints):
         #self._items.append(len(self._items))
         self._elements.append(stru(hint))
         self._elementLabels.append(ustr(hint))
     else:
         #self._items.insert(ind, ind)
         self._elements.insert(ind, stru(hint))
         self._elementLabels.insert(ind, ustr(hint))
     self._itemsNo += 1
     #print c
     self._reloadSelect(ind, veto=True)
     log.log("HintRegisterBrowser.incrementalAdd return", [], 1)
Ejemplo n.º 3
0
 def addHint(self, hint):
     (lcp17, sig17) = self.__dict17.findWord(ustr(hint))
     (lcpLin, sigLin) = self.__dictLin.findWord(ustr(hint))
     (lcpDor, sigDor) = self.__dictDor.findWord(ustr(hint))
     if ustr(lcp17) == ustr(hint) or ustr(lcpLin) == ustr(hint) or ustr(
             lcpDor) == ustr(hint):
         return False
         self.__new.append(str(hint.encode("utf-8")) + "\t" + getUser())
     self.__dict17.addWord(
         ustr(hint), (str(hint.encode("utf-8")), "(" + getUser() + ")"))
     self.__entries.append(
         (str(hint.encode("utf-8")), "", "", "(" + getUser() + ")"))
     self.sort()
     self.__new.append(str(hint.encode("utf-8")) + "\t" + getUser())
     return True
Ejemplo n.º 4
0
 def printYourself(self, level=0):
     if self._level == 0:
         for (k, v) in self._dict.iteritems():
             print(u"  " * level + k + u" " + ustr(v)).encode("utf-8")
     else:
         for (k, v) in self._dict.iteritems():
             print(u"  " * level + k + u":").encode("utf-8")
             v.printYourself(level + 1)
Ejemplo n.º 5
0
 def readUserHints(self, abspath):
     if os.path.exists(abspath + os.sep + "user_hint.reg"):
         f = open(abspath + os.sep + "user_hint.reg")
         for line in f:
             if line == "\n" or line[0] == "#":
                 continue
             els = line[:-1].split("\t")
             for i in range(0, len(els)):
                 els[i] = els[i].replace('\\;', ',').replace('\\\\', '\\')
             self.__entries.append((els[0], "", "", "(" + els[1] + ")"))
             self.__dict17.addWord(ustr(els[0]),
                                   (els[0], "(" + els[1] + ")"))
         f.close()
         self.sort()
 def setRegister(self, reg, getEntry=None):
     #from maleks.maleks.useful import Counter
     #c = Counter()
     #g = Counter()
     log.log("WindowRegisterBrowser.setRegister", [reg, getEntry], 0)
     #print len(reg), self.LIMIT()
     self._reg = reg
     self.__entryGetter = getEntry
     if len(reg) < 2 * self.LIMIT():
         #TODO: !A nie obsluguje hint_browsera?"
         self._smart = False
         RegisterBrowser.setRegister(self, reg, getEntry=getEntry)
     else:
         #print "els", c
         self._smart = True
         self.reset()
         i = 0
         #print "init", c
         self._itemsNo = 0
         for element in reg:  # dla kazdej fiszki w wykazie utworz odpowiedni element i wypelnij slowniki
             if i < self.LIMIT():
                 self.InsertStringItem(i, self._shownLabel(element))
                 self.SetStringItem(i, 1, "")
                 self.SetStringItem(i, 2, "")
                 self.SetStringItem(i, 3,
                                    self._secondColumn(element, getEntry))
             self._elementLabels.append(ustr(self._label(element)))
             #self._items.append(i) # identyfikator elementu jest jednoczesnie jego indeksem w tablicy _items
             #self._item2element.setdefault(i, self._id(element))
             #self._element2item.setdefault(self._id(element), i)
             self._itemsNo += 1
             self._elements.append(
                 self._id(element)
             )  # TODO: A uporzadkowac (label powyzej nie potrzebny, tu wrzucic element a id czytac przez funkcje)
             self._customElementInitialization(element, i)
             i += 1
             #print i, c
         self._window = 0
         self.SetColumnWidth(
             0, wx.LIST_AUTOSIZE)  # dopasuj szerokosc kolumn do
         self.SetColumnWidth(3, wx.LIST_AUTOSIZE)  # ich zawartosci
         self._initialized = True
         #print "koniec", c
     #print "po", g
     log.log("WindowRegisterBrowser.setRegister return", [], 1)
Ejemplo n.º 7
0
 def __pom(left, right):
     if left == right:
         if collator.compare(ustr(self.__list[left]), ustr(what)) > 0:
             return left
         elif collator.compare(ustr(self.__list[left]), ustr(what)) < 0:
             return left + 1
         else:
             return left
     elif left + 1 == right:
         if collator.compare(ustr(self.__list[left]), ustr(what)) == 0:
             return left
         elif collator.compare(ustr(self.__list[left]), ustr(what)) > 0:
             return left
         elif collator.compare(ustr(self.__list[right]),
                               ustr(what)) > 0:
             return right
         elif collator.compare(ustr(self.__list[right]),
                               ustr(what)) == 0:
             return right
         else:
             return right + 1
     lenn = right - left
     center = left + lenn // 2
     if collator.compare(ustr(self.__list[center]), ustr(what)) > 0:
         return __pom(left, center - 1)
     elif collator.compare(ustr(self.__list[center]), ustr(what)) < 0:
         return __pom(center + 1, right)
     else:
         return center
Ejemplo n.º 8
0
 def findHint(self, entry):
     if ustr(entry) == u"":
         return ("", "")
     (lcp17, sig17) = self.__dict17.findWord(ustr(entry))
     (lcpLin, sigLin) = self.__dictLin.findWord(ustr(entry))
     (lcpDor, sigDor) = self.__dictDor.findWord(ustr(entry))
     if compare(ustr(lcp17), ustr(lcpLin), ustr(entry)) >= 0:
         if compare(ustr(lcp17), ustr(lcpDor), ustr(entry)) >= 0:
             return (lcp17, sig17)
         elif compare(ustr(lcpLin), ustr(lcpDor), ustr(entry)) >= 0:
             return (lcpLin, sigLin)
         else:
             return (lcpDor, sigDor)
     elif compare(ustr(lcpLin), ustr(lcpDor), ustr(entry)) >= 0:
         return (lcpLin, sigLin)
     else:
         return (lcpDor, sigDor)
Ejemplo n.º 9
0
 def wrongOrder(self, entry):
     log.log("wrongOrder", [entry], 0)
     msg = ustr(entry) + u": " + _('corrupted alphabetic order')
     self.showMessage(msg)
     log.log("wrongOrder return", [], 1)
Ejemplo n.º 10
0
 def wrongFiche(self, entry):
     log.log("wrongFiche", [entry], 0)
     msg = ustr(entry) + u": " + _('fiche not in order')
     self.showMessage(msg)
     log.log("wrongFiche return", [], 1)
Ejemplo n.º 11
0
 def automaticBinaryStopped(self, target, steps):
     log.log("automaticBinaryStopped", [target, steps], 0)
     msg = _('Search for') + u" \"" + ustr(target) + u"\" " + _(
         'finished') + u". " + _('Steps:') + u" " + unicode(steps)
     self.showMessage(msg)
     log.log("automaticBinaryStopped return", [], 1)
Ejemplo n.º 12
0
 def error(self, ficheId, entry):
     msg = _('Fiche') + u' ' + ustr(ficheId) + u' ' + _(
         'not accepted with entry') + u' ' + ustr(entry)
     self.showMessage(msg)
Ejemplo n.º 13
0
 def submit(self, ficheId, entry):
     msg = _('Fiche') + u' ' + ustr(ficheId) + u' ' + _(
         'submitted for acceptation with entry') + u' ' + ustr(entry)
     self.showMessage(msg)