예제 #1
0
파일: container.py 프로젝트: dlobue/urwid
    def mouse_event(self, size, event, button, col, row, focus):
        """
        Send event to appropriate column.
        May change focus on button 1 press.
        """
        widths = self.column_widths(size)
        
        x = 0
        for i in range(len(widths)):
            if col < x:
                return False
            w = self.widget_list[i]
            end = x + widths[i]
            
            if col >= end:
                x = end + self.dividechars
                continue

            focus = focus and self.focus_col == i
            if is_mouse_press(event) and button == 1:
                if w.selectable():
                    self.set_focus(w)

            if not hasattr(w,'mouse_event'):
                return False

            return w.mouse_event((end-x,)+size[1:], event, button, 
                col - x, row, focus)
        return False
예제 #2
0
파일: container.py 프로젝트: dlobue/urwid
 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, ftrim),(hrows, frows) = self.frame_top_bottom(
         (maxcol, maxrow), focus)
     
     if row < htrim: # within header
         focus = focus and self.focus_part == 'header'
         if 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 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 )
     
     # within body
     focus = focus and self.focus_part == 'body'
     if 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
파일: listbox.py 프로젝트: dlobue/urwid
    def mouse_event(self, size, event, button, col, row, focus):
        """
        Pass the event to the contained widgets.
        May change focus on button 1 press.
        """
        (maxcol, maxrow) = size
        middle, top, bottom = self.calculate_visible((maxcol, maxrow),
            focus=True)
        if middle is None:
            return False
        
        _ignore, focus_widget, focus_pos, focus_rows, cursor = middle
        trim_top, fill_above = top
        _ignore, fill_below = bottom

        fill_above.reverse() # fill_above is in bottom-up order
        w_list = ( fill_above + 
            [ (focus_widget, focus_pos, focus_rows) ] +
            fill_below )

        wrow = -trim_top
        for w, w_pos, w_rows in w_list:
            if wrow + w_rows > row:
                break
            wrow += w_rows
        else:
            return False

        focus = focus and w == focus_widget
        if is_mouse_press(event) and button==1:
            if w.selectable():
                self.change_focus((maxcol,maxrow), w_pos, wrow)
        
        if not hasattr(w,'mouse_event'):
            return False

        return w.mouse_event((maxcol,), event, button, col, row-wrow,
            focus)
예제 #4
0
파일: container.py 프로젝트: dlobue/urwid
    def mouse_event(self, size, event, button, col, row, focus):
        """
        Pass the event to the contained widget.
        May change focus on button 1 press.
        """
        wrow = 0
        item_rows = self.get_item_rows(size,focus)
        for r,w in zip(item_rows, self.widget_list):
            if wrow+r > row:
                break
            wrow += r

        focus = focus and self.focus_item == w
        if is_mouse_press(event) and button==1:
            if w.selectable():
                self.set_focus(w)
        
        if not hasattr(w,'mouse_event'):
            return False

        i = self.widget_list.index(w)
        tsize = self.get_item_size(size, i, focus, item_rows)
        return w.mouse_event(tsize, event, button, col, row-wrow,
            focus)