예제 #1
0
    def OnRightClick(self, event):
        """
        Handles the wx.EVT_LIST_COL_RIGHT_CLICK/wx.EVT_LIST_ITEM_RIGHT_CLICK
        event for the list control.
        """

        flat, style = wx.GetApp().GetPreferences("Use_Flat_Menu", default=[0, (1, "Dark")])

        menu = (flat and [FM.FlatMenu()] or [wx.Menu()])[0]
        MenuItem = (flat and [FM.FlatMenuItem] or [wx.MenuItem])[0]

        # This pops up the "clear all" message
        item = MenuItem(menu, self.popupId, _("Clear History"))
        bmp = self.MainFrame.CreateBitmap("history_clear")
        item.SetBitmap(bmp)
        menu.AppendItem(item)        

        # Popup the menu.  If an item is selected then its handler
        # will be called before PopupMenu returns.
        if flat:
            menu.Popup(wx.GetMousePosition(), self)
        else:
            self.list.PopupMenu(menu)
            menu.Destroy()
예제 #2
0
    def TaskBarTimer(self):
        """
        This timer check periodically the mouse position.

        If the current mouse position is sufficiently far from the coordinates
        it had when entered the taskbar icon and the L{BalloonTip} style is
        ``BT_LEAVE``, the L{BalloonTip} frame is destroyed.
        """

        self.currentmousepos = wx.GetMousePosition()
        mousepos = self.mousepos

        if abs(self.currentmousepos[0] - mousepos[0]) > 30 or \
           abs(self.currentmousepos[1] - mousepos[1]) > 30:
            if hasattr(self, "BalloonFrame"):
                if self._tipstyle == BT_LEAVE:
                    try:
                        self.BalloonFrame.Destroy()
                        self.taskbartime.Stop()
                        del self.taskbartime
                        del self.BalloonFrame
                        self.taskbarcreation = 0
                    except:
                        pass
예제 #3
0
    def OnZoomMenu(self, event):
        """Popup Zoom menu"""
        point = wx.GetMousePosition()
        zoommenu = Menu()
        # Add items to the menu

        zoomwind = wx.MenuItem(
            zoommenu, wx.ID_ANY, _("Zoom to computational region (set with g.region)")
        )
        zoommenu.AppendItem(zoomwind)
        self.Bind(wx.EVT_MENU, self.OnZoomToWind, zoomwind)

        zoomdefault = wx.MenuItem(zoommenu, wx.ID_ANY, _("Zoom to default region"))
        zoommenu.AppendItem(zoomdefault)
        self.Bind(wx.EVT_MENU, self.OnZoomToDefault, zoomdefault)

        zoomsaved = wx.MenuItem(zoommenu, wx.ID_ANY, _("Zoom to saved region"))
        zoommenu.AppendItem(zoomsaved)
        self.Bind(wx.EVT_MENU, self.OnZoomToSaved, zoomsaved)

        savewind = wx.MenuItem(
            zoommenu, wx.ID_ANY, _("Set computational region from display")
        )
        zoommenu.AppendItem(savewind)
        self.Bind(wx.EVT_MENU, self.OnDisplayToWind, savewind)

        savezoom = wx.MenuItem(
            zoommenu, wx.ID_ANY, _("Save display geometry to named region")
        )
        zoommenu.AppendItem(savezoom)
        self.Bind(wx.EVT_MENU, self.SaveDisplayRegion, savezoom)

        # Popup the menu. If an item is selected then its handler
        # will be called before PopupMenu returns.
        self.PopupMenu(zoommenu)
        zoommenu.Destroy()
예제 #4
0
    def updateStatusBar(self, event=None):
        global globalPct
        global labelWidth, borderWidth

        statusText = self.theTimer.getCurTime().ctime() + "  --  "
        statusText += ("start: " + self.firstContactStart.ctime())
        statusText += ("  --  end: " + self.lastContactEnd.ctime())

        self.Refresh(eraseBackground=False, rect=(0, 0, 2000, 2000))
        globalPct = (self.theTimer.updateCurTime() -
                     self.firstContactStart).total_seconds() / self.totalTime

        foo = wx.GetMousePosition()
        bar = self.ScreenToClient(foo)

        if ((bar[0] > (labelWidth + 2 * borderWidth)) and (bar[1] > 0)
                and (bar[0] <
                     (self.GetSize()[0])) and (bar[1] < self.GetSize()[1])):
            temp = (float(bar[0]) / self.GetSize()[0]) * self.totalTime
            bar = datetime.timedelta(seconds=temp)
            foo = self.firstContactStart + bar
            statusText += ("  --  mouse: " + foo.ctime())

        self.SetStatusText(statusText)
예제 #5
0
    def CheckMouseIdle(self):

        mouse_position = wx.GetMousePosition()

        if self._last_mouse_position is None:

            self._last_mouse_position = mouse_position

        elif mouse_position != self._last_mouse_position:

            idle_before_position_update = self.CurrentlyIdle()

            self._timestamps['last_mouse_action'] = HydrusData.GetNow()

            self._last_mouse_position = mouse_position

            idle_after_position_update = self.CurrentlyIdle()

            move_knocked_us_out_of_idle = (
                not idle_before_position_update) and idle_after_position_update

            if move_knocked_us_out_of_idle:

                self.pub('set_status_bar_dirty')
