Skip to content
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

Merge formateli:onoffbutton into master to add OnOffButton #61

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

formateli
Copy link
Contributor

@formateli formateli commented Apr 21, 2020

PR Details:

Description

A simple On/Off button (aka switch button)

Checklist

  • Widget in a separate file in the appropriate folder
  • Widget functions properly on both Windows and Linux
  • Widget code includes docstrings with parameter descriptions
  • Included an example file in /examples
  • Widget is covered by unitttests in /tests
  • Widget includes required assets files
  • Reference to widget in AUTHORS.md
  • Entry in sphinx documentation

@formateli
Copy link
Contributor Author

Hi everyone.
I have developed this widget for a project and I would like to know your observations about it, in order to improve it if necessary.

@sbordeyne
Copy link
Member

I'll review tomorrow in more details, but there are a few things that I see are wrong with this widget, like taking in StringVar, IntVar or BooleanVar types for the variable, typos in the docstrings, and the name of the widget (should probably be ToggleButton instead, states are not on/off all the time).

@formateli
Copy link
Contributor Author

I followed the checkbutton widget as a guidance, which is in essence a toggle button too. The other name I considered for the widget was SwitchButton

@RedFantom RedFantom changed the title OnOffButton widget. Merge formateli:onoffbutton into master to add OnOffButton Apr 24, 2020
@RedFantom
Copy link
Member

Thank you for your pull request! While I quite like the idea of having a widget like this, I'm not quite happy with how this widget looks. Personally, I'd prefer to have an implementation based on new UI elements and layouts with the Checkbutton at its core but the looks of a toggle.

This would be quite a bit harder than a Canvas but it has the potential to look a lot better, possibly even themed if it could be integrated with ttkthemes. If that is something you want to pursue, then I am open to working with you to achieve it.

Right now, the widget should at least have the following:

  • Get its colours from the active ttk theme, so with ttk.Style().lookup("foreground") or something similar.
  • Antialiasing of some sort, to fix the ragged edges of the fields.
  • Support for clicking on the indicator as well as the green/red part of the widget.

Particularly the anti-aliasing is a problem, though it is probably not impossible. Still, it would be slow when using a Canvas so still not ideal. Are you open to working on this some more, @formateli ?

@formateli
Copy link
Contributor Author

Hi, I agree that the widget does not look very good, it is a prototype and has no sense continue with it.
I would like to develop one like the one you mention, please point me at some examples and/or some guidence on how to implement it.

@RedFantom
Copy link
Member

Okay, so the way I envision it is this:

  • The ToggleButton defines custom styles much like the unmerged Notebook widget does. This is advanced Tkinter, and figuring out how it work might take you a few tries. The Notebook widget is really a solid example. These custom elements provide a baselines for when ttkthemes is not available or a theme without those styles is selected.
  • ttkthemes may then be modified to create the styles within the themes, providing themed versions of these widgets. It would basically create a wholly new themed ttk widget. This way, the widget would blend in properly with the application.

As a baseline you could use the images from a GTK theme, such as arc, though something a little more neutral may be more appropriate.

If you can do the first part, I can do the second. Currently I am working on another Tkinter project so I won't have time to build such a ToggleButton in the near future.

@codecov-io
Copy link

codecov-io commented May 9, 2020

Codecov Report

Attention: Patch coverage is 92.15686% with 4 lines in your changes missing coverage. Please review.

Project coverage is 89.79%. Comparing base (ff737ff) to head (21c313a).
Report is 65 commits behind head on master.

Files Patch % Lines
ttkwidgets/onoffbutton.py 92.00% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #61      +/-   ##
==========================================
+ Coverage   89.69%   89.79%   +0.10%     
==========================================
  Files          36       37       +1     
  Lines        3725     3802      +77     
==========================================
+ Hits         3341     3414      +73     
- Misses        384      388       +4     
Files Coverage Δ
ttkwidgets/__init__.py 100.00% <100.00%> (ø)
ttkwidgets/onoffbutton.py 92.00% <92.00%> (ø)

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ff737ff...21c313a. Read the comment docs.

@formateli
Copy link
Contributor Author

Thanks for your guidance. Once I had a better understanding of how styles work in the ttk widgets, I just had to derive the new OnOffButton from ttk.Checkbutton and create new element and layout for this class.
Awaiting your comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants