Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[a37b2b]: plugins / horizontalbrowser.py Maximize Restore History

Download this file

horizontalbrowser.py    185 lines (151 with data), 5.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
'''
This software is licensed under the GPL (GNU General Public License) version 2
as it appears here: http://www.gnu.org/copyleft/gpl.html
It is also included with this archive as `gpl.txt <gpl.txt>`_.
'''
import wx
import wx.lib.mixins.listctrl as listmix
#todo: add icon support
class pseudo_event(object):
def __init__(self, index):
self.index = index
def GetIndex(self):
return self.index
class hbrowser(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
def __init__(self, parent, containers, items):
wx.ListCtrl.__init__(self, parent, style=wx.LC_NO_HEADER|wx.LC_REPORT|wx.LC_ALIGN_LEFT|wx.LC_SINGLE_SEL)#|wx.LC_SMALL_ICON
self.InsertColumn(0, 'unseen')
listmix.ListCtrlAutoWidthMixin.__init__(self)
self.parent = parent
self.containers = {}
self.items = {}
for i,j in containers:
x = self.InsertStringItem(2147483647, "[%s]"%i)
self.containers[x] = i,j
for i,j in items:
x = self.InsertStringItem(2147483647, i)
self.items[x] = i,j
self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelected)
self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnActivated)
self.Bind(wx.EVT_LEFT_DOWN, self.OnClicked)
def Back(self, which=None):
if which is None:
which = self.GetFirstSelected()
self.OnSelected(pseudo_event(which))
def OnClicked(self, e):
index = self.HitTest(e.GetPosition())[0]
if index == self.GetFirstSelected():
self.Back()
else:
e.Skip()
def OnSelected(self, e):
it = e.GetIndex()
if it in self.containers:
name, token = self.containers[it]
self.parent.ExpandChildren(self, token)
else:
self.parent.ClearChildren(self, dc=1)
def OnActivated(self, e):
it = e.GetIndex()
if it in self.containers:
name, token = self.containers[it]
self.parent.ExpandChildren(self, token, dc=1)
else:
name, token = self.items[it]
self.parent.ChildActivated(self, token)
class HorizontalBrowser(wx.Panel):
def __init__(self, parent, get_children, on_activation):
wx.Panel.__init__(self, parent)
self.get_children = get_children
self.on_activation = on_activation
containers, items = get_children(None)
self.lcs = [wx.Panel(self), wx.Panel(self), hbrowser(self, containers, items)]
self.sizer = wx.BoxSizer(wx.HORIZONTAL)
for i in self.lcs:
self.sizer.Add(i, 1, wx.ALL|wx.EXPAND, 2)
othersizer = wx.BoxSizer(wx.HORIZONTAL)
p = wx.Panel(self)
btn = wx.Button(p, -1, "Back")
othersizer.Add(p, 1, wx.ALL|wx.EXPAND, 2)
othersizer.Add(wx.StaticText(self, -1, "Current"), 1, wx.ALL|wx.EXPAND|wx.ALIGN_CENTER, 2)
othersizer.Add(wx.StaticText(self, -1, "Forward"), 1, wx.ALL|wx.EXPAND|wx.ALIGN_CENTER, 2)
self.Bind(wx.EVT_BUTTON, self.OnBack, btn)
sizer2 = wx.BoxSizer(wx.VERTICAL)
sizer2.Add(othersizer, 0, wx.EXPAND)
sizer2.Add(self.sizer, 1, wx.EXPAND)
self.SetSizer(sizer2)
def OnBack(self, e):
if isinstance(self.lcs[-3], hbrowser):
self.lcs[-3].Back()
def ClearChildren(self, lc, dc=0):
self.Freeze()
while self.lcs[-1] != lc:
popped = self.lcs.pop()
self.sizer.Remove(popped)
popped.Destroy()
for i in xrange(min(3+dc, len(self.lcs))):
self.lcs[-1-i].Hide()
if dc:
self.lcs.append(wx.Panel(self))
self.sizer.Add(self.lcs[-1], 1, wx.ALL|wx.EXPAND, 2)
for i in xrange(3):
self.lcs[-1-i].Show()
self.Layout()
self.Thaw()
def ExpandChildren(self, lc, token, dc=0):
if dc:
dc = lc == self.lcs[-2]
print "dc:", dc
self.ClearChildren(lc)
self.Freeze()
for i in xrange(3):
self.lcs[-1-i].Hide()
containers, items = self.get_children(token)
self.lcs.append(hbrowser(self, containers, items))
self.sizer.Add(self.lcs[-1], 1, wx.ALL|wx.EXPAND, 2)
if dc:
self.lcs.append(wx.Panel(self))
self.sizer.Add(self.lcs[-1], 1, wx.ALL|wx.EXPAND, 2)
for i in xrange(3):
self.lcs[-1-i].Show()
self.Layout()
self.Thaw()
def ChildActivated(self, lc, token):
print token
if __name__ == '__main__':
## def get_children(token):
## if token is None:
## token = ()
## return [("<dir %s>"%(token+(i,),), token+(i,)) for i in xrange(5)], [("file_%s"%(token+(i,),), token+(i,)) for i in xrange(5)]
import os, stat
root = ["C:\\", "D:\\", "E:\\", "F:\\"]
sfcn = lambda a,b: cmp(a[0].lower(), b[0].lower())
def get_children(token):
if token is None:
return [(i,i) for i in root], []
try:
l = os.listdir(token)
except:
return [], []
dire = []
file = []
for i in l:
j = os.path.join(token, i)
try:
if stat.S_ISDIR(os.stat(j).st_mode):
dire.append((i,j))
else:
file.append((i,j))
except:
pass
dire.sort(sfcn)
file.sort(sfcn)
return dire, file
def on_activation(token):
pass
a = wx.App(0)
b = wx.Frame(None, title="spacial browser")
c = HorizontalBrowser(b, get_children, on_activation)
b.Show(1)
b.SetSize((800,400))
a.MainLoop()