示例#1
0
 def ensure_open(self, warmup = True):
     if not self.proc or self.proc.state() == QProcess.NotRunning:
         self.proc = QProcess(mw)
         self.proc.start(PROC_CMD, PROC_ARGS)
         self.proc.waitForStarted()
         if warmup:
             self.proc.write('私\n') # Get things running, as it takes a while to load the dictionaries
             self.proc.readyReadStandardOutput.connect(self.warmup_ready)
示例#2
0
class FuritsukiController:
    def __init__(self):
        self.proc = None

    def ensure_open(self, warmup = True):
        if not self.proc or self.proc.state() == QProcess.NotRunning:
            self.proc = QProcess(mw)
            self.proc.start(PROC_CMD, PROC_ARGS)
            self.proc.waitForStarted()
            if warmup:
                self.proc.write('私\n') # Get things running, as it takes a while to load the dictionaries
                self.proc.readyReadStandardOutput.connect(self.warmup_ready)

    def warmup_ready(self):
        self.proc.readAllStandardOutput() # Eat the output from the warmup
        self.proc.readyReadStandardOutput.disconnect(self.warmup_ready)

    def write_input(self, text):
        self.proc.write(text.replace('\n', ' ').encode('utf-8')) # Make sure we only have one line
        self.proc.write(u'\n')
        self.proc.waitForBytesWritten()

    def reading(self, text):
        self.ensure_open(warmup = False)
        self.write_input(text)
        self.proc.waitForReadyRead()
        return unicode(str(self.proc.readLine()), 'utf-8')