| ... |
... |
@@ -15,9 +15,9 @@ |
|
15
|
15
|
# You should have received a copy of the GNU General Public License
|
|
16
|
16
|
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
17
|
|
|
18
|
|
-import os
|
|
19
|
18
|
import math
|
|
20
|
19
|
import logging
|
|
|
20
|
+from pathlib import Path
|
|
21
|
21
|
|
|
22
|
22
|
from gi.repository import Gtk
|
|
23
|
23
|
from gi.repository import Gdk
|
| ... |
... |
@@ -148,7 +148,7 @@ class CSSConfig(): |
|
148
|
148
|
CSSPriority.DEFAULT_THEME_DARK)
|
|
149
|
149
|
|
|
150
|
150
|
def _load_css_from_file(self, filename, priority):
|
|
151
|
|
- path = os.path.join(configpaths.get('STYLE'), filename)
|
|
|
151
|
+ path = Path(configpaths.get('STYLE')) / filename
|
|
152
|
152
|
try:
|
|
153
|
153
|
with open(path, "r") as file_:
|
|
154
|
154
|
css = file_.read()
|
| ... |
... |
@@ -180,8 +180,8 @@ class CSSConfig(): |
|
180
|
180
|
return int(math.ceil(number / 100.0)) * 100
|
|
181
|
181
|
|
|
182
|
182
|
def _gather_available_themes(self):
|
|
183
|
|
- files = os.listdir(configpaths.get('MY_THEME'))
|
|
184
|
|
- self.themes = [file[:-4] for file in files if file.endswith('.css')]
|
|
|
183
|
+ files = Path(configpaths.get('MY_THEME')).iterdir()
|
|
|
184
|
+ self.themes = [file.stem for file in files if file.suffix == '.css']
|
|
185
|
185
|
if 'default' in self.themes:
|
|
186
|
186
|
# Ignore user created themes that are named 'default'
|
|
187
|
187
|
self.themes.remove('default')
|
| ... |
... |
@@ -191,8 +191,8 @@ class CSSConfig(): |
|
191
|
191
|
theme = 'default-dark'
|
|
192
|
192
|
|
|
193
|
193
|
if user:
|
|
194
|
|
- return os.path.join(configpaths.get('MY_THEME'), '%s.css' % theme)
|
|
195
|
|
- return os.path.join(configpaths.get('STYLE'), '%s.css' % theme)
|
|
|
194
|
+ return Path(configpaths.get('MY_THEME')) / f'{theme}.css'
|
|
|
195
|
+ return Path(configpaths.get('STYLE')) / f'{theme}.css'
|
|
196
|
196
|
|
|
197
|
197
|
def _determine_theme_path(self):
|
|
198
|
198
|
# Gets the path of the currently active theme.
|
| ... |
... |
@@ -202,7 +202,7 @@ class CSSConfig(): |
|
202
|
202
|
return self.get_theme_path(theme, user=False)
|
|
203
|
203
|
|
|
204
|
204
|
theme_path = self.get_theme_path(theme)
|
|
205
|
|
- if not theme or not os.path.exists(theme_path):
|
|
|
205
|
+ if not theme or not theme_path.exists():
|
|
206
|
206
|
log.warning('Theme %s not found, fallback to default', theme)
|
|
207
|
207
|
app.config.set('roster_theme', 'default')
|
|
208
|
208
|
log.info('Use Theme: default')
|
| ... |
... |
@@ -462,7 +462,7 @@ class CSSConfig(): |
|
462
|
462
|
def change_theme(self, theme):
|
|
463
|
463
|
user = not theme == 'default'
|
|
464
|
464
|
theme_path = self.get_theme_path(theme, user=user)
|
|
465
|
|
- if not os.path.exists(theme_path):
|
|
|
465
|
+ if not theme_path.exists():
|
|
466
|
466
|
log.error('Change Theme: Theme %s does not exist', theme_path)
|
|
467
|
467
|
return False
|
|
468
|
468
|
self._load_selected(theme_path)
|
| ... |
... |
@@ -473,7 +473,7 @@ class CSSConfig(): |
|
473
|
473
|
|
|
474
|
474
|
def change_preload_theme(self, theme):
|
|
475
|
475
|
theme_path = self.get_theme_path(theme)
|
|
476
|
|
- if not os.path.exists(theme_path):
|
|
|
476
|
+ if not theme_path.exists():
|
|
477
|
477
|
log.error('Change Preload Theme: Theme %s does not exist',
|
|
478
|
478
|
theme_path)
|
|
479
|
479
|
return False
|
| ... |
... |
@@ -492,7 +492,7 @@ class CSSConfig(): |
|
492
|
492
|
|
|
493
|
493
|
old_theme_path = self.get_theme_path(old_theme)
|
|
494
|
494
|
new_theme_path = self.get_theme_path(new_theme)
|
|
495
|
|
- os.rename(old_theme_path, new_theme_path)
|
|
|
495
|
+ old_theme_path.rename(new_theme_path)
|
|
496
|
496
|
self.themes.remove(old_theme)
|
|
497
|
497
|
self.themes.append(new_theme)
|
|
498
|
498
|
self._load_pre(new_theme)
|
| ... |
... |
@@ -507,7 +507,7 @@ class CSSConfig(): |
|
507
|
507
|
|
|
508
|
508
|
def add_new_theme(self, theme):
|
|
509
|
509
|
theme_path = self.get_theme_path(theme)
|
|
510
|
|
- if os.path.exists(theme_path):
|
|
|
510
|
+ if theme_path.exists():
|
|
511
|
511
|
log.error('Add Theme: %s exists already', theme_path)
|
|
512
|
512
|
return False
|
|
513
|
513
|
with open(theme_path, 'w', encoding='utf8'):
|
| ... |
... |
@@ -518,8 +518,8 @@ class CSSConfig(): |
|
518
|
518
|
|
|
519
|
519
|
def remove_theme(self, theme):
|
|
520
|
520
|
theme_path = self.get_theme_path(theme)
|
|
521
|
|
- if os.path.exists(theme_path):
|
|
522
|
|
- os.remove(theme_path)
|
|
|
521
|
+ if theme_path.exists():
|
|
|
522
|
+ theme_path.unlink()
|
|
523
|
523
|
self.themes.remove(theme)
|
|
524
|
524
|
log.info('Remove Theme: Successful removed theme %s', theme)
|
|
525
|
525
|
|