Пример #1
0
 def createCharBitmaps(self):
     dc = MemoryDC()
     dc.SetFont(self.fonts['monospace'])
     cw, ch = dc.GetTextExtent(' ')
     self.charSize = cw, ch
     self.normalChars = {}
     for c in self.charSet:
         bitmap = Bitmap(cw, ch, BITMAP_SCREEN_DEPTH)
         dc.SelectObject(bitmap)
         dc.SetBackground(self.brushes['bkgd'])
         dc.Clear()
         dc.SetTextForeground(Colour(230, 230, 230))
         dc.DrawText(c, 0, 0)
         self.normalChars[c] = bitmap
     self.selectedChars = {}
     for c in self.charSet:
         bitmap = Bitmap(cw, ch, BITMAP_SCREEN_DEPTH)
         dc.SelectObject(bitmap)
         dc.SetBackground(Brush(Colour(70, 80, 90)))
         dc.Clear()
         dc.SetTextForeground(Colour(160, 160, 180))
         if c == ' ': dc.DrawText(c, 0, 0)
         else: dc.DrawText(c, 0, 0)
         self.selectedChars[c] = bitmap
     self.numberChars = {}
     for c in ' 0123456789':
         bitmap = Bitmap(cw, ch, BITMAP_SCREEN_DEPTH)
         dc.SelectObject(bitmap)
         dc.SetBackground(self.brushes['bkgd'])
         dc.Clear()
         dc.SetTextForeground(Colour(150, 150, 200))
         dc.DrawText(c, 0, 0)
         self.numberChars[c] = bitmap
     dc.SelectObject(NullBitmap)
     return
Пример #2
0
def createCharBitmap(setName, fontName, frgd, bkgd):

    global _cw, _ch

    # create device context
    dc = MemoryDC()
    # set font
    dc.SetFont(_fonts[fontName])
    # get font size
    _cw, _ch = dc.GetTextExtent(' ')
    BitmapSet = {}
    for c in _printableCharSet:
        # create bitmap
        bitmap = Bitmap(_cw, _ch, BITMAP_SCREEN_DEPTH)
        # select bitmap
        dc.SelectObject(bitmap)
        # set background
        dc.SetBackground(_brushes[bkgd])
        # clear bitmap
        dc.Clear()
        # set text color
        dc.SetTextForeground(_colours[frgd])
        # write character
        dc.DrawText(c, 0, 0)
        # record
        BitmapSet[c] = bitmap
    # release bitmap
    dc.SelectObject(NullBitmap)
    # record set
    _printableCharBitmaps[setName] = BitmapSet
    # done
    return
Пример #3
0
 def OnFacename(self, facename):
     idx = len(self.font_list)
     self.font_list.append(facename)
     w, h = self.GetTextExtentCached(idx)
     self.bitmaps[idx] = wx.Bitmap(w, h)
     dc = MemoryDC()
     dc.SelectObject(self.bitmaps[idx])
     dc.Clear()
     font = self.MakeFont(facename=facename)
     dc.SetFont(font)
     dc.DrawText(facename, 0, 0)
     wx.CallAfter(self.Append, facename, idx)
     return True
Пример #4
0
 def _createCharBitmap(self, name, font, foreground, background):
     # create device context
     dc = MemoryDC()               
     # set font
     dc.SetFont(self._fonts[font])
     # get font size
     _cw, _ch = dc.GetTextExtent(' ')
     BitmapSet = {}
     for c in self._CharSet:
         # create bitmap
         bitmap = Bitmap(_cw, _ch, BITMAP_SCREEN_DEPTH)
         # select bitmap
         dc.SelectObject(bitmap)
         # set background
         dc.SetBackground(self._brushes[background])
         # clear bitmap
         dc.Clear()
         # set text color
         dc.SetTextForeground(self._colours[foreground])
         # record reference
         BitmapSet[c] = bitmap
         # check alternate drawing 1
         if name == 'nrm' and c == '¶':
             dc.DrawText(' ',0,0)
             continue
         # check alternate drawing 2
         if name == 'sel' and c == ' ':
             dc.DrawText('·',0,0)
             continue
         # draw character
         dc.DrawText(c,0,0) 
     # release bitmap
     dc.SelectObject(NullBitmap)
     # record set
     self._CharBitmaps[name] = BitmapSet
     # done
     return
