예제 #1
0
  def _addText(self, _, data, signature, name):
    """
    @param  _  bytearray  raw data
    @param  data  bytearray  rendered data
    @param  signature  long
    @param  name  str
    """
    #dprint("name = %s" % name)
    view = self._threadViews.get(signature)
    if not view:
      tm = textman.manager()
      try: tt = textman.manager().threadsBySignature()[signature].type
      except KeyError: tt = textman.IGNORED_THREAD_TYPE

      # If old scenario signature is different from current, ignore the old one
      if tt == textman.SCENARIO_THREAD_TYPE:
        ss = self._scenarioSignature()
        if ss and ss != signature:
          tt = textman.IGNORED_THREAD_TYPE
      self._updateThread(textman.TextThread(
        name=name, signature=signature, data=[data], type=tt))
      view = self._threadViews[signature]

    text = self._transformText(textutil.to_unicode(data, self._encoding()))
    if view.hasText():
      view.appendText('\n' + text)
    else:
      view.setText(text)
예제 #2
0
  def renderText(self):
    tm = textman.manager()
    ctx = tm.contextSize()
    texts = tm.recentTexts()

    #assert len(texts) >= ctx
    ret = ""
    if not ctx or not texts or len(texts) < ctx:
      ret += '<br/>'.join((
        "<b>%s</b> (%s)" % (tr_("Context"), tr_("read-only")),
        '',
        tr_("Empty"),
      ))
    else:
      cur = texts[-1]
      prev = None
      if ctx > 1:
        prev = texts[-ctx:-1]

      ret += '<br/>'.join((
        "<b>%s</b> (%s)" % (tr_("Context"), tr_("read-only")),
        '',
        cur.replace('\n', '<br/>'),
      ))
      if prev:
        ret += '<br/>'.join((
          '', '', # Two lines
          "<b>%s</b> (%s)" % (mytr_("Previous context"), tr_("read-only")),
          '',
          '<br/>'.join(prev).replace('\n', '<br/>'),
        ))
    return ret
예제 #3
0
    def load(self):
        tm = textman.manager()
        lang = tm.gameLanguage()
        try:
            langIndex = config.LANGUAGES.index(lang)
        except ValueError:
            langIndex = 0
        self.languageEdit.setCurrentIndex(langIndex)

        enc = tm.encoding()
        self._setEncoding(enc)

        self._lastEncoding = enc
        self._lastScenarioSignature = tm.scenarioThreadSignature()
        self._lastNameSignature = tm.nameThreadSignature()

        self._refreshSaveButton()
        self._refreshEngineLabel()

        #self._refreshHookDialog()

        for role, sig in (
            (defs.SCENARIO_TEXT_ROLE, self._lastScenarioSignature),
            (defs.NAME_TEXT_ROLE, self._lastNameSignature),
        ):
            if sig and sig not in self._threadViews:
                self._createView(signature=sig, role=role)
예제 #4
0
    def _save(self):
        if not self._canSave():
            return
        q = self.q

        tm = textman.manager()

        agent = gameagent.global_()
        engine = agent.engine()
        engineName = defs.to_ith_engine_name(engine)

        scenesig = self._scenarioSignature()
        namesig = self._nameSignature()
        enc = self._encoding()
        lang = self._language()
        #threads = tm.threadsBySignature()
        changed = False
        if scenesig:
            if lang != tm.gameLanguage():
                dprint("language changed")
                changed = True
                skevents.runlater(partial(q.languageChanged.emit, lang))
            if scenesig != self._lastScenarioSignature or enc != self._lastEncoding:
                dprint("scenario thread changed")
                changed = True
                self._lastScenarioSignature = scenesig
                self._lastEncoding = enc
                agent.setEncoding(enc)
                agent.setScenarioSignature(scenesig)
                #name = threads[sig].name
                skevents.runlater(
                    partial(q.scenarioThreadChanged.emit, scenesig, engineName,
                            enc))

        if namesig != self._lastNameSignature:
            dprint("name thread changed")
            changed = True
            self._lastNameSignature = namesig
            agent.setNameSignature(namesig)
            if not namesig:
                skevents.runlater(q.nameThreadDisabled.emit)
            else:
                #name = threads[namesig].name
                skevents.runlater(
                    partial(q.nameThreadChanged.emit, namesig, engineName))

        #sig_set = set(self._otherSignatures())
        #if sig_set != tm.otherSignatures():
        #  dprint("other threads changed")
        #  changed = True
        #  skevents.runlater(partial(
        #      q.otherThreadsChanged.emit,
        #      {sig:threads[sig].name for sig in sig_set}))

        msg = (my.tr("Text settings are saved")
               if changed else my.tr("Text settings are not changed"))
        q.message.emit(msg)
        growl.msg(msg)

        dprint("pass")
