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


json_shell_utils.tcl