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
45d71dcb
Commit
45d71dcb
authored
Jun 21, 2015
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add functionality to add a custom view with the 'C' shortcut.
parent
c261462b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
140 additions
and
16 deletions
+140
-16
topydo/ui/Main.py
topydo/ui/Main.py
+57
-16
topydo/ui/ViewWidget.py
topydo/ui/ViewWidget.py
+83
-0
No files found.
topydo/ui/Main.py
View file @
45d71dcb
...
...
@@ -22,6 +22,7 @@ from topydo.Commands import get_subcommand
from
topydo.ui.CommandLineWidget
import
CommandLineWidget
from
topydo.ui.ConsoleWidget
import
ConsoleWidget
from
topydo.ui.TodoListWidget
import
TodoListWidget
from
topydo.ui.ViewWidget
import
ViewWidget
from
topydo.lib.Config
import
config
from
topydo.lib.Sorter
import
Sorter
from
topydo.lib
import
TodoFile
...
...
@@ -33,15 +34,32 @@ class UIApplication(CLIApplicationBase):
def
__init__
(
self
):
super
(
UIApplication
,
self
).
__init__
()
self
.
todofile
=
TodoFile
.
TodoFile
(
config
().
todotxt
())
self
.
todolist
=
TodoList
.
TodoList
(
self
.
todofile
.
read
())
self
.
columns
=
urwid
.
Columns
([],
dividechars
=
0
,
min_width
=
COLUMN_WIDTH
)
self
.
commandline
=
CommandLineWidget
(
u
(
'topydo> '
))
# console widget
self
.
console
=
ConsoleWidget
()
urwid
.
connect_signal
(
self
.
commandline
,
'blur'
,
self
.
_blur_commandline
)
urwid
.
connect_signal
(
self
.
commandline
,
'execute_command'
,
self
.
_execute_handler
)
urwid
.
connect_signal
(
self
.
console
,
'close'
,
self
.
_hide_console
)
def
hide_console
():
self
.
_console_visible
=
False
urwid
.
connect_signal
(
self
.
console
,
'close'
,
hide_console
)
# view widget
self
.
viewwidget
=
ViewWidget
(
self
.
todolist
)
urwid
.
connect_signal
(
self
.
viewwidget
,
'save'
,
self
.
_create_view
)
def
hide_viewwidget
():
self
.
_viewwidget_visible
=
False
urwid
.
connect_signal
(
self
.
viewwidget
,
'close'
,
hide_viewwidget
)
self
.
mainwindow
=
urwid
.
Pile
([
(
'weight'
,
1
,
self
.
columns
),
...
...
@@ -111,6 +129,10 @@ class UIApplication(CLIApplicationBase):
if
self
.
columns
.
focus_position
>
0
:
self
.
columns
.
focus_position
-=
1
def
_new_view
(
self
):
self
.
viewwidget
.
reset
()
self
.
_viewwidget_visible
=
True
def
_handle_input
(
self
,
p_input
):
dispatch
=
{
':'
:
self
.
_focus_commandline
,
...
...
@@ -120,6 +142,7 @@ class UIApplication(CLIApplicationBase):
'h'
:
self
.
_focus_previous_column
,
'right'
:
self
.
_focus_next_column
,
'l'
:
self
.
_focus_next_column
,
'C'
:
self
.
_new_view
,
}
try
:
...
...
@@ -128,6 +151,10 @@ class UIApplication(CLIApplicationBase):
# the key is unknown, ignore
pass
def
_create_view
(
self
):
self
.
_add_column
(
self
.
viewwidget
.
view
,
self
.
viewwidget
.
title
)
self
.
_viewwidget_visible
=
False
def
_add_column
(
self
,
p_view
,
p_title
):
todolist
=
TodoListWidget
(
p_view
,
p_title
)
no_output
=
lambda
_
:
None
...
...
@@ -144,22 +171,39 @@ class UIApplication(CLIApplicationBase):
self
.
columns
.
contents
.
append
(
item
)
self
.
columns
.
focus_position
=
len
(
self
.
columns
.
contents
)
-
1
def
_show_console
(
self
):
self
.
mainwindow
.
contents
.
append
((
self
.
console
,
(
'pack'
,
None
)))
self
.
mainwindow
.
focus_position
=
2
@
property
def
_console_visible
(
self
):
contents
=
self
.
mainwindow
.
contents
return
len
(
contents
)
==
3
and
isinstance
(
contents
[
2
][
0
],
ConsoleWidget
)
@
_console_visible
.
setter
def
_console_visible
(
self
,
p_enabled
):
contents
=
self
.
mainwindow
.
contents
def
_hide_console
(
self
):
if
self
.
_console_is_visible
():
if
p_enabled
==
True
and
len
(
contents
)
==
2
:
contents
.
append
((
self
.
console
,
(
'pack'
,
None
)))
self
.
mainwindow
.
focus_position
=
2
elif
p_enabled
==
False
and
self
.
_console_visible
:
self
.
console
.
clear
()
del
self
.
mainwindow
.
contents
[
2
]
del
contents
[
2
]
def
_console_is_visible
(
self
):
return
len
(
self
.
mainwindow
.
contents
)
==
3
@
property
def
_viewwidget_visible
(
self
):
contents
=
self
.
mainwindow
.
contents
return
len
(
contents
)
==
3
and
isinstance
(
contents
[
2
][
0
],
ViewWidget
)
def
_print_to_console
(
self
,
p_text
):
if
not
self
.
_console_is_visible
():
self
.
_show_console
()
@
_viewwidget_visible
.
setter
def
_viewwidget_visible
(
self
,
p_enabled
):
contents
=
self
.
mainwindow
.
contents
if
p_enabled
==
True
and
len
(
contents
)
==
2
:
contents
.
append
((
self
.
viewwidget
,
(
'pack'
,
None
)))
self
.
mainwindow
.
focus_position
=
2
elif
p_enabled
==
False
and
self
.
_viewwidget_visible
:
del
contents
[
2
]
def
_print_to_console
(
self
,
p_text
):
self
.
_console_visible
=
True
self
.
console
.
print_text
(
p_text
)
def
_input
(
self
,
p_question
):
...
...
@@ -171,14 +215,11 @@ class UIApplication(CLIApplicationBase):
self
.
mainloop
.
draw_screen
()
user_input
=
self
.
mainloop
.
screen
.
get_input
()
self
.
_
hide_console
()
self
.
_
console_visible
=
False
return
user_input
[
0
]
def
run
(
self
):
self
.
todofile
=
TodoFile
.
TodoFile
(
config
().
todotxt
())
self
.
todolist
=
TodoList
.
TodoList
(
self
.
todofile
.
read
())
view1
=
self
.
todolist
.
view
(
Sorter
(),
[])
self
.
_add_column
(
view1
,
"View 1"
)
...
...
topydo/ui/ViewWidget.py
0 → 100644
View file @
45d71dcb
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2015 Bram Schoenmakers <me@bramschoenmakers.nl>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
urwid
from
six
import
u
from
topydo.lib.Filter
import
get_filter_list
,
DependencyFilter
,
RelevanceFilter
from
topydo.lib.Sorter
import
Sorter
class
ViewWidget
(
urwid
.
LineBox
):
def
__init__
(
self
,
p_todolist
):
self
.
_todolist
=
p_todolist
self
.
titleedit
=
urwid
.
Edit
(
u
(
"Title: "
),
u
(
""
))
self
.
sortedit
=
urwid
.
Edit
(
u
(
"Sort expression: "
),
u
(
""
))
self
.
filteredit
=
urwid
.
Edit
(
u
(
"Filter expression: "
),
u
(
""
))
group
=
[]
self
.
relevantradio
=
urwid
.
RadioButton
(
group
,
u
(
"Only show relevant todo items"
),
True
)
self
.
allradio
=
urwid
.
RadioButton
(
group
,
u
(
"Show all todo items"
))
self
.
pile
=
urwid
.
Pile
([
self
.
titleedit
,
self
.
sortedit
,
self
.
filteredit
,
self
.
relevantradio
,
self
.
allradio
,
urwid
.
Button
(
u
(
"Save"
),
lambda
_
:
urwid
.
emit_signal
(
self
,
'save'
)),
urwid
.
Button
(
u
(
"Cancel"
),
lambda
_
:
urwid
.
emit_signal
(
self
,
'close'
)),
])
self
.
reset
()
super
(
ViewWidget
,
self
).
__init__
(
self
.
pile
)
urwid
.
register_signal
(
ViewWidget
,
[
'save'
,
'close'
])
@
property
def
view
(
self
):
""" Returns a tuple (title, view). """
sorter
=
Sorter
(
self
.
sortedit
.
edit_text
)
filters
=
[]
if
self
.
relevantradio
.
state
==
True
:
filters
.
append
(
DependencyFilter
(
self
.
_todolist
))
filters
.
append
(
RelevanceFilter
())
filters
+=
get_filter_list
(
self
.
filteredit
.
edit_text
.
split
())
return
self
.
_todolist
.
view
(
sorter
,
filters
)
@
view
.
setter
def
view
(
self
,
p_view
):
pass
# TODO
@
property
def
title
(
self
):
return
self
.
titleedit
.
edit_text
@
title
.
setter
def
title
(
self
,
p_title
):
self
.
titleedit
.
edit_text
=
p_title
def
reset
(
self
):
""" Resets the form. """
self
.
titleedit
.
set_edit_text
(
u
(
""
))
self
.
sortedit
.
set_edit_text
(
u
(
""
))
self
.
filteredit
.
set_edit_text
(
u
(
""
))
self
.
relevantradio
.
set_state
(
True
)
self
.
pile
.
focus_item
=
0
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