-
Notifications
You must be signed in to change notification settings - Fork 949
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
Add support for specifying custom icons in ToggleButtons #2182
Conversation
Thanks! I've been thinking more about this, and particularly thinking about consistency with the Image widget. What do you think of having a new attribute, This would be a backwards incompatible change, and might be overkill, considering icons usually are fairly small, so it's not a big deal to transmit them as data URIs rather than in binary. It does make it slightly easier to give an image, as in you don't have to construct a data uri for the image (you can just read in the binary image and set the attribute to the data). Thoughts? How easy is it to construct data URIs in python? |
What about making icon a union of string and image? String means
fontawesome otherwise an image
(from mobile phone)
…On Fri, 31 Aug 2018, 19:34 Jason Grout, ***@***.***> wrote:
Thanks!
I've been thinking more about this, and particularly thinking about
consistency with the Image widget. What do you think of having a new
attribute, icon_format, that can be a mimetype, or the string 'url', or
the string 'fontawesome' (defaulting to 'fontawesome'). The icon attribute
itself would be changed to binary, and the format string would be used to
determine how to interpret the icon attribute.
This would be a backwards incompatible change, and might be overkill,
considering icons usually are fairly small, so it's not a big deal to
transmit them as data URIs rather than in binary. It does make it slightly
easier to give an image, as in you don't have to construct a data uri for
the image (you can just read in the binary image and set the attribute to
the data). Thoughts? How easy is it to construct data URIs in python?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2182 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABryPZ89SZHpH1AT-Z5-LLa25rvf9Hsgks5uWXOrgaJpZM4WMhs3>
.
|
Do you mean the icon attribute would actually be a reference to an image widget? |
Indeed, so all logic of reading images etc on the kernel side is in that
class.
(from mobile phone)
…On Fri, 31 Aug 2018, 21:52 Jason Grout, ***@***.***> wrote:
Do you mean the icon attribute would actually be a reference to an image
widget?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2182 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABryPc47AeXs2aBh86p76Gy7EnE9r4mYks5uWZQPgaJpZM4WMhs3>
.
|
I don't think we have precedent for having an attribute that is the union of a widget reference or a string. @SylvainCorlay - do you have thoughts about having a union attribute of either a widget reference or a string? In the serialization, this really means that if the string starts with the magic value, it's considered a widget reference, otherwise it's a fontawesome name. |
Another option is to have both icon (string) and image (Image) traits, if
someone wants, the both can be used, not super elegant, but clean, and also
quite obvious what image would be.
(from mobile phone)
…On Fri, 31 Aug 2018, 22:03 Jason Grout, ***@***.***> wrote:
I don't think we have precedent for having an attribute that is the union
of a widget reference or a string. @SylvainCorlay
<https://github.com/SylvainCorlay> - do you have thoughts about having a
union attribute of either a widget reference or a string? In the
serialization, this really means that if the string starts with the magic
value, it's considered a widget reference, otherwise it's a fontawesome
name.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2182 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABryPZl8cm-g0L3ZNb1Lltc4bwBbplk8ks5uWZavgaJpZM4WMhs3>
.
|
The icon trait could be of a special Assigning a string would create a font-based icon upon traitlet validation. To get an image, explicitely instantiate an image-based icon. |
I like it, so icon could be similar to Image, except it would create a li
dom element for format=='fontawesome'? And button would create a view, and
would attach that Dom element?
(from mobile phone)
…On Fri, 31 Aug 2018, 23:51 Sylvain Corlay, ***@***.***> wrote:
The icon trait could be of a special Icon type.
Assigning a string would create a font-based icon upon traitlet
validation. To get an image, explicitely instantiate an image-based icon.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2182 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABryPeiYw20u9GXowbZwbaAyDaelhK7kks5uWa_WgaJpZM4WMhs3>
.
|
Yes, probably. We also need to do some work on line height for the containing element for vertical centering. |
4141afb
to
aaea487
Compare
I've started supporting non-unique labels with this PR, but it would make sense to do this with all of the _Selection widget. Shall I leave this in this PR and once we agree do another PR to support it in the others as well? |
ipywidgets/widgets/widget_button.py
Outdated
# warnings.warn("icons names no longer start with 'fa-', " | ||
# "just use the class name itself (for example, 'check' instead of 'fa-check')", DeprecationWarning) | ||
# value = value[3:] | ||
# return value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover?
i.classList.add('fa-' + icon); | ||
if (icon) { | ||
this.iconView = <IconView> await this.create_child_view(icon) | ||
if (description.length === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since of the async we should first put in a placeholder element.
@SylvainCorlay issues addressed that we discussed, should we merge? |
oops, I see I need to follow the same pattern in ToggleButton |
9f0180c
to
da19f86
Compare
Ok, this PR led me to find #2256, we should first solve that and then rebase this on master. |
da19f86
to
e354ab5
Compare
With #2256 in and some cleanups, this is ready for a new review or merge. |
I think with https://github.com/mariobuikhuizen/ipyvuetify I personally don't need this anymore. Happy for someone else to pick this up. |
This adds support for specifying custom icons via the data URI mechanism in ToggleButtons. Here is a preview:
A few open questions:
One thing I wasn't quite sure about is how the icon size should be handled, and how to make sure the icons are properly centered (in the example above there is a slight vertical offset for the two custom icons) - I'm not familiar enough with the notebook CSS.
What is the mechanism for adding tests? I can't see any tests currently for ToggleButtons currently?
I can add the same mechanism for ToggleButton once things are polished with ToggleButtons.
Impremented during the JupyterCon 2018 sprint