Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
topydo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
topydo
Commits
fc49a646
Commit
fc49a646
authored
Jun 20, 2015
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable scrolling inside a todo list.
This is implemented using the ListBox widget.
parent
e3e59df1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
37 deletions
+40
-37
topydo/ui/TodoListWidget.py
topydo/ui/TodoListWidget.py
+30
-37
topydo/ui/TodoWidget.py
topydo/ui/TodoWidget.py
+10
-0
No files found.
topydo/ui/TodoListWidget.py
View file @
fc49a646
...
@@ -25,13 +25,14 @@ class TodoListWidget(urwid.LineBox):
...
@@ -25,13 +25,14 @@ class TodoListWidget(urwid.LineBox):
title_widget
=
urwid
.
Filler
(
urwid
.
Text
(
p_title
,
align
=
'center'
))
title_widget
=
urwid
.
Filler
(
urwid
.
Text
(
p_title
,
align
=
'center'
))
self
.
todo_pile
=
urwid
.
Pile
([])
self
.
todolist
=
urwid
.
SimpleFocusListWalker
([])
self
.
listbox
=
urwid
.
ListBox
(
self
.
todolist
)
self
.
update
()
self
.
update
()
pile
=
urwid
.
Pile
([
pile
=
urwid
.
Pile
([
(
1
,
title_widget
),
(
1
,
title_widget
),
(
1
,
urwid
.
Filler
(
urwid
.
Divider
(
u'
\
u2500
'
))),
(
1
,
urwid
.
Filler
(
urwid
.
Divider
(
u'
\
u2500
'
))),
(
'weight'
,
1
,
urwid
.
Filler
(
self
.
todo_pile
,
valign
=
'top'
)
),
(
'weight'
,
1
,
self
.
listbox
),
])
])
pile
.
focus_position
=
2
pile
.
focus_position
=
2
...
@@ -45,50 +46,42 @@ class TodoListWidget(urwid.LineBox):
...
@@ -45,50 +46,42 @@ class TodoListWidget(urwid.LineBox):
Updates the todo list according to the todos in the view associated
Updates the todo list according to the todos in the view associated
with this list.
with this list.
"""
"""
try
:
old_focus_position
=
self
.
todolist
.
focus
old_focus_position
=
self
.
todo_pile
.
focus_position
except
IndexError
:
old_focus_position
=
0
items
=
[
]
del
self
.
todolist
[:
]
for
todo
in
self
.
view
.
todos
:
for
todo
in
self
.
view
.
todos
:
todowidget
=
TodoWidget
(
todo
,
self
.
view
.
todolist
.
number
(
todo
))
todowidget
=
TodoWidget
(
todo
,
self
.
view
.
todolist
.
number
(
todo
))
items
.
append
((
todowidget
,
(
'pack'
,
None
)))
self
.
todolist
.
append
(
todowidget
)
items
.
append
((
urwid
.
Divider
(
u'-'
),
(
'weight'
,
1
)))
self
.
todolist
.
append
(
urwid
.
Divider
(
u'-'
))
self
.
todo_pile
.
contents
=
items
self
.
todo_pile
.
focus_position
=
min
(
old_focus_position
,
len
(
items
)
-
1
)
def
_focus_down
(
self
):
size
=
len
(
self
.
todo_pile
.
contents
)
if
self
.
todo_pile
.
focus_position
<
size
-
2
:
self
.
todo_pile
.
focus_position
+=
2
def
_focus_up
(
self
):
if
old_focus_position
:
if
self
.
todo_pile
.
focus_position
>
1
:
self
.
todolist
.
set_focus
(
old_focus_position
)
self
.
todo_pile
.
focus_position
-=
2
def
keypress
(
self
,
p_size
,
p_key
):
def
keypress
(
self
,
p_size
,
p_key
):
dispatch
=
{
if
p_key
==
'x'
:
'j'
:
self
.
_focus_down
,
self
.
_complete_selected_item
()
'down'
:
self
.
_focus_down
,
elif
p_key
==
'j'
:
'k'
:
self
.
_focus_up
,
self
.
listbox
.
keypress
(
p_size
,
'down'
)
'up'
:
self
.
_focus_up
,
elif
p_key
==
'k'
:
'x'
:
self
.
_complete_selected_item
,
self
.
listbox
.
keypress
(
p_size
,
'up'
)
}
else
:
if
self
.
listbox
.
keypress
(
p_size
,
p_key
):
try
:
return
super
(
TodoListWidget
,
self
).
keypress
(
p_size
,
p_key
)
dispatch
[
p_key
]()
except
KeyError
:
return
super
(
TodoListWidget
,
self
).
keypress
(
p_size
,
p_key
)
def
selectable
(
self
):
def
selectable
(
self
):
return
True
return
True
def
_complete_selected_item
(
self
):
def
_complete_selected_item
(
self
):
todo
=
self
.
todo_pile
.
focus
.
todo
"""
self
.
view
.
todolist
.
number
(
todo
)
Marks the highlighted todo item as complete.
"""
urwid
.
emit_signal
(
self
,
'execute_command'
,
"do {}"
.
format
(
try
:
text_type
(
self
.
view
.
todolist
.
number
(
todo
))))
todo
=
self
.
listbox
.
focus
.
todo
self
.
view
.
todolist
.
number
(
todo
)
urwid
.
emit_signal
(
self
,
'execute_command'
,
"do {}"
.
format
(
text_type
(
self
.
view
.
todolist
.
number
(
todo
))))
except
AttributeError
:
# No todo item selected
pass
topydo/ui/TodoWidget.py
View file @
fc49a646
...
@@ -50,3 +50,13 @@ class TodoWidget(urwid.WidgetWrap):
...
@@ -50,3 +50,13 @@ class TodoWidget(urwid.WidgetWrap):
super
(
TodoWidget
,
self
).
__init__
(
self
.
widget
)
super
(
TodoWidget
,
self
).
__init__
(
self
.
widget
)
def
keypress
(
self
,
p_size
,
p_key
):
"""
Override keypress to prevent the wrapped Columns widget to
receive any key.
"""
return
p_key
def
selectable
(
self
):
# make sure that ListBox will highlight this widget
return
True
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment