Skip to content

Commit

Permalink
Implementing different colors for different calendars
Browse files Browse the repository at this point in the history
  • Loading branch information
anufrievroman committed Mar 1, 2023
1 parent 3bfcf30 commit 6cd24c0
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 48 deletions.
21 changes: 13 additions & 8 deletions calcure/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
from calcure.dialogues import clear_line
from calcure.screen import Screen
from calcure.savers import TaskSaverCSV, EventSaverCSV
from calcure.colors import Color, initialize_colors
from calcure.loaders import *
from calcure.data import *
from calcure.controls import *
from calcure.helpers import initialize_colors


# Language:
Expand All @@ -41,7 +41,7 @@
from calcure.translations.en import *


__version__ = "2.7.5"
__version__ = "2.7.6"


def read_items_from_user_arguments(screen, user_tasks, user_events, task_saver_csv, event_saver_csv):
Expand Down Expand Up @@ -248,12 +248,17 @@ def icon(self):
@property
def color(self):
"""Select the color depending on the status and type"""
color = Color.EVENTS
if self.event.status == Status.IMPORTANT:
color = Color.IMPORTANT
if self.event.status == Status.UNIMPORTANT:
color = Color.UNIMPORTANT
return color
if self.event.calendar_number is None:
if self.event.status == Status.IMPORTANT:
return Color.IMPORTANT
if self.event.status == Status.UNIMPORTANT:
return Color.UNIMPORTANT
return Color.EVENTS
else:
for color in Color:
if color.value == Color.ICS_CALENDARS0.value + self.event.calendar_number:
return color
return Color.EVENTS

def obfuscate_info(self):
"""Obfuscate the info if privacy mode is on"""
Expand Down
51 changes: 50 additions & 1 deletion calcure/helpers.py → calcure/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,47 @@

import curses
import jdatetime
from enum import Enum, auto

from calcure.data import Color

class Color(Enum):
"""Colors read from user config"""
DAY_NAMES = auto()
WEEKENDS = auto()
HINTS = auto()
TODAY = auto()
DAYS = auto()
WEEKEND_NAMES = auto()
BIRTHDAYS = auto()
PROMPTS = auto()
CONFIRMATIONS = auto()
TITLE = auto()
TODO = auto()
DONE = auto()
IMPORTANT = auto()
TIMER = auto()
TIMER_PAUSED = auto()
HOLIDAYS = auto()
EVENTS = auto()
TIME = auto()
WEATHER = auto()
UNIMPORTANT = auto()
CALENDAR_HEADER = auto()
ACTIVE_PANE = auto()
SEPARATOR = auto()
EMPTY = auto()
CALENDAR_BOARDER = auto()
DEADLINES = auto()
ICS_CALENDARS0 = auto()
ICS_CALENDARS1 = auto()
ICS_CALENDARS2 = auto()
ICS_CALENDARS3 = auto()
ICS_CALENDARS4 = auto()
ICS_CALENDARS5 = auto()
ICS_CALENDARS6 = auto()
ICS_CALENDARS7 = auto()
ICS_CALENDARS8 = auto()
ICS_CALENDARS9 = auto()


def initialize_colors(cf):
Expand Down Expand Up @@ -44,3 +83,13 @@ def initialize_colors(cf):
if not cf.MINIMAL_DAYS_INDICATOR:
curses.init_pair(Color.DAYS.value, curses.COLOR_BLACK, cf.COLOR_DAYS)

if cf.ICS_EVENT_FILES is None:
return

# Assign color pair for each ics file:
for index in range(len(cf.ICS_EVENT_FILES)):
if index < len(cf.COLOR_ICS_CALENDARS):
color = cf.COLOR_ICS_CALENDARS[index]
else:
color = cf.COLOR_EVENTS
curses.init_pair(Color.ICS_CALENDARS0.value + index, color, cf.COLOR_BACKGROUND)
4 changes: 3 additions & 1 deletion calcure/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from calcure.data import AppState



class Config:
"""User configuration loaded from the config.ini file"""
def __init__(self):
Expand Down Expand Up @@ -100,6 +99,7 @@ def create_config_file(self):
"color_active_pane": "2",
"color_separator": "7",
"color_calendar_border": "7",
"color_ics_calendars": "2,3,1,7",
"color_background": "-1",
}

