def mouse_click_ImageButton(wrapper, interaction):
    """ Performs a mouce click on an pyface.ui.wx.ImageButton object.

    Parameters
    ----------
    wrapper : UIWrapper
        The wrapper object wrapping the Custom Button Editor which utilizes
        an ImageButton.
    interaction : instance of traitsui.testing.tester.command.MouseClick
        interaction is unused here, but it is included so that the function
        matches the expected format for a handler.  Note this handler is
        intended to be used with an interaction_class of a MouseClick.
    """

    control = wrapper.target.control
    if not control.IsEnabled():
        return
    wx.MilliSleep(wrapper.delay)

    left_down_event = wx.MouseEvent(
        wx.wxEVT_LEFT_DOWN
    )
    left_up_event = wx.MouseEvent(
        wx.wxEVT_LEFT_UP
    )
    control.ProcessEvent(left_down_event)
    control.ProcessEvent(left_up_event)
Esempio n. 2
0
def test_wxFrame(palette):
    try:
        # New frame
        postCommandEvent(palette.palettePages[0].buttons['wx.Frame'],
                         wx.wxEVT_COMMAND_BUTTON_CLICKED)

        # Open designer
        mp = palette.editor.getActiveModulePage()
        ctrlr = palette.editor.getControllerFromModel(mp.model)
        ctrlr.OnDesigner(None)

        # Select static text
        btn = palette.palettePages[2].buttons['wx.StaticText']
        btn.up = False
        evt = wx.lib.buttons.GenButtonEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED,
                                            btn.GetId())
        evt.SetButtonObj(btn)
        evt.SetIsDown(True)
        wx.PostEvent(btn, evt)
        wx.Yield()

        # Drop component on Designer
        model = palette.editor.getActiveModulePage().model
        evt = wx.MouseEvent(wx.wxEVT_LEFT_DOWN)
        #        evt.SetEventObject(model.views['Designer'])
        evt.m_x = 10
        evt.m_y = 10
        wx.PostEvent(model.views['Designer'], evt)
        wx.Yield()

        # Select Frame
        evt = wx.MouseEvent(wx.wxEVT_LEFT_DOWN)
        evt.m_x = 0
        evt.m_y = 0
        wx.PostEvent(model.views['Designer'], evt)
        wx.Yield()

        constructorPage = palette.editor.inspector.constr
        for nv in constructorPage.nameValues:
            if nv.propName == 'Name':
                nv.propEditor.inspectorEdit()
                nv.propEditor.editorCtrl.editorCtrl.SetValue('TestFrame')
                nv.propEditor.inspectorPost(False)
                break

        # resize designer
        model.views['Designer'].SetDimensions(10, 10, 200, 200)
        model.views['Designer'].SetPosition((0, 0))
        wx.Yield()

        model.views['Designer'].Close()
    except:
        wx.MessageBox('Test failed\n' + ` sys.exc_info() `)
    else:
        #if model.data == frame_answer:
        wx.MessageBox('Test succeeded')
Esempio n. 3
0
	def OnLeftDown(self, event):
		print "Left down"
		if self.ProcessLeftDown(event):
			return
		
		win = event.GetEventObject()
		if win.Rect.Contains(event.Position):
			event.Skip()
		else:
			# do the coords translation now as after DismissAndNotify()
			# m_popup may be destroyed
			event2 = wx.MouseEvent()
			event2.__dict__ = event.__dict__.copy()
			                                                                
			event2.m_x, event2.m_y = self.ClientToScreen((event2.m_x, event2.m_y))
			                                                                
			# clicking outside a popup dismisses it
			self.Dismiss()
			                                                                
			# dismissing a tooltip shouldn't waste a click, i.e. you
			# should be able to dismiss it and press the button with the
			# same click, so repost this event to the window beneath us
			winUnder = wx.FindWindowAtPoint(event2.GetPosition())
			if ( winUnder ):
			    # translate the event coords to the ones of the window
			    # which is going to get the event
			    event2.m_x, event2.m_y = winUnder.ScreenToClient((event2.m_x, event2.m_y))
			                                                                
			    event2.SetEventObject(winUnder);
			    wx.PostEvent(winUnder, event2);
