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
def start_seedwatcher(app, cb_wallet): app.frame_sw = SeedWatcherFrame(app.gui_frame) app.frame_sw.SetIcons(IconBundle(file_path("gui/uniblow.ico"))) HAND_CURSOR = Cursor(CURSOR_HAND) app.gui_panel.devices_choice.SetSelection(0) app.gui_frame.Hide() app.panel_sw = SeedWatcherPanel(app.frame_sw) app.panel_sw.m_textCtrl_mnemo.SetFocus() if sys.platform.startswith("darwin"): app.panel_sw.m_staticTextcopy.SetLabel( "Select asset line, then right click on it to open menu") app.panel_sw.m_button_gen.SetBitmap( Bitmap(file_path("gui/GenSeed.png"), BITMAP_TYPE_PNG)) app.panel_sw.m_button_gen.SetBitmapPressed( Bitmap(file_path("gui/GenSeeddn.png"), BITMAP_TYPE_PNG)) app.panel_sw.m_btnseek.SetBitmap( Bitmap(file_path("gui/SeekAssets.png"), BITMAP_TYPE_PNG)) app.panel_sw.m_btnseek.SetBitmapPressed( Bitmap(file_path("gui/SeekAssetsdn.png"), BITMAP_TYPE_PNG)) app.panel_sw.m_button_gen.SetCursor(HAND_CURSOR) app.panel_sw.m_choice_nwords.SetCursor(HAND_CURSOR) app.panel_sw.m_typechoice.SetCursor(HAND_CURSOR) app.panel_sw.m_btnseek.SetCursor(HAND_CURSOR) app.panel_sw.initialize(cb_wallet) app.frame_sw.Show()
def main(default=True): app = App() screen = ScreenDC() size = screen.GetSize() if default: size = (round(size[0] * 2.5), round(size[1] * 2.5)) bmp = Bitmap(size[0], size[1]) mem = MemoryDC(bmp) mem.Blit(0, 0, size[0], size[1], screen, 0, 0) del mem name = '{}.png'.format(str(randrange(1000))) fname = os.path.join(os.getcwd(), name) bmp.SaveFile(fname, BITMAP_TYPE_PNG) return fname
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
def resize_bitmap(b: wx.Bitmap, width, height) -> wx.Bitmap: """resize bitmap so as to fit in specified width and height so as not to exceed the original size. """ # @todo enable to choice Correct the orientation of the image i: wx.Image = b.ConvertToImage() s: wx.Size = i.GetSize() old_w = s.GetWidth() old_h = s.GetHeight() if old_w <= width and old_h <= height: new_w = width new_h = height else: if old_w > width: new_w = width new_h = (old_h * width) / old_w elif old_h > height: new_w = (old_w * height) / old_h new_h = height # Re-correction if overflowing after correction if new_w > width: new_w = width new_h = (old_h * width) / old_w elif new_h > height: new_w = (old_w * height) / old_h new_h = height i = i.Scale(int(new_w), int(new_h), wx.IMAGE_QUALITY_HIGH) return wx.Bitmap(i)
def _BlankScreen(self, w, h, d): b = Bitmap(w, h, d) dc = MemoryDC() dc.SelectObject(b) self._clear(dc) dc.SelectObject(NullBitmap) return b
def __init__(self, columns, rows): # get geometry sl, sr, st, sb = self._borders # record parameters self.screenSize = columns+sl+sr, rows+st+sb # create character set self.CS = CharacterSet() # get character geometry _cw, _ch = self.CS.get(' ').GetSize() print(_cw, _ch) # record parameters self.charSize = _cw, _ch # create pens self.createSolidPen('_borders', 80, 80, 80) self.createSolidPen('_borderLeft', 150, 50, 50) self.createSolidPen('_cursor', 255, 180, 100, width = 2) # define bitmap parameters w, h, d = (columns+sl+sr)*_cw, (rows+st+sb)*_ch, BITMAP_SCREEN_DEPTH # create screen bitmap self.bitmapBuffer = Bitmap(w, h, d) # create blank bitmap (see comment for _BlankScreen) self.bitmapBlank = self._BlankScreen(w, h, d) # create empty buffer self.textBuffer = [''] # done self._refresh() return
def CreateDC(self, loadBackground: bool, w: int, h: int) -> DC: """ Create a DC, load the background on demand. @param loadBackground @param w : width of the frame. @param h : height of the frame. @return DC """ dc = MemoryDC() bm = self.__workingBitmap # cache the bitmap, to avoid creating a new at each refresh. # only recreate it if the size of the window has changed if (bm.GetWidth(), bm.GetHeight()) != (w, h): bm = self.__workingBitmap = Bitmap(w, h) dc.SelectObject(bm) if loadBackground: self.LoadBackground(dc, w, h) else: dc.SetBackground(Brush(self.GetBackgroundColour())) dc.Clear() self.PrepareDC(dc) return dc
def write(self, oglObjects: List[OglClass]): """ Write data Args: oglObjects: list of exported objects """ mediator: Mediator = self._ctrl mediator.deselectAllShapes() imageType: BitmapType = WxImageFormat.toWxBitMapType(self._imageFormat) window: ScrolledWindow = self._umlFrame context: ClientDC = ClientDC(window) memory: MemoryDC = MemoryDC() x, y = window.GetSize() emptyBitmap: Bitmap = Bitmap(x, y, -1) memory.SelectObject(emptyBitmap) memory.Blit(source=context, xsrc=0, height=y, xdest=0, ydest=0, ysrc=0, width=x) memory.SelectObject(NullBitmap) img: Image = emptyBitmap.ConvertToImage() extension: str = self._imageFormat.__str__() filename: str = f'{self._outputFileName}.{extension}' status: bool = img.SaveFile(filename, imageType) if status is False: self.logger.error(f'Error on image write to {filename}')
def __init__(self, rows, colums): self.bitmap = Bitmap(colums * _cw, rows * _ch, BITMAP_SCREEN_DEPTH) dc = MemoryDC() dc.SelectObject(self.bitmap) dc.SetBackground(_brushes['bgd']) dc.Clear() dc.SelectObject(NullBitmap) return
def GetIcons() -> dict: if not __iconCache: iconsPath = ResPath("icons") files = os.listdir(iconsPath) for file in files: if file.endswith(".png"): __iconCache[file.split(".")[0]] = Bitmap( ResPath("icons/%s" % file), BITMAP_TYPE_PNG) return __iconCache
def scale_bitmap(bitmap: wx.Bitmap, width: int, height: int) -> wx.Bitmap: """Rescales a bitmap to a given size. Converting it to image, rescaling and converting it back. """ image = bitmap.ConvertToImage() image = image.Scale(width, height, wx.IMAGE_QUALITY_HIGH) result = wx.Bitmap(image) return result
def initialize(self, cb_wallet): self.GOOD_BMP = Bitmap(file_path("gui/good.bmp")) self.BAD_BMP = Bitmap(file_path("gui/bad.bmp")) self.m_choice_nwords.Set(WORDSLEN_LIST) self.m_choice_nwords.SetSelection(0) ctab = self.m_dataViewListCtrl1 dv1 = dataview.DataViewColumn("Name", dataview.DataViewTextRenderer(), 0) dv1.SetWidth(125) ctab.AppendColumn(dv1) dv2 = dataview.DataViewColumn("Account", dataview.DataViewTextRenderer(), 1) dv2.SetWidth(372) ctab.AppendColumn(dv2) dv3 = dataview.DataViewColumn("Balance", dataview.DataViewTextRenderer(), 2) dv3.SetWidth(86) ctab.AppendColumn(dv3) self.cb_wallet = cb_wallet
def hd_setup(self, proposal): """Call the HD device option window.""" self.gui_hdframe = gui.window.HDDialog(self.gui_frame) self.gui_hdpanel = HDsetting_panel(self.gui_hdframe) HAND_CURSOR = Cursor(CURSOR_HAND) if proposal: # LocalFile wallet init setup self.gui_hdpanel.GOOD_BMP = Bitmap(file_path("gui/good.bmp")) self.gui_hdpanel.BAD_BMP = Bitmap(file_path("gui/bad.bmp")) self.gui_hdpanel.m_bitmapHDwl.SetBitmap(self.gui_hdpanel.BAD_BMP) self.gui_hdpanel.m_bitmapHDcs.SetBitmap(self.gui_hdpanel.BAD_BMP) self.gui_hdpanel.m_checkBox_secboost.SetCursor(HAND_CURSOR) self.gui_hdpanel.m_textCtrl_mnemo.SetValue(proposal) self.gui_hdpanel.m_usertxt.SetLabel( "Validate this first proposal,\n" "or insert your mnemonic and settings to import\n" "an existing HD wallet.") else: # hardware wallet options self.gui_hdframe.SetTitle("Open hardware wallet options") self.gui_hdpanel.title_text.SetLabel( "Hardware wallet account options") self.gui_hdpanel.m_textwl.Destroy() self.gui_hdpanel.m_textcs.Destroy() self.gui_hdpanel.m_textCtrl_mnemo.Destroy() self.gui_hdpanel.m_bwptxt.Destroy() self.gui_hdpanel.m_textCtrl_pwd.Destroy() self.gui_hdpanel.m_checkBox_secboost.Destroy() self.gui_hdpanel.m_usertxt.SetLabel( "Choose account and index for the key to use.") self.gui_hdframe.SetSize(480, 320) self.gui_hdpanel.m_butOK.SetCursor(HAND_CURSOR) self.gui_hdpanel.m_butcancel.SetCursor(HAND_CURSOR) ret = self.gui_hdframe.ShowModal() if ret == ID_OK: wallet_settings = self.gui_hdpanel.hd_wallet_settings # Removal of stored settings self.gui_hdframe.DestroyChildren() self.gui_hdframe.Destroy() del self.gui_hdframe return wallet_settings else: return None
def __init__(self, title): # init window Frame.__init__(self, None, ID_ANY, title, size=(800, 800)) self.Bind(EVT_CLOSE, lambda x: self.Destroy()) loc = Icon() loc.CopyFromBitmap(Bitmap('icon.ico', BITMAP_TYPE_ANY)) self.SetIcon(loc) with SimpleSizer(self, VERTICAL) as sizer: new_element = OpenGLCanvas(self) sizer.Add(new_element)
def createBufferBitmap(self, width, height): cw, ch = self.charSize self.bmpBuf = Bitmap( width * cw, # bitmap width height * ch, # bitmap heigh BITMAP_SCREEN_DEPTH) # bitmap depth dc = MemoryDC() dc.SelectObject(self.bmpBuf) dc.SetBackground(self.brushes['bkgd']) dc.Clear() dc.SelectObject(NullBitmap) self.Panel.BackgroundBitmap = self.bmpBuf self.screenSize = width, height return
def RescaleBitmap(bmp: wx.Bitmap, sizeNeeded: wx.Size): """ :param bmp: :type bmp: wx.Bitmap :param sizeNeeded: :type sizeNeeded: wx.Size """ if not sizeNeeded.IsFullySpecified(): raise ValueError("New size must be given") img = bmp.ConvertToImage() img.Rescale(sizeNeeded.x, sizeNeeded.y) bmp = wx.Bitmap(img)
def SaveBackground(self, dc: DC): """ Args: dc: The DC to save """ w, h = self.GetSize() bb = self.__backgroundBitmap if (bb.GetWidth(), bb.GetHeight()) != (w, h): bb = self.__backgroundBitmap = Bitmap(w, h) mem = MemoryDC() mem.SelectObject(bb) x, y = self.CalcUnscrolledPosition(0, 0) mem.Blit(0, 0, w, h, dc, x, y) mem.SelectObject(NullBitmap)
def onDrawMe(self, event: CommandEvent): extension: str = 'png' imageType: BitmapType = BITMAP_TYPE_PNG window: ScrolledWindow = self._diagramFrame context: ClientDC = ClientDC(window) memory: MemoryDC = MemoryDC() x, y = window.ClientSize emptyBitmap: Bitmap = Bitmap(x, y, -1) memory.SelectObject(emptyBitmap) memory.Blit(source=context, xsrc=0, height=y, xdest=0, ydest=0, ysrc=0, width=x) memory.SelectObject(NullBitmap) img: Image = emptyBitmap.ConvertToImage() filename: str = f'DiagramDump.{extension}' status: bool = img.SaveFile(filename, imageType)
def SaveBackground(self, dc): """ Save the given dc as the new background image. @param DC dc : the dc to save """ w, h = self.GetSize() bb = self.__backgroundBitmap if (bb.GetWidth(), bb.GetHeight()) != (w, h): bb = self.__backgroundBitmap = Bitmap(w, h) mem = MemoryDC() mem.SelectObject(bb) if __version__ > "2.3.2": x, y = self.CalcUnscrolledPosition(0, 0) mem.Blit(0, 0, w, h, dc, x, y) else: mem.Blit(0, 0, w, h, dc, 0, 0) mem.SelectObject(NullBitmap)
def OnInit(self): icon_path = file_path(ICON_FILE) wicon = IconBundle(icon_path) HAND_CURSOR = Cursor(CURSOR_HAND) self.gui_frame = gui.window.TopFrame(None) self.gui_frame.Bind(EVT_CLOSE, self.OnClose) if sys.platform.startswith("darwin"): self.gui_frame.SetSize((996, 418)) self.gui_panel = gui.window.TopPanel(self.gui_frame) self.gui_frame.SetIcons(wicon) self.gui_panel.hist_button.SetBitmap( Bitmap(file_path("gui/histo.png"), BITMAP_TYPE_PNG)) self.gui_panel.hist_button.SetBitmapPressed( Bitmap(file_path("gui/histodn.png"), BITMAP_TYPE_PNG)) self.gui_panel.copy_button.SetBitmap( Bitmap(file_path("gui/copy.png"), BITMAP_TYPE_PNG)) self.gui_panel.copy_button.SetBitmapPressed( Bitmap(file_path("gui/copydn.png"), BITMAP_TYPE_PNG)) self.gui_panel.send_button.SetBitmap( Bitmap(file_path("gui/send.png"), BITMAP_TYPE_PNG)) self.gui_panel.send_button.SetBitmapPressed( Bitmap(file_path("gui/senddn.png"), BITMAP_TYPE_PNG)) self.gui_panel.send_all.SetBitmap( Bitmap(file_path("gui/swipe.png"), BITMAP_TYPE_PNG)) self.gui_panel.send_all.SetBitmapPressed( Bitmap(file_path("gui/swipedn.png"), BITMAP_TYPE_PNG)) self.gui_panel.devices_choice.SetCursor(HAND_CURSOR) self.gui_panel.coins_choice.SetCursor(HAND_CURSOR) self.gui_panel.network_choice.SetCursor(HAND_CURSOR) self.gui_panel.wallopt_choice.SetCursor(HAND_CURSOR) self.gui_panel.hist_button.SetCursor(HAND_CURSOR) self.gui_panel.copy_button.SetCursor(HAND_CURSOR) self.gui_panel.send_button.SetCursor(HAND_CURSOR) self.gui_panel.send_all.SetCursor(HAND_CURSOR) self.gui_panel.btn_chkaddr.SetCursor(HAND_CURSOR) self.SetTopWindow(self.gui_frame) return True
def CreatePopupMenu(self): menu = Menu() appMenuItem = menu.Append(ID_ANY, "mHosts v" + Settings.version()) if sys.platform != "linux": appMenuItem.Enable(False) appMenuItem.SetBitmap( Bitmap(ResPath("icons/logo.png"), BITMAP_TYPE_PNG)) menu.Append(self.ID_TOGGLE, r"%s主窗口" % ("隐藏" if self.__window.IsShown() else "显示")) menu.AppendSeparator() for hosts in Settings.settings["hosts"]: item = MenuItem(menu, hosts["id"], hosts["name"], kind=ITEM_CHECK) item.Enable(not hosts['alwaysApply']) menu.Append(item) menu.Check(hosts["id"], hosts["active"] or hosts["alwaysApply"]) self.Bind(EVT_MENU, self.__window.OnTaskBarHostsMenuClicked, id=hosts["id"]) newHostMenu = Menu() newHostMenu.Append(self.ID_NEW, "新建") if sys.platform != "linux": newHostMenu.Append(self.ID_IMPORT, "导入").Enable(False) menu.Append(-1, "新建Hosts方案", newHostMenu) menu.AppendSeparator() menu.Append(self.ID_REFRESH_DNS, u"刷新DNS缓存") if os.path.exists(Settings.settings["chromePath"]): chromeMenu = Menu() chromeMenu.Append(self.ID_LUNCH_CHROME, "直接启动") chromeMenu.Append(self.ID_LUNCH_CHROME_CROS, "允许跨域请求") chromeMenu.Append(self.ID_LUNCH_CHROME_NO_PLUGINS, "禁用所有插件") menu.Append(-1, "启动 Google Chrome 浏览器", chromeMenu) menu.AppendSeparator() menu.Append(self.ID_ABOUT, "关于") menu.Append(self.ID_EXIT, "退出") self.menu = menu return menu
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
def createBufferBitmap(self, width, height): # get geometry cw, ch = self.charSize # create bitmap buffer self.bmpBuf = Bitmap( width *cw, # bitmap width height*ch, # bitmap heigh BITMAP_SCREEN_DEPTH) # bitmap depth # create device context dc = MemoryDC() # select buffer dc.SelectObject(self.bmpBuf) # set background dc.SetBackground(self.brushes['bkgd']) # clear buffer dc.Clear() # release bitmap dc.SelectObject(NullBitmap) # hook BackgroundBitmap to bitmapBuffer handle self.Panel.BackgroundBitmap = self.bmpBuf # record geometry self.screenSize = width, height # done return
def load_image(self, path, area=None): self.Scroll(0, 0) self.img_path = path self.wx_image = Image(path, BITMAP_TYPE_ANY) width = self.wx_image.GetWidth() height = self.wx_image.GetHeight() if area: x, y, w, h = area bitmap = Bitmap(self.wx_image) bitmap_to_draw = bitmap.GetSubBitmap(Rect(x, y, w, h)) bitmap = bitmap.ConvertToImage().ConvertToGreyscale( 0.156, 0.308, 0.060).ConvertToBitmap() self.original_bitmap = self._get_bitmap(bitmap, bitmap_to_draw, x, y, w, h, False) else: self.original_bitmap = Bitmap(self.wx_image) self.greyscaled_bitmap = self.original_bitmap.ConvertToImage( ).ConvertToGreyscale(0.209, 0.411, 0.080).ConvertToBitmap() self.static_bitmap.SetBitmap(self.original_bitmap) self.SetScrollbars(self.MIN_SCROLL, self.MIN_SCROLL, width / self.MIN_SCROLL, height / self.MIN_SCROLL)
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
def __init__(self, parent: Window): """ Args: parent: parent window """ super().__init__(parent, style=SUNKEN_BORDER) self._diagram = Diagram(self) self.__keepMoving: bool = False self._selectedShapes: List[Shape] = [ ] # list of the shapes that are selected self._lastMousePosition: Tuple[int, int] = cast(Tuple[int, int], None) self._selector: RectangleShape = cast(RectangleShape, None) # rectangle selector shape self._clickedShape: Shape = cast(Shape, None) # last clicked shape self._moving: bool = False # a drag has been initiated self._xOffset: float = 0.0 # abscissa offset between the view and the model self._yOffset: float = 0.0 # ordinate offset between the view and the model self._zoomStack: List[float] = [] # store all zoom factors applied self._zoomLevel = 0 # number of zoom factors applied self._maxZoomFactor = 6 # can zoom in beyond 600% self._minZoomFactor = 0.2 # can zoom out beyond 20% self._defaultZoomFactor = 1.5 # used when only a point is selected # margins define a perimeter around the work area that must remains # blank and hidden. if we scroll beyond the limits, the diagram is # resized. # self._leftMargin = DEFAULT_MARGIN_VALUE # self._rightMargin = DEFAULT_MARGIN_VALUE # self._topMargin = DEFAULT_MARGIN_VALUE # self._bottomMargin = DEFAULT_MARGIN_VALUE self._isInfinite = False # to know if the frame is infinite or not # paint related w, h = self.GetSize() self.__workingBitmap = Bitmap(w, h) # double buffering self.__backgroundBitmap = Bitmap(w, h) DEFAULT_FONT_SIZE = 12 self._defaultFont = Font(DEFAULT_FONT_SIZE, FONTFAMILY_DEFAULT, FONTSTYLE_NORMAL, FONTWEIGHT_NORMAL) self.SetBackgroundColour(WHITE) self._prefs: PyutPreferences = PyutPreferences() # Mouse events self.Bind(EVT_LEFT_DOWN, self.OnLeftDown) self.Bind(EVT_LEFT_UP, self.OnLeftUp) self.Bind(EVT_LEFT_DCLICK, self.OnLeftDClick) self.Bind(EVT_MIDDLE_DOWN, self.OnMiddleDown) self.Bind(EVT_MIDDLE_UP, self.OnMiddleUp) self.Bind(EVT_MIDDLE_DCLICK, self.OnMiddleDClick) self.Bind(EVT_RIGHT_DOWN, self.OnRightDown) self.Bind(EVT_RIGHT_UP, self.OnRightUp) self.Bind(EVT_RIGHT_DCLICK, self.OnRightDClick) self.Bind(EVT_PAINT, self.OnPaint) if self._prefs.debugDiagramFrame is True: self._debugDialog: DlgDebugDiagramFrame = DlgDebugDiagramFrame( self, ID_ANY) self._debugDialog.startMonitor() self._debugDialog.Show(True)
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')
def getBitmap( ): """Return the data from the resource as a wxBitmap""" return Bitmap(getImage())
class ImagePanel(ScrolledWindow): MIN_SCROLL = 10 def __init__(self, parent): ScrolledWindow.__init__(self, parent) self.wx_image = None self.original_bitmap = None self.greyscaled_bitmap = None self.img_path = None sizer = BoxSizer(VERTICAL) self.static_bitmap = StaticBitmap(self) sizer.Add(self.static_bitmap, 1, flag=FLAG_ALL_AND_EXPAND) self.SetSizer(sizer) def was_image_loaded(self): return (self.img_path and self.wx_image and self.original_bitmap and self.greyscaled_bitmap) def get_image_dimensions(self): return (self.original_bitmap.GetWidth(), self.original_bitmap.GetHeight()) def load_image(self, path, area=None): self.Scroll(0, 0) self.img_path = path self.wx_image = Image(path, BITMAP_TYPE_ANY) width = self.wx_image.GetWidth() height = self.wx_image.GetHeight() if area: x, y, w, h = area bitmap = Bitmap(self.wx_image) bitmap_to_draw = bitmap.GetSubBitmap(Rect(x, y, w, h)) bitmap = bitmap.ConvertToImage().ConvertToGreyscale( 0.156, 0.308, 0.060).ConvertToBitmap() self.original_bitmap = self._get_bitmap(bitmap, bitmap_to_draw, x, y, w, h, False) else: self.original_bitmap = Bitmap(self.wx_image) self.greyscaled_bitmap = self.original_bitmap.ConvertToImage( ).ConvertToGreyscale(0.209, 0.411, 0.080).ConvertToBitmap() self.static_bitmap.SetBitmap(self.original_bitmap) self.SetScrollbars(self.MIN_SCROLL, self.MIN_SCROLL, width / self.MIN_SCROLL, height / self.MIN_SCROLL) def _get_bitmap(self, bitmap, bitmap_to_draw, x, y, w, h, draw_frame=True): bitmap = bitmap.GetSubBitmap( Rect(0, 0, bitmap.GetWidth(), bitmap.GetHeight())) dc = MemoryDC() bdc = BufferedDC(dc) bdc.SelectObject(bitmap) bdc.DrawBitmap(bitmap_to_draw, x, y) if draw_frame: # Black rect to support white pages bdc.SetPen(BLACK_PEN) bdc.SetBrush(TRANSPARENT_BRUSH) bdc.DrawRectangle(x, y, w, h) # Grey rect to support black pages bdc.SetPen(GREY_PEN) bdc.SetBrush(TRANSPARENT_BRUSH) bdc.DrawRectangle(x + 1, y + 1, w - 2, h - 2) bdc.SelectObject(NullBitmap) return bitmap