TomKane has asked for the wisdom of the Perl Monks concerning the following question:
1) Is there some way to turn off the little Tk logo that appears on the caption bar? I'm sure it is not a significant issue for an end user to see it, but why have it on a production application if one can avoid it?
2) When I try to open a new main window via Toplevel, I get what amounts to a second application running, which results in a second icon on the task bar. All I'm trying to achieve is the equivalent of a modal dialog box. BTW, I'm using the form style placement of widgets in my frames.
3) This isn't Perl/Tk specific, but I feel dumb that I haven't figured out how to do this yet: is there a way to create a file of constants like a C ".h" file would contain?
All suggestions and feedback will be appreciated.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Perl/Tk Oddities
by Erez (Priest) on Apr 12, 2008 at 18:45 UTC | |
2) When I try to open a new main window via Toplevel, I get what amounts to a second application running use the Tk::Dialog or the Tk::DialogBox widget:
Software speaks in tongues of man. | [reply] [d/l] |
by TomKane (Beadle) on Apr 13, 2008 at 22:58 UTC | |
| [reply] [d/l] |
by TomKane (Beadle) on Apr 13, 2008 at 15:32 UTC | |
| [reply] |
Re: Perl/Tk Oddities
by Anonymous Monk on Apr 12, 2008 at 20:01 UTC | |
1) Is there some way to turn off the little Tk logo that appears on the caption bar? I'm sure it is not a significant issue for an end user to see it, but why have it on a production application if one can avoid it?This won't turn it off, but will replace the logo with one of your own, which might be blank to achieve the 'turned off' effect. In place of the -file attribute, one can use the -data attribute to use an xbm bitmap defined somewhere in your script. Here's a snippit of non-standalone code as an example.
| [reply] [d/l] [select] |
by TomKane (Beadle) on Apr 13, 2008 at 15:26 UTC | |
| [reply] |
Re: Perl/Tk Oddities
by moritz (Cardinal) on Apr 12, 2008 at 16:40 UTC | |
3) This isn't Perl/Tk specific, but I feel dumb that I haven't figured out how to do this yet: is there a way to create a file of constants like a C ".h" file would contain? Your best bet is to write them into a module. Or you can just dump them in a YAML or XML file and use a module to read those. | [reply] |
by TomKane (Beadle) on Apr 13, 2008 at 15:28 UTC | |
| [reply] |
Re: Perl/Tk Oddities
by TomKane (Beadle) on Jul 22, 2008 at 14:27 UTC | |
The problem with Tk::Dialog and Tk::DialogBox is that they both want to manage the closing buttons in a separate bottom section of the dialog box. From my understanding, there is no way to intercept the results of the bottom buttons. Actually, there is a built-in mechanism through the -command option, and that is where you can save data, etc. But once the bottom button is clicked, you can't cancel it (for example, if the user forgot to enter a critical field) and force the dialog to stay open. The good thing about Tk::Dialog and Tk::DialogBox is that they don't appear to create separate applications with icons showing on the bottom of the display (in Win32). This is despite the fact that both are derived from Tk::Toplevel. As I mentioned earlier, Tk::Toplevel provides a method for building completely functioning dialog boxes with total control of all widgets and processing. There is a drawback, however, in the fact that every Tk::Toplevel is treated by Tk as if it were a separate application, which shows up as an icon on the bottom of the display. The only workaround I've been able to come up with is to use the toplevel->withdraw() function in both the calling module (when it calls a module that has its own respective Toplevel) and then in the called module when it closes down. The crazy thing about this is that the callee must have a link back to the caller, i.e., a subroutine call, to tell the caller that the callee has completed its processing and withdrawn itself, and that it's time for the caller to deiconify() and raise() itself. The use of withdraw() in this way prevents the situation where there are multiple application icons. It's not perfect, however, as I can literally see the withdrawing of one module and the raising of another as the icons repaint themselves at the bottom of the display. But that's a small price to pay for having the control of the Toplevel serving as a dialog: I can completely manage the exiting process and I fully control the positioning of all widgets within the Toplevel (whereas with Tk::Dialog and Tk::DialogBox I have no control of the button placement). If anyone has any suggestions or insights where I may be making a mistake or may be overlooking some option that might make the Tk::Dialog and Tk::DialogBox processing work better, please let me know. Thanks. Tom | [reply] |
by zentara (Archbishop) on Jul 22, 2008 at 16:57 UTC | |
In Gtk2, the preferred method is to wrap the dialog like this. It can be done because the destroy is handled by you outside of the Dialog object. Thanks to muppet and Mathew Braid, for showing me this. It may be possible to subclass the Tk::Dialogbox, and override the default button presses. It has the wait Show and exit methods available, so you should be able to redefine them in a subclass, use You can google for Tk::Derived and find examples how to do it. Basically you just make a package called MyDialog, copy the Show() sub from the Dialogbox.pm into it, and modify it to your liking. You will see where I got the idea for my code in the Dialogbox.pm. :-) Probably the best solution, is to emulate Gtk2's wrapping of the dialog, by redefining exit() in your subclassed DialogBox, so it is controlled from outside the object. I'm not really a human, but I play one on earth Remember How Lucky You Are | [reply] [d/l] [select] |
by TomKane (Beadle) on Jul 23, 2008 at 09:33 UTC | |
As I was formerly a C++ programmer, I am familiar with the concept of overriding functionality. I just hadn't done it in Perl and had been hesitant to start digging down to that level when it came to base functionality of the language. But I started looking into some of the DialogBox.pm code and then discovered XDialogBox.pm. As I was looking at that bunch I discovered that whenever I used an XDialogBox widget, it always resulted in having an extra icon at the bottom of the screen, which is exactly what I've been trying to avoid. Then I saw that there were a couple of commented out lines of code and tried uncommenting them. It turns out that the Toplevel->transient() function was one of them and when I turned it back on, voila, no icon. So, the quick and simple answer to my long search was there all along. Even in "Mastering Perl/Tk", Lidie doesn't mention that particular functionality (the index has the wrong page number, it's really p. 246) for making a new Toplevel appear as a part of the main. That is, the new Toplevel is a "transient" but detached widget within the "master" module that opened the new Toplevel. Now the fun begins, however, because if I use a Toplevel as a dialog box, then I have to have a button or something that will "close" the dialog -- which is done really with the withdraw() function. But this doesn't tell the "master" module that it's closed. As long as the "master" is itself a module and can have a function accessible to the transient Toplevel, the latter can call the former with the message that it (the transient Toplevel) has "closed". I better look into the grab() methods now. Thanks again. Tom | [reply] |