Wednesday, November 13, 2013

gnocl::widget - new command 'attach'

The menu widget allows for the organization of menu items into rows and columns. This can now be achieved using the 'attach' sub-command. Where required, menu items can be allow to span multiple rows or columns. The syntax for this this command is:

<widget-id> attach <menuitem-id> row col <options>

The possible options are -rowSpan (int) and -colSpan (int). 

Menu items are only expanded to fill actual rows and columns. So, if the last item requests a spacing of 2 rows, it will only be allocated the space required for its default rendering.

Modifications available in nightly build.

The following test code shows this in operation:

# test-menu-attach.tcl
#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"


package require Gnocl

set menu [gnocl::menu]

$menu add [gnocl::menuItem -text "%#New" -onClicked {puts "That's new"}]
$menu add [gnocl::menuSeparator]
$menu add [gnocl::menuItem -text "%#Quit" -onClicked exit ]

set file [gnocl::menuItem -text "%__File" -submenu $menu]

set menu [gnocl::menu]

$menu add [gnocl::menuItem -text "%__About" -onClicked {puts "Menu example"}]

set help [gnocl::menuItem -text "%__Help" -submenu $menu]
set box [gnocl::box -orientation vertical -borderWidth 0 -spacing 0]


set extras_menu [gnocl::menu]
set extras  [gnocl::menuItem -text "%__Extras" -submenu $extras_menu]

$box add [gnocl::menuBar  -children [list $file $help $extras]]

set em(1) [gnocl::menuItem -text FIRST]
set em(2) [gnocl::menuItem -text SECOND]
set em(3) [gnocl::menuItem -text THIRD]
set em(4) [gnocl::menuItem -text FOURTH]
set em(5) [gnocl::menuItem -text FIFTH]
set em(6) [gnocl::menuItem -text SIXTH]
set em(7) [gnocl::menuItem -text SEVENTH]
set em(8) [gnocl::menuItem -text EIGTH]
set em(9) [gnocl::menuItem -text NINTH]

$extras_menu attach $em(1) 0 0
$extras_menu attach $em(2) 0 1
$extras_menu attach $em(3) 1 0 -colSpan 2
$extras_menu attach $em(4) 2 0
$extras_menu attach $em(5) 3 0 -rowSpan 2
$extras_menu attach $em(6) 4 1
$extras_menu attach $em(7) 5 0 -rowSpan 2 -colSpan 2
$extras_menu attach $em(8) 5 2
$extras_menu attach $em(8) 6 2

gnocl::window  -child $box -setSize 0.2

gnocl::mainLoop



Saturday, November 09, 2013

gnocl::tree & gnocl::list -highlighting columns

Its possible to use Ctrl-F to launch an interactive search of entries contained within a tree or list view. Prior to any search, however, the column needs to be preselected. This mornings coding session has fixed a couple of issues within the gnocl core modules to enable this process to be done interactively under Tcl control. A single click on a cell in an view can now result in the column being preselected and highlighted. The following example script shows how its done. Get the nightly build for all the updates.

# test-me.tcl
#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

package require Gnocl

set chn2indic:mappings(conjuncts) {
阿呵 āha
阿訶 āha
爍鉢 śva
悉吉利 skri
室佛 śva
地利 dhri
穆帝 mukta
佛囉 pra
帝利 tre
}

#---------------
# view and edit specific lists
#---------------
#
proc chn2indix:view:call_back {w c} {
    set last [$w cget -searchColumn]
    $w columnConfigure $last -background white
    $w columnConfigure $c -background grey
    $w configure -searchColumn $c

    # force window refresh, Gtk+ has some internal issues here!
    if {$last != $c} {
        [gnocl::winfo toplevel $w ] grabFocus
    }
}