예제 #5
0
 def read(self):
   tm = textman.manager()
   ctx = tm.contextSize()
   texts = tm.recentTexts()
   if ctx and texts and len(texts) >= ctx:
     t = '\n'.join(texts[-ctx:])
     import ttsman
     ttsman.speak(t)
예제 #6
0
  def __init__(self, parent=None):
    super(SubtitleContextBean, self).__init__(parent)

    tm = textman.manager()
    tm.contextChanged.connect(self.refresh)
    tm.cleared.connect(self.refresh)

    dprint("pass")
예제 #7
0
    def __init__(self, q):
        self.mem = sharedmem.VnrAgentSharedMemory(q)

        import rpcman
        self.rpc = rpcman.manager()

        self.rpc.agentConnected.connect(q.processAttached)
        self.rpc.agentDisconnected.connect(q.processDetached)
        self.rpc.engineReceived.connect(self._onEngineReceived)

        t = self.injectTimer = QTimer(q)
        t.setSingleShot(False)
        t.setInterval(5000)
        t.timeout.connect(self._onInjectTimeout)

        q.processAttached.connect(self._onAttached)
        q.processDetached.connect(self._onDetached)

        self.clear()

        ss = settings.global_()
        for k, v in _SETTINGS_DICT.iteritems():
            sig = getattr(ss, k + 'Changed')

            sig.connect(
                partial(
                    lambda k, t: self.connectedPid and self.sendSetting(k, t),
                    k))

        for sig in ss.embeddedScenarioWidthChanged, ss.embeddedScenarioWidthEnabledChanged:
            sig.connect(self._sendScenarioWidth)
        for sig in ss.embeddedFontFamilyChanged, ss.embeddedFontEnabledChanged:
            sig.connect(self._sendFontFamily)
        for sig in ss.embeddedFontScaleChanged, ss.embeddedFontScaleEnabledChanged:
            sig.connect(self._sendFontScale)
        for sig in ss.embeddedFontWeightChanged, ss.embeddedFontWeightEnabledChanged:
            sig.connect(self._sendFontWeight)

        import textman
        self.textExtractionEnabled = textman.manager().isEnabled()
        textman.manager().enabledChanged.connect(
            self._setTextExtractionEnabled)

        # Got this value from embeddedprefs.py
        self.extractsAllTexts = False
예제 #8
0
  def _refresh(self):
    enc = self._encoding()

    tm = textman.manager()
    for t in tm.threads():
      self._updateThread(t, encoding=enc, ignoreType=True)

    self._refreshSaveButton()
    self._refreshEncodingEdit()
예제 #9
0
  def __init__(self, parent=None):
    super(GraffitiBean, self).__init__(parent)

    tm = textman.manager()
    tm.cleared.connect(self.clear)
    tm.pageBreakReceived.connect(self.pageBreak)
    tm.rawTextReceived.connect(self.showText)
    tm.translationReceived.connect(self.showTranslation)
    tm.commentReceived.connect(self.showComment)

    dprint("pass")
