pycoze 0.1.281__py3-none-any.whl → 0.1.282__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pycoze/api/lib/tab_cls.py CHANGED
@@ -1,69 +1,73 @@
1
- import os
2
- from .view import ViewCls, WorkflowCls
3
- import time
4
- from pycoze import utils
5
- import json
6
-
7
-
8
- socket = utils.socket
9
- params = utils.params
10
-
11
- class TabCls:
12
- def open_workflow(self, workflow_id: str, wait_for_open=True) -> WorkflowCls:
13
- item_path = os.path.join(params["workspacePath"], 'User', 'Local', 'workflow', workflow_id)
14
- if not os.path.isabs(item_path):
15
- item_path = os.path.abspath(item_path)
16
- info_path = os.path.join(item_path, "info.json")
17
- with open(info_path, 'r', encoding='utf-8') as f:
18
- info = json.load(f)
19
- location = ["LocalWorkflow", item_path]
20
- socket.post("add-tab", {"location": location, "name": info["name"]})
21
- if wait_for_open:
22
- self._wait_for_tab_open(location)
23
- return WorkflowCls(location)
24
-
25
- def _wait_for_tab_open(self, location: list[str] | ViewCls):
26
- times = 0
27
- while not self.is_tab_open(location):
28
- time.sleep(0.01)
29
- times += 1
30
- if times > 1000:
31
- raise Exception("Tab open timeout")
32
-
33
- def get_active(self) -> list[str]:
34
- result = socket.post_and_recv_result("get-active-tab", {})
35
- return result
36
-
37
- def get_all(self) -> list[list[str]]:
38
- results = socket.post_and_recv_result("get-all-tabs", {})
39
- return results
40
-
41
- def close_tab(self, location: list[str] | ViewCls):
42
- if isinstance(location, ViewCls):
43
- location = location.location
44
- self.wait_for_tab_open(location)
45
- socket.post("close-tab", {"location": location})
46
-
47
- def switch_tab(self, location: list[str] | ViewCls):
48
- if isinstance(location, ViewCls):
49
- location = location.location
50
- self.wait_for_tab_open(location)
51
- socket.post("switchTab", {"location": location})
52
-
53
- def is_tab_open(self, location: list[str] | ViewCls):
54
- if isinstance(location, ViewCls):
55
- location = location.location
56
- result = socket.post_and_recv_result("is-tab-open", {"location": location})
57
- return result
58
-
59
- def pin_tab(self, location: list[str] | ViewCls):
60
- if isinstance(location, ViewCls):
61
- location = location.location
62
- self.wait_for_tab_open(location)
63
- socket.post("pin-tab", {"location": location})
64
-
65
- def unpin_tab(self, location: list[str] | ViewCls):
66
- if isinstance(location, ViewCls):
67
- location = location.location
68
- self.wait_for_tab_open(location)
69
- socket.post("unpin-tab", {"location": location})
1
+ import os
2
+ from .view import ViewCls, WorkflowCls
3
+ import time
4
+ from pycoze import utils
5
+ import json
6
+ from typing import Union
7
+
8
+
9
+ socket = utils.socket
10
+ params = utils.params
11
+
12
+
13
+ class TabCls:
14
+ def open_workflow(self, workflow_id: str, wait_for_open=True) -> WorkflowCls:
15
+ item_path = os.path.join(
16
+ params["workspacePath"], "User", "Local", "workflow", workflow_id
17
+ )
18
+ if not os.path.isabs(item_path):
19
+ item_path = os.path.abspath(item_path)
20
+ info_path = os.path.join(item_path, "info.json")
21
+ with open(info_path, "r", encoding="utf-8") as f:
22
+ info = json.load(f)
23
+ location = ["LocalWorkflow", item_path]
24
+ socket.post("add-tab", {"location": location, "name": info["name"]})
25
+ if wait_for_open:
26
+ self._wait_for_tab_open(location)
27
+ return WorkflowCls(location)
28
+
29
+ def _wait_for_tab_open(self, location: Union[list[str], ViewCls]):
30
+ times = 0
31
+ while not self.is_tab_open(location):
32
+ time.sleep(0.01)
33
+ times += 1
34
+ if times > 1000:
35
+ raise Exception("Tab open timeout")
36
+
37
+ def get_active(self) -> list[str]:
38
+ result = socket.post_and_recv_result("get-active-tab", {})
39
+ return result
40
+
41
+ def get_all(self) -> list[list[str]]:
42
+ results = socket.post_and_recv_result("get-all-tabs", {})
43
+ return results
44
+
45
+ def close_tab(self, location: list[str] | ViewCls):
46
+ if isinstance(location, ViewCls):
47
+ location = location.location
48
+ self.wait_for_tab_open(location)
49
+ socket.post("close-tab", {"location": location})
50
+
51
+ def switch_tab(self, location: list[str] | ViewCls):
52
+ if isinstance(location, ViewCls):
53
+ location = location.location
54
+ self.wait_for_tab_open(location)
55
+ socket.post("switchTab", {"location": location})
56
+
57
+ def is_tab_open(self, location: list[str] | ViewCls):
58
+ if isinstance(location, ViewCls):
59
+ location = location.location
60
+ result = socket.post_and_recv_result("is-tab-open", {"location": location})
61
+ return result
62
+
63
+ def pin_tab(self, location: list[str] | ViewCls):
64
+ if isinstance(location, ViewCls):
65
+ location = location.location
66
+ self.wait_for_tab_open(location)
67
+ socket.post("pin-tab", {"location": location})
68
+
69
+ def unpin_tab(self, location: list[str] | ViewCls):
70
+ if isinstance(location, ViewCls):
71
+ location = location.location
72
+ self.wait_for_tab_open(location)
73
+ socket.post("unpin-tab", {"location": location})
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.281
3
+ Version: 0.1.282
4
4
  Summary: Package for pycoze only!