예제 #6
0
    def OnTaskBarMove(self, event):
        """
        Handles the mouse motion inside the taskbar icon area.

        :param `event`: a :class:`MouseEvent` event to be processed.
        """

        if not hasattr(self, "BalloonFrame"):
            if self.taskbarcreation == 0:
                self.mousepos = wx.GetMousePosition()
                self.currentmousepos = self.mousepos
                self.taskbartime = wx.Timer(self._widget)
                self._widget.Bind(wx.EVT_TIMER, self.TaskBarTimer, self.taskbartime)
                self.taskbartime.Start(100)
                self.showtime = wx.Timer(self._widget)
                self._widget.Bind(wx.EVT_TIMER, self.NotifyTimer, self.showtime)
                self.showtime.Start(self._startdelaytime)

            if self.taskbarcreation == 0:
                self.taskbarcreation = 1

            return

        event.Skip()
예제 #7
0
 def movemouse(self, event):
     x, y = self.ScreenToClient(wx.GetMousePosition())
     self.labelX.SetLabel(str(x - 50))
     self.labelY.SetLabel(str(500 - y + 50))
예제 #8
0
 def _mouse_outside_tooltip(self):
     mx, my = wx.GetMousePosition()
     tx, ty = self._last_shown_tooltip.screen_position
     dx, dy = self._last_shown_tooltip.size
     return (mx < tx or mx > tx + dx) or (my < ty or my > ty + dy)
예제 #9
0
 def OnDoubleClick(self, event):
     item, pos = self.HitTest(self.ScreenToClient(wx.GetMousePosition()))
     if item:
         handler = self._controller.get_handler(item)
         handler.double_clicked()
     event.Skip()
    def SetBalloonShape(self, event=None):
        """ Sets the balloon shape."""

        size = self.GetSize()
        pos = self.GetPosition()

        dc = wx.MemoryDC(wx.EmptyBitmap(1, 1))
        textlabel = self._balloonmsg.GetLabel()
        textfont = self._balloonmsg.GetFont()
        textextent = dc.GetFullTextExtent(textlabel, textfont)

        boxheight = size.y - textextent[1] * len(textlabel.split("\n"))
        boxwidth = size.x

        position = wx.GetMousePosition()

        xpos = position[0]
        ypos = position[1]

        if xpos > 20 and ypos > 20:

            # This Is NW Positioning
            positioning = "NW"
            xpos = position[0] - boxwidth + 20
            ypos = position[1] - boxheight - 20

        elif xpos <= 20 and ypos <= 20:

            # This Is SE Positioning
            positioning = "SE"
            xpos = position[0] - 20
            ypos = position[1]

        elif xpos > 20 and ypos <= 20:

            # This Is SW Positioning
            positioning = "SW"
            xpos = position[0] - boxwidth + 20
            ypos = position[1]

        else:

            # This Is NE Positioning
            positioning = "NE"
            xpos = position[0]
            ypos = position[1] - boxheight + 20

        bmp = wx.EmptyBitmap(size.x, size.y)
        dc = wx.BufferedDC(None, bmp)
        dc.BeginDrawing()
        dc.SetBackground(wx.Brush(wx.Colour(0, 0, 0), wx.SOLID))
        dc.Clear()
        dc.SetPen(wx.Pen(wx.Colour(0, 0, 0), 1, wx.TRANSPARENT))

        if self._shape == BT_ROUNDED:
            dc.DrawRoundedRectangle(0, 20, boxwidth, boxheight - 20, 12)

        elif self._shape == BT_RECTANGLE:
            dc.DrawRectangle(0, 20, boxwidth, boxheight - 20)

        if positioning == "NW":
            dc.DrawPolygon(
                ((boxwidth - 40, boxheight), (boxwidth - 20, boxheight + 20),
                 (boxwidth - 20, boxheight)))
        elif positioning == "SE":
            dc.DrawPolygon(((20, 20), (20, 0), (40, 20)))

        elif positioning == "SW":
            dc.DrawPolygon(
                ((boxwidth - 40, 20), (boxwidth - 20, 0), (boxwidth - 20, 20)))

        else:
            dc.DrawPolygon(
                ((20, boxheight), (20, boxheight + 20), (40, boxheight)))

        dc.EndDrawing()

        r = wx.RegionFromBitmapColour(bmp, wx.Colour(0, 0, 0))
        self.hasShape = self.SetShape(r)

        if self._tipstyle == BT_BUTTON:
            colour = self.panel.GetBackgroundColour()
            self._closebutton.SetBackgroundColour(colour)

        self.SetPosition((xpos, ypos))
예제 #11
0
 def OnTimer(self, event):
     screenX, screenY = wx.GetMousePosition()
     x, y = self.ScreenToClientXY(screenX, screenY)
     self.MouseToRow(y)
     self.MouseToCol(x)
     self.SelectUpdate()
예제 #12
0
 def _calculate_position(self):
     x, y = wx.GetMousePosition()
     return x, y + 20