#---------------
# view and edit specific lists
#---------------
#
proc chn2indix:view { set } {

    global chn2indic:mappings

    set vbox [gnocl::vBox]
    set tbar [gnocl::toolBar]
    set lst [gnocl::list -types {string string} -baseFont {Sans 14} -data {0} ]
    set hbox [gnocl::hBox ]
    set but(1) [gnocl::button -text Accept]
    set but(2) [gnocl::button -text Cancel]
    set stat [gnocl::statusBar]

    # add toolbar widgets
    $tbar add item -text "%#New"

    $lst columnConfigure 1 -editable 1 -background grey
    $lst configure -onSelectionChanged {puts "%p"} -searchColumn 1
   
    # atttempt to highlight selected column   
    $lst configure -onButtonRelease {
        set col [lindex [%w coordsToPath %x %y] 1]
        chn2indix:view:call_back %w $col
     
    }

    $vbox add $tbar  -fill {1 0} -expand 0
    $vbox add $lst -fill {1 1} -expand 1
    $hbox add $but(2) -align right -fill {0 1} -expand 0
    $hbox add $but(1) -align right -fill {0 1} -expand 0
    $vbox add $hbox -fill {1 0} -expand 0 -align right
    $vbox add $stat -fill {1 0} -expand 0

    # populate the list
    set i 0
    foreach {a b} [set chn2indic:mappings($set) ] {
        $lst add [list $a $b] -singleRow 1
        incr i
    }

    $stat push "$i items in the current list."

gnocl::window -child $vbox -width 200 -height 400 -x 950 -y 200

}

chn2indix:view conjuncts



Friday, November 08, 2013

gnocl::tree boolean toggling -solved!

Just completed the job of bringing the button toggling into the main code module. Took longer than I anticipated. The logic of it all was straight forward but, for some unknown reason, the Gtk+ libraries kept rejecting booleans typed variables for the value setting! So, these were set to uint and all works well!



gnocl::tree issues around toggling booleans

The gnocl::tree and gnocl::list widgets automatically set tick boxes for columns identified as containing boolean data.  The present distribution (0.9.96) will cause a warning if a tree view is created, data added but no callback script set for the column containing the toggle item. Furthermore, the Gtk library code does not automatically toggle the cell widget anyway! This is something to add into the gnocl core and so I've added this to the 'todo' list.

So, when a script has the following type of widget declaration...

set tree [gnocl::tree \
-treeLines 1 \
-ruleHint 1 \
-types {string boolean} \
-titles {"Mapping Source" "Select"}]

Make sure that this configuration follows immeadiately...

$tree columnConfigure 1 -onToggled {
if { [%w get %p %c] } {
%w cellConfigure %p %c -value 0
} else {
%w cellConfigure %p %c -value 1
}
}



Saturday, October 19, 2013

gnocl::text tag rollover effects

Suprisingly, to me at least, tag rollover is not standard feature of the GtkTextTag. I've had Tcl a solution for some time now but always felt that this needed to be moved in to the package code itself. Whilst implementing rollover effects isn't difficult, matters would be made easier if the widget internals offered tag signals which tracked motion in and out of the tag rather than giving the simpler 'event' event binding. Well, its sorted now and the following test script illustrates how it works. There's a little more tweeking that can be done to the source code to allow similar changes to the rollover tag background colour. Finally,  runtime changes to the rollover colour setting (default = red) for the script will affect all instances of text widgets within a script.

# tagRollover.tcl

#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

package require Gnocl

set text [gnocl::text ]

$text configure -rollOverColor red

# whenever the pointer moves, clear any rollOver highlight
 $text configure -onMotion { #puts MOTION }


for {set j 0} {$j <= 5 } {incr j} {
 # create new, rollOver tag
 $text tag create _tag_rollOver_$j -rollOver 1 -fontWeight bold -foreground blue -onEvent {puts "HELLO!"}

 # use it
 $text insert end "This is "
 $text insert end "Gnocl tag $j" -tags _tag_rollOver_$j
 $text insert end "! \n"
}

gnocl::window -title "Text TagRollover Effects" -child $text -setSize 0.25
gnocl::mainLoop


Wednesday, August 28, 2013

gnocl::label -last of the signal bindings done!

Just added the last two signal bindings for this widget.
-onActivateCurrentLink
-onActivateLink
Nightly build updated.

Tuesday, August 27, 2013

gnocl::label -more options added

With the ability to copy text from the label widget being added, the widget can report a number of events. Those added today include: -onPopulatePopup, -onCopyClipboard, -onMoveCursor.

Available in today's 'nightly-build'.



Thursday, July 25, 2013

Running the Gnome 'yelp' Help System from Tcl/Gnocl applications.

I implemented some yelp help pages a while ago for my major app. After installing, however, the pages would load but not the graphics. When calling yelp all that needs to be passed is the directory containing all the pages, graphics, media etc. that are part of the help. To resolve this I resorted to launching a separate shell script to handle the help system. So, good-bye to:

set app(baseDir) $ENV(home)/help
exec yelp $app(baseDir)/help &


and hello to

exec my_yelp.sh &

Where my_yelp.sh is nothing more complex than

cd $HOME/help
yelp ./



Saturday, July 13, 2013

Its a lot of work!

Decided add to the ability to get more feedback from the gnocl package. The implementation of the cget command across the various widgets is still a little patchy and I've just added a new command, 'options' to all the widgets which will return a list of valid switches. With well over 50  modules to update this is a lot of work! Its taken me about 5hrs so far!
Following that I will add a similar command to obtain the valid widget and contents (e.g. text tags) sub-commands. For some widgets with just a handful of options and commands it something of an overkill but, then comes the task of updating the documentation.
I've completed most of the support in place for using pango markup strings in the text widget. The set of available tags is pre-defined, but quite extensive. Just a little more work in this area before the handling of <span.. </span> will work properly. Added this is a new toolbar with all the necessary buttons for the pango markup in place.


Monday, July 01, 2013

Dockable side toolbars

Gtk offers a dockable toolbar but this cannot be re-docked elsewhere on screen. The screenshot below shows a possible workaround using notebook groups. As the toolbar must be configured as either horizontal or vertical whenever a new page is dropped onto a notebook, then the toolbar will be automatically re-oriented. The accompanying script is basically for proof of principle rather than a realistic package.





proc addToolBarItems {tb} {
    foreach item {Open Close New Cut Paste Copy} {
        $tb add item -icon %#$item
    }
}


set container [gnocl::box]
set table [gnocl::table]
$container add $table -fill {1 1} -expand 1

set nb(1) [gnocl::notebook -groupId 1 -onPageAdded { %c configure -orientation %d } -data horizontal]
set nb(2) [gnocl::notebook -groupId 1 -tabPosition left -onPageAdded { %c configure -orientation %d } -data vertical]
set nb(3) [gnocl::notebook -groupId 1 -tabPosition right -onPageAdded { %c configure -orientation %d } -data vertical]
set nb(4) [gnocl::notebook -groupId 1 -onPageAdded { %c configure -orientation %d } -data horizontal]
set box(1) [gnocl::box -orientation vertical]

$table add $nb(1) 0 0 -columnSpan 3 -expand 0 -fill {1 0}
$table add $nb(2) 0 1 -expand 0 -fill {0 1}
$table add $box(1) 1 1  -expand 1 -fill {1 1}
$table add $nb(3)] 2 1 -expand 0 -fill {0 1}
$table add $nb(4) 0 2 -columnSpan 3 -expand 0 -fill {1 0}

$box(1) add [gnocl::text] -fill {1 1} -expand 1

set tb(1) [gnocl::toolBar -style icons]
set tb(2) [gnocl::toolBar -style icons -orientation vertical]
set tb(3) [gnocl::toolBar -style icons -orientation vertical]
set tb(4) [gnocl::toolBar -style icons]

addToolBarItems $tb(1)
addToolBarItems $tb(2)
addToolBarItems $tb(3)
addToolBarItems $tb(4)

$nb(1) addPage $tb(1) "TB1"
$nb(2) addPage $tb(2) "TB2"
$nb(3) addPage $tb(3) "TB3"
$nb(4) addPage $tb(4) "TB4"

gnocl::window \
    -child $container \
    -setSize 0.3 \
    -title test-side-toolbars
   

Recent Enhancements

Added the following enhancements to the nightly build code.

2013-07:
   gnocl::notebook
        o new options
            -data
        o added extra percentage subtitution strings to -onPageAdded, -onPageRemoved
            %c child
            %n page number
            %d data

2013-06:
    gnocl::toolBar
        o configure/cget -orientation now works

Monday, May 27, 2013

gnocl::label cget

Fixed bug that appeared in the label widget cget subcommand after the move over to using LabelParams in the source code. At the moment cget -text returns the text without markup. Next step is to test for markup and return markup string if applicable.

Wednesday, May 15, 2013

gnocl::box remove command debugged

Problems with the remove child command resolved. This will be more useful when toggling the display of UI items. If the -visible option is used to manipulate object, space will still be allocated for the hidden object. This may be acceptable at times, but in large, complex layouts hiding already packed widgets may alter the overall window sizing or affect the relative sizing of other containers such as the gnocl::paned widget.

Test script:

#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

