Repository
- Highlight lines in the plaintext view
Parent commits : 7db7323b6fdd139f91a42ba802012b83422770b4,Children commits :
By lds on 2008-12-21 20:35:18
- Highlight lines in the plaintext view
- Pkaintext view key handling
git-svn-id: http://shan/svn/repos/factorize@15 51b56bfc-b269-4856-8701-af1c38ee6d62
Difference with parent commit 7db7323b6fdd139f91a42ba802012b83422770b4
Files modified:
factorize.py
---
+++
@@ -218,4 +218,4 @@
if opt.skipped_fields is None:
opt.skipped_fields = "3"
log = Log("/home/lds/Temporaire/log")
- gui.start(log)
+ gui.start(log, opt)
gui.py
---
+++
@@ -263,8 +263,7 @@
s.tree.highlighted -= 1
- def HandleKeys(s):
- c = s.stdscr.getch()
+ def HandleKeys(s, c):
if c == curses.KEY_DOWN:
s.CursorDown()
elif c == curses.KEY_UP:
@@ -282,26 +281,32 @@
elif c == curses.KEY_LEFT:
if s.tree.highlighted_node and s.tree.highlighted_node != s.tree.root:
s.tree.highlighted_node.folded = True
-
- elif c == ord('q'):
- sys.exit(0)
-
-def main(stdscr, log):
+
+def main(stdscr, log, opt):
curses.savetty()
try:
curses.curs_set(0)
tree = TreeView(log)
- plain = PlainView(log)
+ plain = PlainView(log, opt)
gui = Gui(stdscr, tree)
- #for y in range(0, 100):
- # for x in range(0, 100):
- # try: pad.addch(y,x, ord('a') + (x*x+y*y) % 26 )
- # except curses.error: pass
+ kb_handler = gui
while 1:
tree.Display()
plain.Display(tree.highlighted_node)
- gui.HandleKeys()
+
+ # Global key handler
+ c = stdscr.getch()
+ if c == ord('q'):
+ sys.exit(0)
+ #elif c == curses.KEY_BTAB:
+ elif c == 9:
+ if kb_handler == gui:
+ kb_handler = plain
+ else:
+ kb_handler = gui
+ else:
+ kb_handler.HandleKeys(c)
finally:
curses.resetty()
@@ -316,5 +321,5 @@
# finally:
# curses.endwin()
-def start(log):
- curses.wrapper(main, log)
+def start(log, opt):
+ curses.wrapper(main, log, opt)
plain_gui.py
---
+++
@@ -1,9 +1,9 @@
-from factorize import CommonWord, opt
import curses
class PlainView:
- def __init__(s, log):
+ def __init__(s, log, opt):
+ s.opt = opt
s.x_pos = 61
s.x_off = 0
s.y_off = 0
@@ -12,24 +12,18 @@
s.log = log
s.pad = curses.newpad(s.y_size,s.x_size)
- s.cursor = 0
- s.offset = 0
-
def Match(s, line, highlighted):
if highlighted is None:
- return
+ return False
- if opt is None:
- return
-
- words = line.split()[0:int(opt.skipped_fileds)]
+ words = line
word_no = 0
if len(words) < len(highlighted.factorized_words):
return False
for hl_word in highlighted.factorized_words:
- if (not isinstance(hl_word, CommonWord)) and hl_word.word != words[word_no]:
+ if hl_word.isCommon() and hl_word.word != words[word_no]:
return False
word_no += 1
return True
@@ -37,15 +31,31 @@
def Display(s, highlighted):
for no, line in enumerate(s.log.lines[s.y_off : s.y_off + s.y_size - 1]):
+ to_match = line.full_line.split()[int(s.opt.skipped_fields):]
+
disp = line.full_line[s.x_off:s.x_off+s.x_size]
- #s.pad.addstr(no, 0, "a")
- attr = 0
- if s.Match(line.full_line, highlighted):
+ if len(disp) < s.x_size:
+ disp += (s.x_size - len(disp)) * ' '
+
+ if s.Match(to_match, highlighted):
s.pad.addstr(no, 0, disp, curses.color_pair(1))
else:
s.pad.addstr(no, 0, disp)
s.pad.refresh(0,0,0,s.x_pos,s.y_size,s.x_size + s.x_pos)
- #def HandleKey(s):
-
+ def HandleKeys(s, c):
+ if c == curses.KEY_DOWN:
+ s.y_off += 1
+ elif c == curses.KEY_UP:
+ s.y_off -= 1
+ elif c == curses.KEY_NPAGE or c == ord(' '):
+ s.y_off += 10
+ elif c == curses.KEY_PPAGE:
+ s.y_off -= 10
+
+ if s.y_off < 0:
+ s.y_off = 0
+ if s.y_off + s.y_size >= len(s.log.lines):
+ s.y_off = len(s.log.lines) - s.y_size
+