예제 #13
0
파일: toolbars.py 프로젝트: cwhite911/grass
    def OnAdditionalToolMenu(self, event):
        """Menu for additional tools"""
        point = wx.GetMousePosition()
        toolMenu = Menu()

        for label, itype, handler, desc in (
            (
                _("Break selected lines/boundaries at intersection"),
                wx.ITEM_CHECK,
                self.OnBreak,
                "breakLine",
            ),
            (
                _("Connect selected lines/boundaries"),
                wx.ITEM_CHECK,
                self.OnConnect,
                "connectLine",
            ),
            (_("Copy categories"), wx.ITEM_CHECK, self.OnCopyCats, "copyCats"),
            (
                _("Copy features from (background) vector map"),
                wx.ITEM_CHECK,
                self.OnCopy,
                "copyLine",
            ),
            (_("Copy attributes"), wx.ITEM_CHECK, self.OnCopyAttrb, "copyAttrs"),
            (
                _("Feature type conversion"),
                wx.ITEM_CHECK,
                self.OnTypeConversion,
                "typeConv",
            ),
            (
                _("Flip selected lines/boundaries"),
                wx.ITEM_CHECK,
                self.OnFlip,
                "flipLine",
            ),
            (
                _("Merge selected lines/boundaries"),
                wx.ITEM_CHECK,
                self.OnMerge,
                "mergeLine",
            ),
            (
                _("Snap selected lines/boundaries (only to nodes)"),
                wx.ITEM_CHECK,
                self.OnSnap,
                "snapLine",
            ),
            (_("Split line/boundary"), wx.ITEM_CHECK, self.OnSplitLine, "splitLine"),
            (_("Query features"), wx.ITEM_CHECK, self.OnQuery, "queryLine"),
            (
                _("Z bulk-labeling of 3D lines"),
                wx.ITEM_CHECK,
                self.OnZBulk,
                "zbulkLine",
            ),
        ):
            # Add items to the menu
            item = wx.MenuItem(
                parentMenu=toolMenu, id=wx.ID_ANY, text=label, kind=itype
            )
            toolMenu.AppendItem(item)
            self.MapWindow.Bind(wx.EVT_MENU, handler, item)
            if self.action["desc"] == desc:
                item.Check(True)

        # Popup the menu.  If an item is selected then its handler
        # will be called before PopupMenu returns.
        self.MapWindow.PopupMenu(toolMenu)
        toolMenu.Destroy()

        if self.action["desc"] == "addPoint":
            self.ToggleTool(self.additionalTools, False)
예제 #14
0
 def on_right_click(self, event):
     self.popup_menu(event,
                     self.widget.ScreenToClient(wx.GetMousePosition()))
예제 #15
0
 def onRightDown(self, event):
     #pos = event.GetPosition()   # for some reason returns position relative to lc1
     pos = self.ScreenToClient(wx.GetMousePosition())  # a bit hack
     self.PopupMenu(MyPopupMenu(self), pos)
예제 #16
0
    def OnRightClick(self, event):
        """ Handles the wx.EVT_TREE_ITEM_RIGHT_CLICK event for the tree control. """

        item = event.GetItem()
        if not item:
            # No item selected
            return

        selections = self.GetSelections()
        if len(selections) > 1 and self.rootItem in selections:
            # The user chose a mix of children plus the root item
            # Don't do anything, as there are no actions to do
            return

        flat, style = wx.GetApp().GetPreferences("Use_Flat_Menu",
                                                 default=[0, (1, "Dark")])

        menu = (flat and [FM.FlatMenu()] or [wx.Menu()])[0]
        MenuItem = (flat and [FM.FlatMenuItem] or [wx.MenuItem])[0]

        if item == self.rootItem:

            # The user clicked on the root item
            # There are a couple of options here: either add a new project or
            # delete all the existing projects from the tree
            item = MenuItem(menu, self.popupIds[0], _("New project..."))
            bmp = self.MainFrame.CreateBitmap("project")
            item.SetBitmap(bmp)
            menu.AppendItem(item)
            item = MenuItem(menu, self.popupIds[1], _("Delete all projects"))
            bmp = self.MainFrame.CreateBitmap("delete_all")
            item.SetBitmap(bmp)
            menu.AppendItem(item)
            item.Enable(self.HasChildren(self.rootItem))

        else:

            self.selectedItem = item

            # The user clicked on one of children (the project)
            # There are a couple of options here: either load the selected projects or
            # delete them
            item = MenuItem(menu, self.popupIds[2], _("Load project(s)"))
            bmp = self.MainFrame.CreateBitmap("load_project")
            item.SetBitmap(bmp)
            menu.AppendItem(item)
            item = MenuItem(menu, self.popupIds[3], _("Edit project name"))
            bmp = self.MainFrame.CreateBitmap("project_edit")
            item.SetBitmap(bmp)
            menu.AppendItem(item)
            item.Enable(len(selections) == 1)
            menu.AppendSeparator()
            item = MenuItem(menu, self.popupIds[4], _("Delete project(s)"))
            bmp = self.MainFrame.CreateBitmap("delete_project")
            item.SetBitmap(bmp)
            menu.AppendItem(item)
            menu.AppendSeparator()
            item = MenuItem(menu, self.popupIds[5], _("Import from file..."))
            bmp = self.MainFrame.CreateBitmap("importproject")
            item.SetBitmap(bmp)
            menu.AppendItem(item)
            item.Enable(len(selections) == 1)
            item = MenuItem(menu, self.popupIds[6],
                            _("Copy to new project..."))
            bmp = self.MainFrame.CreateBitmap("copyproject")
            item.SetBitmap(bmp)
            menu.AppendItem(item)
            item.Enable(len(selections) == 1)

        # Popup the menu.  If an item is selected then its handler
        # will be called before PopupMenu returns.
        if flat:
            menu.Popup(wx.GetMousePosition(), self)
        else:
            self.PopupMenu(menu)
            menu.Destroy()

        event.Skip()