package require Gnocl

proc swap_parent {w} {
    global box
   
    set p [$w parent]
    if {$p eq $box(1)} {
        $box(1) remove $w
        $box(2) add $w -fill {1 1} -expand 1
    } else {
        $box(2) remove $w
        $box(1) add $w -fill {1 1} -expand 1
    }
}
 

set box(1) [gnocl::box]
set box(2) [gnocl::box]

set win(1) [gnocl::window -title "Window #1" -x 100 -child $box(1) -width 200 -height 100]
set win(2) [gnocl::window -title "Window #2" -x 400 -child $box(2)  -width 200 -height 100]


set but(1) [gnocl::button -text "Click-Me!" -onClicked {swap_parent %w}]

$box(1) add $but(1) -fill {1 1} -expand 1


Tuesday, May 14, 2013

gnocl::label new options -background and -foreground

Spent a couple of hours today hacking this feature together. Ordinarily the base colour of a label is defined by the system style and can be overidden. Alternatively, it's possible to use markup strings. But... what if the text is set through a traced variable?
It is possible to modify the default pango settings for the label and modify these during runtime. It was fiddly to implement but now it works. To achieve similar result in the past required embedding the label into an eventBox.

Here's some demo code...


#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

package require Gnocl

set lab [gnocl::label -text hello -baseFont {Sans 25} -foreground white -background blue]
set box [gnocl::eventBox -child $lab -background red]
gnocl::window -child $box -setSize 0.125


Thursday, April 11, 2013

Recent Code Changes

Haven't posted anything to the blog recently, so here's a summary of the code changes made over the past month.

gnocl::box
added commands, reorder, addStart
corrected bugs in addBegin command

gnocl::paned
fixed bug in -onHandleMoved option
new options
-onButtonPress
-onButtonRelease
-tooltip

gnocl::expander
new option
-onActivate

gnocl::text
resolved problems with tag sub-command "ranges"

Monday, March 11, 2013

New megawidget gnocl::richtextToolBar

A while ago added I development code to handle pango markup in gnocl::text widgets. The next step, I felt, was adding a toolbar megawidget which would do all the necessary widget application with no extra scripting. Its working fine so far. I'll need to create some custom icons for the buttons and compile these into the sources but this should be straightforward. Perhaps the name of widget needs revising, its a bit too long. Anyway, here's my test script.

#--------------------------
# test_gtk_richTextToolBar.tcl
#--------------------------
#!/bin/sh
#\
exec tclsh "$0" "$@"

package require Gnocl

set txt [gnocl::text -wrapMode word -markupTags 1]
set rtbar [gnocl::richTextToolBar -text $txt]
set vbox [gnocl::vBox]

$txt lorem

$vbox add $rtbar
$vbox add $txt -fill {1 1} -expand 1

gnocl::window -child $vbox -setSize 0.3

Tuesday, March 05, 2013

Converting between different colour formats

Excluding the use of named Unix colours, Gtk+ employs three numeric ways of describing colours: rgb, hex and decimal. The choice of modes is largely determined by the library being wrapped. Cairo, for instance, only accepts colours in decimal formats. Some conversion is handled in the gnocl sources but, here's a package of proc which will convert between all three formats and also make allowances for the extra alpha channel.

#---------------
# colour-conversions.tcl
#---------------
# William J Giddings
# 04-Mar-2013
#---------------
# Notes:
# Manipulate colour expresions.
#---------------

#---------------
# convert integer RGBA values to hexadecimal
#---------------
#
proc RGB2hex {clr} {    
    if { [llength $clr] == 4 } {
        scan $clr "%d %d %d %d" r g b a
        return [format "#%02x%02x%02x%02x" $r $g $b $a]
    } else {
        scan $clr "%d %d %d" r g b
        return [format "#%02x%02x%02x" $r $g $b]  
    }
    return -1
}

#---------------
# convert hexadecimal values to RGBA
#---------------
#
proc hex2RGB {clr} {
    scan [string range $clr 1 2] %x R
    scan [string range $clr 3 4] %x G
    scan [string range $clr 5 6] %x B

    if {[string length $clr] == 7} {
        return "$R $G $B"
    } else {
        scan [string range $clr 7 8] %x A
        return "$R $G $B $A"
    }
    return -1
}



