예제 #1
0
    def _init_elements(self, mainframe, group):
        """Initialize the elements and labels based on the context set.

        Args:
            mainframe: The main QWebFrame.
            group: A Group enum member (which elements to find).
        """
        elems = []
        for f in self._context.frames:
            elems += f.findAllElements(webelem.SELECTORS[group])
        elems = [e for e in elems if webelem.is_visible(e, mainframe)]
        # We wrap the elements late for performance reasons, as wrapping 1000s
        # of elements (with ~50 methods each) just takes too much time...
        elems = [webelem.WebElementWrapper(e) for e in elems]
        filterfunc = webelem.FILTERS.get(group, lambda e: True)
        elems = [e for e in elems if filterfunc(e)]
        if not elems:
            raise cmdexc.CommandError("No elements found.")
        strings = self._hint_strings(elems)
        for e, string in zip(elems, strings):
            label = self._draw_label(e, string)
            self._context.elems[string] = ElemTuple(e, label)
        keyparsers = objreg.get('keyparsers',
                                scope='window',
                                window=self._win_id)
        keyparser = keyparsers[usertypes.KeyMode.hint]
        keyparser.update_bindings(strings)
예제 #2
0
 def _init_elements(self):
     """Initialize the elements and labels based on the context set."""
     elems = []
     for f in self._context.frames:
         elems += f.findAllElements(webelem.SELECTORS[self._context.group])
     elems = [e for e in elems
              if webelem.is_visible(e, self._context.mainframe)]
     # We wrap the elements late for performance reasons, as wrapping 1000s
     # of elements (with ~50 methods each) just takes too much time...
     elems = [webelem.WebElementWrapper(e) for e in elems]
     filterfunc = webelem.FILTERS.get(self._context.group, lambda e: True)
     elems = [e for e in elems if filterfunc(e)]
     if not elems:
         raise cmdexc.CommandError("No elements found.")
     strings = self._hint_strings(elems)
     log.hints.debug("hints: {}".format(', '.join(strings)))
     for e, string in zip(elems, strings):
         label = self._draw_label(e, string)
         elem = ElemTuple(e, label)
         self._context.all_elems.append(elem)
         self._context.elems[string] = elem
     keyparsers = objreg.get('keyparsers', scope='window',
                             window=self._win_id)
     keyparser = keyparsers[usertypes.KeyMode.hint]
     keyparser.update_bindings(strings)
예제 #3
0
파일: hints.py 프로젝트: pyrho/qutebrowser
    def _init_elements(self, mainframe, group):
        """Initialize the elements and labels based on the context set.

        Args:
            mainframe: The main QWebFrame.
            group: A Group enum member (which elements to find).
        """
        elems = []
        for f in self._context.frames:
            elems += f.findAllElements(webelem.SELECTORS[group])
        elems = [e for e in elems if webelem.is_visible(e, mainframe)]
        # We wrap the elements late for performance reasons, as wrapping 1000s
        # of elements (with ~50 methods each) just takes too much time...
        elems = [webelem.WebElementWrapper(e) for e in elems]
        filterfunc = webelem.FILTERS.get(group, lambda e: True)
        elems = [e for e in elems if filterfunc(e)]
        if not elems:
            raise cmdexc.CommandError("No elements found.")
        strings = self._hint_strings(elems)
        for e, string in zip(elems, strings):
            label = self._draw_label(e, string)
            self._context.elems[string] = ElemTuple(e, label)
        keyparsers = objreg.get('keyparsers', scope='window',
                                window=self._win_id)
        keyparser = keyparsers[usertypes.KeyMode.hint]
        keyparser.update_bindings(strings)
예제 #4
0
 def _init_elements(self):
     """Initialize the elements and labels based on the context set."""
     elems = []
     for f in self._context.frames:
         elems += f.findAllElements(webelem.SELECTORS[self._context.group])
     elems = [
         e for e in elems if webelem.is_visible(e, self._context.mainframe)
     ]
     # We wrap the elements late for performance reasons, as wrapping 1000s
     # of elements (with ~50 methods each) just takes too much time...
     elems = [webelem.WebElementWrapper(e) for e in elems]
     filterfunc = webelem.FILTERS.get(self._context.group, lambda e: True)
     elems = [e for e in elems if filterfunc(e)]
     if not elems:
         raise cmdexc.CommandError("No elements found.")
     strings = self._hint_strings(elems)
     log.hints.debug("hints: {}".format(', '.join(strings)))
     for e, string in zip(elems, strings):
         label = self._draw_label(e, string)
         elem = ElemTuple(e, label)
         self._context.all_elems.append(elem)
         self._context.elems[string] = elem
     keyparsers = objreg.get('keyparsers',
                             scope='window',
                             window=self._win_id)
     keyparser = keyparsers[usertypes.KeyMode.hint]
     keyparser.update_bindings(strings)