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!

Sorting help

Status
Not open for further replies.

jameshi

Technical User
Jun 23, 2005
3
US
Hello all. I am trying to create a gui for an email application. It should be able to speak to pop3. I have a very basic interface in development. My question is, i have 3 buttons From, Date and Subject. I want to be able to sort by these buttons (sort of like how outlook is set up). Here's the code I have for what i have now. Also if you have any tips on connecting to pop3 w/o using the pop library would be appreciated. Thanks.

catch {console show}
set auto_path [linsert $auto_path 0 [file dirname [info script]]]


proc OpenProc {} {
WriteInfoStr "You selected OpenProc"
}

proc CloseProc {} {
WriteInfoStr "You selected CloseProc"
}

proc HelpProc {} {
WriteInfoStr "You selected HelpProc"
}


proc AddMenuCmd { menu label acc cmd } {
$menu add command -label $label -accelerator $acc -command $cmd
}

proc WriteInfoStr { str } {
.fr.infofr.l configure -text $str
}


set hMenu .menufr
menu $hMenu -borderwidth 2 -relief sunken
$hMenu add cascade -menu $hMenu.file -label File -underline 0
$hMenu add cascade -menu $hMenu.help -label Help -underline 0

set fileMenu $hMenu.file
menu $fileMenu -tearoff 0

AddMenuCmd $fileMenu "Open ..." "Ctrl+O" OpenProc
AddMenuCmd $fileMenu "Close ..." "Ctrl+W" CloseProc
AddMenuCmd $fileMenu "Quit ..." "Ctrl+Q" exit
bind . <Control-o> OpenProc
bind . <Control-w> CloseProc
bind . <Control-q> exit

set helpMenu $hMenu.help
menu $helpMenu -tearoff 0
AddMenuCmd $helpMenu "About ..." "F1" HelpProc
bind . <F1> HelpProc

wm protocol . WM_DELETE_WINDOW "exit"
. configure -menu $hMenu

frame .fr
pack .fr -fill both -expand 1

frame .fr.toolfr -relief sunken -borderwidth 1
frame .fr.listfr -relief sunken -borderwidth 1 -bg white
frame .fr.infofr -relief sunken -borderwidth 1 -bg cyan
frame .fr.workfr -relief sunken -borderwidth 1 -bg green


# Create toolbar buttons

image create photo .open -format GIF -file open.gif
button .fr.toolfr.open -image .open -width 100 -height 30

image create photo .delete -format GIF -file delete_button.gif
button .fr.toolfr.delete -image .delete -width 100 -height 30

image create photo .exit -format GIF -file exit.gif
button .fr.toolfr.exit -image .exit -width 100 -height 30 -command exit

pack .fr.toolfr.open .fr.toolfr.delete .fr.toolfr.exit -side left -padx 2 -pady 2 -expand 0

pack .fr.toolfr -side top -fill x

# Toolbar is on the top row of grid
grid .fr.toolfr -row 0 -column 0 -sticky ew


# List of mail is on the second row of grid
# Need to create three columns for list of From, Date, Subject
button .fr.listfr.from -text From -command sort_From
button .fr.listfr.date -text Date -command sort_Date
button .fr.listfr.subject -text Subject -command sort_Subject
pack .fr.listfr.from .fr.listfr.date .fr.listfr.subject -side left -fill x
pack .fr -side top



grid .fr.listfr -row 1 -column 0 -ipadx 200 -ipady 50 -sticky ew

# Info on the open mail message is on the third row of grid
grid .fr.infofr -row 2 -column 0 -ipadx 200 -ipady 20 -sticky ew

# Messaage is on the fourth row of grid
grid .fr.workfr -row 3 -column 0 -ipadx 200 -ipady 70 -sticky ew


grid rowconfigure .fr 1 -weight 1
grid columnconfigure .fr 0 -weight 1

label .fr.listfr.l \
-text "List of mail goes here; with From, Date, Subject columns" \
-bg white

pack .fr.listfr.l \
-fill x -expand 1


label .fr.infofr.l \
-text "Mail Info goes here; display From:, Date:, Subject: of the open message" \
-bg cyan

pack .fr.infofr.l \
-fill x -expand 1


label .fr.workfr.l \
-text "Message body goes here" \
-bg green

pack .fr.workfr.l \
-fill x -expand 1
 
First of all, I don't know how to access a pop server without using the pop3 library. Why don't you want to use it?

As for sorting, I think the best way is to make a "list of lists". That is, create a list, say msgList. Each element of msgList will be a 3-element list: {from, date, subject}. Then you have (there are other ways to do this) 3 buttons: fromSort, dateSort, subjSort. When you press, for example, fromSort, the command executed would be:
set msgList [lsort $msgList 0];displayList $msgList.
When you press dateSort, the command would be:
set msgList [lsort $msgList 1]; displayList $msgList,
and so on. The proc, displayList would be something like:

proc displayList {dList} {
<text widget> delete 0.0 end
foreach rcrd $dList {
<text widget> insert end [lindex $rcrd 0]\t[lindex $rcrd 1]\t[lindex $rcrd 2]
}
}


_________________
Bob Rashkin
rrashkin@csc.com
 
Hey Bong, thanks for the help. I thought if I manually opened the port it would allow me more freedom and control over it. I guess it would be easier to use the pop3 lib.

I am not quite sure what you mean "list of lists". I'm sort of new to all of this, but I'll try what you said above. Thanks.

I used this to create the buttons. Is there a way to have them expand across the whole screen?
 
Sorry forgot to attach this: (i don't see and edit post button anywhere)

set column 0
set xposition 5
foreach var {From Date Subject} {
frame .fr.listfr.f$var -relief sunken -borderwidth 1 -bg white
button .fr.listfr.l$var -text $var -bg gray -command sort
grid .fr.listfr.l$var -row 0 -column $column -columnspan 1 -sticky n -padx 1
grid .fr.listfr.f$var -row 1 -column $column -rowspan 1 -sticky n -pady 1
incr column
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top