Beispiel #1
0
    def OnMouseMove(self, event):
        rect = RectS(self.Size)
        pos = self.ScreenToClient(GetMousePosition())

        if not rect.Contains(pos):
            self.OnMouseLeave(event)
        elif not self.hover:
            self.OnMouseEnter(event)
Beispiel #2
0
    def OnMotion(self, event):
        """Ensures mouse release."""

        if self.native:
            event.Skip()
            return

        r = RectS(self.Size)
        if self.HasCapture() and not event.LeftIsDown() and \
            not r.Contains(event.Position):
            self.ReleaseAllCapture()
Beispiel #3
0
    def OnPaint(self, event):
        "Draws the button's background."

        # excape if native
        if self.native:
            event.Skip()
            return

        rect = RectS(self.Size)

        parent, grandparent = self.Parent, self.GrandParent
        if parent.__class__.__name__ == "Tab" and self.side_tabs:
            #Clipping the button for when partualy hidden
            cliptangle = RectS(self.Size)
            sy = self.Rect.y
            sw, sh = self.Size
            py = parent.Position.y
            pph = grandparent.Size.height - 16

            if parent.Position.y + parent.Size.height > grandparent.Size.height-16 and \
               sy + sh + py > pph:
                cliptangle = Rect(0, 0, sw, pph - (sy + py))
                dc = wx.PaintDC(self)
                dc.SetClippingRect(cliptangle)
        else:
            dc = AutoBufferedPaintDC(self)

        # actual drawing of background
        currentstate=5 if self.isdown else \
                     6 if self.state and self.notified else \
                     self.state+(self.hovered*2) if self.state else \
                     0

        if self.rendernative:

            nrect = rect if self.type == 'combo' else rect.Inflate(1, 1)
            #wx.RendererNative.Get().DrawPushButton(self,dc,nrect,self.backgrounds[currentstate])
            part = 1
            state = self.backgrounds[currentstate]
            self.DrawNativeLike(dc, part, state, nrect)
        else:
            background = self.backgrounds[currentstate]
            from cgui import SplitImage4
            if isinstance(background, SplitImage4):
                ApplySmokeAndMirrors(self, background.GetBitmap(self.Size))
            else:
                ApplySmokeAndMirrors(self)
            background.Draw(dc, rect)

        #TODO: Backgroundless icon buttons

        if not (self.type == 'combo' and self.rendernative):
            self.DrawContent(dc)
Beispiel #4
0
 def CheckParentalContact(self, pos, ignoresubmenu=False):
     """
     Checks if the mouse is inside one of the parent menus of this menu
     """
     rect = RectS(self.spine.Size)
     mp = self.spine.ScreenToClient(pos)
     if rect.Contains(mp) and (
             ignoresubmenu
             or not self.spine.items[self.spine.HitTest(mp)].menu or
             not self.spine.items[self.spine.HitTest(mp)].menu.IsShown()):
         return True
     if isinstance(self.Parent, SimpleMenu):
         return self.Parent.CheckParentalContact(pos, ignoresubmenu)
     return False
