Example #1
0
 def send_ctrl_to_process(self, letter):
     char = chr("abcdefghijklmnopqrstuvwxyz".index(letter) + 1)
     byte_array = QByteArray()
     byte_array.append(char)
     self.process.write(byte_array)
     self.process.waitForBytesWritten(-1)
     self.shell.write(LOCALE_CODEC.toUnicode(byte_array), flush=True)
Example #2
0
 def read_output(self, error=False):
     if error:
         self.process.setReadChannel(QProcess.StandardError)
     else:
         self.process.setReadChannel(QProcess.StandardOutput)
     qba = QByteArray()
     while self.process.bytesAvailable():
         if error:
             qba += self.process.readAllStandardError()
         else:
             qba += self.process.readAllStandardOutput()
     text = to_text_string(locale_codec.toUnicode(qba.data()))
     if error:
         self.error_output += text
     else:
         self.output += text
Example #3
0
    def load_font(self, prefix, ttf_filename, charmap_filename, directory=None):
        """Loads a font file and the associated charmap

        If `directory` is None, the files will be looked up in ./fonts/

        Arguments
        ---------
        prefix: str
            prefix string to be used when accessing a given font set
        ttf_filename: str
            ttf font filename
        charmap_filename: str
            charmap filename
        directory: str or None, optional
            directory for font and charmap files
        """

        def hook(obj):
            result = {}
            for key in obj:
                result[key] = unichr(int(obj[key], 16))
            return result

        if directory is None:
            directory = os.path.join(
                os.path.dirname(os.path.realpath(__file__)), 'fonts')

        with open(os.path.join(directory, ttf_filename), 'rb') as f:
            font_data = QByteArray(f.read())

        with open(os.path.join(directory, charmap_filename), 'r') as codes:
            self.charmap[prefix] = json.load(codes, object_hook=hook)

        id_ = QFontDatabase.addApplicationFontFromData(font_data)
        loadedFontFamilies = QFontDatabase.applicationFontFamilies(id_)

        if(loadedFontFamilies):
            self.fontname[prefix] = loadedFontFamilies[0]
        else:
            print('Font is empty')
Example #4
0
 def get_stderr(self):
     self.process.setReadChannel(QProcess.StandardError)
     qba = QByteArray()
     while self.process.bytesAvailable():
         qba += self.process.readAllStandardError()
     return self.transcode(qba)