Пример #5
0
 def createCharBitmaps(self):
     # create device context
     dc = MemoryDC()               
     # set font
     dc.SetFont(self.fonts['monospace'])
     # get font size (monospace)
     cw, ch = dc.GetTextExtent(' ')
     # record geometry
     self.charSize = cw, ch
     # NORMAL CHARACTERS
     self.normalChars = {}
     # create bitmaps
     for c in self.charSet:
         # create black and white bitmap
         bitmap = Bitmap(cw, ch, BITMAP_SCREEN_DEPTH)
         # select bitmap
         dc.SelectObject(bitmap)
         # set background
         dc.SetBackground(self.brushes['bkgd'])
         # clear bitmap
         dc.Clear()
         # set text color
         dc.SetTextForeground(Colour(230,230,230))
         # write character
         dc.DrawText(c,0,0)
         # create reference to bitmap
         self.normalChars[c] = bitmap
     # SELECTED CHARACTERS
     self.selectedChars = {}
     # create bitmaps
     for c in self.charSet:
         # create black and white bitmap
         bitmap = Bitmap(cw, ch, BITMAP_SCREEN_DEPTH)
         # select bitmap
         dc.SelectObject(bitmap)
         # set background
         dc.SetBackground(Brush(Colour(70, 80, 90)))
         # clear bitmap
         dc.Clear()
         # set text color
         dc.SetTextForeground(Colour(160,160,180))
         # write character
         dc.DrawText(c,0,0)
         # create reference to bitmap
         self.selectedChars[c] = bitmap
     # NUMBER CHARACTERS
     self.numberChars = {}
     # create bitmaps
     for c in ' 0123456789':
         # create black and white bitmap
         bitmap = Bitmap(cw, ch, BITMAP_SCREEN_DEPTH)
         # select bitmap
         dc.SelectObject(bitmap)
         # set background
         dc.SetBackground(self.brushes['bkgd'])
         # clear bitmap
         dc.Clear()
         # set text color
         dc.SetTextForeground(Colour(150,150,200))
         # write character
         dc.DrawText(c,0,0)
         # create reference to bitmap
         self.numberChars[c] = bitmap
     # release bitmap
     dc.SelectObject(NullBitmap)
     # done
     return
Пример #6
0
    def OnRefreshPanel(self, event):
        """
        Refresh dialog box

        """
        import time
        # constants
        backRed: int = 230
        backGreen: int = 255
        backBlue: int = 230  # Background color

        frontRed: int = 64
        frontGreen: int = 0
        frontBlue: int = 64  # Foreground color

        FADE_IN_LENGTH: int = 63
        self.logger.debug(f'Enter OnRefreshPanel')
        # Init memory buffer
        tdc: MemoryDC = MemoryDC()
        tdc.SelectObject(Bitmap(FrameWidth, FrameHeight))
        while not tdc.IsOk():
            time.sleep(0.05)
            tdc = MemoryDC()
            tdc.SelectObject(Bitmap(FrameWidth, FrameHeight))

        tdc.SetTextForeground(Colour(frontRed, frontGreen, frontBlue))
        tdc.SetBackground(
            Brush(Colour(backRed, backGreen, backBlue), BRUSHSTYLE_SOLID))
        tdc.Clear()
        font = tdc.GetFont()
        font.SetFamily(FONTFAMILY_MODERN)
        font.SetPointSize(12)
        tdc.SetFont(font)

        # Fade-in
        position = self.textPosition
        if position < FADE_IN_LENGTH:
            n = float(position) / float(FADE_IN_LENGTH)
            r = backRed - n * (backRed - frontRed)
            g = backGreen - n * (backGreen - frontGreen)
            b = backBlue - n * (backBlue - frontBlue)
            r = int(r)
            g = int(g)
            b = int(b)
            tdc.SetTextForeground(Colour(r, g, b))

        # Display text
        for j in range(1, len(self._textToShow)):
            # Draw text ?
            if position > FADE_IN_LENGTH:
                y = y0 + j * dy - (position - FADE_IN_LENGTH)
                if -dy < y < FrameHeight:
                    tdc.DrawText(self._textToShow[j], x0, y)
            else:  # Draw initial screen with fade in
                y = y0 + j * dy
                if -dy < y < FrameHeight:
                    tdc.DrawText(self._textToShow[j], x0, y)

        # Show memory dc to current dc (blit)
        dc = PaintDC(self._panel)
        dc.Blit(0, 0, FrameWidth, FrameHeight, tdc, 0, 0)
        tdc.SelectObject(NullBitmap)
        self.logger.debug(f'Exit OnRefreshPanel')
