comparison Lib/tkinter/FileDialog.py @ 4893:c2eac126e8ff legacy-trunk

Fix the following bug: - When dragging the mouse in either listbox, the *first* entry clicked on is selected rather than the last (but the last one is highlighted). This is done by changing the bindtags so that our binding is executed after the default binding (which sets the 'active' index to the last item selected), and using 'active' instead of 'anchor' as the index to ask for.
author Guido van Rossum <guido@python.org>
date Fri, 03 Jan 1997 23:39:26 +0000
parents 0d1463a45b6f
children
comparison
equal deleted inserted replaced
4892:1c089c5b66e9 4893:c2eac126e8ff
8 8
9 """ 9 """
10 10
11 from Tkinter import * 11 from Tkinter import *
12 from Dialog import Dialog 12 from Dialog import Dialog
13
14 ANCHOR = 'anchor'
15 13
16 import os 14 import os
17 import fnmatch 15 import fnmatch
18 16
19 17
71 self.filesbar = Scrollbar(self.midframe) 69 self.filesbar = Scrollbar(self.midframe)
72 self.filesbar.pack(side=RIGHT, fill=Y) 70 self.filesbar.pack(side=RIGHT, fill=Y)
73 self.files = Listbox(self.midframe, exportselection=0, 71 self.files = Listbox(self.midframe, exportselection=0,
74 yscrollcommand=(self.filesbar, 'set')) 72 yscrollcommand=(self.filesbar, 'set'))
75 self.files.pack(side=RIGHT, expand=YES, fill=BOTH) 73 self.files.pack(side=RIGHT, expand=YES, fill=BOTH)
74 btags = self.files.bindtags()
75 self.files.bindtags(btags[1:] + btags[:1])
76 self.files.bind('<ButtonRelease-1>', self.files_select_event) 76 self.files.bind('<ButtonRelease-1>', self.files_select_event)
77 self.files.bind('<Double-ButtonRelease-1>', self.files_double_event) 77 self.files.bind('<Double-ButtonRelease-1>', self.files_double_event)
78 self.filesbar.config(command=(self.files, 'yview')) 78 self.filesbar.config(command=(self.files, 'yview'))
79 79
80 self.dirsbar = Scrollbar(self.midframe) 80 self.dirsbar = Scrollbar(self.midframe)
81 self.dirsbar.pack(side=LEFT, fill=Y) 81 self.dirsbar.pack(side=LEFT, fill=Y)
82 self.dirs = Listbox(self.midframe, exportselection=0, 82 self.dirs = Listbox(self.midframe, exportselection=0,
83 yscrollcommand=(self.dirsbar, 'set')) 83 yscrollcommand=(self.dirsbar, 'set'))
84 self.dirs.pack(side=LEFT, expand=YES, fill=BOTH) 84 self.dirs.pack(side=LEFT, expand=YES, fill=BOTH)
85 self.dirsbar.config(command=(self.dirs, 'yview')) 85 self.dirsbar.config(command=(self.dirs, 'yview'))
86 btags = self.dirs.bindtags()
87 self.dirs.bindtags(btags[1:] + btags[:1])
86 self.dirs.bind('<ButtonRelease-1>', self.dirs_select_event) 88 self.dirs.bind('<ButtonRelease-1>', self.dirs_select_event)
87 self.dirs.bind('<Double-ButtonRelease-1>', self.dirs_double_event) 89 self.dirs.bind('<Double-ButtonRelease-1>', self.dirs_double_event)
88 90
89 self.ok_button = Button(self.botframe, 91 self.ok_button = Button(self.botframe,
90 text="OK", 92 text="OK",
131 def dirs_double_event(self, event): 133 def dirs_double_event(self, event):
132 self.filter_command() 134 self.filter_command()
133 135
134 def dirs_select_event(self, event): 136 def dirs_select_event(self, event):
135 dir, pat = self.get_filter() 137 dir, pat = self.get_filter()
136 subdir = self.dirs.get(ANCHOR) 138 subdir = self.dirs.get('active')
137 dir = os.path.normpath(os.path.join(self.directory, subdir)) 139 dir = os.path.normpath(os.path.join(self.directory, subdir))
138 self.set_filter(dir, pat) 140 self.set_filter(dir, pat)
139 141
140 def files_double_event(self, event): 142 def files_double_event(self, event):
141 self.ok_command() 143 self.ok_command()
142 144
143 def files_select_event(self, event): 145 def files_select_event(self, event):
144 file = self.files.get(ANCHOR) 146 file = self.files.get('active')
145 self.set_selection(file) 147 self.set_selection(file)
146 148
147 def ok_event(self, event): 149 def ok_event(self, event):
148 self.ok_command() 150 self.ok_command()
149 151