pyglove 0.5.0.dev202510290810__py3-none-any.whl → 0.5.0.dev202510300013__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.

Potentially problematic release.


This version of pyglove might be problematic. Click here for more details.

@@ -158,6 +158,39 @@ class TabControl(HtmlControl):
158
158
  position='beforebegin',
159
159
  )
160
160
 
161
+ def remove(self, index_or_name: Union[int, str]) -> Tab:
162
+ """Removes a tab identified by index or name."""
163
+ index = self.indexof(index_or_name)
164
+ if index == -1:
165
+ raise ValueError(f'Tab not found: {index_or_name!r}')
166
+
167
+ with pg_flags.notify_on_change(False):
168
+ tab = self.tabs.pop(index)
169
+
170
+ self._run_javascript(
171
+ f"""
172
+ const button = document.querySelectorAll('#{self.element_id()}-button-group > .tab-button')[{index}];
173
+ if (button) {{
174
+ button.remove();
175
+ }}
176
+ const content = document.querySelectorAll('#{self.element_id()}-content-group > .tab-content')[{index}];
177
+ if (content) {{
178
+ content.remove();
179
+ }}
180
+ """
181
+ )
182
+
183
+ if not self.tabs:
184
+ self._sync_members(selected=0)
185
+ return tab
186
+
187
+ if self.selected == index:
188
+ new_selected = index - 1 if index == len(self.tabs) else index
189
+ self.select(max(0, new_selected))
190
+ elif self.selected > index:
191
+ self._sync_members(selected=self.selected - 1)
192
+ return tab
193
+
161
194
  def indexof(self, index_or_name: Union[int, str]) -> int:
162
195
  if isinstance(index_or_name, int):
163
196
  index = index_or_name
@@ -154,6 +154,43 @@ class TabControlTest(unittest.TestCase):
154
154
  self.assertEqual(len(scripts), 1)
155
155
  self.assertEqual(tab.selected, 1)
156
156
 
157
+ def test_remove(self):
158
+ tabs = [tab_lib.Tab(l, l, name=l) for l in ['a', 'b', 'c', 'd']]
159
+ tc = tab_lib.TabControl(tabs, selected='c')
160
+ self.assertEqual([t.name for t in tc.tabs], ['a', 'b', 'c', 'd'])
161
+ self.assertEqual(tc.selected, 2)
162
+
163
+ # Trigger rendering so scripts are tracked.
164
+ _ = tc.to_html()
165
+ with tc.track_scripts() as scripts:
166
+ tc.remove('b')
167
+ self.assertEqual(len(scripts), 1)
168
+ self.assertEqual([t.name for t in tc.tabs], ['a', 'c', 'd'])
169
+ self.assertEqual(tc.selected, 1)
170
+
171
+ with tc.track_scripts() as scripts:
172
+ # Remove currently selected tab 'c'
173
+ tc.remove('c')
174
+ # 1 script for remove, 1 for select.
175
+ self.assertEqual(len(scripts), 2)
176
+ self.assertEqual([t.name for t in tc.tabs], ['a', 'd'])
177
+ self.assertEqual(tc.selected, 1)
178
+
179
+ with tc.track_scripts() as scripts:
180
+ tc.remove(1)
181
+ self.assertEqual(len(scripts), 2)
182
+ self.assertEqual([t.name for t in tc.tabs], ['a'])
183
+ self.assertEqual(tc.selected, 0)
184
+
185
+ with tc.track_scripts() as scripts:
186
+ tc.remove('a')
187
+ self.assertEqual(len(scripts), 1)
188
+ self.assertEqual(tc.tabs, [])
189
+ self.assertEqual(tc.selected, 0)
190
+
191
+ with self.assertRaisesRegex(ValueError, 'Tab not found'):
192
+ tc.remove('x')
193
+
157
194
 
158
195
  if __name__ == '__main__':
159
196
  unittest.main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyglove
3
- Version: 0.5.0.dev202510290810
3
+ Version: 0.5.0.dev202510300013
4
4
  Summary: PyGlove: A library for manipulating Python objects.