#---------------
# express value in range as decimal between 0 and 1
#---------------
#
proc unitize {val {range 255} {places 3}} {    
    return [format "%1.${places}f" [expr ${val}.0/$range]]
}

#---------------
# convert integer RGBA list to Cairo decicmal colours
#---------------
#
proc RGB2Dec {clr} {
    if { [llength $clr] == 3} {    
        scan $clr "%d %d %d" r g b
        set r [unitize $r]
        set g [unitize $g]
        set b [unitize $b]  
        return "$r $g $b"
    } else {
        scan $clr "%d %d %d %d" r g b a
        set r [unitize $r]
        set g [unitize $g]
        set b [unitize $b]
        set a [unitize $a]
        return "$r $g $b $a"
    }

    return -1

}

#---------------
# convert hexadecimal colour values to Cairo decicmal colours
#---------------
#
proc HEX2Dec {clr} {
    return [RGB2Dec [hex2RGB $clr]]
}

#---------------
# convert decimal colour to RGB
#---------------
#
proc Dec2RGB {clr} {
    if {[llength $clr] == 3 } {
        scan $clr "%f %f %f" r g b
        set r [format %d [expr int($r * 255)]]
        set g [format %d [expr int($g * 255)]]
        set b [format %d [expr int($b * 255)]]
        return "$r $g $b"
    } else {
        scan $clr "%f %f %f %f" r g b a        
        set r [format %d [expr int($r * 255)]]
        set g [format %d [expr int($g * 255)]]
        set b [format %d [expr int($b * 255)]]
        set a [format %d [expr int($a * 255)]]        
        return "$r $g $b $a"
    }
    return -1
}

#---------------
# convert decimal colour to hexadecimal
#---------------
#
proc Dec2Hex {clr} {
    if {[llength $clr] == 3 } {
        scan $clr "%f %f %f" r g b a    
        set r [format %d [expr int($r * 255)]]
        set g [format %d [expr int($g * 255)]]
        set b [format %d [expr int($b * 255)]]        
        return [format "#%02x%02x%02x" $r $g $b]    
    } else {
        scan $clr "%f %f %f %f" r g b a        
        set r [format %d [expr int($r * 255)]]
        set g [format %d [expr int($g * 255)]]
        set b [format %d [expr int($b * 255)]]
        set a [format %d [expr int($a * 255)]]        
        return [format "#%02x%02x%02x%02x" $r $g $b $a]
    }
    return -1
}

#---------------
# test
#---------------
set color [RGB2hex "255 255 255"]
puts "1    $color"
set color [RGB2hex "255 255 255 128"]
puts "2    $color"
puts "3    [hex2RGB $color]"
puts "4    [RGB2Dec "255 255 255 127"]"
puts "5    [HEX2Dec #FF0000]"
puts "6    [Dec2RGB "1.0 1.0 1.0 0.5"]"
puts "7    [Dec2Hex "1.0 1.0 1.0 0.5"]"
 

Wednesday, February 20, 2013

Automating the widget creation process.

I spent a couple of hours this morning working out a Tcl script that will create the basic components for custom widgets. There are so many repetitive elements converting a few hundred lines of C code which, if one has to edit it all by hand, takes up too much time. I'm also quite notorious for being unable to spot spelling and grammar errors and so any extra help is always welcome. The way in which the module generator works is create create a sub-directory in the src folder, create the necessary *.h, *.c and readme (working on the autodocs pages next) and then patches the Makefile and the files gnocl.c and gnocl.h in readiness for the first compile.

When I've got this to work properly, moving the whole lot into a separate, standalone Tcl/Gnocl app would be the best next move. In this case the main gnocl package can give bindings to the core Gtk+ widget set and any custom extras in a unique package that can be loaded as required.

Saturday, February 16, 2013

gnocl::level

This morning I took a look at the task of adding more custom widgets to the gnocl tool-kit. What has always capture my imagination is the 'recording' and 'playback' level indicators typically found in sound recording apps. Now, I've no real idea of what should be looked for in such widget other than it should flash on and off, rise up and down and occasionally go into a red zone. So, I've added some experimental code to see how it should be pieced together and it looks like fun. There is still some way to go in order to make all the options configurable and the widget resizeable. If anyone's interested in the making serious use of it, please give me feedback and then I can enhance the code in a more meaningful way. Here's a screen shot and demo script.



# test-level.tcl

#!./bin/sh
#\
exec tclsh "$0" "$@"