예제 #10
0
  def load(self):
    th = texthook.global_()

    self.currentIgnoresRepeat = th.removesRepeat()
    self.ignoresRepeatButton.setChecked(self.currentIgnoresRepeat)

    self.currentKeepsSpace = th.keepsSpace()
    self.keepsSpaceButton.setChecked(self.currentKeepsSpace)

    tm = textman.manager()
    self.removesRepeatButton.setChecked(tm.removesRepeatText())

    self.keepsThreadsButton.setChecked(tm.keepsThreads())
    #self.keepsThreadsButton.setEnabled(bool(texthook.global_().currentHookCode()))

    lang = tm.gameLanguage()
    try: langIndex = config.LANGUAGES.index(lang)
    except ValueError: langIndex = 0
    self.languageEdit.setCurrentIndex(langIndex)

    enc = tm.encoding()
    self._setEncoding(enc)


    nullThreadFound = False
    for t in tm.threads():
      if t.name == defs.NULL_THREAD_NAME:
        nullThreadFound = True
      self._updateThread(t, encoding=enc)

    if not nullThreadFound:
      t = textman.TextThread(name=defs.NULL_THREAD_NAME, signature=defs.NULL_THREAD_SIGNATURE)
      self._updateThread(t, encoding=enc)

    self._refreshSaveButton()

    self._refreshHookDialog()
예제 #11
0
 def _onText():
     import textman
     tm = textman.manager()
     tm.setEnabled(not tm.isEnabled())
     dprint("pass")
예제 #12
0
 def _onTts():
     import textman
     textman.manager().speakCurrentText()
     dprint("pass")
예제 #13
0
  def _save(self):
    if not self._canSave():
      return
    q = self.q

    tm = textman.manager()
    sig = self._scenarioSignature()
    namesig = self._nameSignature()
    enc = self._encoding()
    lang = self._language()
    threads = tm.threadsBySignature()
    changed = False
    if sig:
      if lang != tm.gameLanguage():
        dprint("language changed")
        changed = True
        skevents.runlater(partial(
            q.languageChanged.emit,
            lang))
      if sig != tm.scenarioSignature() or enc != tm.encoding():
        dprint("scenario thread changed")
        changed = True
        name = threads[sig].name if sig in threads else defs.NULL_THREAD_NAME
        skevents.runlater(partial(
            q.scenarioThreadChanged.emit,
            sig, name, enc))

    if namesig != tm.nameSignature():
      dprint("name thread changed")
      changed = True
      if not namesig or namesig not in threads:
        skevents.runlater(q.nameThreadDisabled.emit)
      else:
        name = threads[namesig].name
        skevents.runlater(partial(
            q.nameThreadChanged.emit,
            namesig, name))

    sig_set = set(self._otherSignatures())
    if sig_set != tm.otherSignatures():
      dprint("other threads changed")
      changed = True
      skevents.runlater(partial(
          q.otherThreadsChanged.emit,
          {sig:threads[sig].name for sig in sig_set}))

    if sig:
      if self._removesRepeat() != tm.removesRepeatText():
        changed = True
        skevents.runlater(partial(
            q.removesRepeatTextChanged.emit,
            self._removesRepeat()))

      if self._ignoresRepeat() != self.currentIgnoresRepeat:
        self.currentIgnoresRepeat = self._ignoresRepeat()
        changed = True
        skevents.runlater(partial(
            q.ignoresRepeatTextChanged.emit,
            self.currentIgnoresRepeat))

      if self._keepsSpace() != self.currentKeepsSpace:
        self.currentKeepsSpace = self._keepsSpace()
        changed = True
        skevents.runlater(partial(
            q.keepsSpaceChanged.emit,
            self.currentKeepsSpace))

      if self._keepsThreads() != tm.keepsThreads():
        changed = True
        skevents.runlater(partial(
            q.keepsThreadsChanged.emit,
            self._keepsThreads()))

    msg = (my.tr("Text settings are saved") if changed else
           my.tr("Text settings are not changed"))
    q.message.emit(msg)
    growl.msg(msg)

    dprint("pass")
예제 #14
0
 def _reset(self):
   textman.manager().removeIgnoredThreads()
   self.clear()
   self.load()