Updated 2011-08-31 03:03:09 by RLE

Carsten Zerbst This is a GUI to display RSS items of a single stream. It uses the RSS Reader as underlying library.

The most interesting is how to use it:
   wish rssGUI.tcl http://wiki.tcl.tk/rss.xml

and its usage of the text widget. For each news item only the title is displayed. If the mouse enters into the title, the complete message is displayed. If you wipe with your mouse over the gui, message for message is displayed completely. Doubleclicking on the title or message will open the link in an internet browser.

Some translations for german words used in the code sichtbar -> visible, gerade -> even, ungerade -> odd

AK: The code refers to a gif file aus.gif (translate: off.gif), which is not present in the code itself, nor on this page. This causes the GUI to stop and stay empty. - RS suggests to inline small images in base64 format, to be loaded with -data. See Creating image photo data from GIF files.

TS aus.gif could be found in ftp://ftp.linux-magazin.de/pub/magazin/2005/03/Federlesen/ From Invoking browsers i made the following modification (because my browser is always running)
  <    catch {exec $binary  -remote "OpenURL($url,new-tab)" &}
  ---
  >    catch {exec $binary $url &}

 #!/bin/sh
 # einfacher RSS Reader
 #  \
 exec wish $0 $@

 package require Tk
 package require opt

 source czrss.tcl

 namespace eval ::rssgui {
    #variable text
    variable counter

    proc init {} {
        variable counter
        set counter 0

        # white background weißer Hintergrund
        . configure -background white
        option add *background white

        # main windows | Hauptfenster
        text .text  -relief flat -wrap word \
            -selectbackground blue \
            -yscrollcommand {.sby set}  \
            -highlightthickness 0

        grid .text -row 1 -column 1 -sticky nesw

        scrollbar .sby -orient vert -command {.text yview} \
                        -highlightthickness 0
        grid .sby -row 1 -column 2 -sticky ns

        frame .buttons 
        grid .buttons -row 2 -columnspan 3 -sticky e 
        image create photo aus -file aus.gif
        button .buttons.exit -command {exit 0} \
            -image aus -relief flat \
            -highlightthickness 0
        pack .buttons.exit -anchor e

        grid rowconfigure . 0 -minsize 10
        grid rowconfigure . 1 -weight 1
        grid rowconfigure . 2 -minsize 10

        grid columnconfigure . 0 -minsize 10
        grid columnconfigure . 1 -weight 1
        grid columnconfigure . 2 -minsize 10
        grid columnconfigure . 3 -minsize 10
        
        # Configure text widget | Text konfigurieren
         .text tag configure title -foreground steelblue -font {Helvetica  12} \
            -spacing1 5 -spacing3 5
         .text tag configure description -foreground black \
             -spacing1 10 -lmargin1 20 -lmargin2 10 -spacing3 5 -elide true 
        .text tag configure gerade -background whitesmoke 
        .text tag configure ungerade -background white
        .text tag configure sichtbar -elide false
        .text conf -state disabled 
    }

    proc setFeed { url } {
        set doc [::czrss::doc create %AUTO% $url ]
        set channel [$doc channel]
        wm title . [$channel title]
        .text conf -state normal
        .text delete 0.0 end
        foreach item [ $doc items ] {
            insertMessage [$item title] [$item description] [$item link]
        }
        .text conf -state disabled        
    }

    # insert a message into the text widget
    proc insertMessage { title description url } {
        variable counter

        set id [ clock clicks]

        if {[expr [incr counter] % 2 ]} {
            set zeile gerade
        } else {
            set zeile ungerade
        }
        
        .text insert end "$title\n" [ list $zeile title $id]
        .text tag bind $id <Enter> [list ::rssgui::enterTag $id]
        .text tag bind $id <Double-1> [list ::rssgui::startBrowser $url]

        incr id
        .text insert end "$description\n" [ list $zeile description $id]
        .text tag bind $id <Double-1> [list ::rssgui::startBrowser $url]
    }

    # called when entering a taged item with the mouse in the text widget 
    proc enterTag { id } {
        set start [ lindex [.text tag nextrange $id 0.0 end] 0]
        set end   [ lindex [.text tag nextrange [expr $id +1 ] 0.0 end] 1]
        .text tag add sichtbar $start $end
        .text tag bind sichtbar <Leave> [list ::rssgui::leaveTag  $id]
    }

    # called when leaving a taged item with the mouse in the text widget 
    proc leaveTag { id } {
        .text tag remove sichtbar 0.0 end
    }
    # start a HTML browser on the local machine
    proc startBrowser {url} {
        puts "startBrowser $url"  
        
        # nimmt erstbesten browser
        foreach browser {galeon firefox mozilla konqueror netscape opera} {
            set binary [lindex [auto_execok $browser] 0]
            if {[string length $binary]} {
                catch {exec $binary $url &}
                break
            }
        }
    }
  }

  tcl::OptProc main {
    {url "RSS-Feed, z.B. http://www.tagesschau.de/newsticker.rdf" }
  } {

    rssgui::init
    rssgui::setFeed $url
  }

  if {[catch { eval main $argv } res]} {
    puts stderr $res
  } else {
    puts stdout $res
  }

HE: Where can one find opt (package require opt) and czrss.tcl (source czrss.tcl) ?

EF: The czrss.tcl can be found from RSS Reader, the opt package is part of the main Tcl library, see Official library of extensions.