Exemplo n.º 1
0
 def _selectFont_slot(self):
     """
     Select Font slot
     """
     font, font_res = self.sysFont_dialog.getFont(self.font, None,
                                                  'Select Font')
     if font_res:
         name = NGL_Font.formatName(font.family(), font.pointSize(),
                                    font.bold())
         self.lineEdit_fontName.setText(name)
         self.font = font
Exemplo n.º 2
0
    def convertQFont(chars_sets, name, font):

        NFontConverter.font = font
        # font.setHintingPreference( QFont.PreferNoHinting )
        # font.setStyleHint( QFont.SansSerif )
        font.setStyleStrategy(QFont.NoAntialias | QFont.PreferQuality)

        # create NGL_Font and generate all chars code
        nfont = NGL_Font(name, font)
        offset = 0
        for char in chars_sets:
            ch_bmp = NFontConverter.font_charBmp(font, char)
            ch_code, ch_offset = NFontConverter.font_bmpCode(ch_bmp)

            nfont.add_char(char, ch_code, offset, ch_bmp)
            offset += ch_offset

        # generate code text out
        nfont.code = NFontCodeGen.font(nfont)

        return nfont
Exemplo n.º 3
0
    def convertQFont(chars_sets, name, font):

        NFontConverter.font = font
        # font.setHintingPreference( QFont.PreferNoHinting )
        # font.setStyleHint( QFont.SansSerif )
        font.setStyleStrategy(QFont.NoAntialias | QFont.PreferQuality)

        # create NGL_Font and generate all chars code
        nfont = NGL_Font(name, font)
        offset = 0
        for char in chars_sets:
            ch_bmp = NFontConverter.font_charBmp(font, char)
            ch_code, ch_offset = NFontConverter.font_bmpCode(ch_bmp)

            nfont.add_char(char, ch_code, offset, ch_bmp)
            offset += ch_offset

        # generate code text out
        nfont.code = NFontCodeGen.font(nfont)

        return nfont
Exemplo n.º 4
0
    def parseFile(self, fontfile):
        if fontfile:
            with open(fontfile, 'r') as f:
                code = f.read()

            _description = self._getFontDescription(code)
            _name = self._parseName(_description).replace('Info', '')
            _start_char, _end_char = self._parseStartEndChars(_description)
            _pchars = self._parseChars(code)

            # crate NGL Font
            ngl_font = NGL_Font(_name)

            # add chars bitmaps to font
            offset = 0
            for pch in _pchars:
                _, ch_offset = NFontConverter.font_bmpCode(pch['bitmap'])
                ngl_font.add_char(pch['char'], None, offset, pch['bitmap'])
                offset += ch_offset

            return ngl_font
Exemplo n.º 5
0
    def _convertFont(self, font, verbose):
        """ Convert parsed QFont to NGL_Font object
        """
        # charters set to converting
        char_range = range(ord(" "), ord("~"))
        chars_sets = "".join([chr(x) for x in char_range])

        if verbose:
            inform("converting font %s, %spt, bold %s" % (font.family(), font.pointSize(), font.bold()))
        name = NGL_Font.formatName(font.family(), font.pointSize(), font.bold())
        # convert and return
        return NFontConverter.convertQFont(chars_sets, name, font)
Exemplo n.º 6
0
    def parseFile(self, fontfile):
        if fontfile:
            with open(fontfile, 'r') as f:
                code = f.read()

            _description = self._getFontDescription( code )
            _name = self._parseName( _description ).replace('Info', '')
            _start_char, _end_char = self._parseStartEndChars( _description )
            _pchars = self._parseChars( code )

            # crate NGL Font
            ngl_font = NGL_Font( _name )

            # add chars bitmaps to font
            offset = 0
            for pch in _pchars:
                _, ch_offset = NFontConverter.font_bmpCode( pch['bitmap'] )
                ngl_font.add_char( pch['char'], None, offset, pch['bitmap'] )
                offset += ch_offset

            return ngl_font
Exemplo n.º 7
0
    def _convertFont(self, font, verbose):
        """ Convert parsed QFont to NGL_Font object
        """
        # charters set to converting
        char_range = range(ord(' '), ord('~'))
        chars_sets = ''.join([chr(x) for x in char_range])

        if verbose:
            inform( 'converting font %s, %spt, bold %s' % (font.family(),
                                                           font.pointSize(),
                                                           font.bold()))
        name = NGL_Font.formatName(font.family(),
                                   font.pointSize(),
                                   font.bold())
        # convert and return
        return NFontConverter.convertQFont(chars_sets, name, font)
