Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
poezio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Pierre-Samuel Le Stang
poezio
Commits
30547aa8
Commit
30547aa8
authored
Jul 22, 2018
by
Link Mauve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
theming: Add typing information.
parent
b5bd6a12
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
16 deletions
+18
-16
poezio/theming.py
poezio/theming.py
+18
-16
No files found.
poezio/theming.py
View file @
30547aa8
...
...
@@ -74,6 +74,7 @@ except ImportError:
import
curses
import
functools
import
os
from
typing
import
Dict
,
List
,
Union
,
Tuple
,
Optional
from
pathlib
import
Path
from
os
import
path
from
poezio
import
colors
,
xdg
...
...
@@ -94,7 +95,7 @@ class Theme:
"""
@
classmethod
def
color_role
(
cls
,
role
):
def
color_role
(
cls
,
role
:
str
):
role_mapping
=
{
'moderator'
:
cls
.
COLOR_USER_MODERATOR
,
'participant'
:
cls
.
COLOR_USER_PARTICIPANT
,
...
...
@@ -105,7 +106,7 @@ class Theme:
return
role_mapping
.
get
(
role
,
cls
.
COLOR_USER_NONE
)
@
classmethod
def
char_affiliation
(
cls
,
affiliation
):
def
char_affiliation
(
cls
,
affiliation
:
str
):
affiliation_mapping
=
{
'owner'
:
cls
.
CHAR_AFFILIATION_OWNER
,
'admin'
:
cls
.
CHAR_AFFILIATION_ADMIN
,
...
...
@@ -115,7 +116,7 @@ class Theme:
return
affiliation_mapping
.
get
(
affiliation
,
cls
.
CHAR_AFFILIATION_NONE
)
@
classmethod
def
color_show
(
cls
,
show
):
def
color_show
(
cls
,
show
:
str
):
show_mapping
=
{
'xa'
:
cls
.
COLOR_STATUS_XA
,
'none'
:
cls
.
COLOR_STATUS_NONE
,
...
...
@@ -129,7 +130,7 @@ class Theme:
return
show_mapping
.
get
(
show
,
cls
.
COLOR_STATUS_NONE
)
@
classmethod
def
char_subscription
(
cls
,
sub
,
keep
=
'incomplete'
):
def
char_subscription
(
cls
,
sub
:
str
,
keep
:
str
=
'incomplete'
):
sub_mapping
=
{
'from'
:
cls
.
CHAR_ROSTER_FROM
,
'both'
:
cls
.
CHAR_ROSTER_BOTH
,
...
...
@@ -382,7 +383,7 @@ theme = Theme()
# Each time we use a color tuple, we check if it has already been used.
# If not we create a new color_pair and keep it in that dict, to use it
# the next time.
curses_colors_dict
=
{}
curses_colors_dict
=
{}
# type: Dict[Union[Tuple[int, int], Tuple[int, int, str]], int]
# yapf: disable
...
...
@@ -406,7 +407,7 @@ table_256_to_16 = [
]
# yapf: enable
load_path
=
[]
load_path
=
[]
# type: List[str]
def
color_256_to_16
(
color
):
...
...
@@ -415,14 +416,14 @@ def color_256_to_16(color):
return
table_256_to_16
[
color
]
def
dump_tuple
(
tup
)
:
def
dump_tuple
(
tup
:
Union
[
Tuple
[
int
,
int
],
Tuple
[
int
,
int
,
str
]])
->
str
:
"""
Dump a tuple to a string of fg,bg,attr (optional)
"""
return
','
.
join
(
str
(
i
)
for
i
in
tup
)
def
read_tuple
(
_str
)
:
def
read_tuple
(
_str
:
str
)
->
Tuple
[
Tuple
[
int
,
int
],
str
]
:
"""
Read a tuple dumped with dump_tumple
"""
...
...
@@ -432,7 +433,7 @@ def read_tuple(_str):
@
functools
.
lru_cache
(
maxsize
=
128
)
def
to_curses_attr
(
color_tuple
)
:
def
to_curses_attr
(
color_tuple
:
Union
[
Tuple
[
int
,
int
],
Tuple
[
int
,
int
,
str
]])
->
int
:
"""
Takes a color tuple (as defined at the top of this file) and
returns a valid curses attr that can be passed directly to attron() or attroff()
...
...
@@ -476,14 +477,14 @@ def to_curses_attr(color_tuple):
return
curses_pair
def
get_theme
():
def
get_theme
()
->
Theme
:
"""
Returns the current theme
"""
return
theme
def
update_themes_dir
(
option
=
None
,
value
=
None
):
def
update_themes_dir
(
option
:
Optional
[
str
]
=
None
,
value
:
Optional
[
str
]
=
None
):
global
load_path
load_path
=
[]
...
...
@@ -516,17 +517,17 @@ def update_themes_dir(option=None, value=None):
log
.
debug
(
'Theme load path: %s'
,
load_path
)
def
prepare_ccolor_palette
(
theme
)
:
def
prepare_ccolor_palette
(
theme
:
Theme
)
->
None
:
"""
Prepare the Consistent Color Generation (XEP-0392) palette for a theme.
"""
if
theme
.
CCG_PALETTE
is
not
None
:
return
return
None
if
any
(
bg
!=
-
1
for
fg
,
bg
in
theme
.
LIST_COLOR_NICKNAMES
):
# explicitly disable CCG, can’t handle dynamic background colors
theme
.
CCG_PALETTE
=
{}
return
return
None
theme
.
CCG_PALETTE
=
colors
.
generate_ccg_palette
(
[
...
...
@@ -536,14 +537,15 @@ def prepare_ccolor_palette(theme):
],
theme
.
CCG_Y
,
)
return
None
def
reload_theme
():
def
reload_theme
()
->
Optional
[
str
]
:
theme_name
=
config
.
get
(
'theme'
)
global
theme
if
theme_name
==
'default'
or
not
theme_name
.
strip
():
theme
=
Theme
()
return
return
None
new_theme
=
None
exc
=
None
try
:
...
...
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