#!/usr/bin/wish #package require Tk #package require tclx # global config variables set ICON_DIR "/home/tomas/.fvwm/icons" if {! [file exists $ICON_DIR] } { set ICON_DIR "" } listbox .lb -yscrollcommand {.sb set} -height 0 -width 0 scrollbar .sb -command {.lb yview} frame .b -borderwidth 1 pack .b -side bottom -fill x button .b.refresh -text refresh -command {getdevices .lb} button .b.show -text show -command show_selected button .b.quit -text quit -command exit pack .b.refresh .b.show .b.quit -in .b -side left pack .sb -side right -fill y pack .lb -side left -fill both -expand true bind .lb "" show_selected bind . "" show_selected bind . "q" exit wm geometry . 320x600+20+20 wm minsize . 200 200 wm command . [concat $argv0 $argv] wm group . . if { $ICON_DIR ne "" } { image create photo .main_icon -file "$ICON_DIR/device_folder.ppm" image create photo .dev_icon -file "$ICON_DIR/device1.ppm" wm iconphoto . .main_icon } #puts "winfo of '.'" #puts [winfo name .] proc add_device {dev} { upvar devices devices if { [lsearch -exact $devices $dev] == -1 } { lappend devices $dev } } proc getdevices {lb} { $lb delete 0 [$lb size] set devices "" set fp [open "|find /sys/block /sys/class /sys/devices -type f -name dev* -printf %h\\n" "r"] while { ![eof $fp ] } { gets $fp line if {[string length "$line"] > 0 } { add_device [string replace $line 0 3] } } close $fp foreach d [ glob -types d -directory /sys/class/net -nocomplain * ] { add_device [string replace $d 0 3] } foreach d $devices { $lb insert end $d } } proc show_selected {} { foreach name [.lb curselection] { show [.lb get $name] } } proc show {name} { # exec udevinfo -a -p $name >@ stdout set wname [string map {"." "_"} $name] if {[winfo exists .$wname ]} { wm deiconify .$wname raise .$wname } else { toplevel .$wname -class "DeviceInfo" # toplevel .$wname -class [. cget -class] wm group .$wname . wm title .$wname $name wm iconname .$wname [lindex [split $name "/" ] end] upvar #0 ICON_DIR ICON_DIR_X if { $ICON_DIR_X ne "" } { wm iconphoto .$wname .dev_icon } text .$wname.t -wrap none \ -yscrollcommand ".$wname.vs set" \ -xscrollcommand ".$wname.hs set" scrollbar .$wname.vs -command ".$wname.t yview" scrollbar .$wname.hs -command ".$wname.t xview" -orient horizontal pack .$wname.vs -side right -fill y pack .$wname.hs -side bottom -fill x pack .$wname.t -side left -fill both -expand 1 if {[file executable "/sbin/udevadm"]} { set fp [open "|/sbin/udevadm info --attribute-walk --path $name" "r"] } else { set fp [open "|udevinfo -a -p $name" "r"] } .$wname.t insert end [read $fp] close $fp bind .$wname "q" "destroy .$wname" } } getdevices .lb