package require Gnocl

proc display {} {
    global lev
    set hb(1) [gnocl::hBox]
        for {set i 0} {$i<20} {incr i} {
            set lev($i) [gnocl::level]
            $hb(1) add $lev($i) -padding 0
            $lev($i) set [expr $i * 10]
        }

    set eb [gnocl::eventBox -background black -child $hb(1)]
    return $eb
}


proc draw {} {
    global lev
        for {set i 0} {$i<[array size lev]} {incr i} {
            set val [expr 50+ int ( rand() * 50) ]
            $lev($i) set $val
       
        }

    after 100 draw
}

gnocl::window -child [display]
draw


Sunday, February 10, 2013

gnocl::labelEntry

The currently nightly build has code for some useful megawidgets which yet need fully documenting. One of these is the gnocl::labelEntry. Apart from having a label and entry the re is also the possibility of adding a child widget. This type of object can certainly be made in gnocl from simpler components, but this higher level of abstraction just makes life that much easier!

Here's a screen shot and sample script.



# test-le.tcl
#!/bin/sh \
exec tclsh "$0" "$@"

package require Gnocl

set app(find,regexp) 1

set cb(1) [gnocl::checkButton \
    -text "regexp" \
    -variable app(find,regexp)]

set le(1) [gnocl::labelEntry \
    -text "Search For:" \
    -variable app(find) \
    -primaryIcon "%#Paste" \
    -secondaryIcon "%#Clear" \
    -onIconPress {puts "Yo!"}]
       
$le(1) configure \
    -child $cb(1)       

gnocl::window \
    -child $le(1) \
    -title "gnocl::labelEntry"



Saturday, February 09, 2013

Switching the display of the Gnome desktop icons.

I am a minimalist. Some clutter makes be uncomfortable and lots of its makes me utterly confused. So, when it gets to the point where my desktop has a mountain of icons on it something has to go -its usually my temper but those icons can be hidden. The usual approach is to dig into the Gnome Configuration Editor to switch the Nautilus preferences. That's fine once or twice, but what if we want immediate de-clutter? The gnoclGconf package offers a solution. Here's a simple script to handle the job.



# toggle desktop icons

#!./bin/sh
#\
exec tclsh "$0" "$@"

package require Gnocl
package require GnoclGconf

gnocl::gconf set /apps/nautilus/preferences/show_desktop \
    [gnocl::toggle [gnocl::gconf get /apps/nautilus/preferences/show_desktop] ] \
    -type boolean

exit


Dropping this into my $HOME/bin directory means that I can use this as a command from any terminal. For more convenience I've added a panel launcher. So, now we see it, now we don't! Bye bothersome icons, hello helpful icons!
 

Sunday, January 27, 2013

Checking to see which entry has the active input focus.

Gtk provides no simple way telling a calling program which entry widget contains the active keyboard focus. Specific widgets can be interrogated as to whether they possess keyboard input focus on either a global scale or simply within their own toplevel window. My own pet project is working on the translation of Chinese texts and the api of my translation editor will have multiple editable widgets on screen at any one time. Up till now I've used focus events to set a global variable identifying which widget has focus, but there are other ways. Today I just added the hasToplevelFocus and has hasGlobalFocus commands to the gnocl::text widget. There always was, of course the option to use cget -hasFocus. Here's my test script.

#---------------
# test-chinese-punct-toolbar.tcl
#---------------
#
#!/bin/sh
#\
exec tclsh "$0" "$@"

package require Gnocl

#---------------
# insert punc mark it currently active text
#---------------
proc do_chn_punc { mark } {

    foreach w $::texts {
        if { [$w isToplevelFocus] == 1 } {
            $w insert cursor $mark
        }
    }
}

