コード例 #1
0
ファイル: frameapp.py プロジェクト: Bouhmarc/python-openzwave
    def mouse_event(self, size, event, button, col, row, focus):
        """
        Pass mouse event to appropriate part of frame.
        Focus may be changed on button 1 press.
        """
        (maxcol, maxrow) = size
        (htrim, ctrim, ftrim), (hrows, crows, frows) = self.frame_top_bottom(
            (maxcol, maxrow), focus)

        if row < htrim:  # within header
            focus = focus and self.focus_part == 'header'
            if urwid.is_mouse_press(event) and button == 1:
                if self.header.selectable():
                    self.set_focus('header')
            if not hasattr(self.header, 'mouse_event'):
                return False
            return self.header.mouse_event((maxcol, ), event, button, col, row,
                                           focus)

        if row >= maxrow - ftrim:  # within footer
            focus = focus and self.focus_part == 'footer'
            if urwid.is_mouse_press(event) and button == 1:
                if self.footer.selectable():
                    self.set_focus('footer')
            if not hasattr(self.footer, 'mouse_event'):
                return False
            return self.footer.mouse_event((maxcol, ), event, button, col,
                                           row - maxrow + frows, focus)

        if row >= maxrow - ftrim - ctrim:  # within columns
            #TODO mangae values / result
            widths = self.columns.column_widths((maxcol, maxrow))
            focus = focus and (self.focus_part == 'command' or self.focus_part
                               == 'value' or self.focus_part == 'result')
            if col <= widths[0]:
                #we are in the command
                if urwid.is_mouse_press(event) and button == 1:
                    if self._command.selectable():
                        self.set_focus('command')
                if not hasattr(self._command, 'mouse_event'):
                    return False
                return self._command.mouse_event(
                    (maxcol, ), event, button, col,
                    row - maxrow + frows + crows - 1, focus)
            if len(widths) == 3:
                last = 2
            else:
                last = 1
            if col >= maxcol - widths[last]:
                #we are in the result
                if urwid.is_mouse_press(event) and button == 1:
                    if self._result != None and self._result.selectable():
                        self.set_focus('result')
                if not hasattr(self._result, 'mouse_event'):
                    return False
                return self._result.mouse_event(
                    (maxcol, ), event, button, col - maxcol + widths[last],
                    row - maxrow + frows + crows - 1, focus)
            #we are in the value
            if urwid.is_mouse_press(event) and button == 1:
                if self._value != None and self._value.selectable():
                    self.set_focus('value')
            if not hasattr(self._value, 'mouse_event'):
                return False
            return self._value.mouse_event(
                (maxcol, ), event, button,
                col - maxcol + widths[1] + widths[2],
                row - maxrow + frows + crows - 1, focus)

        # within body
        focus = focus and self.focus_part == 'body'
        if urwid.is_mouse_press(event) and button == 1:
            if self.body.selectable():
                self.set_focus('body')

        if not hasattr(self.body, 'mouse_event'):
            return False
        return self.body.mouse_event((maxcol, maxrow - htrim - ftrim), event,
                                     button, col, row - htrim, focus)
コード例 #2
0
ファイル: frameapp.py プロジェクト: Bouhmarc/python-openzwave
    def mouse_event(self, size, event, button, col, row, focus):
        """
        Pass mouse event to appropriate part of frame.
        Focus may be changed on button 1 press.
        """
        (maxcol, maxrow) = size
        (htrim, ctrim, ftrim),(hrows, crows, frows) = self.frame_top_bottom(
            (maxcol, maxrow), focus)

        if row < htrim: # within header
            focus = focus and self.focus_part == 'header'
            if urwid.is_mouse_press(event) and button==1:
                if self.header.selectable():
                    self.set_focus('header')
            if not hasattr(self.header, 'mouse_event'):
                return False
            return self.header.mouse_event( (maxcol,), event,
                button, col, row, focus )

        if row >= maxrow-ftrim: # within footer
            focus = focus and self.focus_part == 'footer'
            if urwid.is_mouse_press(event) and button==1:
                if self.footer.selectable():
                    self.set_focus('footer')
            if not hasattr(self.footer, 'mouse_event'):
                return False
            return self.footer.mouse_event( (maxcol,), event,
                button, col, row-maxrow+frows, focus )

        if row >= maxrow-ftrim-ctrim: # within columns
        #TODO mangae values / result
            widths = self.columns.column_widths((maxcol, maxrow))
            focus = focus and (self.focus_part == 'command' or self.focus_part == 'value' or self.focus_part == 'result')
            if col <= widths[0]  :
                #we are in the command
                if urwid.is_mouse_press(event) and button==1:
                    if self._command.selectable():
                        self.set_focus('command')
                if not hasattr(self._command, 'mouse_event'):
                    return False
                return self._command.mouse_event( (maxcol,), event,
                button, col, row-maxrow+frows+crows-1, focus )
            if len(widths) == 3 :
                last=2
            else :
                last=1
            if col >= maxcol - widths[last]  :
                #we are in the result
                if urwid.is_mouse_press(event) and button==1:
                    if  self._result != None and self._result.selectable():
                        self.set_focus('result')
                if not hasattr(self._result, 'mouse_event'):
                    return False
                return self._result.mouse_event( (maxcol,), event,
                button, col-maxcol+widths[last], row-maxrow+frows+crows-1, focus )
            #we are in the value
            if urwid.is_mouse_press(event) and button==1:
                if self._value != None and self._value.selectable():
                    self.set_focus('value')
            if not hasattr(self._value, 'mouse_event'):
                return False
            return self._value.mouse_event( (maxcol,), event,
            button, col-maxcol+widths[1]+widths[2], row-maxrow+frows+crows-1, focus )

        # within body
        focus = focus and self.focus_part == 'body'
        if urwid.is_mouse_press(event) and button==1:
            if self.body.selectable():
                self.set_focus('body')

        if not hasattr(self.body, 'mouse_event'):
            return False
        return self.body.mouse_event( (maxcol, maxrow-htrim-ftrim),
            event, button, col, row-htrim, focus )
コード例 #3
0
ファイル: menu.py プロジェクト: jmcb/urwidx
    def mouse_event (self, size, event, button, x, y, focus):
        if button != 1 or not urwid.is_mouse_press(event):
            return False

        self._emit('click')
        return True