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);
def _get_window_at(self, x, y): """ Locates the wxPython at the specified window coordinates (if any). """ window = wx.FindWindowAtPoint(self.control.ClientToScreenXY(x, y)) if window is self.control: window = None return window
def test_utilsSomeOtherStuff(self): wx.GetBatteryState() wx.GetPowerType() wx.GetKeyState(wx.WXK_F1) wx.GetMousePosition() wx.GetMouseState() wx.EnableTopLevelWindows(True) wx.FindWindowAtPoint((1, 1)) wx.NewId() wx.RegisterId(12345) wx.GetUserName() wx.GetUserId() wx.GetOsDescription()
def on_drop_files(self, x, y, filenames): if len(filenames) > 1: misc.error_message(_("Please only drop one file at a time")) return False # find the control and then the property screen_xy = self.ClientToScreen((x, y)) ctrl = wx.FindWindowAtPoint(screen_xy) if not ctrl: return False for p_name in self.current_widget.PROPERTIES: if p_name[0].isupper(): continue prop = self.current_widget.properties.get(p_name) if not prop or not hasattr(prop, "on_drop_file"): continue if (hasattr(prop, "label_ctrl") and prop.label_ctrl.ScreenRect.Contains(screen_xy) and prop.label_ctrl.IsShownOnScreen() ) or prop.has_control(ctrl): return prop.on_drop_file(filenames[0]) return False
def OnLeftDownTestWin(self, evt): frame = self.testWin.GetFrame() wx.SetCursor(wx.NullCursor) frame.ReleaseMouse() frame.Unbind(wx.EVT_LEFT_DOWN) self.frame.tb.ToggleTool(view.frame.ID_TOOL_LOCATE, False) self.frame.miniFrame.tb.ToggleTool(view.frame.ID_TOOL_LOCATE, False) scrPos = view.testWin.object.ClientToScreen(evt.GetPosition()) obj = wx.FindWindowAtPoint(scrPos) if not obj: return item = self.testWin.FindObjectItem(self.testWin.item, obj) if not item: return # If window has a sizer use it as parent if obj.GetSizer(): obj = obj.GetSizer() item = self.testWin.FindObjectItem(self.testWin.item, obj) Presenter.unselect() self.tree.EnsureVisible(item) self.tree.SelectItem(item)
def WhereToDrop(self, x, y, d): # Find object by position if wx.Platform == '__WXMAC__': # on mac x,y relative to children scrPos = self.win.ClientToScreen((x, y)) else: scrPos = view.testWin.object.ClientToScreen((x, y)) obj = wx.FindWindowAtPoint(scrPos) if not obj: return wx.DragNone, () if obj.GetId() == Highlight.ID_HL: self.onHL = True return d, () item = view.testWin.FindObjectItem(view.testWin.item, obj) if not item: return wx.DragNone, () # If window has a sizer use it as parent if obj.GetSizer(): obj = obj.GetSizer() item = view.testWin.FindObjectItem(view.testWin.item, obj) return d, (obj, item)
def _FilterEvent_scrollUnder(self, evt): """ Variant of FilterEvent to scroll the window currently under the cursor with the mouse wheel. Under Windows, normally the focused window is scrolled """ if isinstance(evt, wx.MouseEvent) and \ wx.wxEVT_MOUSEWHEEL == evt.GetEventType(): oldObj = evt.GetEventObject() scPos = evt.GetEventObject().ClientToScreen(evt.GetPosition()) wnd = wx.FindWindowAtPoint(scPos) if wnd is not None and wnd is not oldObj: # newPos = wnd.ScreenToClient(scPos) evt.m_x, evt.m_y = 0, 0 # newPos evt.SetEventObject(wnd) scrollUnits = (evt.GetWheelRotation() // evt.GetWheelDelta()) * evt.GetLinesPerAction() if isinstance(wnd, wx.ScrolledWindow): x, y = wnd.GetViewStart() wnd.Scroll(x, y - scrollUnits) # elif isinstance(wnd, wx.ListCtrl): # print "--FilterEvent31", repr(wnd.HasScrollbar(wx.VERTICAL)) # elif wnd.HasScrollbar(wx.VERTICAL): # # print "--FilterEvent31" # y = wnd.GetScrollPos(wx.VERTICAL) # wnd.SetScrollPos(wx.VERTICAL, y - scrollUnits) else: # print "--FilterEvent45", repr(((evt.GetEventObject()), scrollUnits, wnd.HasScrollbar(wx.VERTICAL))) wnd.ProcessEvent(evt) return wx.EventFilter.Event_Processed result = wx.App.FilterEvent(self, evt) return result
def on_text_lose_focus(self, new_msg): if self.searching: return self.on_search_timer() # Cancel the status button timer if it's running. self.cancel_timer() if getattr(self, 'skipenter', False): wx.CallAfter(lambda: setattr(self, 'skipenter', False)) else: # don't set status if we lost focus because the user is clicking # on the state button if wx.GetMouseState().LeftDown() and wx.FindWindowAtPoint( wx.GetMousePosition()) is self.cbutton: return profile_status = self.get_profile_status() if new_msg == '': self.display.empty_text = profile_status.hint if new_msg != profile_status.message or self.status_state != profile_status.status: # entering a new text value clears all exceptions newmsg = StatusMessage(new_msg, self.status_state, new_msg) self.set_profile_status(newmsg)
def 程序_取指定坐标处组件(x, y): '传入桌面上坐标' return wx.FindWindowAtPoint((x, y))
def hit(): return wx.FindWindowAtPoint(wx.GetMousePosition())
# Copyright (c) 2003-2007 Open Source Applications Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # prints the block found under the cursor import wx window = wx.FindWindowAtPoint(wx.GetMousePosition()) while True: blockItem = getattr(window, 'blockItem', None) if blockItem is None: method = getattr(window, 'GetParent', None) if method is not None: window = method() else: break else: print blockItem.blockName, blockItem break