예제 #17
0
    def onmenu(e):
        m = wx.Menu()
        m.Append(-1, 'test')
        f.PopupMenu(m, f.ScreenToClient(wx.GetMousePosition()))

        update()
예제 #18
0
 def OnMouseDown(self, event):
     self.lastMousePos = wx.GetMousePosition()
     self.dragging = True
예제 #19
0
 def _GetCursorDate(self):
     x, y = self.ScreenToClientXY(*wx.GetMousePosition())
     if self._hScroll.IsShown():
         x += self._hScroll.GetThumbPosition()
     return self._start + datetime.timedelta(
         minutes=int(self._precision * x / self._eventWidth))
예제 #20
0
    def __init__(self,
                 klass,
                 base_classes=None,
                 message="Select Class",
                 toplevel=True):
        pos = wx.GetMousePosition()
        wx.Dialog.__init__(self, common.main, -1, _(message), pos)

        self.standalone = self.base = None

        if base_classes:
            # base class
            self.base = wx.RadioBox(self,
                                    -1, ("base class"),
                                    choices=base_classes,
                                    style=wx.RA_VERTICAL)
            self.base.SetSelection(0)

        self.number = 1
        self.class_names = set(_get_all_class_names(common.root))
        self.toplevel_names = set(c.name for c in common.root.children)
        self.toplevel = toplevel  # if this is True, the name must be unique, as the generated class will have it
        # class
        self._klass = klass
        if common.root.language.lower() != 'xrc':
            klass = self.get_next_class_name(klass)
        self.klass = wx.TextCtrl(self, -1, klass)
        self.klass.Bind(wx.EVT_TEXT, self.on_text)  # for validation

        # for frame or standalone? this is used by the derived class below and just for menu bar and tool bar
        if self.parent_property and self.parent:
            # self.parent must be set by the derived class in this case; here we check whether it is set already
            choices = [
                "Add to %s '%s'" % (self.parent.base[2:], self.parent.name),
                "Standalone"
            ]
            self.standalone = wx.RadioBox(self,
                                          -1, ("Type"),
                                          choices=choices,
                                          style=wx.RA_VERTICAL)
            self.standalone.Bind(wx.EVT_RADIOBOX, self.on_standalone)
            if self.parent.properties[self.parent_property].value:
                self.standalone.SetSelection(1)
                self.standalone.Disable()
            else:
                self.standalone.SetSelection(0)
                self.klass.Disable()

        # layout
        szr = wx.BoxSizer(wx.VERTICAL)
        if self.standalone: szr.Add(self.standalone, 0, wx.ALL | wx.EXPAND, 5)
        if self.base: szr.Add(self.base, 0, wx.ALL | wx.EXPAND, 5)
        hszr = wx.BoxSizer(wx.HORIZONTAL)
        hszr.Add(
            wx.StaticText(
                self,
                -1,
                _("class"),
            ), 0,
            wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL, 3)
        hszr.Add(self.klass, 2)
        szr.Add(hszr, 0, wx.EXPAND)
        # buttons
        btnbox = wx.BoxSizer(wx.HORIZONTAL)
        self.btnOK = btnOK = wx.Button(self, wx.ID_OK, _('OK'))
        btnCANCEL = wx.Button(self, wx.ID_CANCEL, _('Cancel'))
        btnbox.Add(btnOK, 0, wx.ALL, 3)
        btnbox.Add(btnCANCEL, 0, wx.ALL, 3)
        btnOK.SetFocus()
        szr.Add(btnbox, 0, wx.ALL | wx.ALIGN_CENTER, 3)
        self.SetAutoLayout(True)
        self.SetSizer(szr)
        szr.Fit(self)
예제 #21
0
파일: imwinmenu.py 프로젝트: sgricci/digsby
def GetMenu(self):
    try:
        self._menu.Destroy()
    except AttributeError:
        pass

    from gui.uberwidgets.umenu import UMenu
    m = UMenu(self, onshow=self._onpopupshown)

    self._menu = m
    self._topid = id(self.Top)

    self.keep_on_top = m.AddCheckItem(_('&Keep on Top'),
                                      callback=self.Top.ToggleOnTop)
    self.view_past_chats_item = m.AddItem(_('&View Past Chats'),
                                          callback=self._on_view_past_chats)

    m.AddSep()

    add, addcheck, setmode = m.AddItem, m.AddCheckItem, self.set_mode

    c = self.capsbuttons = {}
    buddy = self.Buddy
    for bname, caption in buttons:
        if bname == 'files':
            c[bname] = add(caption, callback=lambda: self.Buddy.send_file())
        else:
            if buddy is None or (bname == 'sms' and 'SMS' not in buddy.caps):
                continue

            c[bname] = addcheck(
                caption,
                callback=lambda b=bname: setmode(b, toggle_tofrom=b == 'im'))

    m.AddSep()

    self.edit_items = {}
    self.edit_items['Copy'] = add(_('Copy\tCtrl+C'), id=wx.ID_COPY)

    # add a "Copy Link" item if the mouse is hovering over a link
    message_area = getattr(self, 'message_area', None)
    if message_area is not None:  # may not be created yet.
        ctrl = wx.FindWindowAtPointer()
        if ctrl is message_area:
            info = ctrl.HitTest(ctrl.ScreenToClient(wx.GetMousePosition()))
            if info.Link:
                add(_('Copy &Link'),
                    callback=lambda: clipboard.copy(info.Link))

    self.paste_item = self.edit_items['Paste'] = add(_('Paste\tCtrl+V'),
                                                     id=wx.ID_PASTE)
    self.paste_index = len(self._menu) - 1

    if pref('debug.message_area.show_edit_source', False):
        add(_('Edit Source'), callback=lambda: self.message_area.EditSource())
    if pref('debug.message_area.show_jsconsole', False):
        from gui.browser import jsconsole
        add(_('&Javascript Console'),
            callback=lambda: jsconsole.show_console())

    # text size menu
    if message_area is not None and message_area.IsShownOnScreen():
        textsize_menu = UMenu(self)
        self.textbigger = textsize_menu.AddItem(
            _('&Increase Text Size\tCtrl+='),
            callback=message_area.IncreaseTextSize)
        self.textsmaller = textsize_menu.AddItem(
            _('&Decrease Text Size\tCtrl+-'),
            callback=message_area.DecreaseTextSize)
        textsize_menu.AddSep()
        textsize_menu.AddItem(_('&Reset Text Size\tCtrl+0'),
                              callback=message_area.ResetTextSize)

        m.AddSubMenu(textsize_menu, _('&Text Size'))

    m.AddSep()

    # these checkboxes affect a global preference that immediately takes effect in
    # all open ImWins
    self.roomlist_item = m.AddCheckItem(_('Show &Room List'),
                                        callback=self.toggle_roomlist)
    self.actions_item = m.AddPrefCheck('messaging.show_actions_bar',
                                       _('Show &Actions Bar'))
    self.formatting_item = m.AddPrefCheck('messaging.show_formatting_bar',
                                          _('Show &Formatting Bar'))

    return self._menu
예제 #22
0
 def GiveFeedback (self, effect):
     windowX, windowY = wx.GetMousePosition()
     self.drawableObject.Show (effect != wx.DragMove)
     x, y = self.drawableObject.canvas.ScreenToClientXY (windowX, windowY)
     self.drawableObject.dragImage.Move((x, y))
     return False
예제 #23
0
 def onCommand(self, event):
     if wx.GetMouseState().LeftIsDown():
         x = self.sCommand.ScreenToClient(wx.GetMousePosition()).x
         val = self.sCommand.GetMin() + (self.sCommand.GetMax(
         ) - self.sCommand.GetMin()) * x / self.sCommand.GetSize().x
         self.sCommand.SetValue(val)
예제 #24
0
 def on_timer(self, event):
     screenX, screenY = wx.GetMousePosition()
     x, y = self.ScreenToClient((screenX, screenY))
     row, cell = self.pixel_pos_to_row_cell(x, y)
     print(("on_timer: time=%f pos=%d,%d" % (time.time(), row, cell)))
     self.handle_on_motion(event, row, cell)
예제 #25
0
    def TIMERUIUpdate(self):

        new_options = HG.client_controller.new_options

        if new_options.GetBoolean('always_show_hover_windows'):

            self._SizeAndPosition()

            self.Show()

            return

        if self._hide_until is not None:

            if HydrusData.TimeHasPassed(self._hide_until):

                self._hide_until = None

            else:

                return

        if self._current_media is None or not self.GetParent().IsShown():

            if self.IsShown():

                if HG.hover_window_report_mode:

                    HydrusData.ShowText(
                        repr(self) +
                        ' - hiding because nothing to show or parent hidden.')

                self.Hide()

        else:

            (mouse_x, mouse_y) = wx.GetMousePosition()

            (my_width, my_height) = self.GetSize()

            (should_resize, (my_ideal_width, my_ideal_height),
             (my_ideal_x, my_ideal_y)) = self._GetIdealSizeAndPosition()

            if my_ideal_width == -1:

                my_ideal_width = max(my_width, 50)

            if my_ideal_height == -1:

                my_ideal_height = max(my_height, 50)

            (my_x, my_y) = self.GetPosition()

            in_ideal_x = my_ideal_x <= mouse_x and mouse_x <= my_ideal_x + my_ideal_width
            in_ideal_y = my_ideal_y <= mouse_y and mouse_y <= my_ideal_y + my_ideal_height

            in_actual_x = my_x <= mouse_x and mouse_x <= my_x + my_width
            in_actual_y = my_y <= mouse_y and mouse_y <= my_y + my_height

            # we test both ideal and actual here because setposition is not always honoured by the OS
            # for instance, in Linux on a fullscreen view, the top taskbar is hidden, but when hover window is shown, it takes focus and causes taskbar to reappear
            # the reappearance shuffles the screen coordinates down a bit so the hover sits +20px y despite wanting to be lined up with the underlying fullscreen viewer
            # wew lad

            in_position = (in_ideal_x or in_actual_x) and (in_ideal_y
                                                           or in_actual_y)

            menu_open = HG.client_controller.MenuIsOpen()

            dialog_open = False

            tlps = wx.GetTopLevelWindows()

            for tlp in tlps:

                if isinstance(tlp, wx.Dialog):

                    dialog_open = True

            mime = self._current_media.GetMime()

            mouse_is_over_interactable_media = mime == HC.APPLICATION_FLASH and self.GetParent(
            ).MouseIsOverMedia()

            mouse_is_near_animation_bar = self.GetParent(
            ).MouseIsNearAnimationBar()

            mouse_is_over_something_important = mouse_is_over_interactable_media or mouse_is_near_animation_bar

            focus_is_good = ClientGUICommon.TLPHasFocus(
                self) or ClientGUICommon.TLPHasFocus(self.GetParent())

            ready_to_show = in_position and not mouse_is_over_something_important and focus_is_good and not dialog_open and not menu_open
            ready_to_hide = not menu_open and (not in_position or dialog_open
                                               or not focus_is_good)

            def get_logic_report_string():

                tuples = []

                tuples.append(('in position: ', in_position))
                tuples.append(('menu open: ', menu_open))
                tuples.append(('dialog open: ', dialog_open))
                tuples.append(('mouse over interactable media: ',
                               mouse_is_over_interactable_media))
                tuples.append(('mouse near animation bar: ',
                               mouse_is_near_animation_bar))
                tuples.append(('focus is good: ', focus_is_good))

                message = os.linesep * 2 + os.linesep.join(
                    (a + str(b) for (a, b) in tuples)) + os.linesep

                return message

            if ready_to_show:

                self._SizeAndPosition()

                if not self.IsShown():

                    if HG.hover_window_report_mode:

                        HydrusData.ShowText(
                            repr(self) + ' - showing.' +
                            get_logic_report_string())

                    self.Show()

            elif ready_to_hide:

                if self.IsShown():

                    if HG.hover_window_report_mode:

                        HydrusData.ShowText(
                            repr(self) + ' - hiding.' +
                            get_logic_report_string())

                    self.Hide()
