Commit 01753741 authored by Jacek Sowiński's avatar Jacek Sowiński

Support user-specified column-layout file

User can now use '-l' option with an argument *after* 'columns' command
and topydo will try to load column layout from that location. If it
won't find specified file it will use standard column-layout file
locations as a fallback.

Example of use:
Will work: `topydo columns -l ~/fooBar_columns`
Won't work: `topydo -l ~/fooBar_columns columns`

Implements #147
parent 5f5476fc
...@@ -15,10 +15,12 @@ ...@@ -15,10 +15,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import configparser import configparser
from os.path import expanduser
from topydo.lib.Config import home_config_path, config from topydo.lib.Config import home_config_path, config
def columns():
def columns(p_alt_layout_path=None):
""" """
Returns list with complete column configuration dicts. Returns list with complete column configuration dicts.
""" """
...@@ -49,6 +51,8 @@ def columns(): ...@@ -49,6 +51,8 @@ def columns():
"/etc/topydo_columns.conf", "/etc/topydo_columns.conf",
] ]
if p_alt_layout_path is not None:
files.insert(0, expanduser(p_alt_layout_path))
for filename in files: for filename in files:
if cp.read(filename): if cp.read(filename):
break break
......
...@@ -15,7 +15,9 @@ ...@@ -15,7 +15,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import datetime import datetime
import getopt
import shlex import shlex
import sys
import time import time
import urwid import urwid
...@@ -30,7 +32,7 @@ from topydo.lib.Utils import get_terminal_size ...@@ -30,7 +32,7 @@ from topydo.lib.Utils import get_terminal_size
from topydo.lib.View import View from topydo.lib.View import View
from topydo.lib import TodoFile from topydo.lib import TodoFile
from topydo.lib import TodoList from topydo.lib import TodoList
from topydo.ui.CLIApplicationBase import CLIApplicationBase from topydo.ui.CLIApplicationBase import CLIApplicationBase, error
from topydo.ui.columns.CommandLineWidget import CommandLineWidget from topydo.ui.columns.CommandLineWidget import CommandLineWidget
from topydo.ui.columns.ConsoleWidget import ConsoleWidget from topydo.ui.columns.ConsoleWidget import ConsoleWidget
from topydo.ui.columns.KeystateWidget import KeystateWidget from topydo.ui.columns.KeystateWidget import KeystateWidget
...@@ -92,7 +94,19 @@ class UIApplication(CLIApplicationBase): ...@@ -92,7 +94,19 @@ class UIApplication(CLIApplicationBase):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self._process_flags() args = self._process_flags()
try:
opts, args = getopt.getopt(args[1:], 'l:')
except getopt.GetoptError as e:
error(str(e))
sys.exit(1)
self.alt_layout_path = None
for opt, value in opts:
if opt == "-l":
self.alt_layout_path = value
self.column_width = config().column_width() self.column_width = config().column_width()
self.todofile = TodoFile.TodoFile(config().todotxt()) self.todofile = TodoFile.TodoFile(config().todotxt())
...@@ -576,7 +590,7 @@ class UIApplication(CLIApplicationBase): ...@@ -576,7 +590,7 @@ class UIApplication(CLIApplicationBase):
return False return False
def run(self): def run(self):
layout = columns() layout = columns(self.alt_layout_path)
if len(layout) > 0: if len(layout) > 0:
for column in layout: for column in layout:
self._add_column(self._viewdata_to_view(column)) self._add_column(self._viewdata_to_view(column))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment