4.1.0.0b4set.tab_to_front()标记即将废弃,用activate_tab()代替;Frame增加set.property()和set.style()

This commit is contained in:
g1879 2024-07-10 14:44:59 +08:00
parent 58285fc0ad
commit 523f92f640
7 changed files with 52 additions and 36 deletions

View File

@ -14,4 +14,4 @@ from ._pages.chromium_page import ChromiumPage
from ._pages.mix_page import MixPage
from ._pages.mix_page import MixPage as WebPage
__version__ = '4.1.0.0b3'
__version__ = '4.1.0.0b4'

View File

@ -376,15 +376,17 @@ class Chromium(object):
while self.tabs_count != end_len and perf_counter() < end_time:
sleep(.1)
def activate_tab(self, id_or_ind):
def activate_tab(self, id_ind_tab):
"""使标签页变为活动状态
:param id_or_ind: 标签页idstr或标签页序号int序号从1开始
:param id_ind_tab: 标签页idstrTab对象或标签页序号int序号从1开始
:return: None
"""
if isinstance(id_or_ind, int):
id_or_ind += -1 if id_or_ind else 1
id_or_ind = self.tab_ids[id_or_ind]
self._run_cdp('Target.activateTarget', targetId=id_or_ind)
if isinstance(id_ind_tab, int):
id_ind_tab += -1 if id_ind_tab else 1
id_ind_tab = self.tab_ids[id_ind_tab]
elif isinstance(id_ind_tab, ChromiumTab):
id_ind_tab = id_ind_tab.tab_id
self._run_cdp('Target.activateTarget', targetId=id_ind_tab)
def reconnect(self):
"""断开重连"""

View File

@ -135,7 +135,7 @@ class Chromium(object):
mix: bool = False,
as_id: bool = False) -> List[ChromiumTab, str]: ...
def activate_tab(self, tab_id: Union[int, str]) -> None: ...
def activate_tab(self, id_ind_tab: Union[int, str, ChromiumTab]) -> None: ...
def _new_tab(self,
obj,

View File

@ -148,12 +148,12 @@ class ChromiumPage(ChromiumBase):
"""
return self.browser.new_tab(url=url, new_window=new_window, background=background, new_context=new_context)
def activate_tab(self, id_or_ind):
def activate_tab(self, id_ind_tab):
"""使标签页变为活动状态
:param id_or_ind: 标签页idstr或标签页序号int序号从1开始
:param id_ind_tab: 标签页idstrTab对象或标签页序号int序号从1开始
:return: None
"""
self.browser.activate_tab(id_or_ind)
self.browser.activate_tab(id_ind_tab)
def close(self):
"""关闭Page管理的标签页"""

View File

@ -101,7 +101,7 @@ class ChromiumPage(ChromiumBase):
def new_tab(self, url: str = None, new_window: bool = False, background: bool = False,
new_context: bool = False) -> ChromiumTab: ...
def activate_tab(self, tab_id: Union[int, str]) -> None: ...
def activate_tab(self, id_ind_tab: Union[int, str, ChromiumTab]) -> None: ...
def close(self) -> None: ...

View File

@ -229,15 +229,6 @@ class BrowserSetter(BrowserBaseSetter):
self._cookies_setter = BrowserCookiesSetter(self._owner)
return self._cookies_setter
def tab_to_front(self, tab_or_id):
"""激活标签页使其处于最前面
:param tab_or_id: 标签页对象或id
:return: None
"""
if not isinstance(tab_or_id, str): # 传入Tab对象
tab_or_id = tab_or_id.tab_id
self._owner.activate_tab(tab_or_id)
def auto_handle_alert(self, on_off=True, accept=True):
"""设置是否启用自动处理弹窗
:param on_off: bool表示开或关
@ -274,6 +265,16 @@ class BrowserSetter(BrowserBaseSetter):
raise ValueError(f'''mode参数只能是 '{"', '".join(types.keys())}' 之一,现在是:{mode}''')
self._owner._dl_mgr.set_file_exists('browser', mode)
# ---------- 即将废弃 ----------
def tab_to_front(self, tab_or_id):
"""激活标签页使其处于最前面
:param tab_or_id: 标签页对象或id
:return: None
"""
if not isinstance(tab_or_id, str): # 传入Tab对象
tab_or_id = tab_or_id.tab_id
self._owner.activate_tab(tab_or_id)
class ChromiumBaseSetter(BrowserBaseSetter):
@ -427,17 +428,6 @@ class TabSetter(ChromiumBaseSetter):
class ChromiumPageSetter(TabSetter):
def tab_to_front(self, tab_or_id=None):
"""激活标签页使其处于最前面
:param tab_or_id: 标签页对象或id为None表示当前标签页
:return: None
"""
if not tab_or_id:
tab_or_id = self._owner.tab_id
elif not isinstance(tab_or_id, str): # 传入Tab对象
tab_or_id = tab_or_id.tab_id
self._owner.browser.activate_tab(tab_or_id)
def auto_handle_alert(self, on_off=True, accept=True, all_tabs=False):
"""设置是否启用自动处理弹窗
:param on_off: bool表示开或关
@ -450,6 +440,18 @@ class ChromiumPageSetter(TabSetter):
else:
self._owner._alert.auto = accept if on_off else None
# ---------- 即将废弃 ----------
def tab_to_front(self, tab_or_id=None):
"""激活标签页使其处于最前面
:param tab_or_id: 标签页对象或id为None表示当前标签页
:return: None
"""
if not tab_or_id:
tab_or_id = self._owner.tab_id
elif not isinstance(tab_or_id, str): # 传入Tab对象
tab_or_id = tab_or_id.tab_id
self._owner.browser.activate_tab(tab_or_id)
class MixPageSetter(ChromiumPageSetter):
def __init__(self, owner):
@ -589,6 +591,22 @@ class ChromiumFrameSetter(ChromiumBaseSetter):
"""
self._owner.frame_ele.set.attr(name, value)
def property(self, name, value):
"""设置元素property属性
:param name: 属性名
:param value: 属性值
:return: None
"""
self._owner.frame_ele.set.property(name=name, value=value)
def style(self, name, value):
"""设置元素style样式
:param name: 样式名称
:param value: 样式值
:return: None
"""
self._owner.frame_ele.set.style(name=name, value=value)
class LoadMode(object):
"""用于设置页面加载策略的类"""

View File

@ -98,8 +98,6 @@ class BrowserSetter(BrowserBaseSetter):
_owner: Chromium = ...
_cookies_setter: BrowserCookiesSetter = ...
def tab_to_front(self, tab_or_id: Union[str, ChromiumTab]) -> None: ...
@property
def cookies(self) -> BrowserCookiesSetter: ...
@ -159,8 +157,6 @@ class TabSetter(ChromiumBaseSetter):
class ChromiumPageSetter(TabSetter):
_owner: ChromiumPage = ...
def tab_to_front(self, tab_or_id: Union[str, ChromiumTab] = None) -> None: ...
def auto_handle_alert(self, on_off: bool = True, accept: bool = True, all_tabs: bool = False) -> None: ...