예제 #26
0
    def on_mouse_events(self, event):
        """Overriding the ruler to capture wheel events
        """
        wheel_dir = event.GetWheelRotation()
        x, _ = self.panel.GetViewStart()
        pos = event.GetPosition()[0] + x
        mods = event.GetModifiers()
        if wheel_dir:
            if mods == wx.MOD_NONE:
                if wheel_dir < 0:
                    self.zoom_out(pos)
                elif wheel_dir > 0:
                    self.zoom_in(pos)
            event.Skip()

        op = None  # the mouse operation to process
        next_mode = None  # next state after operation
        mode = self.cursor_mode

        # determine state machine command
        if mode == "select":
            if event.ButtonDown():
                if (event.LeftIsDown()
                        and event.AltDown()) or event.MiddleIsDown():
                    op = "start drag"
                elif event.ShiftDown() and self.ruler.has_selection:
                    op = "start extend selection"
                else:
                    op = "start selection"
            elif event.LeftUp():
                if self.ruler.has_selection:
                    op = "finish selection"
                elif self.select_start >= 0:
                    op = "select item"
                self.release_mouse()
            elif event.Dragging():
                if event.ShiftDown() and self.ruler.has_selection:
                    op = "extend selection"
                elif self.is_selecting:
                    op = "extend selection"
                elif event.LeftIsDown():
                    op = "select threshold"
            elif event.Moving():
                op = "hit test"
            else:
                op = "unknown"
                next_mode = mode

        elif mode == "drag handle":
            if event.ButtonDown():
                if event.LeftIsDown():
                    op = "start extend selection"
                    next_mode = "select"
            elif event.Moving():
                op = "hit test"

        elif mode == "drag_mode":
            if event.ButtonDown():
                if (event.LeftIsDown()
                        and event.AltDown()) or event.MiddleIsDown():
                    op = "start drag"
            elif event.ButtonUp():
                op = "end drag"
                if event.AltDown():
                    next_mode = "drag_mode"
            elif event.Moving():
                op = "hit test"
                next_mode = "drag_mode"
            else:
                op = "unknown"
                next_mode = mode

        elif mode == "dragging":
            if event.ButtonUp():
                op = "end drag"
                if event.AltDown():
                    next_mode = "drag_mode"
            elif event.Dragging() or (event.LeftIsDown() and
                                      event.AltDown()) or event.MiddleIsDown():
                op = "dragging"
            else:
                op = "unknown"
                next_mode = mode

        # print "mouse: state=%s op=%s pos=%d btns=%s%s%s" % (mode, op, pos, "L" if event.LeftIsDown() else "l", "M" if event.MiddleIsDown() else "m", "R" if event.RightIsDown() else "r")

        # process state machine commands
        if op == "start selection":
            self.pause_playback()
            self.selection_cleared_callback()
            self.ruler.selected_ranges = []
            self.select_start = self.position_to_value(pos)
            self.select_end = None
            self.caret_value = None
            self.Refresh()
        elif op == "select threshold":
            start_pos = self.value_to_position(self.select_start, True)
            if abs(pos - start_pos) > self.select_threshold:
                self.select_end = self.position_to_value(pos)
                self.ruler.selected_ranges = [(self.select_start,
                                               self.select_end)]
                self.selection_started_callback(self.ruler.selected_ranges)
                self.Refresh()
        elif op == "start extend selection":
            last_start, last_end = self.ruler.selected_ranges[-1]
            value = self.position_to_value(pos)
            start, end = self.select_start, self.select_end
            if mode == "drag handle":
                # nearest end to handle determines which edge is moving
                if abs(value - start) < abs(value - end):
                    self.select_start = end
            else:
                if value < self.select_start:
                    self.select_start = end
            self.select_end = value
            self.ruler.selected_ranges[-1] = (self.select_start,
                                              self.select_end)
            self.selection_extended_callback(self.ruler.selected_ranges,
                                             self.ruler.marks_in_selection())
            self.Refresh()
        elif op == "extend selection":
            last_start, last_end = self.ruler.selected_ranges[-1]
            value = self.position_to_value(pos)
            self.ruler.selected_ranges[-1] = (last_start, value)
            self.selection_extended_callback(self.ruler.selected_ranges,
                                             self.ruler.marks_in_selection())
            self.Refresh()
        elif op == "finish selection":
            start, end = self.ruler.selected_ranges[-1]
            if end < start:
                start, end = end, start
            self.select_start, self.select_end = start, end
            self.selection_finished_callback(self.ruler.selected_ranges)
            if self.HasCapture():
                self.ReleaseMouse()
        elif op == "start drag":
            self.drag_start = wx.GetMousePosition()[
                0]  # absolute mouse pos (see below)
            self.view_at_drag_start, _ = self.panel.GetViewStart()
            next_mode = "dragging"
            if not self.HasCapture():
                self.CaptureMouse()
        elif op == "dragging":
            pos = wx.GetMousePosition()[0]  # absolute mouse pos
            delta = pos - self.drag_start
            x = self.view_at_drag_start - delta
            self.panel.Scroll(x, 0)
            next_mode = "dragging"
        elif op == "end drag":
            self.drag_start = -1
            if self.HasCapture():
                self.ReleaseMouse()
        elif op == "hit test":
            if self.has_selection:
                start, end = self.ruler.selected_ranges[-1]
                if self.ruler.hit_test_value(
                        pos, start) or self.ruler.hit_test_value(pos, end):
                    next_mode = "drag handle"
            label = self.ruler.hit_test(pos)
            if label is not None:
                self.over_item_callback(pos, label)
            else:
                self.not_over_item_callback(pos)
        elif op == "drag handle":
            start, end = self.ruler.selected_ranges[-1]
            if self.ruler.hit_test_value(
                    pos, start) or self.ruler.hit_test_value(pos, end):
                pass
            else:
                next_mode = "select"
        elif op == "select item":
            self.caret_value = None
            if self.ruler.has_selection:
                self.ruler.selected_ranges = []
                self.Refresh()
            p = self.value_to_position(self.select_start)
            item = self.ruler.hit_test(p)
            if item is not None:
                self.selected_item_callback(item)
        else:
            log.debug("unknown state for mouse")
            if self.HasCapture():
                self.ReleaseMouse()

        if next_mode is None:
            next_mode = "select"
        self.set_mode(next_mode)
        event.Skip()
