import Pmw
import Tkinter
class DoubleSelects:
def __init__(self, hull):
self.level = len(hull.treeLevel) #hasn't been added to list yet!
self._hull = hull
self.name = "Pane 0"
hull.browser.add(self.name, min= .1,size=150 )
num = len(hull.browser.panes())
rel = 1.0/num
print "REL", rel
hull.browser.configure(hull_width=num*150)
for i in range(num):
hull.browser.configurepane(i,size=rel)
self.innerPane = Pmw.PanedWidget(hull.browser.pane(self.name))
self.topName = 'Pane ' + str(num) + "t"
self.innerPane.add(self.topName, size = .5,)
self.topBox = Pmw.ScrolledListBox(self.innerPane.pane(self.topName),
listbox_selectmode='single',
vscrollmode = 'dynamic',
selectioncommand=self.selectionNodeCommand,
dblclickcommand=self.defNodeCmd)
self.topBox.pack(fill= 'both', expand = 'yes', padx=0, pady=0)
self.topBox.component('listbox').configure(exportselection=0)
self.bottomName = 'Pane ' + str(num) + "b"
self.innerPane.add(self.bottomName, size=.5 ,)
self.bottomBox = Pmw.ScrolledListBox(
self.innerPane.pane(self.bottomName),
listbox_selectmode='single',
vscrollmode = 'dynamic',
selectioncommand=self.selectionLeafCommand,
dblclickcommand=self.defLeafCmd)
self.bottomBox.pack(fill = 'both', expand='yes', padx = 0, pady = 0)
self.bottomBox.component('listbox').configure(exportselection=0)
self.innerPane.pack(expand = 1, fill='both')
def selectionNodeCommand(self):
sels = self.topBox.getcurselection()
if len(sels) == 0:
print 'No selection'
else:
print "bbb", self._hull.tree
nodes, leaves = self._hull.tree._selected(sels[0],self.level)
apply(self.topbox.insert,('end',)+tuple(nodes))
# print self._hull.current
# print 'Selection:', sels[0]
# self._hull.selectedNode(self.level,sels)
# self.list = self.tree.getRootNodeNames()
# print "LIST", list
# apply(self.topbox.insert,('end',)+tuple(self.list))
def defNodeCmd(self):
sels = self.topBox.getcurselection()
if len(sels) == 0:
print 'No selection for double click'
else:
print 'Double click:', sels[0]
def selectionLeafCommand(self):
sels = self.bottomBox.getcurselection()
if len(sels) == 0:
print 'No selection'
else:
print 'Selection:', sels[0]
# display the contents of the selected file in a dialog box which
# is appended to self.tmpwindict in order to facilitate easy
# deletion
import string # for string.join
import os # for os.sep
# construct the file name given the selected directory list.
# NOTE: if a file is selected under the root directory, then
# there will be a double-slash prepended to its name.
# this is legal under unix, not sure if it is so under DOS.
# also, the slash character must be replaced with a p
# fn = os.sep + string.join(self._hull.current + sels[0], os.sep) + os.sep + sels[0]
# self._hull.selectedNode(self.level, self.topBox.getcurselection())
s = self._hull.current[:self.level+1]
s.append(sels[0])
fn = os.sep + string.join(s, os.sep)
print '*** file selected is \'', fn, '\'.'
print '*** file directory is ', s
print '*** app trees: ', self._hull.trees
print '*** app treeLevel: ', self._hull.treeLevel
self._hull.tmpwindict[sels[0]]= Pmw.TextDialog()
self._hull.tmpwindict[sels[0]].component('scrolledtext').importfile(fn)
def defLeafCmd(self):
sels = self.bottomBox.getcurselection()
if len(sels) == 0:
print 'No selection for double click'
else:
print 'Double click:', sels[0]
class TreeBrowser(Pmw.MegaWidget):
def __init__(self, parent=None, tree=None, **kw):
self.tree = tree
self.tmpwindict = {} # temporary window list implemented as a dict
# format: { 'name',