def send_event(self, widget, event): """ Send an event to the Slider programmatically. Arguments --------- widget : The widget to sent the event to. event : The desired event to be proccessed. """ event_type = EVENT_MAP[event] if event_type in (wx.EVT_LEFT_DOWN, wx.EVT_LEFT_UP): position = wx.Point(100, 10) self.send_wx_mouse_event(widget, event_type, position=position) else: value = widget.GetValue() if event_type == wx.EVT_SCROLL_BOTTOM: value = widget.GetMin() elif event_type == wx.EVT_SCROLL_TOP: value = widget.GetMax() elif event_type == wx.EVT_SCROLL_LINEUP: value += widget.GetLineSize() elif event_type == wx.EVT_SCROLL_LINEDOWN: value -= widget.GetLineSize() elif event_type == wx.EVT_SCROLL_PAGEUP: value += widget.GetPageSize() elif event_type == wx.EVT_SCROLL_PAGEDOWN: value -= widget.GetPageSize() widget.SetValue(value) event = wx.ScrollEvent(event_type.typeId, widget.GetId()) widget.GetEventHandler().ProcessEvent(event) self.process_wx_events(self.app)
def _send_scroll_event(self): """ This method fires the EVT_SCROLL_CHANGED event. This means that the value has changed to a definite position, and it should only be sent when the user is done moving the slider. """ evt = wx.ScrollEvent(wx.wxEVT_SCROLL_CHANGED) evt.SetEventObject(self) self.GetEventHandler().ProcessEvent(evt)
def _CreateEvent(self, event): """ Internal use, creates a new wxScrollEvent that has this wxPyPanel instance as the event object. :param event: wx event metric. :return: None """ self._UpdateValues() event = wx.ScrollEvent(event, self.GetId()) event.SetEventObject(self) self.GetEventHandler().ProcessEvent(event) self.Slider.Refresh() self.Refresh()
def _one_down(self): """ Attempt to force the tree to scroll down. Fails. Will leave this here for one day. http://wxpython-users.1045709.n5.nabble.com/\ Cross-platform-issues-Programmatically-Scrolling\ -a-TreeCtrl-td2300200.html """ sp = 100 #self.treectrl.GetScrollPos(wx.VERTICAL) srange = 100 # self.treectrl.GetScrollRange(wx.VERTICAL) - \ #self.treectrl.GetScrollThumb(wx.VERTICAL) e = wx.ScrollEvent(wx.wxEVT_SCROLLWIN_LINEDOWN, self.treectrl.GetId(), min(sp + 1, srange), wx.VERTICAL) print sp, srange self.treectrl.GetEventHandler().ProcessEvent(e)
def key_click_slider(control, interaction, delay): """ Performs simulated typing of a key on the given wxSlider after a delay. Only allowed keys are: "Left", "Right", "Up", "Down", "Page Up", "Page Down" Also, note that up related keys correspond to an increment on the slider, and down a decrement. Parameters ---------- control : wxSlider The wx Object to be acted on. interaction : instance of command.KeyClick The interaction object holding the key input to be simulated being typed delay : int Time delay (in ms) in which the key click will be performed. Raises ------ ValueError If the interaction.key is not one of the valid keys. """ valid_keys = {"Left", "Right", "Up", "Down", "Page Up", "Page Down"} if interaction.key not in valid_keys: raise ValueError( "Unexpected Key. Supported keys are: {}".format(sorted(valid_keys)) ) if not control.HasFocus(): control.SetFocus() value = control.GetValue() if interaction.key in {"Up", "Right"}: position = min(control.GetMax(), value + control.GetLineSize()) elif interaction.key == "Page Up": position = min(control.GetMax(), value + control.GetPageSize()) elif interaction.key == "Page Down": position = max(control.GetMin(), value - control.GetPageSize()) elif interaction.key in {"Down", "Left"}: position = max(control.GetMin(), value - control.GetLineSize()) else: raise ValueError( "Unexpected Key. Supported keys are: {}".format(sorted(valid_keys)) ) wx.MilliSleep(delay) control.SetValue(position) event = wx.ScrollEvent( wx.wxEVT_SCROLL_CHANGED, control.GetId(), position ) wx.PostEvent(control, event)
def test_ScrollEvent_ctor(self): evt = wx.ScrollEvent()