Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8332199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:39:16+00:00 2026-06-09T02:39:16+00:00

I am using the class below for adding rubberbands. However, everytime that I create

  • 0

I am using the class below for adding rubberbands. However, everytime that I create the rubberband(left click), there is a flicker/flash. I do not know why this is happening. Also, I am putting the rubberband in a ScrolledWindow.

import wx
class wxPyRubberBander:
    """ A class to manage mouse events/ rubberbanding of a wx.Python
        canvas object """

    def __init__(self, canvas):

        # canvas object
        self._canvas = canvas
        # mouse selection start point
        self.m_stpoint=wx.Point(0,0)
        # mouse selection end point
        self.m_endpoint=wx.Point(0,0)
        # mouse selection cache point
        self.m_savepoint=wx.Point(0,0)

        # flags for left click/ selection
        self._leftclicked=False
        self._selected=False

        # Register event handlers for mouse
        self.RegisterEventHandlers()

    def RegisterEventHandlers(self):
        """ Register event handlers for this object """

        wx.EVT_LEFT_DOWN(self._canvas, self.OnMouseEvent)
        wx.EVT_LEFT_UP(self._canvas, self.OnMouseEvent)
        wx.EVT_MOTION(self._canvas, self.OnMouseEvent)


    def OnMouseEvent(self, event):
        """ This function manages mouse events """


        if event:

            # set mouse cursor
            # get device context of canvas
            dc= wx.ClientDC(self._canvas)
            # Set logical function to XOR for rubberbanding
            dc.SetLogicalFunction(wx.XOR)

            # Set dc brush and pen
            # Here I set brush and pen to white and grey respectively
            # You can set it to your own choices

            # The brush setting is not really needed since we
            # dont do any filling of the dc. It is set just for 
            # the sake of completion.

            wbrush = wx.Brush(wx.Colour(255,255,255), wx.TRANSPARENT)
            wpen = wx.Pen(wx.Colour(200, 200, 200), 1, wx.SOLID)
            dc.SetBrush(wbrush)
            dc.SetPen(wpen)


        if event.LeftDown():

           # Left mouse button down, change cursor to
           # something else to denote event capture
           self.m_stpoint = event.GetPosition()

           # invalidate current canvas
           self._canvas.Refresh()
           # cache current position
           self.m_savepoint = self.m_stpoint
           self._selected = False
           self._leftclicked = True

        elif event.Dragging():   

            # User is dragging the mouse, check if
            # left button is down

            if self._leftclicked:

                # reset dc bounding box
                dc.ResetBoundingBox()
                dc.BeginDrawing()
                w = (self.m_savepoint.x - self.m_stpoint.x)
                h = (self.m_savepoint.y - self.m_stpoint.y)

                # To erase previous rectangle
                dc.DrawRectangle(self.m_stpoint.x, self.m_stpoint.y, w, h)

                # Draw new rectangle
                self.m_endpoint =  event.GetPosition()

                w = (self.m_endpoint.x - self.m_stpoint.x)
                h = (self.m_endpoint.y - self.m_stpoint.y)

                # Set clipping region to rectangle corners
                dc.SetClippingRegion(self.m_stpoint.x, self.m_stpoint.y, w,h)
                dc.DrawRectangle(self.m_stpoint.x, self.m_stpoint.y, w, h) 
                dc.EndDrawing()

                self.m_savepoint = self.m_endpoint # cache current endpoint

        elif event.LeftUp():

            # User released left button, change cursor back   
            self._selected = True  #selection is done
            self._leftclicked = False # end of clicking  


    def GetCurrentSelection(self):
        """ Return the current selected rectangle """

        # if there is no selection, selection defaults to
        # current viewport

        left = wx.Point(0,0)
        right = wx.Point(0,0)

        # user dragged mouse to right
        if self.m_endpoint.y > self.m_stpoint.y:
            right = self.m_endpoint
            left = self.m_stpoint
        # user dragged mouse to left
        elif self.m_endpoint.y < self.m_stpoint.y:
            right = self.m_stpoint
            left = self.m_endpoint

        return (left.x, left.y, right.x, right.y)


    def ClearCurrentSelection(self):
        """ Clear the current selected rectangle """

        box = self.GetCurrentSelection()

        dc=wx.ClientDC(self._canvas)

        w = box[2] - box[0]
        h = box[3] - box[1]
        dc.SetClippingRegion(box[0], box[1], w, h)
        dc.SetLogicalFunction(wx.XOR)

        # The brush is not really needed since we
        # dont do any filling of the dc. It is set for 
        # sake of completion.

        wbrush = wx.Brush(wx.Colour(255,255,255), wx.TRANSPARENT)
        wpen = wx.Pen(wx.Colour(200, 200, 200), 1, wx.SOLID)
        dc.SetBrush(wbrush)
        dc.SetPen(wpen)
        dc.DrawRectangle(box[0], box[1], w,h)
        self._selected = False 

        # reset selection to canvas size
        self.ResetSelection()    

    def ResetSelection(self):
        """ Resets the mouse selection to entire canvas """

        self.m_stpoint = wx.Point(0,0)
        sz=self._canvas.GetSize()
        w,h=sz.GetWidth(), sz.GetHeight()
        self.m_endpoint = wx.Point(w,h)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:39:19+00:00Added an answer on June 9, 2026 at 2:39 am

    maybe freezing it would work

     def OnMouseEvent(self, event):
        """ This function manages mouse events """
        if not self._canvas.IsFrozen(): #prevent multiple freezes
            self._canvas.Freeze() #freeze it from updates
        if event:
    
            # set mouse cursor
            # get device context of canvas
            dc= wx.ClientDC(self._canvas)
            # Set logical function to XOR for rubberbanding
            dc.SetLogicalFunction(wx.XOR)
    
            # Set dc brush and pen
            # Here I set brush and pen to white and grey respectively
            # You can set it to your own choices
    
            # The brush setting is not really needed since we
            # dont do any filling of the dc. It is set just for 
            # the sake of completion.
    
            wbrush = wx.Brush(wx.Colour(255,255,255), wx.TRANSPARENT)
            wpen = wx.Pen(wx.Colour(200, 200, 200), 1, wx.SOLID)
            dc.SetBrush(wbrush)
            dc.SetPen(wpen)
    
    
        if event.LeftDown():
    
           # Left mouse button down, change cursor to
           # something else to denote event capture
           self.m_stpoint = event.GetPosition()
    
           # invalidate current canvas
           self._canvas.Refresh()
           # cache current position
           self.m_savepoint = self.m_stpoint
           self._selected = False
           self._leftclicked = True
    
        elif event.Dragging():   
    
            # User is dragging the mouse, check if
            # left button is down
    
            if self._leftclicked:
    
                # reset dc bounding box
                dc.ResetBoundingBox()
                dc.BeginDrawing()
                w = (self.m_savepoint.x - self.m_stpoint.x)
                h = (self.m_savepoint.y - self.m_stpoint.y)
    
                # To erase previous rectangle
                dc.DrawRectangle(self.m_stpoint.x, self.m_stpoint.y, w, h)
    
                # Draw new rectangle
                self.m_endpoint =  event.GetPosition()
    
                w = (self.m_endpoint.x - self.m_stpoint.x)
                h = (self.m_endpoint.y - self.m_stpoint.y)
    
                # Set clipping region to rectangle corners
                dc.SetClippingRegion(self.m_stpoint.x, self.m_stpoint.y, w,h)
                dc.DrawRectangle(self.m_stpoint.x, self.m_stpoint.y, w, h) 
                dc.EndDrawing()
    
                self.m_savepoint = self.m_endpoint # cache current endpoint
    
        elif event.LeftUp():
    
            # User released left button, change cursor back   
            self._selected = True  #selection is done
            self._leftclicked = False # end of clicking  
        if self._canvas.IsFrozen(): #prevent multiple thaws
            self._canvas.Thaw() #thaw it so it updates
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that I am using below. And I am using this
I tried to send an email using this class below, but no success, no
I am using the class pasted below to listen for the keypress event ctrl
When I try to execute the below class using ICriteria, if (_userGroupId > 0
In the class below, I am using a singleThreadScheduledExecutor. My question is, do I
I have added checkbox in display table using decorator class as shown in below
Am using below third party API in my project development http://undesigned.org.za/2007/10/22/amazon-s3-php-class I have done
I am using the below JS code in order to change the class when
I am using the below code in my test class , to load all
I am creating excel file using below code public class ResultSetToExcel { private HSSFWorkbook

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.