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

using improved L&F #16

Open
chrstphrchvz opened this issue Mar 14, 2018 · 7 comments
Open

using improved L&F #16

chrstphrchvz opened this issue Mar 14, 2018 · 7 comments

Comments

@chrstphrchvz
Copy link
Collaborator

chrstphrchvz commented Mar 14, 2018

I haven't used HSW12 much lately, but I did come across how there are ways to have improved look-and-feel for Tk (I believe it is the Tcl/Tk "Tile" feature specifically). I imagine that this would probably be worthwhile supporting e.g. for macOS so that a native look-and-feel is used and maybe even XQuartz is not needed--I'll upload a screenshot once I have my Mac running again if this is the case.

It seems the easiest way might be to try Tcl::pTk. With little effort I was able to use the "hijack" approach (i.e. launch using perl -MTcl::pTk::TkHijack hsw12.pl). I can at least get the GUI to appear after addressing a couple of minor issues:

  • Tk::Exists has to be explicitly used as Tk::Exists rather than just Exists (please correct me if there is some other Exists besides Tk::Exists that's being used)

  • There is an error when allowing autofocus;


bad option "focus": must be cget or configure at /usr/local/share/perl/5.24.1/Tcl/pTk/Widget.pm line 336.

If I comment out focusFollowsMouse it works fine, but I do not know what exactly causes the error. Personally I'm fine without the autofocus.

I'll note that it did take a few more steps to use Tcl::pTk than just regular Perl/Tk, since neither Linux distributions, macports, nor ActiveState PPM seem to provide it, although they do tend to provide the prerequisite modules prepackaged (e.g. Tix for Tcl; and Tcl, Class::ISA, and Sub::Name for Perl). I imagine whoever is still successfully using HSW12 is adventurous enough to go through these steps as well.

Also, I'd be inclined to have HSW12 use Tcl::pTk only if it is available and still work without it otherwise. Maybe some variation of the approach used here will suffice.

@chrstphrchvz
Copy link
Collaborator Author

Here's what it looks like on a Mac, indeed it does not need XQuartz:

screen shot 2018-03-22 at 7 42 25 pm

There are a few more issues apparent when running it on a Mac.

  • Right-click actions are instead bound to the the middle mouse button, if mouse even has one. I wonder if this is something Tcl::pTk should be adjusting automatically, so I'll probably ask them.
  • Register window: the CCR buttons are checkboxes rather than pushbuttons, so it tries placing labels to the side but there is not much room by default. Here's what it looks like if the window is larger:

screen shot 2018-03-22 at 9 46 35 pm

  • The UPLOAD button also slightly too small for the label text.
  • Menubuttons get translated to aqua pulldown lists, which looks unusual but still functional. Using the system menubar would be more ideal anyways.

I'm not in any hurry to get these fixed, just trying this as a fun experiment. For now I've pushed any progress to a separate branch.

@hotwolf
Copy link
Owner

hotwolf commented Mar 24, 2018

Hello Christopher,

That's quite an accomplishment to get the HSW12 GUI running without an X server. Have you also tried to connect a D-Bug12 pod and use the terminal? The terminal relies on a "fileevent" callback. It would be interesting to see if that mechanism still works after replacing the Tk framework.

I think we should merge your code into the master branch. I like your approach of of probing the existence of Tcl/pTk first. Additionally we could add a command line argument to the "hsw12.pl" script to explicitly select the Tk framework.

Thanks for all the work, that you've put in the IDE.

Dirk

@chrstphrchvz
Copy link
Collaborator Author

Hi Dirk, thanks for replying. I had not tried connecting my Dragon12 board, indeed the terminal doesn't yet work with Tcl::pTk but still does with Tk. It fails as soon as I select the port with this error:

Tcl::pTk::Error: Can't locate sys/ioctl.ph in @INC (did you run h2ph?) (@INC contains: /Users/christopherchavez/git/HSW12/Perl CODE(0x7fa6048e0ce0) /opt/local/lib/perl5/site_perl/5.26/darwin-thread-multi-2level /opt/local/lib/perl5/site_perl/5.26 /opt/local/lib/perl5/vendor_perl/5.26/darwin-thread-multi-2level /opt/local/lib/perl5/vendor_perl/5.26 /opt/local/lib/perl5/5.26/darwin-thread-multi-2level /opt/local/lib/perl5/5.26) at /opt/local/lib/perl5/site_perl/5.26/Tcl/pTk/Widget.pm line 2142.

    while executing
"::perl::CODE(0x7fa604746178)"
    (menu invoke)

 Error Started at hsw12.pl line 75.

 Stack Trace:
  at /opt/local/lib/perl5/site_perl/5.26/Tcl/pTk.pm line 898.
 	eval {...} called at /opt/local/lib/perl5/site_perl/5.26/Tcl/pTk.pm line 898
 	Tcl::pTk::DoOneEvent(Tcl::pTk=SCALAR(0x7fa6043b3050), 0) called at /opt/local/lib/perl5/site_perl/5.26/Tcl/pTk.pm line 876
 	Tcl::pTk::MainLoop() called at hsw12.pl line 75

I'm wondering if that's due to my installation though. I'll keep digging.

I was able to 'modernize' the menubar after some finding & replacing, so it should be able to use the system menubar. I then had to figure out what was causing a strange error but only with TkHijack. It turned out that it didn't like the .'s at the end of Import... being used in a cascade's label:

bad window path name ".menu02.mnonf.import.." at /opt/local/lib/perl5/site_perl/5.26/Tcl/pTk/Widget.pm line 332.
 at /opt/local/lib/perl5/site_perl/5.26/Tcl/pTk/Menu/Item.pm line 123.
 at /opt/local/lib/perl5/site_perl/5.26/Tcl/pTk/MegaWidget.pm line 121.
	Tcl::pTk::Widget::new("Tcl::pTk::Menu", Tcl::pTk::Menu=HASH(0x7f8b0f6c3108), "Name", "Import...", "-tearoff", "false") called at /opt/local/lib/perl5/site_perl/5.26/Tcl/pTk/MegaWidget.pm line 58
	Tcl::pTk::Widget::Menu(Tcl::pTk::Menu=HASH(0x7f8b0f6c3108), "Name", "Import...", "-tearoff", "false") called at /opt/local/lib/perl5/site_perl/5.26/Tcl/pTk/Menu/Item.pm line 123
	Tcl::pTk::Menu::Cascade::PreInit("Tcl::pTk::Menu::Cascade", Tcl::pTk::Menu=HASH(0x7f8b0f6c3108), HASH(0x7f8b0e49ce58)) called at /opt/local/lib/perl5/site_perl/5.26/Tcl/pTk/Menu/Item.pm line 49
	Tcl::pTk::Menu::Item::new("Tcl::pTk::Menu::Cascade", Tcl::pTk::Menu=HASH(0x7f8b0f6c3108), "-label", "Import...", "-tearoff", "false") called at /opt/local/lib/perl5/site_perl/5.26/Tcl/pTk/MegaWidget.pm line 58
	Tcl::pTk::Menu::Cascade(Tcl::pTk::Menu=HASH(0x7f8b0f6c3108), "-label", "Import...", "-tearoff", "false") called at /opt/local/lib/perl5/site_perl/5.26/Tcl/pTk/Menu/Item.pm line 153
	Tcl::pTk::Menu::Cascade::cascade(Tcl::pTk::Menu::Cascade=ARRAY(0x7f8b0f6c3d20), "-label", "Import...", "-tearoff", "false") called at /Users/christopherchavez/git/HSW12/Perl/hsw12_gui.pm line 476
	hsw12_gui::create_main_window(hsw12_gui=HASH(0x7f8b0e004278)) called at /Users/christopherchavez/git/HSW12/Perl/hsw12_gui.pm line 4573
	hsw12_gui::build_gui(hsw12_gui=HASH(0x7f8b0e004278)) called at /Users/christopherchavez/git/HSW12/Perl/hsw12_gui.pm line 358
	hsw12_gui::new("hsw12_gui", undef) called at hsw12.pl line 71
 at /opt/local/lib/perl5/site_perl/5.26/Tcl/pTk/Menu/Item.pm line 123.

@chrstphrchvz
Copy link
Collaborator Author

Sorry if this discussion is becoming a bit unwieldy for a single issue, I might be inclined to split this into separate issues.

This effort is probably going to take a quite bit more debugging and polishing, but I haven't given up. I'm finding quite a few of the issues also apply to the modified widget demo program for Tcl::pTk, so I might use that as a starting point for correspondence with pTk. I think it would then be interesting to use HSW12 as a test case to help further improve pTk at the same time. I'll still try to incorporate any "safe" changes to the main branch and try adding a command-line option as you suggested.

  • I ran h2ph as the Can't locate sys/ioctl.ph in @INC error suggested, using some suggestions specific to macports. Now I can select the port and the terminal will say Connected to device... but not much else happens. Resetting the MCU doesn't show the D-Bug12 prompt, and typing anything in the terminal causes yet another error:
Tcl::pTk::Error: Can't call method "K" on an undefined value at /Users/christopherchavez/git/HSW12/Perl/hsw12_gui.pm line 1520.

    while executing
"if {$catchVal != 0} {
                        if { $retVal != "_TK_BREAK_\n" } { # BREAK returns are not errors
                                return..."
    (command bound to event)

 Error Started at hsw12.pl line 74.

 Stack Trace:
  at /opt/local/lib/perl5/site_perl/5.26/Tcl/pTk.pm line 898.
 	eval {...} called at /opt/local/lib/perl5/site_perl/5.26/Tcl/pTk.pm line 898
 	Tcl::pTk::DoOneEvent(Tcl::pTk=SCALAR(0x7fe8478f9fb0), 0) called at /opt/local/lib/perl5/site_perl/5.26/Tcl/pTk.pm line 876
 	Tcl::pTk::MainLoop() called at hsw12.pl line 74
  • There is a similar error for double clicking to edit the source code:
Tcl::pTk::Error: Can't call method "x" on an undefined value at /Users/christopherchavez/git/HSW12/Perl/hsw12_gui.pm line 2674.

    while executing
"if {$catchVal != 0} {
                        if { $retVal != "_TK_BREAK_\n" } { # BREAK returns are not errors
                                return..."
    (command bound to event)

 Error Started at hsw12.pl line 74.

 Stack Trace:
  at /opt/local/lib/perl5/site_perl/5.26/Tcl/pTk.pm line 898.
 	eval {...} called at /opt/local/lib/perl5/site_perl/5.26/Tcl/pTk.pm line 898
 	Tcl::pTk::DoOneEvent(Tcl::pTk=SCALAR(0x7fe6eab2d278), 0) called at /opt/local/lib/perl5/site_perl/5.26/Tcl/pTk.pm line 876
 	Tcl::pTk::MainLoop() called at hsw12.pl line 74
  • On the Mac, scrolling with the mouse wheel for ROText widgets (terminal, source code, and variables) only works when the mouse is over the scrollbar/trough and not the entire widget. The same happens with the ROText in the MainWindow of the widget demo.

  • I've noticed that some of the submenu labels are always black:
    screen shot 2018-03-26 at 4 43 42 am

    If the dark menu bar is enabled in System Preferences, then they aren't legible until hovered:
    screen shot 2018-03-26 at 4 44 11 am

    I think the cause might be related to how the menu is being constructed, since in the widget demo's menus example we see correct behavior for the toplevel menus but not submenus, and nearly the opposite for the menus2 example (which uses -menuitems).

    menus:
    screen shot 2018-03-26 at 3 56 56 am

    menus2:
    screen shot 2018-03-26 at 5 23 16 am

  • Windows don't move together as a group with Tcl::pTk on Mac.

  • The MainWindow is empty with Tcl::pTk. Should it be hidden?

  • For XQuartz (i.e. no Tcl::pTk) or non-macOS, the MainWindow has a bit of empty space under the menubar. I'm still figuring out my way around Perl/Tk, but there probably is a way to compact it automatically.
    screen shot 2018-03-26 at 5 35 00 am

@chrstphrchvz
Copy link
Collaborator Author

I've begun opening issues on the CPAN issue tracker for Tcl::pTk, including for some of the issues discussed here. I think some of the issues I might have a chance of resolving myself by looking through at Tcl::pTk::Widget or Tcl::pTk::Menu and seeing if there's any simple mistakes with how things are being translated from Perl/Tk syntax to Tcl/Tk. But for other issues, I probably want to get the maintainer's input on how to address, like for whether right-click should automatically adjust to using button 2 on macOS-aqua.

For now I have the MainWindow hidden (using $self->{gui}->{main}->withdraw) on macOS-aqua.

@chrstphrchvz
Copy link
Collaborator Author

I have been making progress on finding Tcl::pTk issues, as well as fixing some of the easier ones. But I think until the terminal is working and the Menubutton text color issue is addressed, I'm inclined not to have HSW12 try using Tcl::pTk automatically yet. I think once I get some changes documented they can be merged into the master branch.

Some of the issues in Tcl::pTk are "inherited" from either Perl/Tk or Tcl::Tk code that it borrows verbatim, for example binding to the correct mouse button for right- or middle-click events, or handling mousewheel scrolling correctly. So the fixes I've found for these in Tcl::pTk likely apply to Perl/Tk and/or Tcl::Tk: eserte/perl-tk#35. Though some other users of Tcl::pTk have reported issues which are caused by Perl/Tk having improved something but Tcl::pTk never having copied over the improvement.

The current maintainer of Tcl::pTk replied to one of the issues, and asked if I was interested in co-maintaining it since he doesn't currently have the resources to do so. I need to check again with him if he's still able to add me. https://rt.cpan.org/Ticket/Display.html?id=125050#txn-1784565

MacPorts let me add a port Tcl::pTk (p5-tcl-ptk) so that it doesn't have to be installed directly from CPAN, and I have included patches in the meantime: macports/macports-ports#2036

I had installed Tcl/Tk through MacPorts, so I thought I had been running Tcl/Tk 8.6.8. But it turned out that I was running Tcl/Tk 8.5.9, which is what is bundled with recent macOS versions. After bringing it up with MacPorts folks, we think the issue might be that their p5-tcl port (the Tcl.pm module) is finding the system Tcl/Tk instead of MacPorts Tcl/Tk. But then a few days ago I managed to get Tcl.pm to run using MacPorts Tcl/Tk, however I'm not sure how I got it working, nor do I know how to get it back to using Tk 8.5. So it may have been a problem on my specific MacPorts installation rather than MacPorts itself. https://trac.macports.org/ticket/56638

I wanted to make sure I could try the latest Tcl/Tk, in case any bugs I found in Tk 8.5.9 had been fixed. I think the only change I've noticed so far is that the CCR bits are now properly rendered as buttons rather than checkboxes, so there isn't an issue with them being crowded:

registers_tk8 6

I figured out why focusFollowsMouse didn't work, but even with it working the behavior is somewhat different under aqua than it is under X11. With X11, things such as another window's buttons or entry widgets will get focused if hovered over even if another window is currently in focus, but in aqua they only get focused if the window they're in is in focus.

I found that instead of using -width to shrink the ENTER, UPLOAD, and CLEAR buttons, setting -padx => 0 will let the buttons be sized automatically to the label text while leaving as much room as possible for the input Entry:

screen shot 2018-06-21 at 2 42 11 am
screen shot 2018-06-21 at 2 41 57 am

@chrstphrchvz
Copy link
Collaborator Author

I've been added as a co-maintainer for Tcl::pTk, and have posted a new version of Tcl::pTk (0.93) to CPAN containing fixes to some of the issues that I and other users have found.

The menubutton issue might be an upstream Tcl/Tk issue since I was able to find the issue from a Tcl/Tk program (gitk): https://rt.cpan.org/Public/Bug/Display.html?id=125049#txn-1795332

I'm not sure if I'll be able to get fileevent or an alternative working on macOS, but I'll keep talking with the maintainer of Tcl.pm for ideas: gisle/tcl.pm#14

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

No branches or pull requests

2 participants