Interface with 64 toggleable elements: what's the best way?



Hi, folks--

I'm a longtime Tk user who's decided to make the jump to Gtk+ for the
newest project.  I've run into an interface design issue that I hope
someone can offer some help with.

I'm designing a GUI that will allow the user to specify two 32-bit
hexadecimal numbers, a "mask" and a "value".  (These numbers will be
applied as a test to some arbitrary integer X; the test succeeds if
the expression "(X & mask) == value" is true.)  I want the interface
to allow the user to specify both numbers by entering the hex numbers
directly, and/or by toggling individual bits.  I have in mind
something like the following:

            33222222222211111111110000000000
            10987654321098765432109876543210
mask bits:  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.x
value bits: ......................xx.......x

Hex mask:  |_0xfffffffd_|
Hex value: |_0x00000301_|

The "hex mask" and "hex value" elements are text entry widgets.  The
upper portion of the interface is currently laid out using a 33x4
table.  The "x" and "." characters represent some kind of toggle-able
element.  Changes to the hex strings are to be reflected immediately in
the toggles, and vice versa.

My quandary is in choosing a toggle-able element to represent the
bits.

I initially rejected a checkbutton widget, assuming it would be too
wide; I need something which is no wider than the digit characters
above it.  (OK, I just checked and found that this is indeed the
case.)

My first attempt was to represent the bits as empty label widgets,
which I could "toggle" by flipping the background colors.  I then
discovered that setting background colors isn't as trivial with Gtk+
as it is with Tk.  My efforts were complicated by the fact that style
operations seem to have gone through a great deal of flux; no
documentation I could find seemed to exactly match my version of Gtk+
(1.2.8), and I often had to dive into the source to figure out what
was what.  I eventually came up with the following (I'm using the Perl
bindings, btw):

my $style = Gtk::Style::copy(Gtk::Widget->get_default_style());
my $white = Gdk::Gdk::Color->parse('white');
$style->fg('normal', $white);
Gtk::Widget->push_style($style);
#  create some labels

I was able to create labels with white text using this method, but
when I changed the "fg" to "bg", the labels did not have white
backgrounds.  I tried many different code permutations, but without
any success, so I gave up on that idea.

My next idea was to represent the bits as pixmaps: an empty circle for
a clear bit, and a filled circle for a set bit.  I want my program to
be completely standalone, so now I'm trying to create a pair of
textual xpm's that look like decent circles, which isn't completely
trivial.

I could keep slogging on, but I thought I would first ask you folks
for some advice.  Besides the two above approaches, I thought of two
others.  The first is to represent each bit as a canvas widget onto
which I'd draw (say) filled or empty circles or rectangles.  This
would involve asking the canvas for its current size, which, at least
under Tk, was always a somewhat dicey proposition.  The other was to
change my current 33x4 table into a single canvas widget, onto which
I'd draw everything: labels, set bits, and clear bits.

Are any of my ideas workable, or is there a better way?  Thanks in
advance for any help.


-- 
Sean McAfee
etzwane schwag org



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]