Esempio n. 4
0
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        self.data = data.data()
        self.buttons = {}
        self.sizers = {}
        self.static_sizers = {}
        self.canvas = {}
        self.panels = {}
        self.grids = {}
        self.check_boxes = {}
        self.texts = {}
        self.spins = {}

        self.menu_bars = {}
        self.menus = {}
        self.menu_items = {}

        self.mouse = wx.MouseEvent()

        self.create_menu()
        self.create_ui()

        self.Show()
        i = [
            key for key in self.data.GetList()
            if self.data.CheckKey(key, 'active')
        ]
        for widget in i:
            key = self.data.GetWidget(widget)
            if not key['active']:
                if self.data.GetValue(key['parent'], 'w_type') == 'sizer':
                    self.sizers[key['parent']].Hide(key['position'])
                elif self.data.GetValue(key['parent'],
                                        'w_type') == 'static_sizer':
                    self.static_sizers[key['parent']].Hide(key['position'])
Esempio n. 5
0
def GetAllClickableIndices( panel ):
    
    click = wx.MouseEvent( wx.wxEVT_LEFT_DOWN )
    
    current_y = 5
    
    click.SetX( 10 )
    click.SetY( current_y )
    
    all_clickable_indices = {}
    
    while panel._GetIndexUnderMouse( click ) is not None:
        
        index = panel._GetIndexUnderMouse( click )
        
        if index not in all_clickable_indices:
            
            all_clickable_indices[ index ] = current_y
            
        
        current_y += 5
        
        click.SetY( current_y )
        
    
    return all_clickable_indices
def click_on_image(image_control):
    """Click on the image controlled by given image_control."""
    if is_wx():
        import wx

        event_down = wx.MouseEvent(wx.EVT_LEFT_DOWN.typeId)
        wx.PostEvent(image_control, event_down)
        event_up = wx.MouseEvent(wx.EVT_LEFT_UP.typeId)
        event_up.SetX(0)
        event_up.SetY(0)
        wx.PostEvent(image_control, event_up)

    elif is_qt():
        image_control.click()

    else:
        raise unittest.SkipTest("Test not implemented for this toolkit")
Esempio n. 7
0
    def on_canvas_motion(self, event):
        old_target = self.target
        self.target = None

        for button in reversed(self._buttons):
            contains = (button.position[0] <= event.x <=
                        button.position[0] + button.size[0]
                        and button.position[1] <= event.y <=
                        button.position[1] + button.size[1])

            if contains:
                if button is self.target:
                    return

                self.target = button
                wx.PostEvent(button, wx.MouseEvent(wx.wxEVT_ENTER_WINDOW))

        if old_target is not None and old_target is not self.target:
            wx.PostEvent(old_target, wx.MouseEvent(wx.wxEVT_LEAVE_WINDOW))

        event.Skip()
Esempio n. 8
0
    def on_canvas_mouse(self, event):

        if event.GetEventType() in [wx.wxEVT_MOTION, wx.wxEVT_LEFT_DOWN,
                                    wx.wxEVT_LEFT_UP, wx.wxEVT_MOTION | wx.wxEVT_LEFT_DOWN]:
            UIM = UIManager()
            tcc = UIM.list('track_canvas_controller', self._controller_uid)[0]

            new_event = wx.MouseEvent(event.GetEventType())
            pos = tcc.view.ScreenToClient(wx.GetMousePosition())
            new_event.SetPosition(pos)
            new_event.Skip()
            tcc.view.GetEventHandler().ProcessEvent(new_event)
Esempio n. 9
0
def LeftClick(block):
    """ Simulates a left mouse click on the block or widget """
    mouseEnter = _wx.MouseEvent(_wx.wxEVT_ENTER_WINDOW)
    mouseDown = _wx.MouseEvent(_wx.wxEVT_LEFT_DOWN)
    mouseDown.m_leftDown = True
    mouseUp = _wx.MouseEvent(_wx.wxEVT_LEFT_UP)
    mouseLeave = _wx.MouseEvent(_wx.wxEVT_LEAVE_WINDOW)
    try:
        widget = block.widget
    except AttributeError:
        widget = block
    mouseEnter.SetEventObject(widget)
    mouseDown.SetEventObject(widget)
    mouseUp.SetEventObject(widget)
    mouseLeave.SetEventObject(widget)
    widget.ProcessEvent(mouseEnter)
    widget.ProcessEvent(mouseDown)
    widget.ProcessEvent(mouseUp)
    widget.ProcessEvent(mouseLeave)
    _wx.GetApp().Yield()
    ev = _wx.IdleEvent()
    _wx.GetApp().ProcessEvent(ev)
