def __createBitmap(self, parent, background, type, state): if state == 1: if type == 'tree': state = wx.CONTROL_EXPANDED elif type == 'checkbox': state = wx.CONTROL_CHECKED else: state = wx.CONTROL_PRESSED #There are some strange bugs in RendererNative, the alignment is incorrect of the drawn images #Thus we create a larger bmp, allowing for borders bmp = wx.EmptyBitmap(24, 24) dc = wx.MemoryDC(bmp) dc.SetBackground(wx.Brush(background)) dc.Clear() #max size is 16x16, using 4px as a border if type == 'checkbox': wx.RendererNative.Get().DrawCheckBox(parent, dc, (4, 4, 16, 16), state) elif type == 'tree': wx.RendererNative.Get().DrawTreeItemButton(parent, dc, (4, 4, 16, 16), state) elif type == 'arrow': wx.RendererNative.Get().DrawDropArrow(parent, dc, (4, 4, 16, 16), state) dc.SelectObject(wx.NullBitmap) del dc #determine actual size of drawn icon, and return this subbitmap bb = wx.RegionFromBitmapColour(bmp, background).GetBox() return bmp.GetSubBitmap(bb)
def __init__(self, parent, normal, pressed=None, disabled=None, title=None, id=None, MainFrame=None): super(ShapedButton, self).__init__(parent, id, style=wx.BORDER_NONE) self.normal = normal self.pressed = pressed self.disabled = disabled self.title = title self.id = id self.region = wx.RegionFromBitmapColour(normal, wx.Colour(0, 0, 0, 0)) self._clicked = False self._selected = False self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) self.Bind(wx.EVT_SIZE, self.on_size) self.Bind(wx.EVT_PAINT, self.on_paint) self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down) self.Bind(wx.EVT_LEFT_DCLICK, self.on_left_dclick) self.Bind(wx.EVT_LEFT_UP, self.on_left_up) self.Bind(wx.EVT_MOTION, self.on_motion) self.Bind(wx.EVT_LEAVE_WINDOW, self.on_leave_window)
def OnSize(self, event): # The Buffer init is done here, to make sure the buffer is always # the same size as the Window self.Width, self.Height = self.GetClientSizeTuple() # Make new off screen bitmap: this bitmap will always have the # current drawing in it, so it can be used to save the image to # a file, or whatever. # This seems required on MacOS, it doesn't like wx.EmptyBitmap with # size = (0, 0) # Thanks to Gerard Grazzini if "__WXMAC__" in wx.Platform: if self.Width == 0: self.Width = 1 if self.Height == 0: self.Height = 1 self._Buffer = wx.EmptyBitmap(self.Width, self.Height) memory = wx.MemoryDC() memory.SelectObject(self._Buffer) memory.SetBackground(wx.Brush(self.GetBackgroundColour())) memory.SetPen(wx.TRANSPARENT_PEN) memory.Clear() minradius = min(0.9 * self.Width / 2, 0.9 * self.Height / 2) memory.DrawCircle(self.Width / 2, self.Height / 2, minradius) memory.SelectObject(wx.NullBitmap) self._region = wx.RegionFromBitmapColour(self._Buffer, self.GetBackgroundColour()) self._minradius = minradius self.UpdateDrawing()
def GetClickRegion(self, bitmap): """ build the clickable region, use mask if available, else black as transparent color """ if bitmap.GetMask(): region = wx.RegionFromBitmap(bitmap) else: region = wx.RegionFromBitmapColour(bitmap, wx.Color(0, 0, 0, 0)) return region
def __init__(self, parent, normal, pressed=None, disabled=None): super(ShapedButton, self).__init__(parent, -1, style=wx.BORDER_NONE) self.normal = normal self.pressed = pressed self.disabled = disabled self.region = wx.RegionFromBitmapColour(normal, wx.Colour(0, 0, 0, 0)) self._clicked = False self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) self.Bind(wx.EVT_SIZE, self.on_size) self.Bind(wx.EVT_PAINT, self.on_paint) self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down)
def __init__(self, parent, message, title, icon): """ Default class constructor. :param `parent`: the frame parent; :param `message`: the message to display in the :class:`PyBusyInfo`; :param `title`: the main :class:`PyBusyInfo` title; :param `icon`: an icon to draw as the frame icon, an instance of :class:`Bitmap`. """ wx.Frame.__init__( self, parent, wx.ID_ANY, title, wx.DefaultPosition, wx.DefaultSize, wx.NO_BORDER | wx.FRAME_TOOL_WINDOW | wx.FRAME_SHAPED | wx.STAY_ON_TOP) panel = wx.Panel(self) panel.SetCursor(wx.HOURGLASS_CURSOR) self._message = message self._title = title self._icon = icon dc = wx.ClientDC(self) textWidth, textHeight, dummy = dc.GetMultiLineTextExtent(self._message) sizeText = wx.Size(textWidth, textHeight) self.SetClientSize( (max(sizeText.x, 340) + 60, max(sizeText.y, 40) + 60)) # need to size the panel correctly first so that text.Centre() works panel.SetSize(self.GetClientSize()) # Bind the events to draw ourselves panel.Bind(wx.EVT_PAINT, self.OnPaint) panel.Bind(wx.EVT_ERASE_BACKGROUND, self.OnErase) self.Centre(wx.BOTH) # Create a non-rectangular region to set the frame shape size = self.GetSize() bmp = wx.EmptyBitmap(size.x, size.y) dc = wx.BufferedDC(None, bmp) dc.SetBackground(wx.Brush(wx.Colour(0, 0, 0), wx.SOLID)) dc.Clear() dc.SetPen(wx.Pen(wx.Colour(0, 0, 0), 1)) dc.DrawRoundedRectangle(0, 0, size.x, size.y, 12) r = wx.RegionFromBitmapColour(bmp, wx.Colour(0, 0, 0)) # Store the non-rectangular region self.reg = r if wx.Platform == "__WXGTK__": self.Bind(wx.EVT_WINDOW_CREATE, self.SetBusyShape) else: self.SetBusyShape()
def Position(self): w, h = self._interior.GetClientSizeTuple() h += self.ARROWSIZE if self._getRect is None: tw, th = self._target.GetSizeTuple() tx, ty = 0, 0 else: tx, ty, tw, th = self._getRect() tx, ty = self._target.ClientToScreen(wx.Point(tx, ty)) dpyIndex = max(0, wx.Display.GetFromPoint(wx.Point(tx, ty)) or 0) rect = wx.Display(dpyIndex).GetClientArea() x = max(rect.GetLeft(), min(rect.GetRight() - w, int(tx + tw / 2 - w / 2))) y = ty - h direction = 'bottom' if y < rect.GetTop(): y = ty + th direction = 'top' mask = wx.EmptyBitmap(w, h) memDC = wx.MemoryDC() memDC.SelectObject(mask) try: memDC.SetBrush(wx.BLACK_BRUSH) memDC.SetPen(wx.BLACK_PEN) memDC.DrawRectangle(0, 0, w, h) memDC.SetBrush(wx.WHITE_BRUSH) memDC.SetPen(wx.WHITE_PEN) if direction == 'bottom': memDC.DrawPolygon([ (0, 0), (w, 0), (w, h - self.ARROWSIZE), (tx + int(tw / 2) - x + int(self.ARROWSIZE / 2), h - self.ARROWSIZE), (tx + int(tw / 2) - x, h), (tx + int(tw / 2) - x - int(self.ARROWSIZE / 2), h - self.ARROWSIZE), (0, h - self.ARROWSIZE) ]) else: memDC.DrawPolygon([ (0, self.ARROWSIZE), (tx + int(tw / 2) - x - int(self.ARROWSIZE / 2), self.ARROWSIZE), (tx + int(tw / 2) - x, 0), (tx + int(tw / 2) - x + int(self.ARROWSIZE / 2), self.ARROWSIZE), (w, self.ARROWSIZE), (w, h), (0, h) ]) self._sizer.SetDirection(direction) finally: memDC.SelectObject(wx.NullBitmap) self.SetDimensions(x, y, w, h) self.SetShape(wx.RegionFromBitmapColour(mask, wx.Colour(0, 0, 0))) self.Layout()
def __createBitmap(self, parent, background, type, state): if state == 1: if type == 'tree': state = wx.CONTROL_EXPANDED elif type == 'checkbox': state = wx.CONTROL_CHECKED else: state = wx.CONTROL_PRESSED # There are some strange bugs in RendererNative, the alignment is incorrect of the drawn images # Thus we create a larger bmp, allowing for borders bmp = wx.EmptyBitmap(24, 24) dc = wx.MemoryDC(bmp) dc.SetBackground(wx.Brush(background)) dc.Clear() # max size is 16x16, using 4px as a border if type == 'checkbox': wx.RendererNative.Get().DrawCheckBox(parent, dc, (4, 4, 16, 16), state) elif type == 'tree': wx.RendererNative.Get().DrawTreeItemButton(parent, dc, (4, 4, 16, 16), state) elif type == 'arrow': arrow = PyEmbeddedImage( "iVBORw0KGgoAAAANSUhEUgAAAAcAAAAECAYAAABCxiV9AAAAAXNSR0IArs4c6QAAAARnQU1B" "AACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3YXJlAFBhaW50Lk5F" "VCB2My41LjEwMPRyoQAAADFJREFUGFdjYGBg+I8Tf/jwQRSbJFCckQFIcIEZSCYA+RxAzAyS" "BGFGmAIgzQTlMwAAOBAx4jYP9TUAAAAASUVORK5CYII=") return arrow.GetBitmap() elif type == 'slider': slider = PyEmbeddedImage( "iVBORw0KGgoAAAANSUhEUgAAAAkAAAAICAYAAAArzdW1AAAAAXNSR0IArs4c6QAAAARnQU1B" "AACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3YXJlAFBhaW50Lk5F" "VCB2My41LjEwMPRyoQAAAOZJREFUKFM9j71rg1AUxd9LIUuX/gvZRAcRdfBjqp+jIoKYoZBQ" "UdEO+pysa6f+mZ0ayJCWri/nhcYLP7icc+6BS3Rd/3Jdl6dpyrMsW0mShNu2zU3T/CaKovC2" "bV+naXoGOTiAPRihN8Inqqryuq6Nvu83gALyD4W+Ez6RJOmnKIrPYRieGGMbNBCwxU7Lspxk" "Wf4jvu83mqadUP0xz/MDoIKu65hhGGf4jIgJw/CABy7jOPbLslC07BG4BEHwcguIyfN8G8dx" "4zjOb1VVR3x7jqKoFvoaui+4fLcs6+R53ttdQ/vjFXw5XtzmpGeLAAAAAElFTkSuQmCC" ) return slider.GetBitmap() dc.SelectObject(wx.NullBitmap) del dc # determine actual size of drawn icon, and return this subbitmap bb = wx.RegionFromBitmapColour(bmp, background).GetBox() return bmp.GetSubBitmap(bb)
def __init__(self, normal, *args, **kw_args): super(ShapedButton, self).__init__(*args, **kw_args) self.SetWindowStyle(self.GetWindowStyle() | wx.NO_BORDER | wx.TRANSPARENT_WINDOW) self.normal = wx.Bitmap(normal) self.pressed = None self.disabled = None self.region = wx.RegionFromBitmapColour(self.normal, wx.Colour(0, 0, 0, 0)) self._clicked = False self.SetBackgroundStyle(wx.BG_STYLE_PAINT) self.SetSize(self.DoGetBestSize()) self.Bind(wx.EVT_SIZE, self.on_size) self.Bind(wx.EVT_PAINT, self.on_paint) self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down) self.Bind(wx.EVT_LEFT_DCLICK, self.on_left_dclick) self.Bind(wx.EVT_LEFT_UP, self.on_left_up) self.Bind(wx.EVT_MOTION, self.on_motion) self.Bind(wx.EVT_LEAVE_WINDOW, self.on_leave_window)
def make_bitmap(self, width, height): ''' Creates a wx.Bitmap with the specified size, drawing this MultiImage's total contents onto the bitmap. @param mask_color an optional parameter for the bitmap's mask ''' size = (width, height) bitmap = TransparentBitmap(size) if not hasattr(self, 'temp_dc'): self.temp_dc = wx.MemoryDC() self.temp_dc.SelectObject(bitmap) self.drawtodc(self.temp_dc, wx.Rect(0, 0, *size)) self.temp_dc.SelectObject(wx.NullBitmap) self.region = wx.RegionFromBitmapColour(bitmap, (0, 0, 0, 0)) # gui.toolbox.toscreen(self.region.ConvertToBitmap(),500,500) return bitmap
def SetBalloonShape(self, event=None): """ Sets the balloon shape.""" size = self.GetSize() pos = self.GetPosition() dc = wx.MemoryDC(wx.EmptyBitmap(1, 1)) textlabel = self._balloonmsg.GetLabel() textfont = self._balloonmsg.GetFont() textextent = dc.GetFullTextExtent(textlabel, textfont) boxheight = size.y - textextent[1] * len(textlabel.split("\n")) boxwidth = size.x position = wx.GetMousePosition() xpos = position[0] ypos = position[1] if xpos > 20 and ypos > 20: # This Is NW Positioning positioning = "NW" xpos = position[0] - boxwidth + 20 ypos = position[1] - boxheight - 20 elif xpos <= 20 and ypos <= 20: # This Is SE Positioning positioning = "SE" xpos = position[0] - 20 ypos = position[1] elif xpos > 20 and ypos <= 20: # This Is SW Positioning positioning = "SW" xpos = position[0] - boxwidth + 20 ypos = position[1] else: # This Is NE Positioning positioning = "NE" xpos = position[0] ypos = position[1] - boxheight + 20 bmp = wx.EmptyBitmap(size.x, size.y) dc = wx.BufferedDC(None, bmp) dc.BeginDrawing() dc.SetBackground(wx.Brush(wx.Colour(0, 0, 0), wx.SOLID)) dc.Clear() dc.SetPen(wx.Pen(wx.Colour(0, 0, 0), 1, wx.TRANSPARENT)) if self._shape == BT_ROUNDED: dc.DrawRoundedRectangle(0, 20, boxwidth, boxheight - 20, 12) elif self._shape == BT_RECTANGLE: dc.DrawRectangle(0, 20, boxwidth, boxheight - 20) if positioning == "NW": dc.DrawPolygon( ((boxwidth - 40, boxheight), (boxwidth - 20, boxheight + 20), (boxwidth - 20, boxheight))) elif positioning == "SE": dc.DrawPolygon(((20, 20), (20, 0), (40, 20))) elif positioning == "SW": dc.DrawPolygon( ((boxwidth - 40, 20), (boxwidth - 20, 0), (boxwidth - 20, 20))) else: dc.DrawPolygon( ((20, boxheight), (20, boxheight + 20), (40, boxheight))) dc.EndDrawing() r = wx.RegionFromBitmapColour(bmp, wx.Colour(0, 0, 0)) self.hasShape = self.SetShape(r) if self._tipstyle == BT_BUTTON: colour = self.panel.GetBackgroundColour() self._closebutton.SetBackgroundColour(colour) self.SetPosition((xpos, ypos))
def __init__(self, interface, message=u"", icone=None, couleurClaire=wx.Colour(206, 196, 190), couleurFoncee=wx.Colour(169, 156, 146), bouton_non=True, texte_non=_(u"Non"), image_non="Efface.png", bouton_oui=True, texte_oui=_(u"Oui"), image_oui="Validation.png", listeItems=[], multiSelection=True, ): wx.Dialog.__init__(self, interface, -1, style=wx.NO_BORDER|wx.FRAME_SHAPED|wx.STAY_ON_TOP) self.interface = interface self.message = message self.icone = icone self.multiSelection = multiSelection # Regarde si un thème existe dans l'interface if interface != None : dictTheme = interface.GetTheme() if "dlg" in dictTheme : couleurClaire = dictTheme["dlg"]["couleurClaire"] couleurFoncee = dictTheme["dlg"]["couleurFoncee"] # Propriétés self.SetBackgroundColour(couleurClaire) self.SetFont(wx.Font(28, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "MS Shell Dlg 2")) # Panneau gauche self.panel_gauche = wx.Panel(self, -1) self.panel_gauche.SetBackgroundColour(couleurFoncee) self.panel_gauche.SetMinSize((-1, 600)) # Icone if icone == "erreur" : bmp = wx.Bitmap(Chemins.GetStaticPath("Images/Badgeage/Erreur.png"), wx.BITMAP_TYPE_ANY) elif icone == "exclamation" : bmp = wx.Bitmap(Chemins.GetStaticPath("Images/Badgeage/Exclamation.png"), wx.BITMAP_TYPE_ANY) elif icone == "information" : bmp = wx.Bitmap(Chemins.GetStaticPath("Images/Badgeage/Information.png"), wx.BITMAP_TYPE_ANY) elif icone == "question" : bmp = wx.Bitmap(Chemins.GetStaticPath("Images/Badgeage/Question.png"), wx.BITMAP_TYPE_ANY) elif icone == "commentaire" : bmp = wx.Bitmap(Chemins.GetStaticPath("Images/Badgeage/Commentaire.png"), wx.BITMAP_TYPE_ANY) else : bmp = wx.NullBitmap self.ctrl_icone = wx.StaticBitmap(self.panel_gauche, -1, bitmap=bmp) # Panneau droite ## message = textwrap.wrap(message, 30) ## self.label_message = wx.StaticText(self, -1, u"\n".join(message)) self.label_message = wx.StaticText(self, -1, message) self.label_message.SetMinSize((600, 200)) # Boutons Toggle self.ctrl_choix = CTRL_Choix(self, listeItems=listeItems, multiSelection=multiSelection, couleurClaire=couleurClaire, couleurFoncee=couleurFoncee, taille=(500, -1)) if len(listeItems) == 0 : self.ctrl_choix.Enable(False) # Boutons self.ctrl_non = GB.GradientButton(self, -1, wx.Bitmap(Chemins.GetStaticPath("Images/Badgeage/%s" % image_non), wx.BITMAP_TYPE_ANY), u" %s " % texte_non) self.ctrl_non.SetTopStartColour(wx.Colour(228, 98, 79)) self.ctrl_non.SetTopEndColour(wx.Colour(223, 70, 25)) self.ctrl_non.SetBottomStartColour(wx.Colour(223, 70, 25)) self.ctrl_non.SetBottomEndColour(wx.Colour(228, 98, 79)) self.ctrl_non.SetPressedTopColour(wx.Colour(195, 76, 70)) self.ctrl_non.SetPressedBottomColour(wx.Colour(195, 76, 70)) self.ctrl_non.Show(bouton_non) self.ctrl_oui = GB.GradientButton(self, -1, wx.Bitmap(Chemins.GetStaticPath("Images/Badgeage/%s" % image_oui), wx.BITMAP_TYPE_ANY), u" %s " % texte_oui) self.ctrl_oui.SetTopStartColour(wx.Colour(159, 207, 80)) self.ctrl_oui.SetTopEndColour(wx.Colour(131, 193, 36)) self.ctrl_oui.SetBottomStartColour(wx.Colour(131, 193, 36)) self.ctrl_oui.SetBottomEndColour(wx.Colour(159, 207, 80)) self.ctrl_oui.SetPressedTopColour(wx.Colour(60, 160, 84)) self.ctrl_oui.SetPressedBottomColour(wx.Colour(60, 160, 84)) self.ctrl_oui.Show(bouton_oui) # Désactive la touche OUI si multiSelection activée if len(listeItems) > 0 and self.multiSelection == True : self.ctrl_oui.Enable(False) # Texte d'attente self.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "MS Shell Dlg 2")) self.label_attente = wx.StaticText(self, -1, _(u"Veuillez patienter...")) self.label_attente.SetForegroundColour(couleurFoncee) if bouton_non == True or bouton_oui == True : self.label_attente.Show(False) # Binds self.Bind(wx.EVT_BUTTON, self.OnBoutonNon, self.ctrl_non) self.Bind(wx.EVT_BUTTON, self.OnBoutonOui, self.ctrl_oui) # Touches de raccourcis if bouton_non == True or bouton_oui == True : self.Bind(wx.EVT_MENU, self.OnBoutonNon, id=ID_NON) self.Bind(wx.EVT_MENU, self.OnBoutonOui, id=ID_OUI) accel_tbl = wx.AcceleratorTable([ (0, ord('N'), ID_NON), (0, ord('O'), ID_OUI), (0, 13, ID_OUI), (0, wx.WXK_BACK, ID_NON), (0, ord('A'), ID_NON), ]) self.SetAcceleratorTable(accel_tbl) # Layout grid_sizer_base = wx.FlexGridSizer(rows=1, cols=2, vgap=10, hgap=10) # Panneau gauche grid_sizer_gauche = wx.FlexGridSizer(rows=3, cols=1, vgap=10, hgap=10) grid_sizer_gauche.Add(self.ctrl_icone, 0, wx.ALL, 20) self.panel_gauche.SetSizer(grid_sizer_gauche) grid_sizer_base.Add(self.panel_gauche, 1, wx.EXPAND, 0) # Panneau droit grid_sizer_droit = wx.FlexGridSizer(rows=4, cols=1, vgap=10, hgap=10) grid_sizer_droit.Add(self.label_message, 0, 0, 0) # Boutons de Choix grid_sizer_droit.Add(self.ctrl_choix, 1, wx.EXPAND|wx.TOP, 10) # Bouton Veuillez patienter grid_sizer_droit.Add(self.label_attente, 0, wx.ALIGN_RIGHT, 0) # Boutons grid_sizer_boutons = wx.FlexGridSizer(rows=1, cols=3, vgap=20, hgap=20) grid_sizer_boutons.Add((1, 1), 0, wx.EXPAND, 0) grid_sizer_boutons.Add(self.ctrl_non, 0, wx.ALL, 0) grid_sizer_boutons.Add(self.ctrl_oui, 0, wx.ALL, 0) grid_sizer_boutons.AddGrowableCol(0) grid_sizer_droit.Add(grid_sizer_boutons, 1, wx.EXPAND|wx.TOP, 20) grid_sizer_droit.AddGrowableRow(1) grid_sizer_droit.AddGrowableCol(0) grid_sizer_base.Add(grid_sizer_droit, 1, wx.EXPAND|wx.ALL, 20) self.SetSizer(grid_sizer_base) grid_sizer_base.Fit(self) grid_sizer_base.AddGrowableRow(0) grid_sizer_base.AddGrowableCol(1) self.Layout() self.CenterOnScreen() # Création de la forme de la fenêtre size = self.GetSize() if 'phoenix' in wx.PlatformInfo: bmp = wx.Bitmap(size.x, size.y) else : bmp = wx.EmptyBitmap(size.x, size.y) dc = wx.BufferedDC(None, bmp) dc.SetBackground(wx.Brush(wx.Colour(0, 0, 0), wx.SOLID)) dc.Clear() dc.SetPen(wx.Pen(wx.Colour(0, 0, 0), 1)) dc.DrawRoundedRectangle(0, 0, size.x, size.y, 20) if 'phoenix' in wx.PlatformInfo: r = wx.Region(bmp, wx.Colour(0, 0, 0)) else : r = wx.RegionFromBitmapColour(bmp, wx.Colour(0, 0, 0)) self.reg = r if wx.Platform == "__WXGTK__": self.Bind(wx.EVT_WINDOW_CREATE, self.SetBusyShape) else: self.SetBusyShape() # Synthèse vocale wx.CallAfter(self.Vocal)