예제 #27
0
    def onLeftUp(self, event):
        if self.useMouseToo == False or self.autosolveActive == True:
            return

        self.dragdrop = False
        csr = wx.StockCursor(wx.CURSOR_ARROW)
        self.SetCursor(csr)

        if self.displayDirty == True:  # wenn eine Meldung auf dem Display steht und ein weiterer Zug gemacht
            self.NewPaint(
            )  # wird, dann muss erstmal die Meldung gelöscht werden.

        x, y = self.dsp.mousePosToPlaygroundPos(
            self.ScreenToClient(wx.GetMousePosition()))

        if self.gotFocus == True:  # wenn das Fenster gerade frisch fokussiert wurde...
            self.gotFocus = False  # ...dann soll der Player wohl nicht zur angeklickten
            return  # Position bewegt werden.

        if not(1<=x<=(self.size[0]-2) and 1<=y<=(self.size[1]-2) and \
               1<=self.from_x<=(self.size[0]-2) and 1<=self.from_y<=(self.size[1]-2)):
            return
        elif self.pg_stat[y][x] in ("i", "u") or \
             self.pg_stat[self.from_y][self.from_x] in ("i", "u"):
            return

        if (self.from_x, self.from_y) != (x, y):
            if (self.from_x, self.from_y) == self.playerpos:
                # Der Spieler soll (unnötigerweise per D&D) bewegt werden. Also Weg suchen.
                ms = self.sm.findBestWayTo(self.pg_stat, self.pg_dynp,
                                           self.playerpos, (x, y))
                if ms != "":
                    rc = 0
                else:
                    rc = 5
            else:
                # Eine Box soll bewegt werden. Also Weg suchen.
                rc, ms = self.sm.findBestPushTrackTo(
                    self.pg_stat, self.pg_dof, self.pg_dynp, self.playerpos,
                    (self.from_x, self.from_y), (x, y))
            if rc == 0:
                # Weg gefunden - also Ausführen bzw. Anzeigen.
                self.showMoves(ms)
            else:
                # kein Weg gefunden.
                self.markProblem(rc, self.from_x, self.from_y, x, y)
        else:
            # Es soll nur der Spieler bewegt werden. Also Weg suchen.
            ms = self.sm.findBestWayTo(self.pg_stat, self.pg_dynp,
                                       self.playerpos, (x, y))
            if ms != "":
                # Weg gefunden.
                self.showMoves(ms)
            else:
                # kein Weg gefunden.
                if 1 <= x <= (self.size[0] - 2) and 1 <= y <= (self.size[1] -
                                                               2):
                    if self.pg_stat[y][x] not in ("i", "u"):
                        self.markProblem(4, self.from_x, self.from_y, x, y)

        self.checkForIsSolved()
예제 #28
0
파일: base.py 프로젝트: yncat/falcon
 def GiveFeedback(self, effect):
     self.hImage.Move(
         globalVars.app.hMainView.hFrame.ScreenToClient(
             wx.GetMousePosition()))
     return False
예제 #29
0
    def drawpoint(self, event):
        x3 = int(self.labelX.GetLabel())
        y3 = int(self.labelY.GetLabel())
        tag = str(self.entertag.GetValue())
        if tag == '':
            return

        if x3 > 500 or x3 < 0 or y3 > 500 or y3 < 0:
            wx.MessageBox('超出範圍!', caption='超出範圍警告')
            return
        elif self.x1.GetValue() != '' and self.y1.GetValue() != '' and self.x2.GetValue() != '' \
                and self.y2.GetValue() != '' and tag.strip() != '':

            conn = psycopg2.connect(database=self.dbnametext,
                                    user='******',
                                    password='******',
                                    host='localhost',
                                    port='5432')
            cur = conn.cursor()
            cur.execute('select tag from ' + self.relationnametext +
                        ' where "x1"=\'' + self.x1.GetValue() +
                        '\' and "y1"=\'' + self.y1.GetValue() +
                        '\' and "x2"=\'' + self.x2.GetValue() +
                        '\' and "y2"=\'' + self.y2.GetValue() + '\'')
            tagrows = cur.fetchall()
            taglist = []
            for i in range(0, len(tagrows)):
                taglist.append(tagrows[i][0])
            if str(self.entertag.GetValue()) in taglist:
                x, y = self.ScreenToClient(wx.GetMousePosition())
                g = wx.BufferedDC(wx.ClientDC(self), self.buffer)
                g.SetPen(wx.Pen(wx.BLUE, 1))
                g.SetBrush(wx.Brush('grey', style=wx.BRUSHSTYLE_TRANSPARENT))
                g.DrawEllipse(x, y, 3, 3)
                g.SetTextForeground(wx.BLUE)
                g.DrawText(tag, x + 2, y + 2)
                if self.plotsize == 1:
                    cur.execute('update ' + self.relationnametext +
                                ' set "x3"=\'' + str(x3 / 5) +
                                '\' where "tag"=\'' + tag + '\'')
                    conn.commit()
                    cur.execute('update ' + self.relationnametext +
                                ' set "y3"=\'' + str(y3 / 5) +
                                '\' where "tag"=\'' + tag + '\'')
                    conn.commit()
                elif self.plotsize == 10:
                    cur.execute('update ' + self.relationnametext +
                                ' set "x3"=\'' + str(x3) +
                                '\' where "tag"=\'' + tag + '\'')
                    conn.commit()
                    cur.execute('update ' + self.relationnametext +
                                ' set "y3"=\'' + str(y3) +
                                '\' where "tag"=\'' + tag + '\'')
                    conn.commit()
                elif self.plotsize == 20:
                    cur.execute('update ' + self.relationnametext +
                                ' set "x3"=\'' + str(x3 * 2) +
                                '\' where "tag"=\'' + tag + '\'')
                    conn.commit()
                    cur.execute('update ' + self.relationnametext +
                                ' set "y3"=\'' + str(y3 * 2) +
                                '\' where "tag"=\'' + tag + '\'')
                    conn.commit()
                conn.close()
            else:
                wx.MessageBox('此小樣方無此資料!')
                conn.close()
예제 #30
0
 def cell_under_cursor(self):
     x, y = self.ScreenToClient(wx.GetMousePosition())
     x -= self.RowLabelSize
     return self.XYToCell(*self.CalcUnscrolledPosition(x, y))