Esempio n. 10
0
    def onLeftDown(self, event):
        """
        Invoke when pressing on left.
        Record the center of the circle.
        """

        # initialize the colour of the buttons
        [
            btn.SetBackgroundColour(wx.Colour(180, 180, 180))
            for btn in self.buttonPool
        ]
        mouseEvent = wx.MouseEvent(event)
        self.center = self.getPosition(
            mouseEvent.GetLogicalPosition(wx.ClientDC(self)).Get(),
            mouseEvent.GetEventObject().GetId())
        print(mouseEvent.GetEventObject().GetId())
        print(self.center)
        self.SetStatusText(str(self.center))
Esempio n. 11
0
 def mousey(self, event):
     """
     C{wx.EVT_MOUSE_EVENTS} handler
     """
     newCursor = None
     
     #newCursor = self._currentCursor
     
     if event.Entering() or event.Moving():
         urlStart, urlEnd = self._get_url_range_at_cursor(event)
         if urlStart != urlEnd:
             newCursor = self.HAND_CURSOR
             self._showHand = True
         else:
             newCursor = self._currentCursor
             self._showHand = False
     elif event.Leaving():
         self._showHand = False
         newCursor = self._currentCursor
     elif wx.Platform == '__WXMAC__' and event.LeftDown():
         # On the Mac only, try to open URLs on left-down. Other
         # platforms will send wx.EVT_LEFT_UP events, which is
         # a better place to do this (as noted above).
         urlStart, urlEnd = self._get_url_range_at_cursor(event)
         if urlStart != urlEnd:
             # Fake a up-mouse event. Handlers for wx.EVT_TEXT_URL
             # should check for mouse up to get best behaviour on all
             # platforms (wx.TE_AUTO_URL-enabled TextCtrls actually
             # send this event on mouse down and mouse moved events
             # as well) ...
             upMouse = wx.MouseEvent(wx.wxEVT_LEFT_UP)
             self.post_url_event(upMouse, urlStart, urlEnd)
             return
 
     if newCursor is not None:
         wx.SetCursor(newCursor)
 
     if self._showHand:
         wx.CallAfter(wx.SetCursor, self.HAND_CURSOR)
 
     event.Skip()
Esempio n. 12
0
 def AddPickerFile(self,
                   sizer,
                   label="",
                   width=-1,
                   width2=None,
                   height=None,
                   value="",
                   mode="L",
                   wildcard="All files (*.*)|*.*",
                   onSelect=None,
                   **kwargs):
     width2 = width2 or self.LINE_HEIGHT
     height = height or self.LINE_HEIGHT
     text = (UI.TextWithHint if "hint" in kwargs else UI.Text)(self,
                                                               value=value,
                                                               size=wx.Size(
                                                                   width,
                                                                   height),
                                                               **kwargs)
     btn = UI.Button(self,
                     size=wx.Size(width2, height),
                     tag="...",
                     edge=("TRB", ""))
     if mode == "L":
         func = lambda: text.SetValue(
             Ut.ShowOpenFileDialog(self, self.L.Get("GENERAL_HEAD_LOAD"),
                                   wildcard) or text.GetValue())
     else:
         func = lambda: text.SetValue(
             Ut.ShowSaveFileDialog(self, self.L.Get("GENERAL_HEAD_SAVE"),
                                   wildcard) or text.GetValue())
     btn.Func = (
         (self.GetGrandParent().Disable, ), func, onSelect,
         self.GetGrandParent().Enable,
         lambda: wx.PostEvent(btn, wx.MouseEvent(wx.wxEVT_LEAVE_WINDOW)))
     subSizer = wx.BoxSizer(wx.HORIZONTAL)
     subSizer.Add(text, width == -1)
     subSizer.Add(btn, width2 == -1)
     self._AddCtrl(sizer, label, subSizer, width == -1, False, True)
     text.label = subSizer.label
     return text
Esempio n. 13
0
    def onMotion(self, event):
        """
        Invoke when moving the mouse.
        Draw a circle on the screen.
        """

        mouseEvent = wx.MouseEvent(event)
        # process only when left is being pressed
        if mouseEvent.Dragging():
            # get the current position
            position = self.getPosition(
                mouseEvent.GetLogicalPosition(wx.ClientDC(self)).Get(),
                mouseEvent.GetEventObject().GetId())
            # calculate the radius
            self.radius = math.sqrt((position[0] - self.center[0])**2 +
                                    (position[1] - self.center[1])**2)
            dc = wx.ClientDC(self)
            # force to refresh
            self.Refresh()
            self.Update()
            dc.SetPen(wx.Pen(wx.Colour(0, 0, 255)))
            dc.SetBrush(
                wx.Brush(wx.Colour(0, 0, 0), style=wx.BRUSHSTYLE_TRANSPARENT))
            dc.DrawCircle(*self.center, self.radius)