Merge pull request #303 from pranavladkat/main
Fix minor bugs in Table and Menu widget
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
import asyncio
|
||||||
import random
|
import random
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
@ -69,10 +70,19 @@ class Table(Pane, dict):
|
|||||||
self._formatters = {}
|
self._formatters = {}
|
||||||
self.headings = headings
|
self.headings = headings
|
||||||
self.is_shown = True
|
self.is_shown = True
|
||||||
if return_clicked_cells:
|
def wrapper(rId, cId=None):
|
||||||
self.win.handlers[self.id] = lambda rId, cId: func(self[rId], cId)
|
if return_clicked_cells:
|
||||||
else:
|
func(self[rId], cId)
|
||||||
self.win.handlers[self.id] = lambda rId: func(self[rId])
|
else:
|
||||||
|
func(self[rId])
|
||||||
|
|
||||||
|
async def async_wrapper(rId, cId=None):
|
||||||
|
if return_clicked_cells:
|
||||||
|
await func(self[rId], cId)
|
||||||
|
else:
|
||||||
|
await func(self[rId])
|
||||||
|
|
||||||
|
self.win.handlers[self.id] = async_wrapper if asyncio.iscoroutinefunction(func) else wrapper
|
||||||
self.return_clicked_cells = return_clicked_cells
|
self.return_clicked_cells = return_clicked_cells
|
||||||
|
|
||||||
headings = list(headings)
|
headings = list(headings)
|
||||||
|
|||||||
@ -49,10 +49,20 @@ class SwitcherWidget(Widget):
|
|||||||
class MenuWidget(Widget):
|
class MenuWidget(Widget):
|
||||||
def __init__(self, topbar, options, default, separator, align, func):
|
def __init__(self, topbar, options, default, separator, align, func):
|
||||||
super().__init__(topbar, value=default, func=func)
|
super().__init__(topbar, value=default, func=func)
|
||||||
|
self.options = list(options)
|
||||||
self.run_script(f'''
|
self.run_script(f'''
|
||||||
{self.id} = {topbar.id}.makeMenu({list(options)}, "{default}", {jbool(separator)}, "{self.id}", "{align}")
|
{self.id} = {topbar.id}.makeMenu({list(options)}, "{default}", {jbool(separator)}, "{self.id}", "{align}")
|
||||||
''')
|
''')
|
||||||
|
|
||||||
|
def set(self, option):
|
||||||
|
if option not in self.options:
|
||||||
|
raise ValueError(f"Option {option} not in menu options ({self.options})")
|
||||||
|
self.value = option
|
||||||
|
self.run_script(f'''
|
||||||
|
{self.id}.updateMenu("{option}")
|
||||||
|
''')
|
||||||
|
self.win.handlers[self.id](option)
|
||||||
|
|
||||||
|
|
||||||
class ButtonWidget(Widget):
|
class ButtonWidget(Widget):
|
||||||
def __init__(self, topbar, button, separator, align, func):
|
def __init__(self, topbar, button, separator, align, func):
|
||||||
|
|||||||
Reference in New Issue
Block a user