Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ask some advise 1

Status
Not open for further replies.

stewang

Programmer
Aug 21, 2003
77
NZ
Hello all:
I'd like to ask you give me some advises. And I use linux
machine at the movement.
I want to select a song or music from a folder, and put the song or music of the name on a listbox which in another window.

My question are following;
1> which option can support me to get the song or the music of name?

2> after the song or music of name is in the listbox, I can also save the song or music which in the listbox to another directory when I click a save button.

So the song or music name is not just a simply string, I guest. If the name not just a simply name, what is it?
This is another my question.

Would anyone help me. please.

Code:
menu .mbar

. configure -menu .mbar

menu .mbar.file -tearoff 0

.mbar add cascade -label "File" -underline 0    -menu .mbar.file

.mbar.file add command -label "Open" -underline 0    -command openFile

proc openFile {} {
 set filename [tk_getOpenFile -multiple 1] 
	set thefile [open $filename r] 
        puts "the file : $thefile"             
	set filecontent [read $thefile]        
	close $thefile       
}
 
1/ If you want to listen the song, you need the snak extension:
2/ I understand your question as "what is a file?".
Hmm..
A file is a named piece of data that is saved on disk and can be retrieved from its name.
The complete name of a file is its path.
The path of a file is the list of all dirs from where to go to attain the file, followed by the short name of the file.
The short name of the file (or simply the name if no ambiguity) is the name of the file inside the last subdir.

The data are the content of the file. This can be almost anything. As data that snak can interpret as a song.
The name of the file can or cannot be the name of the song.
It's better when the name of a file gives an idea of what are the data.

So, to answer your question, the name of a file is a way to say to snack which song to play because this name permits snack to get the corresponding data.

3/ I added some code to yours to handle the list of the file names and the listbox:
Code:
  package require Tk
  # the menu bar
  menu .mbar
  . configure -menu .mbar
  menu .mbar.file -tearoff 0
  .mbar add cascade -label "File" -underline 0 -menu .mbar.file
  .mbar.file add command -label "Open" -underline 0 -command openFile
  .mbar.file add command -label "Save" -underline 0 -command saveFile
  .mbar.file add separator
  .mbar.file add command -label "Quit" -underline 0 -command exitApp
  wm protocol . WM_DELETE_WINDOW exitApp
  menu .mbar.list -tearoff 0
  .mbar add cascade -label "List" -underline 0 -menu .mbar.list
  .mbar.list add command -label "Remove" -underline 0 -command removeName
  .mbar.list add command -label "Clear" -underline 0 -command clearList
  # the list box
  set ::names {}
  listbox .l -listvar ::names -width 40
  pack .l -expand 1 -fill both
  # the actions
    # get some file names
    # add the new ones to the listbox
    # do something with the content of each new file
  proc openFile {}   {
    # get some file names
    set filenames [tk_getOpenFile -multiple 1]
    foreach fn $filenames     {
      # check if its a new one
      if {[lsearch $::names $fn] == -1}       {
        # add the name to the listbox
        lappend ::names $fn
        # get the file content and do something with it
        set thefile [open $fn r]
        puts "the file : $thefile"             
        set filecontent [read $thefile]        
        close $thefile
      }
    }
    # sort the listbox content
    set ::names [lsort $::names]
  }
    # get the currently selected name
    # copy the corresponding file somewhere
    # remove the name from the listbox
  proc saveFile {}   {
    # get the currently selected name
    set n [.l curselection]
    if {$n != ""}     {
      # get the old name
      set source [lindex $::names $n]
      # get the new name
      set target [tk_getSaveFile]
      if {$target != ""}       {
        # copy the file content to the new position
        file copy $source $target
        # remove the name from the listbox
        removeName
      }
    }
  }
    # get the currently selected name
    # remove the name from the listbox
  proc removeName {}   {
    # get the currently selected name
    set n [.l curselection]
    set name [lindex $::names $n]
    set n [lsearch $::names $name]
    if {$n != -1}     {
      set ::names [lreplace $::names $n $n]
    }
  }
    # clear the listbox
  proc clearList {} { set ::names {} }
    # exit
  proc exitApp {} { exit }
HTH

ulis
 
Thanks a lot, ulis.
I will try to understand your code later on, I may come back to ask your some question about this, if I can not understand
it.

rgds
stewang
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top