2
# This file is part of GNU Enterprise.
4
# GNU Enterprise is free software; you can redistribute it
5
# and/or modify it under the terms of the GNU General Public
6
# License as published by the Free Software Foundation; either
7
# version 2, or (at your option) any later version.
9
# GNU Enterprise is distributed in the hope that it will be
10
# useful, but WITHOUT ANY WARRANTY; without even the implied
11
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
# PURPOSE. See the GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public
15
# License along with program; see the file COPYING. If not,
16
# write to the Free Software Foundation, Inc., 59 Temple Place
17
# - Suite 330, Boston, MA 02111-1307, USA.
19
# Copyright 2002-2005 Free Software Foundation
34
from constants import *
35
from Control import Control
36
from ScrollBar import ScrollBar
38
class FileSelectPad(Control):
44
def __init__(self, Root, Y, X,H, W, **properties):
45
Control.__init__(self, Root, '', properties)
57
self.NAME = 'fileselectpad'
58
self.SetMethod("SYSRUN",self.Run)
59
self.SetMethod("GOTFOCUS",self.GotFocus)
60
self.SetMethod("LOSTFOCUS",self.LostFocus)
61
# self.SetMethod("SYSPAINT",self.Paint)
62
self.SetMethod("PAINT",self.Paint)
65
self.COLDISP = W / self.COLWIDTH
77
def Run(self,v1,v2,v3):
80
self.__SetHilit(v2,v3)
82
self.sb.Set(self.hilit / rows)
83
if self.dirlist[self.hilit-1][:1] != 'D':
84
active = self.GetMethod("ACTIVE")
85
if active != None and self.Verify(None,None,None):
86
apply(active,(self,self.dirlist[self.hilit-1][self.__prefix_width__:],None))
87
action = self.GetMethod("ACTION")
88
if action != None and self.Verify(None,None,None):
89
if self.path[-1:] != '/':
91
apply(action,(self,self.path + self.dirlist[self.hilit-1][self.__prefix_width__:],None))
93
Container = self.SCREEN
95
self.__DrawItem(self.hilit,1)
98
ch = Container.GetChar()
99
if self.PARENT.BreakOrder(ch) :
101
if ch in (Container.TokNextField,):
103
elif ch == Container.TokActivate:
104
action = self.GetMethod("ACTION")
105
if action != None and self.Verify(None,None,None):
106
if self.path[-1:] != '/':
108
apply(action,(self,self.path + self.dirlist[self.hilit-1][self.__prefix_width__:], None))
109
elif ch == Container.TokDownArrow:
111
if self.Verify(None,None,None) and self.sb != None:
112
col = (self.hilit) / self.ROWS
114
elif ch == Container.TokUpArrow:
116
if self.Verify(None,None,None) and self.sb != None:
117
col = (self.hilit) / self.ROWS
119
elif ch == Container.TokLeftArrow:
121
if self.Verify(None,None,None) and self.sb != None:
122
self.sb.Dec(None,None,None)
123
elif ch == Container.TokRightArrow:
125
if self.Verify(None,None,None) and self.sb != None:
126
self.sb.Inc(None,None,None)
127
if self.hilit > len(self.dirlist):
128
self.hilit = len(self.dirlist)
129
elif self.hilit <= 0:
131
active = self.GetMethod("ACTIVE")
132
if active != None and self.Verify(None,None,None):
133
apply(active,(self,self.dirlist[self.hilit-1][self.__prefix_width__:],None))
136
def GotFocus(self,v1,v2,v3):
142
self.Paint(None,None,None)
145
def LostFocus(self,v1,v2,v3):
147
self.Paint(None,None,None)
150
def Display(self, path):
155
if os.access(path, os.R_OK | os.X_OK) and os.path.isdir(path):
157
self.dirlist = os.listdir(path)
158
self.__SortAndMarkDirList()
159
count = len(self.dirlist)
161
colwidth = self.COLWIDTH
162
if (count) * colwidth > self.__area():
168
cols = ((count / rows) * colwidth)
169
self.pad = curses.newpad(rows+1,cols+((self.COLDISP+1) * (colwidth)))
170
self.__initScrollBar( setupSB, (count / rows) )
171
if curses.has_colors():
172
self.pad.bkgdset(' ',curses.color_pair(1))
175
self.Paint(None,None,None)
176
self.SCREEN.Refresh()
179
def __initScrollBar(self, activate, cols):
184
self.sb = ScrollBar(self.PARENT,'filesb',self.H+3,2, self.W)
185
self.PARENT.AddControl(self.sb)
188
self.PARENT.Refresh(None,None,None)
189
self.sb.SetMethod("CHANGED", self.SetCol)
190
elif self.sb != None:
191
self.PARENT.DelControl(self.sb)
193
self.PARENT.Refresh(None,None,None)
196
def SetCol(self,newCol,MaxCol,arg3):
197
self.__DrawItem(self.hilit,1)
199
if newCol <= self._cols and newCol >= 0:
200
self.hilit = (rows * (newCol)) + self.yoffset + 1
203
elif self.hilit > len(self.dirlist):
204
self.hilit = len(self.dirlist)
205
if self.dirlist[self.hilit-1][:1] != 'D':
206
active = self.GetMethod("ACTIVE")
207
if active != None and self.Verify(None,None,None):
208
apply(active,(self,self.dirlist[self.hilit-1][self.__prefix_width__:],None))
209
self.Paint(None, None,None)
210
self.PARENT.Screen().Refresh()
212
def __SortAndMarkDirList(self):
215
path = self.path + '/'
216
dirSort = [ [ not os.path.isdir(path + x), x ] for x in self.dirlist ]
222
i[1] = string.ljust('D',self.__prefix_width__) + i[1]
225
i[1] = string.ljust('',self.__prefix_width__)+i[1]
231
for i in range(0,len(self.dirlist)):
232
if os.path.islink(path + self.dirlist[i][self.__prefix_width__:]):
233
inter = self.dirlist[i][:1] + 'l' + self.dirlist[i][2:]
234
self.dirlist[i] = inter
236
if os.access( path + self.dirlist[i][self.__prefix_width__:], mod ):
237
self.dirlist[i] = self.dirlist[i][:2] + 'r' + self.dirlist[i][3:]
239
self.dirlist[i] = self.dirlist[i][:2] + '-' + self.dirlist[i][3:]
241
if os.access( path + self.dirlist[i][self.__prefix_width__:], mod ):
242
self.dirlist[i] = self.dirlist[i][:3] + 'w' + self.dirlist[i][4:]
244
self.dirlist[i] = self.dirlist[i][:3] + '-' + self.dirlist[i][4:]
246
if os.access( path + self.dirlist[i][self.__prefix_width__:], mod ):
247
self.dirlist[i] = self.dirlist[i][:4] + 'x' + self.dirlist[i][5:]
249
self.dirlist[i] = self.dirlist[i][:4] + '-' + self.dirlist[i][5:]
251
return self.H* self.W
253
def Paint(self,arg1,arg2,arg3):
254
if self.pad != None and self.__first == 0:
255
self.__DrawItem(self.hilit,3)
257
colwidth = self.COLWIDTH
258
self.yoffset = (self.hilit-1) % rows
259
newXoffset = ((self.hilit-1) / rows ) * colwidth
260
self.xoffset = newXoffset
261
self.pad.refresh(0, self.xoffset,self.Y,self.X,
262
self.Y + self._H,self.X + self._W)
264
def fillpad(self, showProgress = 0):
272
if pb != None and len(self.dirlist) > self.__threshhold__:
274
pb.Init(len(self.dirlist))
276
for i in range(1,len(self.dirlist)+1):
280
if i == self.hilit and self.FOCUS:
282
elif self.dirlist[i-1][2] != 'r':
284
self.__DrawItem(i,color)
286
xoffset += self.COLWIDTH
295
def __DrawItem(self,id,col):
296
if self.pad != None and len(self.dirlist)>0:
298
hilitCol = ((id-1) / rows) * self.COLWIDTH
299
hilitRow = (id-1) % rows
301
self.pad.addstr(hilitRow,hilitCol,'')
302
String = str(self.dirlist[id-1][:self.COLWIDTH-2])
303
if String[2]!='r' and col == 1:
305
if curses.has_colors():
306
mods = curses.color_pair(col)
307
for j in range(0,len(String)):
308
if ord(String[j]) == tiHLINE:
309
self.pad.addch(curses.ACS_HLINE, mods)
310
elif ord(String[j]) == tiVLINE:
311
self.pad.addch(curses.ACS_VLINE, mods)
312
elif ord(String[j]) == tiBOX:
313
self.pad.addch(curses.ACS_BOARD, mods)
315
self.pad.addstr(str(String[j]), mods)
316
def __SetHilit(self, YPOS, XPOS):
317
self.__DrawItem(self.hilit,1)
318
colNo = (self.xoffset + (XPOS-self.X)) / self.COLWIDTH
319
self.hilit = ( colNo * self.ROWS) + (YPOS-self.Y) + 1
322
if self.hilit > len(self.dirlist):
323
self.hilit = len(self.dirlist)
324
self.__DrawItem(self.hilit,3)
326
def Verify(self, arg1, arg2, arg3):
327
return self.hilit > 0 and self.hilit <= len(self.dirlist)