5
5
  Home-page: https://github.com/google/pyglove
6
6
  Author: PyGlove Authors
@@ -175,8 +175,8 @@ pyglove/core/views/html/controls/label.py,sha256=2u7z_6o-ANf6EbxufFl_fZ1VFSUrjNw
175
175
  pyglove/core/views/html/controls/label_test.py,sha256=_Fi6vMITup8iFYTiU_1w7FZCXaYp1eMmVBxub8JMYbs,5170
176
176
  pyglove/core/views/html/controls/progress_bar.py,sha256=0an0eCbPCDjwrR58C16NwLZ-cf3Oy0wQerLsiNgGHmk,5235
177
177
  pyglove/core/views/html/controls/progress_bar_test.py,sha256=kKOJDZQtBPkmNcgIBrRQkNNzcTm51ojuFBTRUEDSsp0,3506
178
- pyglove/core/views/html/controls/tab.py,sha256=dn2rs6IBqvjtKvk0BC8ypVYqjjHsqJvP_Bh9y94QjMc,10818
179
- pyglove/core/views/html/controls/tab_test.py,sha256=deRXg4LM4dzVgods5HVTXznrOWdddF6wrcl1RuhmRCA,5656
178
+ pyglove/core/views/html/controls/tab.py,sha256=f3ZfYyXfMmERGOXY4a4bxmOhomL3MQONMossaxw8hQw,11851
179
+ pyglove/core/views/html/controls/tab_test.py,sha256=V0HrY0YaGyVlOykMCFg85QSxOq8eBPa3Fqcv2q1c12s,6912
180
180
  pyglove/core/views/html/controls/tooltip.py,sha256=01BbpuM1twf3FYMUT09_Ck5JSSONe8QE9RmyA9nhCnU,3092
181
181
  pyglove/core/views/html/controls/tooltip_test.py,sha256=17BY-WmZKpz9tCbySPcwG6KJyfeE_MeMyKxtfxorBQ0,3194
182
182
  pyglove/ext/__init__.py,sha256=3jp8cJvKW6PENOZlmVAbT0w-GBRn_kjhc0wDX3XjpOE,755
@@ -218,8 +218,8 @@ pyglove/ext/scalars/randoms.py,sha256=LkMIIx7lOq_lvJvVS3BrgWGuWl7Pi91-lA-O8x_gZs
218
218
  pyglove/ext/scalars/randoms_test.py,sha256=nEhiqarg8l_5EOucp59CYrpO2uKxS1pe0hmBdZUzRNM,2000
219
219
  pyglove/ext/scalars/step_wise.py,sha256=IDw3tuTpv0KVh7AN44W43zqm1-E0HWPUlytWOQC9w3Y,3789
220
220
  pyglove/ext/scalars/step_wise_test.py,sha256=TL1vJ19xVx2t5HKuyIzGoogF7N3Rm8YhLE6JF7i0iy8,2540
221
- pyglove-0.5.0.dev202510290810.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
222
- pyglove-0.5.0.dev202510290810.dist-info/METADATA,sha256=N98bjfXjiuZdX6LBUyAX-P79oxFLmF5ZP933hRs4hIw,7089
223
- pyglove-0.5.0.dev202510290810.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
224
- pyglove-0.5.0.dev202510290810.dist-info/top_level.txt,sha256=wITzJSKcj8GZUkbq-MvUQnFadkiuAv_qv5qQMw0fIow,8
225
- pyglove-0.5.0.dev202510290810.dist-info/RECORD,,
221
+ pyglove-0.5.0.dev202510300013.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
222
+ pyglove-0.5.0.dev202510300013.dist-info/METADATA,sha256=9MLhUC14R53I_-N1v2Y1dQzp6JY5gULUTt6sZoAyCSg,7089
223
+ pyglove-0.5.0.dev202510300013.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
224
+ pyglove-0.5.0.dev202510300013.dist-info/top_level.txt,sha256=wITzJSKcj8GZUkbq-MvUQnFadkiuAv_qv5qQMw0fIow,8
225
+ pyglove-0.5.0.dev202510300013.dist-info/RECORD,,