Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

SOLVED - TK: How to change color of readonly BrowseEntry

by mrider (Sexton)
on Oct 04, 2012 at 19:29 UTC ( #997298=perlquestion: print w/ replies, xml ) Need Help??
mrider has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks,

Background: I'm writing a simple tool that offers end users a number of pre-packaged ad-hoc reports. This tool is to be used in Windows. I started off with the idea of using Win32::GUI (because it has a better native LNF) - but after a considerable amount of wailing and thrashing, I'm starting to wonder if perhaps that isn't where I want to be (more explanation below).

So now I'm working on rewriting the GUI portion in Tk. It's taken me a while, but I'm starting to get a handle on how to layout my widgets and how to get them to behave. I do however have one problem: I'm simulating a Windows read-only combobox using a Tk::BrowseEntry that has the state option set to readonly. However, everyone that I've shown mockups to thinks the entire dropdown is disabled, not just the edit function. The edit portion is the same color as the window background, and the text is a lighter color.

I understand why the author did the LNF like that and I don't necessarily disagree. My concern is that my users will think the whole widget is disabled, rather than just the edit portion (based on my user testing). So for my specific window, I'd like for the edit portion to BE disabled, but not LOOK disabled. If you'll forgive the ASCII art, below is what I'm looking for.

------------------------------------- Chooser: | Foo (how to make this white?) |V| ------------------------------------- | Foo | | Bar | | Bas | ---------------------------------

I can figure out how to change everything except the part where it says "(how to make this white?)" to a different color. In the code sample below I've made everything red, since red jumps out at me. The color is not important - what is important is that the one section I want to change is the only section that doesn't change.

#!/usr/bin/perl use strict; use Tk; use Tk::BrowseEntry; my $mw = MainWindow->new(); $mw->geometry("300x300+100+100"); my @choices = ("Foo", "Bar", "Bas"); my $dd_value; my $dd = $mw->BrowseEntry( -label => 'Chooser', -variable => \$dd_value, -state => 'readonly' )->pack(); foreach my $choice (@choices) { $dd->insert('end', $choice); } $dd_value = $choices[0]; $dd->Subwidget('entry')->configure(-bg => "#FF0000"); $dd->Subwidget('arrow')->configure(-bg => "#FF0000"); $dd->Subwidget('choices')->configure(-bg => "#FF0000"); $dd->Subwidget('slistbox')->configure(-bg => "#FF0000"); #What else can I configure to a different color?? MainLoop;

So is there another exported widget that I can't find? Or maybe I should be using a different widget (e.g. something other than BrowseEntry)? I'm even willing to edit the original Perl module if necessary. I'll just add the edit to the instructions regarding how to install Perl onto a development machine.

[More explanation]
  1. Win32::GUI has some odd behavior. For example, all of my widgets start with a flat "XP" style, but one of them changes to the older indented style when I change values in a completely different widget.
  2. CPAN's Win32::GUI appears to be unmaintained. For example, if you download the code from CPAN you'll need to immediately edit line 101 and change it from "if($[ < 5.008000) {" to "if($] < 5.008000) {". How could they not notice that problem?
  3. General lack of documentation. Far too many entries are simply [TBD] for my taste.

 

 

I don't know if all the anonymous monks were the same monks or not. But the suggestion about trying JBrowseEntry helped. The page for JBrowseEntry doesn't mention this, but looking down through the source code for the module I found a place where the code looks at the -disabledforeground and -disabledbackground options. On a lark, I tried that in BrowseEntry as well, and it works there. In fact I'd say that JBrowseEntry is worth having around as much to see what all options are available as anything. Anyway the answer is:

my $dd = $mw->BrowseEntry( -label => 'Chooser', -variable => \$dd_value, -state => 'readonly' -disabledforeground => '#000000', -disabledbackground => '#FFFFFF', )->pack();

Comment on SOLVED - TK: How to change color of readonly BrowseEntry
Select or Download Code
Re: TK: How to change color of readonly BrowseEntry
by Anonymous Monk on Oct 04, 2012 at 19:39 UTC

    Win32::GUI has some odd behavior. For example, all of my widgets start with a flat "XP" style, but one of them changes to the older indented style when I change values in a completely different widget.

    Hmm, sounds fishy :) but I've seen weirder :)

    How could they not notice that problem?

    Because it isn't much of a problem :)

    Checking perl version is the wrong way to check for File::Spec version, File::Spec had a verion number even in 5.005 in 1998 :)

    General lack of documentation. Far too many entries are simply TBD for my taste.

    It has way too much documentation if you ask me :) Its just a thin wrapper around MFC, all the real documentation is on MSDN, how things should be have, all that

      Considering that the module doesn't work unless one edits that line - I'd say it's a problem...

      PLUS, all they have to do is download the module and install/use it once. It'll frikkin jump out and bite them on the donkey!

        Considering that the module doesn't work unless one edits that line - I'd say it's a problem...

        Oh really? http://cpansearch.perl.org/src/ROBERTMAY/Win32-GUI-1.06/Win32-GUI-BitmapInline/BitmapInline.pm

        if($[ < 5.008000) { $tmpfile =~ /^(.*)$/; $tmpfile = $1; }

        So it always untaints $1, I don't see how that could break anything

        PLUS, all they have to do is download the module and install/use it once. It'll frikkin jump out and bite them on the donkey!

        This is why you ought to make life easy :) make your own distribution :) its easy

Re: TK: How to change color of readonly BrowseEntry
by Anonymous Monk on Oct 04, 2012 at 19:43 UTC

    I'm even willing to edit the original Perl module if necessary. I'll just add the edit to the instructions regarding how to install Perl onto a development machine.

    That sounds icky :) If you need to modify behaviour, copy/paste/rename and make your own changes

    As for iinstallation, you might as well release a binary distribution using http://sourceforge.net/projects/citrusperl/ or binaries using http://www.cavapackager.com/ or perlapp or even PAR/pp

      I agree it's not my first choice - but I'm willing to go to those lengths if I have to. Don't want to. Will if I have to.
Re: TK: How to change color of readonly BrowseEntry
by Anonymous Monk on Oct 04, 2012 at 19:49 UTC
    What do you mean by LNF?
      Sorry: Look And Feel.
        Make that Look aNd Feel :(
Re: TK: How to change color of readonly BrowseEntry
by Anonymous Monk on Oct 04, 2012 at 19:50 UTC
      I'll give it a shot. Thanks!

        Actually, I got a clue how to do this reading the source code for JBrowseEntry:

        my $dd = $mw->BrowseEntry( -label => 'Chooser', -variable => \$dd_value, -state => 'readonly' -disabledforeground => '#000000', -disabledbackground => '#FFFFFF', )->pack();
Re: SOLVED - TK: How to change color of readonly BrowseEntry
by Sandy (Curate) on Oct 04, 2012 at 21:45 UTC
    This works on unix and windows
    #!/usr/bin/perl use strict; use warnings; use Tk; use Tk::BrowseEntry; my $update = "hello"; my $mw=MainWindow->new(); my $bb = $mw->BrowseEntry( -variable => \$update, -state=>'readonly', -disabledbackground=>'red' )->pack; $bb->insert( 'end', qw(one two three) ); MainLoop;
    UPDATE: You found the answer before me.

    PS: I got the answer from the CPAN description of Entry (which is a sub-widget of browse entry)

      I got the answer in a very round about way. So your answer is appreciated even though I already had an answer, since I now know how to get the answer. Said another way, you improved my knowledge. Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://997298]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2014-11-23 12:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (131 votes), past polls