Exemplo n.º 8
0
    def __init__(self, name, dataSlot=None, parent=None):
        """ Constructor """
        super(NFontConverterWidget, self).__init__(parent)

        self.settings = QSettings('NeilLab', 'NGL Font')

        # load main ui window
        uifile = pkg_resources.resource_filename('ngl_utils.nfont',
                                                 'qtres/ngl_font.ui')
        self.uic = uic.loadUi(uifile, self)

        self.nfont_view = CodeView_Window(self)
        self.sysFont_dialog = QFontDialog(self)

        # def sysfont and font name
        self.font = QFont('Times', 8)
        self.NGL_Font = None
        fname = NGL_Font.formatName(self.font.family(), self.font.pointSize(),
                                    self.font.bold())
        self.lineEdit_fontName.setText(fname)

        # generates chars set for combobox
        self._charstersRangesInit()

        # font edit widget
        self.edit_view = NFontEditWidget('__util__')

        # connect signals / slots
        self.tBtn_Font.clicked.connect(self._selectFont_slot)
        self.tBtn_AddChars.clicked.connect(self._add_chars_slot)
        self.tBtn_Convert.clicked.connect(self._convert_slot)
        self.tBtn_Save.clicked.connect(self._saveAs_slot)
        self.tBtn_ViewOut.clicked.connect(self._view_out_slot)
        self.tBtn_Edit.clicked.connect(self._edit_font_slot)

        if name == '__main__':
            self.tBtn_Close.setText('Close')
            self.tBtn_Close.clicked.connect(self._close_slot)
        else:
            self.tBtn_Close.setText('Add')
            self.tBtn_Close.clicked.connect(self._ok_slot)
        self.connectDataReadySlot(dataSlot)

        # set window to center and show
        self.frameGeometry().moveCenter(
            QDesktopWidget().availableGeometry().center())
Exemplo n.º 9
0
    def doNGLCode(self, **kwargs):
        """ Generate code for NGL_Label """

        # convert coordinates
        g = self._ngl_geometry()

        # get font pointer name
        _, fontPointerName = NGL_Font.formatQFontName(self.font)

        # if label is a static
        if self.static is True:
            template = 'NGL_Font_DrawString({x}, {y}, {color}, {font}, {transparent}, {text});'

            return template.format(
                x = g.x(),
                y = g.y(),
                color = self._ngl_color('color: rgb'),
                font = fontPointerName,
                transparent = 'Transparent',
                text = '"%s"' % self.text)

        # else return label sctruct code
        else:
            import pkg_resources

            res_path = pkg_resources.resource_filename('ngl_utils', 'templates/label.ntp')
            with open(res_path, 'rt') as f:
                template = f.read()

            textVar = 'static char {0}_text[{1}] = "{2}";'.format(
                self.objectName(),
                len(self.text)+1,
                self.text)

            return template.format(
                pageName = self._ngl_parent_obj_name(),
                itemName = self.objectName(),
                x = g.x(),
                y = g.y(),
                color = self._ngl_color('color: rgb'),
                transparent = 'Transparent',
                textVar = textVar,
                text = '(char*)%s_text' % self.objectName(),
                fontName = fontPointerName
            )
Exemplo n.º 10
0
    def doNGLCode(self, **kwargs):
        """ Generate code for NGL_Label """

        # convert coordinates
        g = self._ngl_geometry()

        # get font pointer name
        _, fontPointerName = NGL_Font.formatQFontName(self.font)

        # if label is a static
        if self.static is True:
            template = 'NGL_Font_DrawString({x}, {y}, {color}, {font}, {transparent}, {text});'

            return template.format(x=g.x(),
                                   y=g.y(),
                                   color=self._ngl_color('color: rgb'),
                                   font=fontPointerName,
                                   transparent='Transparent',
                                   text='"%s"' % self.text)

        # else return label sctruct code
        else:
            import pkg_resources

            res_path = pkg_resources.resource_filename('ngl_utils',
                                                       'templates/label.ntp')
            with open(res_path, 'rt') as f:
                template = f.read()

            textVar = 'static char {0}_text[{1}] = "{2}";'.format(
                self.objectName(),
                len(self.text) + 1, self.text)

            return template.format(pageName=self._ngl_parent_obj_name(),
                                   itemName=self.objectName(),
                                   x=g.x(),
                                   y=g.y(),
                                   color=self._ngl_color('color: rgb'),
                                   transparent='Transparent',
                                   textVar=textVar,
                                   text='(char*)%s_text' % self.objectName(),
                                   fontName=fontPointerName)
