1 # -*- coding: utf-8 -*-
5 This module contains some windows for lfm use.
16 ######################################################################
17 ##### module variables
23 ######################################################################
25 """A superclass for 'error' and 'win' windows"""
27 def __init__(self
, title
, text
, br_att
, br_bg
, bd_att
, bd_bg
, waitkey
= 1):
28 self
.waitkey
= waitkey
29 text
= text
.replace('\t', ' ' * 4)
30 lines
= text
.split('\n')
31 length
= max(map(len, lines
))
33 w
= min(max(max(length
+6, 27+4), len(title
)+6), app
.maxw
-2)
34 if length
< 27 + 4 and len(title
) <= length
:
37 w
= min(max(length
+6, len(title
)+6), app
.maxw
-2)
38 if len(title
) < length
:
42 h
+= int((len(l
)+1) / (app
.maxw
-2))
45 text
= ''.join([l
+'\n' for l
in lines
[-5:]])
47 win
= curses
.newwin(h
, w
,
48 int((app
.maxh
-h
)/2), int((app
.maxw
-w
)/2))
49 self
.pwin
= curses
.panel
.new_panel(win
)
52 print 'Can\'t create window'
54 win
.bkgd(br_bg
, br_att
)
57 if len(title
) > app
.maxw
-14:
58 title
= title
[:app
.maxw
-10] + '...' + '\''
59 win
.addstr(0, int((w
-len(title
)-2)/2), ' %s ' % title
, curses
.A_BOLD
)
61 win
.addstr(2, 2, text
, bd_att
)
63 win
.addstr(2, 1, text
, bd_att
)
65 win
.addstr(h
-1, int((w
-27)/2), ' Press any key to continue ', br_att
)
71 while not self
.pwin
.window().getch():
76 class FixSizeCommonWindow
:
77 """A superclass for messages, with fixed size"""
79 def __init__(self
, title
, text
, downtext
,
80 br_att
, br_bg
, bd_att
, bd_bg
, waitkey
= 1):
81 self
.waitkey
= waitkey
82 text
= text
.replace('\t', ' ' * 4)
84 if len(title
) > w
- 4:
88 if len(downtext
) > w
- 4:
89 downtext
= downtext
[:w
-4]
92 win
= curses
.newwin(h
, w
,
93 int((app
.maxh
-h
)/2), int((app
.maxw
-w
)/2))
94 self
.pwin
= curses
.panel
.new_panel(win
)
97 print 'Can\'t create window'
99 win
.bkgd(br_bg
, br_att
)
102 if len(title
) > app
.maxw
- 14:
103 title
= title
[:app
.maxw
-10] + '...' + '\''
104 win
.addstr(0, int((w
-len(title
)-2)/2), ' %s ' % title
, curses
.A_BOLD
)
106 win
.addstr(2, 2, text
, bd_att
)
108 win
.addstr(2, 1, text
, bd_att
)
110 win
.addstr(h
-1, int((w
-27)/2),
111 ' Press any key to continue ', br_att
)
113 win
.addstr(h
-1, int((w
-len(downtext
)-2)/2),
114 ' %s ' % downtext
, br_att
)
120 while not self
.pwin
.window().getch():
125 class FixSizeProgressBarWindow
:
126 """Like FixSizeCommonWindow but with a ProgressBar"""
128 def __init__(self
, title
, text
, downtext
, percent
,
129 bd_att
, bd_bg
, pb_att
, pb_bg
, waitkey
= 1):
130 title
= title
[:app
.maxw
-14]
131 text
= text
[:app
.maxw
-14]
132 self
.waitkey
= waitkey
133 text
= text
.replace('\t', ' ' * 4)
135 if len(title
) > w
- 4:
137 if len(text
) > w
- 4:
139 if len(downtext
) > w
- 4:
140 downtext
= downtext
[:w
-4]
142 self
.h
, self
.w
= h
, w
143 self
.bd_att
, self
.pb_att
= bd_att
, pb_att
145 win
= curses
.newwin(h
, w
,
146 int((app
.maxh
-h
)/2), int((app
.maxw
-w
)/2))
147 self
.progressbar
= curses
.newpad(1, w
-11+1)
148 self
.pwin
= curses
.panel
.new_panel(win
)
151 print 'Can\'t create window'
153 win
.bkgd(bd_bg
, bd_att
)
154 self
.progressbar
.bkgd(curses
.ACS_CKBOARD
, pb_bg
)
158 def show(self
, title
, text
, downtext
, percent
):
159 self
.pwin
.window().erase()
160 self
.pwin
.window().box(0, 0)
161 if len(title
) > app
.maxw
- 14:
162 title
= title
[:app
.maxw
-10] + '...' + '\''
163 self
.pwin
.window().addstr(0, int((self
.w
-len(title
)-2)/2),
164 ' %s ' % title
, curses
.A_BOLD
)
165 self
.pwin
.window().addstr(2, 2, text
)
166 w1
= percent
* (self
.w
-11) / 100
167 self
.progressbar
.erase()
168 self
.progressbar
.addstr(0, 0, ' ' * w1
, self
.pb_att | curses
.A_BOLD
)
169 self
.pwin
.window().addstr(self
.h
-3, self
.w
-8, '[%3d%%]' % percent
)
171 self
.pwin
.window().addstr(self
.h
-1, int((self
.w
-27)/2),
172 ' Press any key to continue ')
174 self
.pwin
.window().addstr(self
.h
-1, int((self
.w
-len(downtext
)-2)/2),
176 self
.pwin
.window().refresh()
177 y0
= int((app
.maxh
-self
.h
)/2) + 4
178 x0
= int((app
.maxw
-self
.w
)/2) + 2
179 self
.progressbar
.refresh(0, 0, y0
, x0
, y0
+1, x0
+self
.w
-12)
180 self
.pwin
.window().refresh()
183 ######################################################################
184 def error(title
, msg
= '', file = ''):
185 """show an error window"""
190 buf
= '%s: %s' % (file, msg
)
191 CommonWindow(title
, buf
,
192 curses
.color_pair(8),
193 curses
.color_pair(8),
194 curses
.color_pair(7) | curses
.A_BOLD
,
195 curses
.color_pair(7)).run()
198 ######################################################################
199 def win(title
, text
):
200 """show a message window and wait for a key"""
202 CommonWindow(title
, text
,
203 curses
.color_pair(1), curses
.color_pair(1),
204 curses
.color_pair(4), curses
.color_pair(4)).run()
207 def win_nokey(title
, text
, downtext
= ''):
208 """show a message window, does not wait for a key"""
210 FixSizeCommonWindow(title
, text
, downtext
,
211 curses
.color_pair(1), curses
.color_pair(1),
212 curses
.color_pair(1), curses
.color_pair(1),
216 ######################################################################
218 """show a not-yet-implemented message"""
221 'Sorry, but this function\n is not implemented yet!',
222 curses
.color_pair(1) | curses
.A_BOLD
, curses
.color_pair(1),
223 curses
.color_pair(4), curses
.color_pair(4)).run()
226 ######################################################################
227 def get_a_key(title
, question
):
228 """show a window returning key pressed"""
230 question
= question
.replace('\t', ' ' * 4)
231 lines
= question
.split('\n')
232 length
= max(map(len, lines
))
233 h
= min(len(lines
)+4, app
.maxh
-2)
234 w
= min(length
+4, app
.maxw
-2)
236 win
= curses
.newwin(h
, w
, int((app
.maxh
-h
)/2), int((app
.maxw
-w
)/2))
237 pwin
= curses
.panel
.new_panel(win
)
240 print 'Can\'t create window'
242 win
.bkgd(curses
.color_pair(1))
246 win
.addstr(0, int((w
-len(title
)-2)/2), ' %s' % title
,
247 curses
.color_pair(1) | curses
.A_BOLD
)
248 for row
, l
in enumerate(lines
):
249 win
.addstr(row
+2, 2, l
)
254 if ch
in (0x03, 0x1B): # Ctrl-C, ESC
257 elif 0x01 <= ch
<= 0xFF:
264 ######################################################################
265 def confirm(title
, question
, default
= 0):
266 """show a yes/no window, returning 1/0"""
269 w
= min(max(34, len(question
)+5), app
.maxw
-2)
271 win
= curses
.newwin(h
, w
, int((app
.maxh
-h
)/2), int((app
.maxw
-w
)/2))
272 pwin
= curses
.panel
.new_panel(win
)
275 print 'Can\'t create window'
277 win
.bkgd(curses
.color_pair(1))
281 win
.addstr(0, int((w
-len(title
)-2)/2), ' %s' % title
.capitalize(),
282 curses
.color_pair(1) | curses
.A_BOLD
)
283 win
.addstr(1, 2 , '%s?' % question
)
286 row
= int((app
.maxh
-h
)/2) + 3
287 col
= int((app
.maxw
-w
)/2)
288 col1
= col
+ int(w
/5) + 1
289 col2
= col
+ int(w
*4/5) - 6
294 attr_yes
= curses
.color_pair(9) | curses
.A_BOLD
295 attr_no
= curses
.color_pair(1) | curses
.A_BOLD
297 attr_yes
= curses
.color_pair(1) | curses
.A_BOLD
298 attr_no
= curses
.color_pair(9) | curses
.A_BOLD
299 btn
= curses
.newpad(1, 8)
300 btn
.addstr(0, 0, '[ Yes ]', attr_yes
)
301 btn
.refresh(0, 0, row
, col1
, row
+ 1, col1
+ 6)
302 btn
= curses
.newpad(1, 7)
303 btn
.addstr(0, 0, '[ No ]', attr_no
)
304 btn
.refresh(0, 0, row
, col2
, row
+ 1, col2
+ 5)
307 if ch
in (curses
.KEY_UP
, curses
.KEY_DOWN
, curses
.KEY_LEFT
,
308 curses
.KEY_RIGHT
, 9):
310 elif ch
in (ord('Y'), ord('y')):
313 elif ch
in (ord('N'), ord('n')):
316 elif ch
in (0x03, 0x1B): # Ctrl-C, ESC
319 elif ch
in (10, 13): # enter
328 ######################################################################
329 def confirm_all(title
, question
, default
= 0):
330 """show a yes/all/no/stop window, returning 1/2/0/-1"""
333 w
= min(max(45, len(question
)+5), app
.maxw
-2)
335 win
= curses
.newwin(h
, w
, int((app
.maxh
-h
)/2), int((app
.maxw
-w
)/2))
336 pwin
= curses
.panel
.new_panel(win
)
339 print 'Can\'t create window'
341 win
.bkgd(curses
.color_pair(1))
345 win
.addstr(0, int((w
-len(title
)-2)/2), ' %s ' % title
,
346 curses
.color_pair(1) | curses
.A_BOLD
)
347 win
.addstr(1, 2 , '%s?' % question
)
350 row
= int((app
.maxh
-h
) / 2) + 3
351 col
= int((app
.maxw
-w
) / 2)
362 attr_yes
= curses
.color_pair(9) | curses
.A_BOLD
363 attr_all
= curses
.color_pair(1) | curses
.A_BOLD
364 attr_no
= curses
.color_pair(1) | curses
.A_BOLD
365 attr_skipall
= curses
.color_pair(1) | curses
.A_BOLD
367 attr_yes
= curses
.color_pair(1) | curses
.A_BOLD
368 attr_all
= curses
.color_pair(9) | curses
.A_BOLD
369 attr_no
= curses
.color_pair(1) | curses
.A_BOLD
370 attr_skipall
= curses
.color_pair(1) | curses
.A_BOLD
372 attr_yes
= curses
.color_pair(1) | curses
.A_BOLD
373 attr_all
= curses
.color_pair(1) | curses
.A_BOLD
374 attr_no
= curses
.color_pair(9) | curses
.A_BOLD
375 attr_skipall
= curses
.color_pair(1) | curses
.A_BOLD
377 attr_yes
= curses
.color_pair(1) | curses
.A_BOLD
378 attr_all
= curses
.color_pair(1) | curses
.A_BOLD
379 attr_no
= curses
.color_pair(1) | curses
.A_BOLD
380 attr_skipall
= curses
.color_pair(9) | curses
.A_BOLD
383 btn
= curses
.newpad(1, 8)
384 btn
.addstr(0, 0, '[ Yes ]', attr_yes
)
385 btn
.refresh(0, 0, row
, col1
, row
+ 1, col1
+ 6)
386 btn
= curses
.newpad(1, 8)
387 btn
.addstr(0, 0, '[ All ]', attr_all
)
388 btn
.refresh(0, 0, row
, col2
, row
+ 1, col2
+ 6)
389 btn
= curses
.newpad(1, 7)
390 btn
.addstr(0, 0, '[ No ]', attr_no
)
391 btn
.refresh(0, 0, row
, col3
, row
+ 1, col3
+ 5)
392 btn
= curses
.newpad(1, 15)
393 btn
.addstr(0, 0, '[ Stop ]', attr_skipall
)
394 btn
.refresh(0, 0, row
, col4
, row
+ 1, col4
+ 7)
397 if ch
in (curses
.KEY_UP
, curses
.KEY_DOWN
, curses
.KEY_LEFT
,
398 curses
.KEY_RIGHT
, 9):
409 elif ch
in (ord('Y'), ord('y')):
412 elif ch
in (ord('A'), ord('a')):
415 elif ch
in (ord('N'), ord('n')):
418 elif ch
in (ord('S'), ord('s'), 0x03, 0x1B): # Ctrl-C, ESC
421 elif ch
in (10, 13): # enter
430 ######################################################################
431 def confirm_all_none(title
, question
, default
= 0):
432 """show a yes/all/no/none/stop window, returning 1/2/0/-2/-1"""
435 w
= min(max(50, len(question
)+5), app
.maxw
-2)
437 win
= curses
.newwin(h
, w
, int((app
.maxh
-h
)/2), int((app
.maxw
-w
)/2))
438 pwin
= curses
.panel
.new_panel(win
)
441 print 'Can\'t create window'
443 win
.bkgd(curses
.color_pair(1))
447 win
.addstr(0, int((w
-len(title
)-2)/2), ' %s ' % title
,
448 curses
.color_pair(1) | curses
.A_BOLD
)
449 win
.addstr(1, 2 , '%s?' % question
)
452 row
= int((app
.maxh
-h
) / 2) + 3
453 col
= int((app
.maxw
-w
) / 2)
465 attr_yes
= curses
.color_pair(9) | curses
.A_BOLD
466 attr_all
= curses
.color_pair(1) | curses
.A_BOLD
467 attr_no
= curses
.color_pair(1) | curses
.A_BOLD
468 attr_none
= curses
.color_pair(1) | curses
.A_BOLD
469 attr_skipall
= curses
.color_pair(1) | curses
.A_BOLD
471 attr_yes
= curses
.color_pair(1) | curses
.A_BOLD
472 attr_all
= curses
.color_pair(9) | curses
.A_BOLD
473 attr_no
= curses
.color_pair(1) | curses
.A_BOLD
474 attr_none
= curses
.color_pair(1) | curses
.A_BOLD
475 attr_skipall
= curses
.color_pair(1) | curses
.A_BOLD
477 attr_yes
= curses
.color_pair(1) | curses
.A_BOLD
478 attr_all
= curses
.color_pair(1) | curses
.A_BOLD
479 attr_no
= curses
.color_pair(9) | curses
.A_BOLD
480 attr_none
= curses
.color_pair(1) | curses
.A_BOLD
481 attr_skipall
= curses
.color_pair(1) | curses
.A_BOLD
483 attr_yes
= curses
.color_pair(1) | curses
.A_BOLD
484 attr_all
= curses
.color_pair(1) | curses
.A_BOLD
485 attr_no
= curses
.color_pair(1) | curses
.A_BOLD
486 attr_none
= curses
.color_pair(9) | curses
.A_BOLD
487 attr_skipall
= curses
.color_pair(1) | curses
.A_BOLD
489 attr_yes
= curses
.color_pair(1) | curses
.A_BOLD
490 attr_all
= curses
.color_pair(1) | curses
.A_BOLD
491 attr_no
= curses
.color_pair(1) | curses
.A_BOLD
492 attr_none
= curses
.color_pair(1) | curses
.A_BOLD
493 attr_skipall
= curses
.color_pair(9) | curses
.A_BOLD
496 btn
= curses
.newpad(1, 8)
497 btn
.addstr(0, 0, '[ Yes ]', attr_yes
)
498 btn
.refresh(0, 0, row
, col1
, row
+ 1, col1
+ 6)
499 btn
= curses
.newpad(1, 8)
500 btn
.addstr(0, 0, '[ All ]', attr_all
)
501 btn
.refresh(0, 0, row
, col2
, row
+ 1, col2
+ 6)
502 btn
= curses
.newpad(1, 7)
503 btn
.addstr(0, 0, '[ No ]', attr_no
)
504 btn
.refresh(0, 0, row
, col3
, row
+ 1, col3
+ 5)
505 btn
= curses
.newpad(1, 9)
506 btn
.addstr(0, 0, '[ NOne ]', attr_none
)
507 btn
.refresh(0, 0, row
, col4
, row
+ 1, col4
+ 7)
508 btn
= curses
.newpad(1, 9)
509 btn
.addstr(0, 0, '[ Stop ]', attr_skipall
)
510 btn
.refresh(0, 0, row
, col5
, row
+ 1, col5
+ 7)
513 if ch
in (curses
.KEY_UP
, curses
.KEY_DOWN
, curses
.KEY_LEFT
,
514 curses
.KEY_RIGHT
, 9):
527 elif ch
in (ord('Y'), ord('y')):
530 elif ch
in (ord('A'), ord('a')):
533 elif ch
in (ord('N'), ord('n')):
536 elif ch
in (ord('O'), ord('o')):
539 elif ch
in (ord('S'), ord('s'), 0x03, 0x1B): # Ctrl-C, ESC
542 elif ch
in (10, 13): # enter
551 ######################################################################
552 class Yes_No_Buttons
:
555 def __init__(self
, w
, h
, d
):
556 self
.row
= int((app
.maxh
-h
) / 2) + 4 + d
557 col
= int((app
.maxw
-w
) / 2)
558 self
.col1
= col
+ int(w
/5) + 1
559 self
.col2
= col
+ int(w
*4/5) - 6
565 attr1
= curses
.color_pair(1) | curses
.A_BOLD
566 attr2
= curses
.color_pair(1) | curses
.A_BOLD
567 elif self
.active
== 1:
568 attr1
= curses
.color_pair(9) | curses
.A_BOLD
569 attr2
= curses
.color_pair(1) | curses
.A_BOLD
571 attr1
= curses
.color_pair(1) | curses
.A_BOLD
572 attr2
= curses
.color_pair(9) | curses
.A_BOLD
573 btn
= curses
.newpad(1, 8)
574 btn
.addstr(0, 0, '[<Yes>]', attr1
)
575 btn
.refresh(0, 0, self
.row
, self
.col1
, self
.row
+ 1, self
.col1
+ 6)
576 btn
= curses
.newpad(1, 7)
577 btn
.addstr(0, 0, '[ No ]', attr2
)
578 btn
.refresh(0, 0, self
.row
, self
.col2
, self
.row
+ 1, self
.col2
+ 5)
581 def manage_keys(self
):
582 tmp
= curses
.newpad(1, 1)
585 if ch
in (0x03, 0x1B): # Ctrl-C, ESC
587 elif ch
== ord('\t'):
589 elif ch
in (10, 13): # enter
598 ######################################################################
600 """An entry line to enter a dir. or file, a pattern, etc"""
602 def __init__(self
, w
, h
, x
, y
, path
, with_historic
, with_complete
,
604 self
.enc
= app
.prefs
.settings
['encoding']
606 self
.entry
= curses
.newwin(1, w
-4+1, x
, y
)
608 print 'Can\'t create window'
610 self
.entry
.attrset(curses
.color_pair(11) | curses
.A_BOLD
)
615 self
.entry_width
= w
- 4
617 self
.panelpath
= panelpath
618 self
.pos
= len(self
.utext())
621 self
.with_complete
= with_complete
622 self
.with_historic
= with_historic
623 if self
.with_historic
:
624 self
.historic
= historic
[:]
625 self
.historic_i
= len(self
.historic
)
628 """ decoded self.text with respection to encoding """
629 return self
.text
.decode(self
.enc
)
632 """ byte pos in self.text for decoded self.text """
633 return len(self
.utext()[:self
.pos
].encode(self
.enc
))
638 ew
= self
.entry_width
639 ltext
= len(self
.utext())
643 textstr
= text
+ ' ' * (ew
- ltext
)
645 textstr
= text
.decode(self
.enc
)[:ew
].encode(self
.enc
)
647 if pos
> ltext
- (ew
-1):
648 relpos
= ew
- 1 - (ltext
- pos
)
649 textstr
= text
.decode(self
.enc
)[ltext
-ew
+1:].encode(self
.enc
) + ' '
651 relpos
= pos
- int(pos
/ew
)*ew
652 textstr
= text
.decode(self
.enc
)[int(pos
/ew
)*ew
:int(pos
/ew
)*ew
+ew
].encode(self
.enc
)
653 self
.entry
.bkgd(curses
.color_pair(1))
655 self
.entry
.addstr(textstr
.decode(self
.enc
)[:ew
].encode(self
.enc
), curses
.color_pair(11) | curses
.A_BOLD
)
656 self
.entry
.move(0, relpos
)
660 def manage_keys(self
):
663 ch
= self
.entry
.getch()
664 # print 'key: \'%s\' <=> %c <=> 0x%X <=> %d' % \
665 # (curses.keyname(ch), ch & 255, ch, ch)
666 if ch
in (0x03, 0x1B): # Ctrl-C, ESC
668 elif ch
== curses
.KEY_UP
:
669 if self
.with_historic
:
670 if self
.historic_i
> 0:
671 if self
.historic_i
== len(self
.historic
):
672 if self
.text
== None:
674 self
.historic
.append(self
.text
)
676 self
.text
= self
.historic
[self
.historic_i
]
677 self
.pos
= len(self
.text
)
680 elif ch
== curses
.KEY_DOWN
:
681 if self
.with_historic
:
682 if self
.historic_i
< len(self
.historic
) - 1:
684 self
.text
= self
.historic
[self
.historic_i
]
685 self
.pos
= len(self
.text
)
688 elif ch
== 0x14: # Ctrl-T
690 elif ch
in (10, 13): # enter
692 elif ch
== ord('\t'): # tab
693 if self
.with_complete
:
694 entries
= files
.complete(self
.text
, self
.panelpath
)
698 elif len(entries
) == 1:
699 selected
= entries
.pop()
701 y
, x
= self
.entry
.getbegyx()
702 selected
= SelectItem(entries
, y
+ 1, x
- 2).run()
706 self
.text
= files
.join(self
.text
, selected
)
707 self
.pos
= len(self
.text
)
711 # chars and edit keys
712 elif ch
== 0x17: # Ctrl-W
713 if self
.text
== None or self
.text
== '':
719 if text
[len(text
)-1] == os
.sep
:
720 text
= os
.path
.dirname(text
)
721 text
= os
.path
.dirname(text
)
722 if text
!= '' and text
!= os
.sep
:
725 self
.pos
= len(self
.text
)
726 elif ch
== 0x04: # Ctrl-D
727 if self
.text
== None or self
.text
== '':
731 self
.pos
= len(self
.text
)
732 elif ch
== curses
.KEY_IC
: # insert
733 self
.ins
= not self
.ins
734 elif ch
in (curses
.KEY_HOME
, 0x01): # home
736 elif ch
in (curses
.KEY_END
, 0x05): # end
737 self
.pos
= len(self
.utext())
738 elif ch
== curses
.KEY_LEFT
and self
.pos
> 0:
740 elif ch
== curses
.KEY_RIGHT
and self
.pos
< len(self
.utext()):
742 elif ch
in (8, 127, curses
.KEY_BACKSPACE
) and len(self
.utext()) > 0 and \
743 self
.pos
> 0: # backspace
745 utext
= utext
[:self
.pos
-1] + utext
[self
.pos
:]
746 self
.text
= utext
.encode(self
.enc
)
748 elif ch
== curses
.KEY_DC
and self
.pos
< len(self
.text
): # del
750 utext
= utext
[:self
.pos
] + utext
[self
.pos
+1:]
751 self
.text
= utext
.encode(self
.enc
)
752 elif len(self
.text
) < 255 and 32 <= ch
<= 255:
755 uchar
= self
.buf
.decode(self
.enc
)
756 except UnicodeDecodeError:
762 self
.text
= self
.text
[:bpos
] + uchar
.encode(self
.enc
) + self
.text
[bpos
:]
764 self
.text
= self
.text
[:bpos
] + uchar
.encode(self
.enc
) + self
.text
[bpos
+1:]
771 ######################################################################
773 """An entry window to enter a dir. or file, a pattern, ..."""
775 def __init__(self
, title
, help, path
= '', with_historic
= 1,
776 with_complete
= 1, panelpath
= ''):
778 w
= min(max(34, len(help)+5), app
.maxw
-2)
780 win
= curses
.newwin(h
, w
, int((app
.maxh
-h
)/2), int((app
.maxw
-w
)/2))
781 self
.entry
= EntryLine(w
, h
,
782 int((app
.maxh
-h
)/2)+2, int((app
.maxw
-w
+4)/2),
783 path
, with_historic
, with_complete
,
785 self
.btns
= Yes_No_Buttons(w
, h
, 0)
786 self
.pwin
= curses
.panel
.new_panel(win
)
789 print 'Can\'t create window'
791 win
.bkgd(curses
.color_pair(1))
794 win
.addstr(1, 2 , '%s:' % help)
795 win
.addstr(0, int((w
-len(title
)-2)/2), ' %s ' % title
,
796 curses
.color_pair(1) | curses
.A_BOLD
)
799 self
.with_historic
= with_historic
800 self
.active_widget
= self
.entry
804 self
.entry
.entry
.refresh() # needed to avoid a problem with blank paths
812 ans
= self
.active_widget
.manage_keys()
813 if ans
== -1: # Ctrl-C
816 elif ans
== ord('\t'): # tab
817 if self
.active_widget
== self
.entry
:
818 self
.active_widget
= self
.btns
821 answer
= self
.entry
.text
822 elif self
.active_widget
== self
.btns
and self
.btns
.active
== 1:
827 self
.active_widget
= self
.entry
830 elif ans
== 0x14: # Ctrl-T
831 # this is a hack, we need to return to refresh Entry
832 return [self
.entry
.text
]
833 elif ans
== 10: # return values
835 answer
= self
.entry
.text
839 # save new historic entries
840 if self
.with_historic
:
841 if self
.entry
.text
and self
.entry
.text
!= '*':
842 if len(historic
) < HISTORIC_MAXLEN
:
843 historic
.append(self
.entry
.text
)
848 historic
.append(self
.entry
.text
)
853 ######################################################################
855 """An entry window to enter 2 dirs. or files, patterns, ..."""
857 def __init__(self
, title
, help1
= '', path1
= '',
858 with_historic1
= 1, with_complete1
= 1, panelpath1
= '',
859 help2
= '', path2
= '',
860 with_historic2
= 1, with_complete2
= 1, panelpath2
= '',
863 w
= min(max(34, max(len(help1
), len(help2
))+5), app
.maxw
-2)
865 win
= curses
.newwin(h
, w
, int((app
.maxh
-h
)/2)-1, int((app
.maxw
-w
)/2))
866 self
.entry1
= EntryLine(w
, h
,
867 int((app
.maxh
-h
)/2) + 1,
868 int((app
.maxw
-w
+4) / 2),
869 path1
, with_historic1
, with_complete1
,
871 self
.entry2
= EntryLine(w
, h
,
872 int((app
.maxh
-h
)/2) + 4,
873 int((app
.maxw
-w
+4) / 2),
874 path2
, with_historic2
, with_complete2
,
876 self
.btns
= Yes_No_Buttons(w
, h
, 2)
877 self
.pwin
= curses
.panel
.new_panel(win
)
880 print 'Can\'t create window'
882 win
.bkgd(curses
.color_pair(1))
885 win
.addstr(1, 2 , '%s:' % help1
)
886 win
.addstr(4, 2 , '%s:' % help2
)
887 win
.addstr(0, int((w
-len(title
)-2)/2), ' %s ' % title
,
888 curses
.color_pair(1) | curses
.A_BOLD
)
891 self
.with_historic
= with_historic1
or with_historic2
892 self
.active_entry_i
= active_entry
893 if self
.active_entry_i
== 0:
894 self
.active_entry
= self
.entry1
896 self
.active_entry
= self
.entry2
900 # needed to avoid a problem with blank paths
901 self
.entry1
.entry
.refresh()
902 self
.entry2
.entry
.refresh()
912 if self
.active_entry_i
in [0, 1]:
913 ans
= self
.active_entry
.manage_keys()
915 ans
= self
.btns
.manage_keys()
916 if ans
== -1: # Ctrl-C
919 elif ans
== ord('\t'): # tab
920 self
.active_entry_i
+= 1
921 if self
.active_entry_i
> 3:
922 self
.active_entry_i
= 0
923 if self
.active_entry_i
== 0:
924 self
.active_entry
= self
.entry1
927 elif self
.active_entry_i
== 1:
928 self
.active_entry
= self
.entry2
931 elif self
.active_entry_i
== 2:
939 elif ans
== 0x14: # Ctrl-T
940 # this is a hack, we need to return to refresh Entry
941 return [self
.entry1
.text
, self
.entry2
.text
, self
.active_entry_i
]
942 elif ans
== 10: # return values
948 # save new historic entries
949 if self
.with_historic
:
950 for text
in self
.entry1
.text
, self
.entry2
.text
:
951 if text
!= None and text
!= '' and text
!= '*':
952 if len(historic
) < 100:
953 historic
.append(text
)
958 historic
.append(text
)
959 ans1
, ans2
= self
.entry1
.text
, self
.entry2
.text
961 ans1
, ans2
= None, None
966 ######################################################################
968 """A window to select an item"""
970 def __init__(self
, entries
, y0
, x0
, entry_i
= ''):
971 h
= (app
.maxh
-1) - (y0
+1) + 1
972 # h = min(h, len(entries)+5)
973 w
= min(max(map(len, entries
)), int(app
.maxw
/2)) + 4
975 win
= curses
.newwin(h
, w
, y0
, x0
)
976 self
.pwin
= curses
.panel
.new_panel(win
)
979 print 'Can\'t create window'
983 win
.bkgd(curses
.color_pair(4))
984 self
.entries
= entries
986 self
.entry_i
= self
.entries
.index(entry_i
)
992 win
= self
.pwin
.window()
996 y
, x
= win
.getbegyx()
997 h
, w
= win
.getmaxyx()
999 nels
= len(self
.entries
)
1000 entry_a
= int(self
.entry_i
/h0
) * h0
1001 for i
in xrange(h0
):
1003 line
= self
.entries
[entry_a
+ i
]
1006 if len(line
) > w
- 3:
1007 if (w
- 3) % 2 == 0: # even
1008 line
= line
[:int((w
-3)/2)] + '~' + line
[-int((w
-3)/2)+2:]
1010 line
= line
[:int((w
-3)/2)+1] + '~' + line
[-int((w
-3)/2)+2:]
1012 win
.addstr(i
+1, 2, line
, curses
.color_pair(4))
1015 cursor
= curses
.newpad(1, w
-1)
1016 cursor
.bkgd(curses
.color_pair(1))
1018 line
= self
.entries
[self
.entry_i
]
1019 if len(line
) > w
- 2:
1020 if (w
- 2) % 2 == 0: # even
1021 line
= line
[:int((w
-2)/2)] + '~' + line
[-int((w
-2)/2)+2:]
1023 line
= line
[:int((w
-2)/2)+1] + '~' + line
[-int((w
-2)/2)+2:]
1024 cursor
.addstr(0, 1, line
, curses
.color_pair(1) | curses
.A_BOLD
)
1026 cur_row
= y
+ self
.entry_i
% h0
1027 cursor
.refresh(0, 0, cur_row
, x
, cur_row
, x
+ w
- 3)
1030 n
= max(int(h0
*h0
/nels
), 1)
1031 y0
= min(max(int(int(self
.entry_i
/h0
)*h0
*h0
/nels
),0), h0
- n
)
1034 win
.vline(y0
+1, w
-1, curses
.ACS_CKBOARD
, n
)
1036 win
.vline(1, w
-1, '^', 1)
1037 if n
== 1 and (y0
+ 1 == 1):
1038 win
.vline(2, w
-1, curses
.ACS_CKBOARD
, n
)
1039 if nels
- 1 > entry_a
+ h0
- 1:
1040 win
.vline(h0
, w
-1, 'v', 1)
1041 if n
== 1 and (y0
== h0
- 1):
1042 win
.vline(h0
-1, w
-1, curses
.ACS_CKBOARD
, n
)
1045 def manage_keys(self
):
1046 h
, w
= self
.pwin
.window().getmaxyx()
1047 nels
= len(self
.entries
)
1050 ch
= self
.pwin
.window().getch()
1051 if ch
in (0x03, 0x1B, ord('q'), ord('Q')): # Ctrl-C, ESC
1053 elif ch
in (curses
.KEY_UP
, ord('k'), ord('K')):
1054 if self
.entry_i
!= 0:
1056 elif ch
in (curses
.KEY_DOWN
, ord('j'), ord('J')):
1057 if self
.entry_i
!= nels
- 1:
1059 elif ch
in (curses
.KEY_PPAGE
, curses
.KEY_BACKSPACE
, 0x08, 0x02):
1060 if self
.entry_i
< h
- 3:
1063 self
.entry_i
-= h
- 2
1064 elif ch
in (curses
.KEY_NPAGE
, ord(' '), 0x06):
1065 if self
.entry_i
+ (h
-2) > nels
- 1:
1066 self
.entry_i
= nels
- 1
1068 self
.entry_i
+= h
- 2
1069 elif ch
in (curses
.KEY_HOME
, 0x01):
1071 elif ch
in (curses
.KEY_END
, 0x05):
1072 self
.entry_i
= nels
- 1
1073 elif ch
== 0x13: # Ctrl-S
1074 theentries
= self
.entries
[self
.entry_i
:]
1075 ch2
= self
.pwin
.window().getkey()
1076 for e
in theentries
:
1077 if e
.find(ch2
) == 0:
1081 self
.entry_i
= self
.entries
.index(e
)
1082 elif ch
in (0x0A, 0x0D): # enter
1083 return self
.entries
[self
.entry_i
]
1089 selected
= self
.manage_keys()
1090 self
.pwin
.below().top()
1095 ######################################################################
1097 """A window to select a file"""
1099 def __init__(self
, entries
, entry_i
= ''):
1101 h
= (app
.maxh
-1) - (y0
+1) + 1
1102 # w = max(map(len, entries)) + 4
1104 x0
= int((app
.maxw
-w
) / 2)
1106 win
= curses
.newwin(h
, w
, y0
, x0
)
1107 self
.pwin
= curses
.panel
.new_panel(win
)
1109 except curses
.error
:
1110 print 'Can\'t create window'
1114 win
.bkgd(curses
.color_pair(4))
1115 self
.entries
= entries
1117 self
.entry_i
= self
.entries
.index(entry_i
)
1124 win
= self
.pwin
.window()
1128 y
, x
= win
.getbegyx()
1129 h
, w
= win
.getmaxyx()
1131 nels
= len(self
.entries
)
1132 entry_a
= int(self
.entry_i
/h0
) * h0
1133 for i
in xrange(h0
):
1135 line
= self
.entries
[entry_a
+i
]
1138 if len(line
) >= w
- 3:
1139 if (w
- 3) % 2 == 0: # even
1140 line
= line
[:int((w
-3)/2)] + '~' + line
[-int((w
-3)/2)+3:]
1142 line
= line
[:int((w
-3)/2)+1] + '~' + line
[-int((w
-3)/2)+3:]
1144 win
.addstr(i
+1, 2, line
, curses
.color_pair(4))
1147 cursor
= curses
.newpad(1, w
-2)
1148 cursor
.attrset(curses
.color_pair(1) | curses
.A_BOLD
)
1149 cursor
.bkgdset(curses
.color_pair(1))
1151 line
= self
.entries
[self
.entry_i
]
1152 if len(line
) >= w
- 3:
1153 if (w
- 2) % 2 == 0: # even
1154 line
= line
[:int((w
-2)/2)] + '~' + line
[-int((w
-2)/2)+3:]
1156 line
= line
[:int((w
-2)/2)+1] + '~' + line
[-int((w
-2)/2)+3:]
1157 cursor
.addstr(0, 1, line
, curses
.color_pair(1) | curses
.A_BOLD
)
1159 cursor
.refresh(0, 0, y
+ self
.entry_i
% h0
,
1160 x
, y
+ self
.entry_i
% h0
, x
+w
-3)
1163 n
= max(int(h0
*h0
/nels
), 1)
1164 y0
= min(max(int(int(self
.entry_i
/h0
)*h0
*h0
/nels
),0), h0
- n
)
1167 win
.vline(y0
+1, w
-1, curses
.ACS_CKBOARD
, n
)
1169 win
.vline(1, w
-1, '^', 1)
1170 if n
== 1 and (y0
+ 1 == 1):
1171 win
.vline(2, w
-1, curses
.ACS_CKBOARD
, n
)
1172 if nels
- 1 > entry_a
+ h0
- 1:
1173 win
.vline(h0
, w
-1, 'v', 1)
1174 if n
== 1 and (y0
== h0
- 1):
1175 win
.vline(h0
-1, w
-1, curses
.ACS_CKBOARD
, n
)
1177 win
.hline(h
-3, 1, curses
.ACS_HLINE
, w
-2)
1178 win
.hline(h
-3, 0, curses
.ACS_LTEE
, 1)
1179 win
.hline(h
-3, w
-1, curses
.ACS_RTEE
, 1)
1181 '[ Go ] [ Panelize ] [ View ] [ Edit ] [ Do ] [ Quit ]',
1182 curses
.color_pair(4))
1183 if self
.btn_active
== 0:
1184 attr0
= curses
.color_pair(1) | curses
.A_BOLD
1185 attr1
= attr2
= attr3
= attr4
= attr5
= curses
.color_pair(4)
1186 elif self
.btn_active
== 1:
1187 attr1
= curses
.color_pair(1) | curses
.A_BOLD
1188 attr0
= attr2
= attr3
= attr4
= attr5
= curses
.color_pair(4)
1189 elif self
.btn_active
== 2:
1190 attr2
= curses
.color_pair(1) | curses
.A_BOLD
1191 attr0
= attr1
= attr3
= attr4
= attr5
= curses
.color_pair(4)
1192 elif self
.btn_active
== 3:
1193 attr3
= curses
.color_pair(1) | curses
.A_BOLD
1194 attr0
= attr1
= attr2
= attr4
= attr5
= curses
.color_pair(4)
1195 elif self
.btn_active
== 4:
1196 attr4
= curses
.color_pair(1) | curses
.A_BOLD
1197 attr0
= attr1
= attr2
= attr3
= attr5
= curses
.color_pair(4)
1199 attr5
= curses
.color_pair(1) | curses
.A_BOLD
1200 attr0
= attr1
= attr2
= attr3
= attr4
= curses
.color_pair(4)
1201 win
.addstr(h
-2, 3, '[ Go ]', attr0
)
1202 win
.addstr(h
-2, 11, '[ PAnelize ]', attr1
)
1203 win
.addstr(h
-2, 25, '[ View ]', attr2
)
1204 win
.addstr(h
-2, 35, '[ Edit ]', attr3
)
1205 win
.addstr(h
-2, 45, '[ Do ]', attr4
)
1206 win
.addstr(h
-2, 53, '[ Quit ]', attr5
)
1210 def manage_keys(self
):
1211 h
, w
= self
.pwin
.window().getmaxyx()
1212 nels
= len(self
.entries
)
1215 ch
= self
.pwin
.window().getch()
1216 if ch
in (0x03, 0x1B, ord('q'), ord('Q')): # Ctrl-C, ESC
1218 elif ch
in (curses
.KEY_UP
, ord('k'), ord('K')):
1219 if self
.entry_i
!= 0:
1221 elif ch
in (curses
.KEY_DOWN
, ord('j'), ord('j')):
1222 if self
.entry_i
!= nels
- 1:
1224 elif ch
in (curses
.KEY_PPAGE
, curses
.KEY_BACKSPACE
, 0x08, 0x02):
1225 if self
.entry_i
< (h
- 5):
1228 self
.entry_i
-= (h
- 4)
1229 elif ch
in (curses
.KEY_NPAGE
, ord(' '), 0x06):
1230 if self
.entry_i
+ (h
-4) > nels
- 1:
1231 self
.entry_i
= nels
- 1
1233 self
.entry_i
+= (h
- 4)
1234 elif ch
in (curses
.KEY_HOME
, 0x01):
1236 elif ch
in (curses
.KEY_END
, 0x05):
1237 self
.entry_i
= nels
- 1
1238 elif ch
== 0x13: # Ctrl-S
1239 theentries
= self
.entries
[self
.entry_i
:]
1240 ch2
= self
.pwin
.window().getkey()
1241 for e
in theentries
:
1242 if e
.find(ch2
) == 0:
1246 self
.entry_i
= self
.entries
.index(e
)
1247 elif ch
== 0x09: # tab
1248 if self
.btn_active
== 5:
1251 self
.btn_active
+= 1
1252 elif ch
in (0x0A, 0x0D): # enter
1253 if self
.btn_active
== 0:
1254 return 0, self
.entries
[self
.entry_i
]
1255 elif self
.btn_active
== 1:
1257 elif self
.btn_active
== 2:
1258 return 2, self
.entries
[self
.entry_i
]
1259 elif self
.btn_active
== 3:
1260 return 3, self
.entries
[self
.entry_i
]
1261 elif self
.btn_active
== 4:
1262 return 4, self
.entries
[self
.entry_i
]
1263 elif self
.btn_active
== 5:
1265 elif ch
in (ord('a'), ord('A')):
1267 elif ch
in (curses
.KEY_F3
, ord('v'), ord('V')):
1268 return 2, self
.entries
[self
.entry_i
]
1269 elif ch
in (curses
.KEY_F4
, ord('e'), ord('E')):
1270 return 3, self
.entries
[self
.entry_i
]
1271 elif ch
in (ord('@'), ord('d'), ord('D')):
1272 return 4, self
.entries
[self
.entry_i
]
1278 selected
= self
.manage_keys()
1283 ######################################################################
1285 """A window to select a menu option"""
1287 def __init__(self
, title
, entries
):
1288 h
= len(entries
) + 4
1289 w
= max(map(len, entries
)) + 4
1290 y0
= int((app
.maxh
-h
) / 2)
1291 x0
= int((app
.maxw
-w
) / 2)
1293 win
= curses
.newwin(h
, w
, y0
, x0
)
1294 self
.pwin
= curses
.panel
.new_panel(win
)
1296 except curses
.error
:
1297 print 'Can\'t create window'
1301 win
.bkgd(curses
.color_pair(3))
1303 self
.entries
= entries
1305 self
.keys
= [e
[0] for e
in entries
]
1309 win
= self
.pwin
.window()
1312 y
, x
= win
.getbegyx()
1313 h
, w
= win
.getmaxyx()
1314 attr
= curses
.color_pair(7)
1315 win
.addstr(0, int((w
-len(self
.title
)-2)/2), ' %s ' % self
.title
, attr
)
1316 for i
in xrange(h
-2):
1318 line
= self
.entries
[i
]
1322 win
.addstr(i
+2, 2, line
, curses
.color_pair(3))
1325 cursor
= curses
.newpad(1, w
-2)
1326 cursor
.bkgd(curses
.color_pair(1))
1328 line
= self
.entries
[self
.entry_i
]
1329 cursor
.addstr(0, 1, line
, curses
.color_pair(1) | curses
.A_BOLD
)
1331 cursor
.refresh(0, 0, y
+ self
.entry_i
% (h
-4) + 1,
1332 x
, y
+ self
.entry_i
% (h
-4) + 1, x
+w
-3)
1335 def manage_keys(self
):
1338 ch
= self
.pwin
.window().getch()
1339 if ch
in (0x03, 0x1B, ord('q'), ord('Q')): # Ctrl-C, ESC
1341 elif ch
in (curses
.KEY_UP
, ord('k'), ord('K')):
1342 if self
.entry_i
!= 0:
1344 elif ch
in (curses
.KEY_DOWN
, ord('j'), ord('J')):
1345 if self
.entry_i
!= len(self
.entries
) - 1:
1347 elif ch
in (curses
.KEY_HOME
, 0x01, curses
.KEY_PPAGE
, 0x08, 0x02,
1348 curses
.KEY_BACKSPACE
):
1350 elif ch
in (curses
.KEY_END
, 0x05, curses
.KEY_NPAGE
, ord(' '), 0x06):
1351 self
.entry_i
= len(self
.entries
) - 1
1352 elif ch
== 0x13: # Ctrl-S
1353 theentries
= self
.entries
[self
.entry_i
:]
1354 ch2
= self
.pwin
.window().getkey()
1355 for e
in theentries
:
1356 if e
.find(ch2
) == 0:
1360 self
.entry_i
= self
.entries
.index(e
)
1361 elif ch
in (0x0A, 0x0D): # enter
1362 return self
.entries
[self
.entry_i
]
1363 elif 0 <= ch
<= 255 and chr(ch
).lower() in self
.keys
:
1364 return self
.entries
[self
.keys
.index(chr(ch
).lower())]
1370 selected
= self
.manage_keys()
1375 ######################################################################
1377 """A window to change permissions, owner or group"""
1379 def __init__(self
, file, fileinfo
, i
= 0, n
= 0):
1382 y0
= int((app
.maxh
-h
) / 2)
1383 x0
= int((app
.maxw
-w
) / 2)
1385 win
= curses
.newwin(h
, w
, y0
, x0
)
1386 self
.pwin
= curses
.panel
.new_panel(win
)
1388 except curses
.error
:
1389 print 'Can\'t create window'
1393 win
.bkgd(curses
.color_pair(1))
1396 self
.perms_old
= files
.perms2str(fileinfo
[files
.FT_PERMS
])
1397 self
.perms
= [l
for l
in self
.perms_old
]
1398 self
.owner
= fileinfo
[files
.FT_OWNER
]
1399 self
.group
= fileinfo
[files
.FT_GROUP
]
1400 self
.owner_old
= self
.owner
[:]
1401 self
.group_old
= self
.group
[:]
1408 def show_btns(self
):
1409 win
= self
.pwin
.window()
1410 h
, w
= win
.getmaxyx()
1411 attr1
= curses
.color_pair(1) | curses
.A_BOLD
1412 attr2
= curses
.color_pair(9) | curses
.A_BOLD
1413 win
.addstr(h
-2, w
-21, '[<Ok>]', attr1
)
1414 win
.addstr(h
-2, w
-13, '[ Cancel ]', attr1
)
1415 if self
.entry_i
== 5:
1416 win
.addstr(h
-2, w
-21, '[<Ok>]', attr2
)
1417 elif self
.entry_i
== 6:
1418 win
.addstr(h
-2, w
-13, '[ Cancel ]', attr2
)
1420 win
.addstr(h
-2, 3, '[ All ]', attr1
)
1421 win
.addstr(h
-2, 12, '[ Ignore ]', attr1
)
1422 if self
.entry_i
== 7:
1423 win
.addstr(h
-2, 3, '[ All ]', attr2
)
1424 elif self
.entry_i
== 8:
1425 win
.addstr(h
-2, 12, '[ Ignore ]', attr2
)
1429 win
= self
.pwin
.window()
1433 attr
= curses
.color_pair(1) | curses
.A_BOLD
1434 title
= 'Change permissions, owner or group'
1435 win
.addstr(0, int((self
.w
-len(title
)-2)/2), ' %s ' % title
, attr
)
1436 win
.addstr(2, 2, '\'%s\'' % self
.file, attr
)
1438 win
.addstr(2, self
.w
-12-2, '%4d of %-4d' % (self
.i
, self
.n
))
1439 win
.addstr(4, 7, 'owner group other owner group')
1440 win
.addstr(5, 2, 'new: [---] [---] [---] [----------] [----------]')
1441 win
.addstr(6, 2, 'old: [---] [---] [---] [----------] [----------]')
1442 win
.addstr(6, 8, self
.perms_old
[0:3])
1443 win
.addstr(6, 15, self
.perms_old
[3:6])
1444 win
.addstr(6, 22, self
.perms_old
[6:9])
1445 l
= len(self
.owner_old
)
1447 owner
= self
.owner_old
[:10]
1449 owner
= self
.owner_old
+ '-' * (10-l
)
1450 win
.addstr(6, 32, owner
)
1451 l
= len(self
.group_old
)
1453 group
= self
.group_old
[:10]
1455 group
= self
.group_old
+ '-' * (10-l
)
1456 win
.addstr(6, 46, group
)
1458 perms
= ''.join(self
.perms
)
1459 win
.addstr(5, 8, perms
[0:3])
1460 win
.addstr(5, 15, perms
[3:6])
1461 win
.addstr(5, 22, perms
[6:9])
1464 owner
= self
.owner
[:10]
1466 owner
= self
.owner
+ '-' * (10-l
)
1467 win
.addstr(5, 32, owner
)
1470 group
= self
.group
[:10]
1472 group
= self
.group
+ '-' * (10-l
)
1473 win
.addstr(5, 46, group
)
1474 if self
.entry_i
== 0:
1475 win
.addstr(5, 8, perms
[0:3],
1476 curses
.color_pair(5) | curses
.A_BOLD
)
1477 elif self
.entry_i
== 1:
1478 win
.addstr(5, 15, perms
[3:6],
1479 curses
.color_pair(5) | curses
.A_BOLD
)
1480 elif self
.entry_i
== 2:
1481 win
.addstr(5, 22, perms
[6:9],
1482 curses
.color_pair(5) | curses
.A_BOLD
)
1483 elif self
.entry_i
== 3:
1484 win
.addstr(5, 32, owner
,
1485 curses
.color_pair(5) | curses
.A_BOLD
)
1486 elif self
.entry_i
== 4:
1487 win
.addstr(5, 46, group
,
1488 curses
.color_pair(5) | curses
.A_BOLD
)
1493 def manage_keys(self
):
1494 y
, x
= self
.pwin
.window().getbegyx()
1497 ch
= self
.pwin
.window().getch()
1498 if ch
in (0x03, 0x1B, ord('c'), ord('C'), ord('q'), ord('Q')):
1500 elif ch
in (ord('\t'), 0x09, curses
.KEY_DOWN
, curses
.KEY_RIGHT
):
1502 if self
.entry_i
== 4:
1504 elif self
.entry_i
== 8:
1506 elif self
.entry_i
== 6:
1511 if self
.entry_i
== 6:
1515 elif ch
in (curses
.KEY_UP
, curses
.KEY_LEFT
):
1517 if self
.entry_i
== 0:
1519 elif self
.entry_i
== 5:
1521 elif self
.entry_i
== 7:
1526 if self
.entry_i
== 0:
1530 elif ch
in (ord('r'), ord('R')):
1531 if not 0 <= self
.entry_i
<= 2:
1533 d
= self
.entry_i
* 3
1534 if self
.perms
[d
] == 'r':
1538 elif ch
in (ord('w'), ord('W')):
1539 if not 0 <= self
.entry_i
<= 2:
1541 d
= 1 + self
.entry_i
* 3
1542 if self
.perms
[d
] == 'w':
1546 elif ch
in (ord('x'), ord('X')):
1547 if not 0 <= self
.entry_i
<= 2:
1549 d
= 2 + self
.entry_i
* 3
1550 if self
.perms
[d
] == 'x':
1554 elif ch
in (ord('t'), ord('T')):
1555 if not self
.entry_i
== 2:
1557 if self
.perms
[8] == 't':
1558 self
.perms
[8] = self
.perms_old
[8]
1561 elif ch
in (ord('s'), ord('S')):
1562 if not 0 <= self
.entry_i
<= 1:
1564 d
= 2 + self
.entry_i
* 3
1565 if self
.perms
[d
] == 's':
1566 self
.perms
[d
] = self
.perms_old
[d
]
1569 elif ch
in (0x0A, 0x0D):
1570 if self
.entry_i
== 3:
1571 owners
= files
.get_owners()
1574 owners
.index(self
.owner
)
1576 owners
.append(self
.owner
)
1577 ret
= SelectItem(owners
, y
+6, x
+32, self
.owner
).run()
1581 elif self
.entry_i
== 4:
1582 groups
= files
.get_groups()
1585 groups
.index(self
.group
)
1587 groups
.append(self
.group
)
1588 ret
= SelectItem(groups
, y
+6, x
+32, self
.group
).run()
1592 elif self
.entry_i
== 6:
1594 elif self
.i
and self
.entry_i
== 7:
1595 return self
.perms
, self
.owner
, self
.group
, 1
1596 elif self
.i
and self
.entry_i
== 8:
1599 return self
.perms
, self
.owner
, self
.group
, 0
1600 elif self
.i
and ch
in (ord('i'), ord('I')):
1602 elif self
.i
and ch
in (ord('a'), ord('A')):
1603 return self
.perms
, self
.owner
, self
.group
, 1
1609 selected
= self
.manage_keys()
1614 ######################################################################
1617 try: # some terminals don't allow '2'
1637 ######################################################################