mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
close_tabs()的tabs_or_ids参数改为必填
This commit is contained in:
parent
e6df59e958
commit
b854df764c
@ -191,27 +191,22 @@ class Chromium(object):
|
||||
def get_tabs(self, title=None, url=None, tab_type='page'):
|
||||
return self._get_tabs(title=title, url=url, tab_type=tab_type, mix=True, as_id=False)
|
||||
|
||||
def close_tabs(self, tabs_or_ids=None, others=False):
|
||||
all_tabs = set(self.tab_ids)
|
||||
def close_tabs(self, tabs_or_ids, others=False):
|
||||
if isinstance(tabs_or_ids, str):
|
||||
tabs = {tabs_or_ids}
|
||||
elif isinstance(tabs_or_ids, ChromiumTab):
|
||||
tabs = {tabs_or_ids.tab_id}
|
||||
elif tabs_or_ids is None:
|
||||
tabs = {self.tab_ids[0]}
|
||||
elif isinstance(tabs_or_ids, (list, tuple)):
|
||||
tabs = set(i.tab_id if isinstance(i, ChromiumTab) else i for i in tabs_or_ids)
|
||||
else:
|
||||
raise TypeError('tabs_or_ids参数只能传入标签页对象或id。')
|
||||
|
||||
all_tabs = set(self.tab_ids)
|
||||
if others:
|
||||
tabs = all_tabs - tabs
|
||||
|
||||
end_len = len(set(all_tabs) - set(tabs))
|
||||
if end_len <= 0:
|
||||
if len(all_tabs - tabs) <= 0:
|
||||
self.quit()
|
||||
return
|
||||
|
||||
for tab in tabs:
|
||||
self._close_tab(tab_id=tab)
|
||||
|
||||
|
@ -116,8 +116,8 @@ class ChromiumPage(ChromiumBase):
|
||||
def close(self):
|
||||
self.browser._close_tab(self.tab_id)
|
||||
|
||||
def close_tabs(self, tabs_or_ids=None, others=False):
|
||||
self.browser.close_tabs(tabs_or_ids=tabs_or_ids or self.tab_id, others=others)
|
||||
def close_tabs(self, tabs_or_ids, others=False):
|
||||
self.browser.close_tabs(tabs_or_ids=tabs_or_ids, others=others)
|
||||
|
||||
def quit(self, timeout=5, force=True, del_data=False):
|
||||
self.browser.quit(timeout, force, del_data=del_data)
|
||||
|
@ -198,10 +198,10 @@ class ChromiumPage(ChromiumBase):
|
||||
|
||||
def close_tabs(self,
|
||||
tabs_or_ids: Union[str, ChromiumTab, List[Union[str, ChromiumTab]],
|
||||
Tuple[Union[str, ChromiumTab]]] = None,
|
||||
Tuple[Union[str, ChromiumTab]]],
|
||||
others: bool = False) -> None:
|
||||
"""关闭传入的标签页,默认关闭当前页。可传入多个
|
||||
:param tabs_or_ids: 要关闭的标签页对象或id,可传入列表或元组,为None时关闭当前页
|
||||
"""关闭传入的标签页,可传入多个
|
||||
:param tabs_or_ids: 要关闭的标签页对象或id,可传入列表或元组
|
||||
:param others: 是否关闭指定标签页之外的
|
||||
:return: None
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user