Skip to content

Commit

Permalink
Adding display of error though curses interface
Browse files Browse the repository at this point in the history
  • Loading branch information
anufrievroman committed Mar 10, 2023
1 parent 3197e10 commit 868c3ea
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 7 deletions.
21 changes: 21 additions & 0 deletions calcure/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import logging

from calcure.calendars import Calendar
from calcure.errors import error
from calcure.configuration import cf
from calcure.weather import Weather
from calcure.importers import Importer
Expand Down Expand Up @@ -546,6 +547,22 @@ def render(self):
self.display_line(self.screen.y_max - 1, 0, hint, Color.HINTS)


class ErrorView(View):
"""Display the error messages"""

def __init__(self, stdscr, y, x, screen):
super().__init__(stdscr, y, x)
self.screen = screen
self.error = error

def render(self):
"""Render this view on the screen"""
if self.error.has_occured:
clear_line(self.stdscr, self.screen.y_max - 2)
self.display_line(self.screen.y_max - 2, 0, MSG_ERRORS, Color.IMPORTANT)
self.error.clear_buffer()


class SeparatorView(View):
"""Display the separator in the split screen"""

Expand Down Expand Up @@ -955,6 +972,7 @@ def main(stdscr) -> None:
welcome_screen_view = WelcomeScreenView(stdscr, 0, 0, screen)
footer_view = FooterView(stdscr, 0, 0, screen)
separator_view = SeparatorView(stdscr, 0, 0, screen)
error_view = ErrorView(stdscr, 0, 0, screen)

# Show welcome screen on the first run:
if cf.is_first_run:
Expand Down Expand Up @@ -982,6 +1000,7 @@ def main(stdscr) -> None:
monthly_screen_view.render()
if screen.split: separator_view.render()
footer_view.render()
error_view.render()
control_monthly_screen(stdscr, user_events, screen, importer)

# Daily (active) screen:
Expand All @@ -994,6 +1013,7 @@ def main(stdscr) -> None:
daily_screen_view.render()
if screen.split: separator_view.render()
footer_view.render()
error_view.render()
control_daily_screen(stdscr, user_events, screen, importer)

# JOURNAL
Expand All @@ -1012,6 +1032,7 @@ def main(stdscr) -> None:
journal_screen_view.render()
if screen.split: separator_view.render()
footer_view.render()
error_view.render()
control_journal_screen(stdscr, user_tasks, screen, importer)

# Help screen:
Expand Down
8 changes: 1 addition & 7 deletions calcure/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,19 +342,13 @@ def read_parameters_from_user_arguments(self):
pass


# Initialise config:
cf = Config()

# Create config folder:
if not os.path.exists(cf.config_folder):
os.makedirs(cf.config_folder)

# Start logging:
logging.basicConfig(level=logging.INFO,
format="[%(levelname)s] %(message)s",
encoding='utf-8',
handlers=[logging.FileHandler(f"{cf.config_folder}/info.log", 'w'),
logging.StreamHandler()],)