Exemplo n.º 11
0
    def doNGLCode(self, **kwargs):

        import pkg_resources

        res_path = pkg_resources.resource_filename('ngl_utils',
                                                   'templates/graphscale.ntp')
        with open(res_path, 'rt') as f:
            template = f.read()

        # convert coordinates
        g = self._ngl_geometry()

        # orientation
        ori = {1: 'NGL_Horizontal', 2: 'NGL_Vertical'}

        # get font pointer name
        _, fontPointerName = NGL_Font.formatQFontName(self.font)

        return template.format(pageName=self._ngl_parent_obj_name(),
                               itemName=self.objectName(),
                               x0=g.x(),
                               y0=g.y(),
                               x1=g.x() + g.width() - 1,
                               y1=g.y() + g.height() - 1,
                               minimum=self.minimum,
                               maximum=self.maximum,
                               scalecent=self.scaleCent,
                               labels='{%s}' % self.labels,
                               labels_cnt=len(self.labels.split(',')),
                               units='"%s"' % self.units,
                               showlabels=self.showLabels,
                               showlines=self.showLines,
                               flip=self.flip,
                               orientation=ori[self.orientation],
                               font=fontPointerName,
                               color=self._ngl_color('color: rgb'))
Exemplo n.º 12
0
    def doNGLCode(self, **kwargs):

        import pkg_resources

        res_path = pkg_resources.resource_filename('ngl_utils', 'templates/checkbox.ntp')
        with open(res_path, 'rt') as f:
            template = f.read()

        # convert coordinates
        g = self._ngl_geometry()

        # get font pointer name
        _, fontPointerName = NGL_Font.formatQFontName(self.font)

        # text var
        __text_var_name = self.objectName().lower() + '_text'
        __text_var = 'static const char {0}[{1}] = "{2}";'.format(__text_var_name,
                                                                  len(self._text)+1,
                                                                  self._text)
        __text_pointer = __text_var_name

        return template.format(
            pageName = self._ngl_parent_obj_name(),
            itemName = self.objectName(),
            text_var = __text_var,
            x0 = g.x(),
            y0 = g.y(),
            x1 = g.x() + g.width() - 1,
            y1 = g.y() + g.height() - 1,
            checked = self._checked,
            font_pointer = fontPointerName.replace('(NGL_Font*)', ''),
            text_pointer = __text_pointer,
            color = hex(NGL_Colors.fromQColor(self._color)),
            text_color = self._ngl_color('color: rgb'),
            p_event = self.clickEventName
        )
Exemplo n.º 13
0
    def doNGLCode(self, **kwargs):

        import pkg_resources

        res_path = pkg_resources.resource_filename('ngl_utils', 'templates/graphscale.ntp')
        with open(res_path, 'rt') as f:
            template = f.read()

        # convert coordinates
        g = self._ngl_geometry()

        # orientation
        ori = {1: 'NGL_Horizontal', 2: 'NGL_Vertical'}

        # get font pointer name
        _, fontPointerName = NGL_Font.formatQFontName(self.font)

        return template.format(
                pageName = self._ngl_parent_obj_name(),
                itemName = self.objectName(),
                x0 = g.x(),
                y0 = g.y(),
                x1 = g.x() + g.width() - 1,
                y1 = g.y() + g.height() - 1,
                minimum = self.minimum,
                maximum = self.maximum,
                scalecent = self.scaleCent,
                labels = '{%s}' % self.labels,
                labels_cnt = len(self.labels.split(',')),
                units = '"%s"' % self.units,
                showlabels = self.showLabels,
                showlines = self.showLines,
                flip = self.flip,
                orientation = ori[self.orientation],
                font = fontPointerName,
                color = self._ngl_color('color: rgb'))
Exemplo n.º 14
0
    def doNGLCode(self, **kwargs):

        import pkg_resources

        res_path = pkg_resources.resource_filename('ngl_utils',
                                                   'templates/checkbox.ntp')
        with open(res_path, 'rt') as f:
            template = f.read()

        # convert coordinates
        g = self._ngl_geometry()

        # get font pointer name
        _, fontPointerName = NGL_Font.formatQFontName(self.font)

        # text var
        __text_var_name = self.objectName().lower() + '_text'
        __text_var = 'static const char {0}[{1}] = "{2}";'.format(
            __text_var_name,
            len(self._text) + 1, self._text)
        __text_pointer = __text_var_name

        return template.format(pageName=self._ngl_parent_obj_name(),
                               itemName=self.objectName(),
                               text_var=__text_var,
                               x0=g.x(),
                               y0=g.y(),
                               x1=g.x() + g.width() - 1,
                               y1=g.y() + g.height() - 1,
                               checked=self._checked,
                               font_pointer=fontPointerName.replace(
                                   '(NGL_Font*)', ''),
                               text_pointer=__text_pointer,
                               color=hex(NGL_Colors.fromQColor(self._color)),
                               text_color=self._ngl_color('color: rgb'),
                               p_event=self.clickEventName)
Exemplo n.º 15
0
 def _ngl_font_pointer(self):
     if self.font:
         return NGL_Font.formatPointerName(self._ngl_font_name())
Exemplo n.º 16
0
 def _ngl_font_name(self):
     if self.font:
         return NGL_Font.formatName(self.font.family(), self.font.pointSize(), self.font.bold())
     else:
         return ""