Expand Down Expand Up @@ -251,6 +251,8 @@ def read_config_file(self):
self.COLOR_ACTIVE_PANE = int(conf.get("Colors", "color_active_pane", fallback=2))
self.COLOR_SEPARATOR = int(conf.get("Colors", "color_separator", fallback=7))
self.COLOR_CALENDAR_BOARDER= int(conf.get("Colors", "color_calendar_border", fallback=7))
self.COLOR_ICS_CALENDARS = conf.get("Colors", "color_ics_calendars", fallback="2,3,1,7")
self.COLOR_ICS_CALENDARS = [int(number) for number in self.COLOR_ICS_CALENDARS.split(",")]

# Journal colors:
self.COLOR_TODO = int(conf.get("Colors", "color_todo", fallback=7))
Expand Down
39 changes: 6 additions & 33 deletions calcure/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,40 +39,10 @@ class Frequency(enum.Enum):
YEARLY = 5


class Color(enum.Enum):
"""Colors read from user config"""
DAY_NAMES = 1
WEEKENDS = 2
HINTS = 3
TODAY = 4
DAYS = 5
WEEKEND_NAMES = 6
BIRTHDAYS = 7
PROMPTS = 8
CONFIRMATIONS = 9
TITLE = 10
TODO = 11
DONE = 12
IMPORTANT = 13
TIMER = 14
TIMER_PAUSED = 15
HOLIDAYS = 16
EVENTS = 17
TIME = 18
WEATHER = 19
UNIMPORTANT = 20
CALENDAR_HEADER = 21
ACTIVE_PANE = 22
SEPARATOR = 23
EMPTY = 24
CALENDAR_BOARDER = 24
DEADLINES = 25


class Task:
"""Tasks crated by the user"""

def __init__(self, item_id, name, status, timer, privacy, year=0, month=0, day=0):
def __init__(self, item_id, name, status, timer, privacy, year=0, month=0, day=0, calendar_number=None):
self.item_id = item_id
self.name = name
self.status = status
Expand All @@ -81,6 +51,7 @@ def __init__(self, item_id, name, status, timer, privacy, year=0, month=0, day=0
self.year = year
self.month = month
self.day = day
self.calendar_number = calendar_number


class Event:
Expand All @@ -96,23 +67,25 @@ def __init__(self, year, month, day, name):
class UserEvent(Event):
"""Events crated by the user"""

def __init__(self, item_id, year, month, day, name, repetition, frequency, status, privacy):
def __init__(self, item_id, year, month, day, name, repetition, frequency, status, privacy, calendar_number=None):
super().__init__(year, month, day, name)
self.item_id = item_id
self.repetition = repetition
self.frequency = frequency
self.status = status
self.privacy = privacy
self.calendar_number = calendar_number


class UserRepeatedEvent(Event):
"""Events that are repetitions of the original user events"""

def __init__(self, item_id, year, month, day, name, status, privacy):
def __init__(self, item_id, year, month, day, name, status, privacy, calendar_number=None):
super().__init__(year, month, day, name)
self.item_id = item_id
self.status = status
self.privacy = privacy
self.calendar_number = calendar_number


class Timer:
Expand Down
3 changes: 2 additions & 1 deletion calcure/dialogues.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import curses
import logging

from calcure.data import Frequency, Color
from calcure.data import Frequency
from calcure.colors import Color


def display_question(stdscr, y, x, question, color):
Expand Down
8 changes: 4 additions & 4 deletions calcure/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def load(self):
if self.ics_task_files is None:
return self.user_ics_tasks

for filename in self.ics_task_files:
for calendar_number, filename in enumerate(self.ics_task_files):

# Quit if file does not exists:
if not os.path.exists(filename) and not filename.startswith('http'):
Expand Down Expand Up @@ -317,7 +317,7 @@ def load(self):
is_private = False

# Add task:
new_task = Task(task_id, name, status, timer, is_private, year, month, day)
new_task = Task(task_id, name, status, timer, is_private, year, month, day, calendar_number)
self.user_ics_tasks.add_item(new_task)

return self.user_ics_tasks
Expand All @@ -338,7 +338,7 @@ def load(self):
if self.ics_event_files is None:
return self.user_ics_events

for filename in self.ics_event_files:
for calendar_number, filename in enumerate(self.ics_event_files):

# Quit if file does not exists:
if not os.path.exists(filename) and not filename.startswith('http'):
Expand Down Expand Up @@ -381,7 +381,7 @@ def load(self):
year, month, day = convert_to_persian_date(year, month, day)

# Add event:
new_event = UserEvent(event_id, year, month, day, name, repetition, frequency, status, is_private)
new_event = UserEvent(event_id, year, month, day, name, repetition, frequency, status, is_private, calendar_number)
self.user_ics_events.add_item(new_event)

return self.user_ics_events

0 comments on commit 6cd24c0

Please sign in to comment.