# Read config file:
cf.create_config_file()
cf.read_config_file_from_user_arguments()
Expand Down
40 changes: 40 additions & 0 deletions calcure/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Module that controls logging and error output"""

import logging
import io

from calcure.configuration import cf


class Error():
"""Error messages displayed to the user"""

def __init__(self):
self.buffer = io.StringIO()
self.file = f"{cf.config_folder}/info.log"

def get_error_text(self):
"""Returns string with the text of the error"""
return self.buffer.getvalue()

def clear_buffer(self):
"""Clear the buffer containing errors"""
self.buffer = io.StringIO()

@property
def has_occured(self):
"""Has any errors occured?"""
return self.get_error_text() != ""


# Initialise error:
error = Error()

# Start logging:
logging.basicConfig(level=logging.INFO,
format="[%(levelname)s] %(message)s",
encoding='utf-8',
handlers=[logging.FileHandler(error.file, 'w'),
logging.StreamHandler(),
logging.StreamHandler(error.buffer),
])
1 change: 1 addition & 0 deletions calcure/translations/br.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
MSG_TS_DEAD_DEL = "Remover data limite da tarefa número: "
MSG_TS_DEAD_DATE = "Adicionar data limite em (AAAA/MM/DD): "
MSG_WEATHER = "Clima está carregando..."
MSG_ERRORS = "Errors have occurred. See info.log file in your config folder."

CALENDAR_HINT = "Espaço · Mudar para diário a · Adicionar evento n/p · Mudar mês ? · Todas as combinações de teclas"
CALENDAR_HINT_D = "Espaço · Mudar para diário a · Adicionar evento n/p · Mudar dia ? · Todas as combinações de teclas"
Expand Down
1 change: 1 addition & 0 deletions calcure/translations/en.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
MSG_TS_DEAD_DEL = "Remove deadline of the task number: "
MSG_TS_DEAD_DATE = "Add deadline on (YYYY/MM/DD): "
MSG_WEATHER = "Weather is loading..."
MSG_ERRORS = "Errors have occurred. See info.log in your config folder."

CALENDAR_HINT = "Space · Switch to journal a · Add event n/p · Change month ? · All keybindings"
CALENDAR_HINT_D = "Space · Switch to journal a · Add event n/p · Change day ? · All keybindings"
Expand Down
1 change: 1 addition & 0 deletions calcure/translations/fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
MSG_TS_DEAD_DEL = "Supprimer l'échéance de la tâche numéro: "
MSG_TS_DEAD_DATE = "Ajouter une date limite le (AAAA/MM/JJ): "
MSG_WEATHER = "La météo se charge..."
MSG_ERRORS = "Des erreurs se sont produites. Voir info.log dans votre dossier de configuration."

CALENDAR_HINT = "Espace · Passer au journal a · Ajouter un événement n/p · Changer de mois ? · Aider"
CALENDAR_HINT_D = "Espace · Passer au journal a · Ajouter un événement n/p · Changer de jour ? · All keybindings"
Expand Down
1 change: 1 addition & 0 deletions calcure/translations/it.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
MSG_TS_DEAD_DEL = "Rimuovi la scadenza per l'attività con numero: "
MSG_TS_DEAD_DATE = "Aggiungi una scandeza per il (AAAA/MM/GG): "
MSG_WEATHER = "Caricamento del meteo..."
MSG_ERRORS = "Errors have occurred. See info.log file in your config folder."

CALENDAR_HINT = "Barra spaziatrice · Passa al diario a · Aggiungi un evento n/p · Cambia mese ? · Mostra tutte le scorciatoie"
CALENDAR_HINT_D = "Barra spaziatrice · Passa al diario a · Aggiungi un evento n/p · Cambia giorno ? · Mostra tutte le scorciatoie"
Expand Down
1 change: 1 addition & 0 deletions calcure/translations/ru.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
MSG_TS_DEAD_DEL = "Удалить дедлайн задачи номер: "
MSG_TS_DEAD_DATE = "Установить дедлайн на (YYYY/MM/DD): "
MSG_WEATHER = "Загружается информации о погоде..."
MSG_ERRORS = "Возникли ошибки. Детали в info.log файле в конфиг директории."

CALENDAR_HINT = "Пробел · Переключить на журнал a · Новое событие n/p · Сменить месяц ? · Клавиши"
CALENDAR_HINT_D = "Пробел · Переключить на журнал a · Новое событие n/p · Сменить день ? · Клавиши"
Expand Down
1 change: 1 addition & 0 deletions calcure/translations/tr.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
MSG_TS_DEAD_DEL = "Görev numarasının son tarihini kaldırın: "
MSG_TS_DEAD_DATE = "Son tarih ekleyin (YYYY/MM/DD): "
MSG_WEATHER = "Hava durumu yükleniyor..."
MSG_ERRORS = "Errors have occurred. See info.log in your config folder."

CALENDAR_HINT = "Space · Günlüğe geç a · Etkinlik ekle n/p · Ayı değiştir ? · Tüm tuş atamaları"
CALENDAR_HINT_D = "Space · Günlüğe geç a · Etkinlik ekle n/p · Günü değiştir ? · Tüm tuş atamaları"
Expand Down
1 change: 1 addition & 0 deletions calcure/translations/zh.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
MSG_TS_DEAD_DEL = "移除截止日期为事件号码: "
MSG_TS_DEAD_DATE = "增加截至日期在(YYYY/MM/DD): "
MSG_WEATHER = "天气插件正在加载..."
MSG_ERRORS = "Errors have occurred. See info.log in your config folder."

CALENDAR_HINT = "Space · 转换到通知栏 a · 增加事件 n/p · 改变月 ? · 所有键位绑定"
CALENDAR_HINT_D = "Space · 转换到通知栏 a · 增加事件 n/p · 改变日 ? · 所有键位绑定"
Expand Down

0 comments on commit 868c3ea

Please sign in to comment.