#---------------
# Insert punctuation marks suited to differing character sets.
#---------------
proc chn_punc { {type jianti} } {

    set marks {
        。    {Full Stop}
        ‘    {Open Single Quote}
        “    {Open Double Quote}
        ”    {Close Double Quote}
        ’    {Close Single Quote}
        、    {Enumeration comma}
        ‧    {Middle dot}
        《    {Open Double Title Mark}
        》    {Close Double Title Mark}
        ……    {Ellipsis}
        ——    {Em Dash}
        —    {En Dash}
        ~    {Wavy Dash}
        }

    if {$type eq "fanti" } {   
    set marks {
        。    {Full Stop}
        「    {Open Single Quote}
        『    {Open Double Quote}
        』    {Close Double Quote}
        」    {Close Single Quote}
        、    {Enumeration comma}
        ‧    {Middle dot}
        《    {Open Double Title Mark}
        〈    {Open Single (Section) Title Mark}
        〉    {Close Single (Section) Title Mark}
        》    {Close Double Title Mark}
        ……    {Ellipsis} 
        ——    {Em Dash}
        —    {En Dash}
        ~    {Wavy Dash}
    } }

    set tb [gnocl::toolBar -style text ]
       
    foreach {mark tip} $marks {
        $tb add item \
            -icon %#New \
            -text $mark \
            -tooltip $tip \
            -onClicked "do_chn_punc $mark"
    }
   
    return $tb
}


set box [gnocl::box -orientation vertical]
set txt(1) [gnocl::text -baseFont {Serif 12}]
set txt(2) [gnocl::text -baseColor #D1FEFF -baseFont {Serif 14}]
gnocl::window -child $box
$box add [chn_punc]
$box add [chn_punc fanti]
$box add $txt(1)
$box add $txt(2)

# list of available texts
set texts [list $txt(1) $txt(2)]
puts $texts

$txt(1) grabFocus





Tuesday, January 22, 2013

gnocl::cairo - moving forward

Spent some time last night working on the proposed gnocl::cairo package. I've got most of the innards working now and the next step will be wrapping the gdk core api into the mixture. Cairo is certainly fast even on my old 32-bit workstation. By default, my development code wants always to work on bitmaps but, of course, Cairo will work on a variety of surfaces. Apart from pixbufs, the additional objects include svn, png, ps, pdf, some other windows, mac and X formats and gdk drawables such as windows. The code is expanding rapidly but, it's getting there!

Wednesday, January 16, 2013

Today's Added Functionality

This is the summary of today's work on the Gnocl sourcecode.

2013-01:
    gnocl::winfo
        o new subcommand
            exists
    gnocl::notebook
        o new options
            -startWidget
            -endWidget
            -onDestroy
    gnocl::label
        o new option
            -onDestroy

Improving Notebook Tearoff Functionality

The Gtk+ libraries provide the necessary support to detach notebook tabs in order to attach them to other notebooks in the same group or to place them in floating windows. This is fine. But, what happens when a floating palette is destroyed? Well, the notebook and any pages that it contains will be lost too. Unfortunately, the Gtk+ libs do not re-attach pages to any original note book when other notebooks in the group are deleted. In otherwords, pages will be lost and it up the application to create new instances. The following script shows how to do it. It relies upon the gnocl::winfo exists sub-command, which has only just been added. So, anyone trying out this script will need to use the nightly build dated 16-Jan-13 or later.

# test-notebook-tearoff.tcl
#!/bin/sh \
exec tclsh "$0" "$@"

package require Gnocl

#---------------
# create notebook contents
#---------------
#
proc addStuff {} {

    set notebook1 [gnocl::notebook \
        -scrollable 1 \
        -tabPosition left \
        -onCreateWindow {
            %w configure -title "TEAR OFF NOTEBOOK"
            } \
        -groupId 1 ]


    proc addFirst {nb} {
   
        if { ![gnocl::winfo exists $nb] } { return }
   
        $nb addPage [gnocl::label \
            -text "First Page" \
            -onDestroy "addFirst $nb"] "%__First"
    }

    proc addSecond {nb} {
   
        if { ![gnocl::winfo exists $nb] } { return }
   
        $nb addPage [gnocl::label \
            -text "Second Page" \
            -onDestroy "addSecond $nb" ] "%__Second"
    }

    proc addThird {nb} {

        if { ![gnocl::winfo exists $nb] } { return }

        $nb addPage [gnocl::label \
            -text "Third Page" \
            -onDestroy "addThird $nb"] "%__Third"
    }

    proc addFourth {nb} {
   
        if { ![gnocl::winfo exists $nb] } { return }
   
        $nb addPage [gnocl::label \
            -text "Fourth Page" \
            -onDestroy "addFourth $nb"] "%__Fourth"
   
    }

    foreach  a [list First Second Third Fourth] { add$a $notebook1 }

    return $notebook1

}

gnocl::window \
    -title "Notebook1" \
    -child [addStuff] \
    -setSize 0.3 \
    -onDestroy exit