Пример #7
0
    def Start(self):

        # define colors
        self.colours = {}
        self.colours['bkgd'] = Colour(52, 61, 70)
        self.colours['text'] = Colour(255, 255, 255)
        self.colours['numb'] = Colour(160, 160, 160)
        self.colours['sepr'] = Colour(200, 120, 120)
        self.colours['selbgd'] = Colour(92, 101, 110)
        self.colours['seltxt'] = Colour(255, 255, 255)

        # brushes
        self.brushes = {}
        # normal background
        b = Brush()
        b.SetStyle(BRUSHSTYLE_SOLID)
        b.SetColour(self.colours['bkgd'])
        self.brushes['bkgd'] = b

        # selected background
        b = Brush()
        b.SetStyle(BRUSHSTYLE_SOLID)
        b.SetColour(self.colours['selbgd'])
        self.brushes['selbgd'] = b

        # pens
        self.pens = {}
        p = Pen()
        p.SetColour(self.colours['sepr'])
        p.SetWidth(1)
        p.SetStyle(PENSTYLE_SOLID)
        self.pens['sepr'] = p

        # create device context to work on bitmaps
        dc = MemoryDC()

        # define font
        self.fonts = {}
        f = Font()
        f.SetFamily(FONTFAMILY_ROMAN)
        f.SetFaceName("Monospace")
        f.SetEncoding(FONTENCODING_DEFAULT)
        f.SetStyle(FONTSTYLE_NORMAL)
        f.SetWeight(FONTWEIGHT_NORMAL)
        f.SetUnderlined(False)
        f.SetPointSize(10)
        self.fonts['monospace'] = f

        # select font
        f = 'monospace'

        # get font size
        dc.SetFont(self.fonts[f])
        w, h = dc.GetTextExtent(' ')

        # build character dictionary
        self.rawChars = {}
        # standard printable ascii table
        for c in range(32, 126):
            self.rawChars[chr(c)] = None
        # extra characters (UK)
        self.rawChars['£'] = None
        # save character size
        self.rawChars['Size'] = w, h

        # set background color
        dc.SetBackground(self.brushes['bkgd'])

        # build characters bitmaps
        for C in self.rawChars.keys():
            if C == 'Size': continue
            # instanciate character bitmap
            self.rawChars[C] = Bitmap(w, h, BITMAP_SCREEN_DEPTH)
            # select bitmap
            dc.SelectObject(self.rawChars[C])
            # clear bitmap
            dc.Clear()
            # set text color
            dc.SetTextForeground(self.colours['text'])
            # draw character shape and color
            dc.DrawText(C, 0, 0)
        # done
        dc.SelectObject(NullBitmap)

        # build selected dictionary
        self.selChars = {}
        # standard printable ascii table
        for c in range(32, 126):
            self.selChars[chr(c)] = None
        # extra characters (UK)
        self.selChars['£'] = None
        # save character size
        self.selChars['Size'] = w, h

        # set background color
        dc.SetBackground(self.brushes['selbgd'])

        # build selected bitmaps
        for C in self.selChars.keys():
            if C == 'Size': continue
            # instanciate character bitmap
            self.selChars[C] = Bitmap(w, h, BITMAP_SCREEN_DEPTH)
            # select bitmap
            dc.SelectObject(self.selChars[C])
            # clear bitmap
            dc.Clear()
            # set text color
            dc.SetTextForeground(self.colours['seltxt'])
            # draw character shape and color
            dc.DrawText(C, 0, 0)
        # done
        dc.SelectObject(NullBitmap)

        # create bitmap buffer display and clear buffer
        self.bitmapBuffer = Bitmap(
            128 * w,  # bitmap width
            10 * h,  # bitmap height
            BITMAP_SCREEN_DEPTH)  # bitmap depth
        dc.SelectObject(self.bitmapBuffer)
        dc.SetBackground(self.brushes['bkgd'])
        dc.Clear()
        dc.SelectObject(NullBitmap)

        # reference BackgroundBitmap to bitmapBuffer
        self.Panel.BackgroundBitmap = self.bitmapBuffer

        # adjust frame position
        scrw, scrh = 3840, 1200  # screen size
        w, h = self.Panel.BackgroundBitmap.GetSize()
        self.Frame.SetPosition(Point(scrw / 4 - 128 * 8 / 2, 800))

        # draw text string
        dc.SelectObject(self.bitmapBuffer)

        t = list("hello")
        # select buffer
        # draw text
        X = 0
        w, h = self.rawChars['Size']
        for c in t:
            dc.DrawBitmap(self.rawChars[c], X, 0)
            X += w

        t = list("World!")
        # select buffer
        # draw text
        X = 0
        w, h = self.selChars['Size']
        for c in t:
            dc.DrawBitmap(self.selChars[c], X, h)
            X += w

        # release bitmap
        dc.SelectObject(NullBitmap)

        # done
        return