Beispiel #5
0
    def PaintMore(self, dc):
        rect = RectS(self.Size)

        rem_ico = self.rem_ico

        dc.DrawBitmap(rem_ico, rect.Width - rem_ico.Width - 4,
                      rect.Height // 2 - rem_ico.Height // 2, True)
Beispiel #6
0
    def OnPaint(self, event):
        dc = wx.AutoBufferedPaintDC(self)
        rect = RectS(self.Size)
        padx, pady = self.padding

        self.bg.Draw(dc, rect)

        dc.Font = self.headerfont
        font_height = self.headerfont.Height

        dc.TextForeground = self.headerfc
        dc.DrawBitmap(self.icon, padx,
                      padx + (font_height // 2) - self.icon.Height // 2, True)

        printable = rect.width - padx
        curserx = rect.x + 2 * padx + self.icon.Width
        cursery = rect.y + pady

        dc.DrawLabel(
            self.account.display_name,
            wx.Rect(curserx, cursery, printable - curserx, font_height))

        curserx += dc.GetTextExtent(self.account.display_name + ' ')[0]

        # TODO: remove this hack!
        if getattr(self.account, 'service', None) != 'twitter':
            dc.DrawLabel(('' if not hasattr(self.account, 'count') else '(' +
                          str(self.account.count) + ')'),
                         Rect(curserx, cursery, printable - curserx,
                              dc.Font.Height))
Beispiel #7
0
    def OnPaint(self, event):
        """
            Standard paints.
        """
        dc = AutoBufferedPaintDC(self)
        rect = RectS(self.Size)

        self.framebg.Draw(dc, rect)
Beispiel #8
0
                def passback(e, passto=passto):
                    if not RectS(passto.Size).Contains(
                            e.Position) or FindWindowAtPointer() != passto:
                        while passto.HasCapture():

                            #                            print "child releasing capture"
                            passto.ReleaseMouse()
                            passto.Parent.AddPendingEvent(e)
                        discon()
                    e.Skip()
Beispiel #9
0
 def OnWheel(self,event):
     """
         Event that handles mouse wheeling,
         maps the events to SetNextActive and SetLastActive
     """
     if RectS(self.Size).Contains(event.Position):
         direction = event.GetWheelRotation()
         if direction<0:
             self.SetNextActive(self.ActiveTab, True)
         elif direction>0:
             self.SetLastActive(self.ActiveTab, True)
Beispiel #10
0
    def MouseCaptureSystem(self, event, mouseinactions, mouseoutactions):
        winatpoint = FindWindowAtPointer()
        isover = winatpoint == self or winatpoint in self.Children

        if not RectS(self.Size).Contains(event.Position) or not isover:
            self.ReleaseAllCapture()
            mouseoutactions()

        else:
            if not self.HasCapture():
                #                print "parent capturing mouse"
                self.CaptureMouse()

                mouseinactions()

            def childwithmouse(p=event.Position):
                for child in self.Children:
                    if child.Shown and child.Rect.Contains(p):
                        return child

            passto = childwithmouse()

            if passto and not passto.HasCapture():

                def passback(e, passto=passto):
                    if not RectS(passto.Size).Contains(
                            e.Position) or FindWindowAtPointer() != passto:
                        while passto.HasCapture():

                            #                            print "child releasing capture"
                            passto.ReleaseMouse()
                            passto.Parent.AddPendingEvent(e)
                        discon()
                    e.Skip()

                def passlost(e, passto=passto):
                    #                    print "child disconecting"
                    discon()
                    #e.Skip()

                passto.Connect(passto.Id, passto.Id, wxEVT_MOTION, passback)
                passto.Connect(passto.Id, passto.Id, wxEVT_MOUSE_CAPTURE_LOST,
                               passlost)

                def discon(passto=passto):
                    passto.Disconnect(passto.Id, passto.Id, wxEVT_MOTION)
                    passto.Disconnect(passto.Id, passto.Id,
                                      wxEVT_MOUSE_CAPTURE_LOST)
#                    print "disconected child capture"

#                print "parent giving mouse to child"

                passto.CaptureMouse()
Beispiel #11
0
    def OnBGPaint(self, event):
        'Handles wx.EVT_ERASE_BACKGROUND.'

        dc = wx.AutoBufferedPaintDC(self)  #wx.BufferedDC(wx.ClientDC(self))

        if self.bg:
            rect = RectS(self.Size)
            self.bg.Draw(dc, rect)
        else:
            self.DrawNativeLike(dc, 0, 0, wx.RectS(self.Size))

        self.ChildPaints(dc)
Beispiel #12
0
    def OnPaint(self, event):

        if self.ItemCount:
            event.Skip()
            return

        dc = wx.AutoBufferedPaintDC(self)
        rect = RectS(self.Size)

        self.OnDrawBackground(dc, rect, 0)

        dc.Font = self.titlefont
        dc.DrawLabel('No Previews' if self.account.count else 'No New Email',
                     rect, wx.ALIGN_CENTER)
Beispiel #13
0
    def OnPaint(self, event):
        dc   = wx.PaintDC(self)
        rect = RectS(self.Size)
        if not self.side_tabs:
            rcount = min(len(self.rows), pref('tabs.rows', 2))
            height = self.tabs[0].Size.height

            y=0
            for unused_i in xrange(rcount):
                self.bg.Draw(dc, Rect(rect.x, y, rect.width, height))
                y += height

        else:
            self.bg.Draw(dc,rect)
Beispiel #14
0
    def OnPaint(self, event):
        dc = AutoBufferedPaintDC(self)
        rect = RectS(self.Size)
        self.bg.Draw(dc, rect)

        # Draw service icon
        icon = self.licon if self.account.is_connected else self.licon.Greyed

        dc.DrawBitmapPoint(icon, self.liconpos, True)

        #The right icon can either be the close icon, the state icon, or nothing
        #Shows the state icon if the list is in ShowAll or nothing if state is CONNECTING, AUTHENTICATING,INITIALIZING, or LOADING_CONTACT_LIST
        #   Otherwise it shows the close button
        ricon = self.stateicon if self.Parent.ShowAll else (
            self.closeicon[self.buttonstate]
            if self.account.state not in ShowNothingStates else None)
        if ricon:
            rconpos = self.riconpos + Point(8 - ricon.Width // 2,
                                            8 - ricon.Height // 2)
            dc.DrawBitmapPoint(ricon, rconpos, True)
        self.buttonshown = bool(ricon)

        # Draw the account name
        dc.Font = self.majorfont
        dc.TextForeground = self.majorfc
        dc.DrawTruncatedText(self.title, self.titlerect)

        # Draws the offline reason or state
        dc.Font = self.minorfont
        dc.TextForeground = self.statefc
        if callable(self.reason):
            self.wrappedreason = Wrap(self.reason(), self.reasonrect.Width,
                                      self.minorfont, dc)
        dc.DrawLabel(self.wrappedreason, self.reasonrect)

        # Draw the link
        dc.Font = self.linkfont
        dc.TextForeground = self.linkfc
        dc.DrawLabel(self.link, self.linkrect)
Beispiel #15
0
 def OnPaint(self, event):
     'Draws an outline around the control.'
     dc = BufferedPaintDC(self)
     dc.Brush = wx.TRANSPARENT_BRUSH
     dc.Pen = wx.Pen(OUTLINE_COLOR)
     dc.DrawRectangleRect(RectS(self.ClientSize))
Beispiel #16
0
    def paint(self, e):
        #
        # translation from C++ version in VListBox::OnPaint
        #


        clientSize = self.ClientSize
        dc = BufferedPaintDC(self)

        # the update rectangle
        rectUpdate = self.GetUpdateClientRect()

        # fill background
        crect = self.ClientRect

        if self.bg is not None:
            self.bg.Draw(dc, crect)
        else:
            dc.Brush = Brush(self.BackgroundColour)
            dc.Pen   = wx.TRANSPARENT_PEN #@UndefinedVariable
            dc.DrawRectangleRect(RectS(self.Size))

        self.PaintMoreBackground(dc, crect)

        # the bounding rectangle of the current line
        rectLine = Rect(0, 0, clientSize.x, 0)

        # iterate over all visible lines
        lineMax = self.GetVisibleEnd()
        lineh    = self.OnMeasureItem
        drawbg   = self.OnDrawBackground
        drawsep  = self.OnDrawSeparator
        drawitem = self.OnDrawItem
        margins  = self.GetMargins()

        for line in xrange(self.GetFirstVisibleLine(), lineMax):
            try:
                hLine = lineh(line)
            except TypeError:
                log.critical('self.OnMeasureItem was None, returning')
                del dc
                return

            rectLine.height = hLine

            # and draw the ones which intersect the update rect
            if rectLine.Intersects(rectUpdate):
                # don't allow drawing outside of the lines rectangle
                clip = DCClipper(dc, rectLine)
                rect = Rect(*rectLine)

                try:
                    drawbg(dc,  Rect(*rect), line)
                except Exception:
                    print_exc()

                try:
                    drawsep(dc, Rect(*rect), line)
                except Exception:
                    print_exc()

                rect.Deflate(margins.x, margins.y)

                try:
                    drawitem(dc, rect, line)
                except Exception:
                    print_exc()
                del clip

            else: # no intersection
                if rectLine.Top > rectUpdate.Bottom:
                    # we are already below the update rect, no need to continue
                    # further
                    break
                else: #the next line may intersect the update rect
                    pass

            rectLine.y += hLine

        return dc
Beispiel #17
0
    def OnPaint(self, e):
        dc = BufferedPaintDC(self)

        if self.bg:
            self.bg.Draw(dc, RectS(self.ClientSize))
        self.ChildPaints(dc)
Beispiel #18
0
 def OnPaint(self, event):
     self.bg.Draw(AutoBufferedPaintDC(self), RectS(self.ClientSize))
Beispiel #19
0
    def OnPaint(self, event):
        'EVT_PAINT handling'
        dc = AutoBufferedPaintDC(self)
        rect = RectS(self.Size)

        # draw the background
        background = self.Parent.hoverbg if self.hover else self.Parent.normalbg
        background.Draw(dc, rect)

        margins = self.Parent.margins
        padding = self.Parent.padding

        # Font setup
        font = None
        sp = self.Parent.menu.spine
        sel = sp.Selection
        if sel > len(sp.items): sel = sp.Selection = -1

        if sel != -1 and sel < len(
                sp.items) and sel >= 0 and sp.items[sel].font:
            font = sp.items[sel].font
            #font.PointSize=self.Font.PointSize
        else:
            font = self.Font

        dc.Font = font
        color = self.Parent.hoverfc if self.hover else self.Parent.normalfc
        dc.TextForeground = color
        fontHeight = font.Height

        # initial cursor setup

        if self.Parent.ForceTextFieldBackground:
            self.Parent.activebg.Draw(dc, rect)

        label = self.DisplayLabel

        # Draw text if value is just a string
        if isinstance(label, basestring):
            cursor = Point(rect.x + margins.left + padding.x,
                           margins.top + padding.y)
            if not label and self.empty_text:
                text = self.empty_text
                dc.SetTextForeground(self.Parent.hintfc)
            else:
                text = label

            text_rect = Rect(cursor.x, cursor.y,
                             rect.width - cursor.x - margins.right - padding.x,
                             fontHeight)
            text_rect, text = self.music_note_hack(dc, text_rect, text,
                                                   fontHeight)
            dc.DrawTruncatedText(text.split('\n', 1)[0],
                                 text_rect,
                                 alignment=wx.ALIGN_LEFT | wx.ALIGN_TOP)

        # or draw each part of the value
        else:
            cursor = Point(rect.x + margins.left + padding.x,
                           ((rect.height - margins.top - margins.bottom) / 2) +
                           margins.top)
            if label is not None:
                for i in label.content:
                    if isinstance(i, Bitmap):
                        dc.DrawBitmapPoint(i,
                                           (cursor.x, cursor.y - i.Height / 2),
                                           True)
                        cursor += Point(i.Width + padding.x, 0)

                    elif isinstance(i, basestring):
                        dc.DrawTruncatedText(
                            i.split('\n', 1)[0],
                            wx.Rect(
                                cursor.x, cursor.y - fontHeight / 2,
                                rect.width - cursor.x - margins.right -
                                padding.x, fontHeight),
                            alignment=wx.ALIGN_LEFT | wx.ALIGN_CENTRE_VERTICAL)
                        cursor += Point(dc.GetTextExtent(i)[0] + padding.x, 0)

        # Draw a background for the textfield
        if self.txtfld.Shown:  # or self.Parent.ForceTextFieldBackground:
            #            dc.Brush = wx.Brush(self.Parent.activebg)
            #            dc.Pen   = wx.TRANSPARENT_PEN
            #
            #            dc.DrawRectangleRect(rect)
            self.Parent.activebg.Draw(dc, rect)
Beispiel #20
0
    def OnPaint(self, event):
        'Standard painting stuff.'

        dc = AutoBufferedPaintDC(self)
        self.framebg.Draw(dc, RectS(self.Size))