5
5
  Home-page: UNKNOWN
6
6
  Author: Yuan Jie Xiong
@@ -7,7 +7,7 @@ pycoze/ai/llm/text_to_image_prompt.py,sha256=0bx2C_YRvjAo7iphHGp1-pmGKsKqwur7dM0
7
7
  pycoze/ai/llm/think.py,sha256=sUgTBdGzcZtL3r-Wx8M3lDuVUmDVz8g3qC0VU8uiKAI,5143
8
8
  pycoze/api/__init__.py,sha256=GGRRRPop0ZxdXe5JRhg2XvHITGIWfNcHA25opJZ0f1w,313
9
9
  pycoze/api/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- pycoze/api/lib/tab_cls.py,sha256=nPbTfWF_Mmz3tKAmGrVdgK21HE9g1074V59nrteiG8c,2612
10
+ pycoze/api/lib/tab_cls.py,sha256=14UcUJTlmeoXV7gMYZOq_m_YTHa8YjqkMm5JUQATrAQ,2589
11
11
  pycoze/api/lib/view.py,sha256=_PIpTfeuTPPlMDKshMGsqFQYMq7ZiO4Hg5XwHwDoU60,7357
12
12
  pycoze/api/lib/window_cls.py,sha256=Yezy-SR_EwVtUjrgXnHRC69WGgXVaXeJHjaxn09Ophg,1737
13
13
  pycoze/bot/__init__.py,sha256=JxnRoCCqx_LFyVb3pLu0qYCsH8ZLuAaMXAtvVUuCHuE,78
@@ -35,8 +35,8 @@ pycoze/utils/arg.py,sha256=jop1tBfe5hYkHW1NSpCeaZBEznkgguBscj_7M2dWfrs,503
35
35
  pycoze/utils/env.py,sha256=5pWlXfM1F5ZU9hhv1rHlDEanjEW5wf0nbyez9bNRqqA,559
36
36
  pycoze/utils/socket.py,sha256=bZbFFRH4mfThzRqt55BAAGQ6eICx_ja4x8UGGrUdAm8,2428
37
37
  pycoze/utils/text_or_file.py,sha256=gpxZVWt2DW6YiEg_MnMuwg36VNf3TX383QD_1oZNB0Y,551
38
- pycoze-0.1.281.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
39
- pycoze-0.1.281.dist-info/METADATA,sha256=gRDvFXAP3MK6MxGBidAvlkFmo8cm-xBMMGCeKSyVetY,755
40
- pycoze-0.1.281.dist-info/WHEEL,sha256=ewwEueio1C2XeHTvT17n8dZUJgOvyCWCt0WVNLClP9o,92
41
- pycoze-0.1.281.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
42
- pycoze-0.1.281.dist-info/RECORD,,
38
+ pycoze-0.1.282.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
39
+ pycoze-0.1.282.dist-info/METADATA,sha256=_phaJAN5a_su7N52zQ92AEz6SpvJsC3DwbBMCWoGu2s,755
40
+ pycoze-0.1.282.dist-info/WHEEL,sha256=ewwEueio1C2XeHTvT17n8dZUJgOvyCWCt0WVNLClP9o,92
41
+ pycoze-0.1.282.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
42
+ pycoze-0.1.282.dist-info/RECORD,,