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 / browser.py Maximize Restore History

Download this file

browser.py    118 lines (92 with data), 3.6 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
'''
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>`_.
'''
#system imports
import os
import stat
import sys
#site-packages imports
import wx
#local imports
import filehistory
def ChangedPage(evt):
nb = evt.GetEventObject()
pn = evt.GetSelection()
if nb.GetPageText(pn).startswith('Browse'):
nb.GetPage(pn).showstuff()
evt.Skip()
class LateBinding:
def __init__(self, obj, name, attr):
self.obj = obj
self.name = name
self.attr = attr
def __call__(self, *args, **kwargs):
return getattr(getattr(self.obj, self.name), self.attr)(*args, **kwargs)
class FilesystemBrowser(wx.Panel):
def __init__(self, parent, root, pathnames=[], maxlen=0):
wx.Panel.__init__(self, parent)
self.root = root
self.pathnames = pathnames
self.maxlen = maxlen
self.op = filehistory.FileHistory(self, callback=[self.chdir, LateBinding(self, 'browser', 'SetPath')], seq=self.pathnames,maxlen=self.maxlen)
self.rp = filehistory.FileHistory(self, remove=1, callback=[self.op.ItemRemove], seq=self.pathnames,maxlen=self.maxlen,
delmsg=('Are you sure you want to delete the pathmark?\n%s', "Delete Pathmark?"))
self.op.callback.append(self.rp.ItemAdd)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(self.sizer)
## self.showstuff()
def showstuff(self):
if hasattr(self, 'button'):
return
## print "called showstuff!"
sizer = self.sizer
self.button = wx.Button(self, -1, "Pathmark...")
wx.EVT_BUTTON(self, self.button.GetId(), self.OnButton)
sizer.Add(self.button, 0, wx.EXPAND)
self.browser = wx.GenericDirCtrl(self, -1, style=wx.DIRCTRL_SHOW_FILTERS, filter=_pype.wildcard, defaultFilter=0)
try:
#for all other wxPython versions
self.browser.ShowHidden(1)
except TypeError:
#for wxPython 2.7.0 - 2.7.1.2
self.browser.ShowHidden = 1
tree = self.browser.GetTreeCtrl()
tree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnActivate, tree)
sizer.Add(self.browser, 1, wx.EXPAND)
#create menu
self.m = wx.Menu()
np = wx.NewId()
self.m.Append(np, "Add Selected Path")
wx.EVT_MENU(self, np, self.OnNewPathmark)
self.m.AppendMenu(wx.NewId(), "Choose Path", self.op)
self.m.AppendSeparator()
self.m.AppendMenu(wx.NewId(), "Remove Path", self.rp)
wx.CallAfter(self.sizer.Layout)
def chdir(self, path):
self.root.config.pop('lastpath', None)
_pype.current_path = path
def gethier(self):
p = self.browser.GetFilePath()
## print "Path:", p
return p
def OnActivate(self, evt):
fn = self.gethier()
try:
st = os.stat(fn)[0]
if stat.S_ISREG(st):
self.root.OnDrop([fn])
except:
evt.Skip()
def OnNewPathmark(self, evt):
fn = self.browser.GetPath()
try:
st = os.stat(fn)[0]
if stat.S_ISDIR(st):
self.op.ItemAdd(fn)
self.rp.ItemAdd(fn)
except:
evt.Skip()
def OnButton(self, evt):
self.PopupMenu(self.m, self.button.GetPositionTuple())