Skip to content

Update gui.py #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
41 changes: 25 additions & 16 deletions remi/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ class Widget(Tag):
EVENT_ONUPDATE = 'onupdate'

@decorate_constructor_parameter_types([])
def __init__(self, **kwargs):
def __init__(self, margin='0px', **kwargs):
"""
Args:
width (int, str): An optional width for the widget (es. width=10 or width='10px' or width='10%').
Expand All @@ -390,7 +390,9 @@ def __init__(self, **kwargs):
self.eventManager = _EventManager(self)
self.oldRootWidget = None # used when hiding the widget

self.style['margin'] = kwargs.get('margin', '0px')
if margin:
self.style['margin'] = margin

self.set_layout_orientation(kwargs.get('layout_orientation', Widget.LAYOUT_VERTICAL))
self.set_size(kwargs.get('width'), kwargs.get('height'))
self.set_style(kwargs.pop('style', None))
Expand Down Expand Up @@ -1306,7 +1308,7 @@ class GenericDialog(Widget):
EVENT_ONCANCEL = 'cancel_dialog'

@decorate_constructor_parameter_types([str, str])
def __init__(self, title='', message='', **kwargs):
def __init__(self, title='', message='', cancel_button=True, **kwargs):
"""
Args:
title (str): The title of the dialog.
Expand All @@ -1315,7 +1317,7 @@ def __init__(self, title='', message='', **kwargs):
"""
super(GenericDialog, self).__init__(**kwargs)
self.set_layout_orientation(Widget.LAYOUT_VERTICAL)
self.style.update({'display':'block', 'overflow':'auto', 'margin':'0px auto'})
self.style.update({'display':'block', 'overflow':'auto', 'margin':'8px auto', 'padding': '8px'})

if len(title) > 0:
t = Label(title)
Expand All @@ -1333,22 +1335,25 @@ def __init__(self, title='', message='', **kwargs):
self.conf = Button('Ok')
self.conf.set_size(100, 30)
self.conf.style['margin'] = '3px'
self.cancel = Button('Cancel')
self.cancel.set_size(100, 30)
self.cancel.style['margin'] = '3px'
hlay = Widget(height=35)
hlay.style['display'] = 'block'
hlay.style['overflow'] = 'visible'
hlay.append(self.conf)
hlay.append(self.cancel)
self.conf.style['float'] = 'right'
self.cancel.style['float'] = 'right'

if cancel_button:
self.cancel = Button('Cancel')
self.cancel.set_size(100, 30)
self.cancel.style['margin'] = '3px'
self.cancel.style['float'] = 'right'
self.cancel.attributes[self.EVENT_ONCLICK] = "sendCallback('%s','%s');" % (
self.identifier, self.EVENT_ONCANCEL)
hlay.append(self.cancel)

self.append(self.container)
self.append(hlay)

self.conf.attributes[self.EVENT_ONCLICK] = "sendCallback('%s','%s');" % (self.identifier, self.EVENT_ONCONFIRM)
self.cancel.attributes[self.EVENT_ONCLICK] = "sendCallback('%s','%s');" % (self.identifier, self.EVENT_ONCANCEL)

self.inputs = {}

Expand Down Expand Up @@ -1667,7 +1672,7 @@ class ListItem(Widget, _MixinTextualWidget):
"""

@decorate_constructor_parameter_types([str])
def __init__(self, text, **kwargs):
def __init__(self, text, tooltip_title='', **kwargs):
"""
Args:
text (str, unicode): The textual content of the ListItem.
Expand All @@ -1677,6 +1682,10 @@ def __init__(self, text, **kwargs):
self.type = 'li'

self.attributes[self.EVENT_ONCLICK] = ''

if tooltip_title:
self.attributes['title'] = tooltip_title

self.set_text(text)

def get_value(self):
Expand Down Expand Up @@ -2119,15 +2128,15 @@ class TableEditableItem(Widget, _MixinTextualWidget):
"""item widget for the TableRow."""

@decorate_constructor_parameter_types([str])
def __init__(self, text='', **kwargs):
def __init__(self, text='', text_style={}, **kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more proficient way to do styling would be to use css stylesheet. Otherwise we should add a style parameter for each widget in a container, like TableItem in Tables, ListItem in ListView and so on... Doesn't it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to use separate stylesheets, because at the moment, there is no documentation about it ;-)
If it means that the whole original stylesheet has to be copied, I don't think it's a good idea...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mutable functions args (dict in signature) are not a good idea

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. If you have your hands already on this, could you change it to None and assign
text_style = text_style or {}
?

"""
Args:
text (str):
kwargs: See Widget.__init__()
"""
super(TableEditableItem, self).__init__(**kwargs)
self.type = 'td'
self.editInput = TextInput()
self.editInput = TextInput(style=text_style, **kwargs)
self.append(self.editInput)
self.editInput.set_on_change_listener(self.onchange)
self.get_text = self.editInput.get_text
Expand Down Expand Up @@ -2720,7 +2729,7 @@ class TreeItem(Widget, _MixinTextualWidget):
"""TreeItem widget can contain other TreeItem."""

@decorate_constructor_parameter_types([str])
def __init__(self, text, **kwargs):
def __init__(self, text, tree_open=False, **kwargs):
"""
Args:
text (str):
Expand All @@ -2733,8 +2742,8 @@ def __init__(self, text, **kwargs):
"sendCallback('%s','%s');" \
"event.stopPropagation();event.preventDefault();" % (self.identifier, self.EVENT_ONCLICK)
self.set_text(text)
self.treeopen = False
self.attributes['treeopen'] = 'false'
self.treeopen = tree_open
self.attributes['treeopen'] = str(tree_open).lower()
self.attributes['has-subtree'] = 'false'

def append(self, value, key=''):
Expand Down