Skip to content

Commit

Permalink
Merge pull request #29 from nwg-piotr/date-format
Browse files Browse the repository at this point in the history
- added "time-format" & "date-format" config keys
  • Loading branch information
nwg-piotr authored Nov 3, 2024
2 parents 5ce3a62 + bb342be commit 1ec89bb
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 24 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ Copy `/etc/nwg-hello/nwg-hello-default.json` to `/etc/nwg-hello/nwg-hello.json`
"gtk-cursor-theme": "",
"prefer-dark-theme": true,
"template-name": "",
"time-format": "%H:%M:%S",
"date-format": "%A, %d. %B",
"lang": "",
"env-vars": []
}
Expand All @@ -142,6 +144,8 @@ Copy `/etc/nwg-hello/nwg-hello-default.json` to `/etc/nwg-hello/nwg-hello.json`
- `"gtk-theme"`, `"gtk-icon-theme"` and `"gtk-cursor-theme"` are of little importance as long, as you use classes and IDs from the default css style sheet.
- `"prefer-dark-theme"` should remain `true`, unless you need to turn it off for use with your own background and/or styling.
- `"template-name"` allows use of own templates: find the built-in `/usr/lib/python3.xx/site-packages/nwg_hello-x.y.z-py3.xx.egg/nwg_hello/template.glade` file, copy to a folder somewhere in `~/`, edit and place as `/etc/nwg-hello/file-name.glade`. Do not change widget IDs. Set your `file-name.glade` as the `"template-name"` value. Leave blank to use the built-in template.
- `"time-format"`: string to format clock with the strftime() function (see: https://www.man7.org/linux/man-pages/man3/strftime.3.html).
- `"date-format"`: string to format date with the strftime() function (see: https://www.man7.org/linux/man-pages/man3/strftime.3.html).
- `"lang"` allows you to force the use of a specific language, regardless of the `$LANG` system variable. Check if we have the translation in the [langs directory](https://github.com/nwg-piotr/nwg-hello/tree/main/nwg_hello/langs).
- `"env-vars"` allows to pass an array of environment variables. Use like this: `["MY_VAR=value", "OTHER_VAR=value1"]`.

Expand Down
2 changes: 2 additions & 0 deletions nwg-hello-default.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"gtk-cursor-theme": "",
"prefer-dark-theme": true,
"template-name": "",
"time-format": "%H:%M:%S",
"date-format": "%A, %d. %B",
"lang": "",
"env-vars": []
}
47 changes: 27 additions & 20 deletions nwg_hello/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,31 @@
eprint(f"Loaded settings from: '{settings_path}'", log=args.log)
# set defaults if key not found
defaults = {
"session_dirs": [
"/usr/share/wayland-sessions",
"/usr/share/xsessions"
],
"gtk-theme": "Adwaita",
"gtk-icon-theme": "",
"gtk-cursor-theme": "",
"prefer-dark-theme": True,
"template-name": "",
"custom_sessions": [],
"monitor_nums": [],
"form_on_monitors": [],
"delay_secs": 1,
"lang": "",
"cmd-sleep": "systemctl suspend",
"cmd-reboot": "systemctl reboot",
"cmd-poweroff": "systemctl poweroff",
"env-vars": []
"session_dirs": [
"/usr/share/wayland-sessions",
"/usr/share/xsessions"
],
"custom_sessions": [
{
"name": "Shell",
"exec": "/usr/bin/bash"
}
],
"monitor_nums": [],
"form_on_monitors": [],
"delay_secs": 1,
"cmd-sleep": "systemctl suspend",
"cmd-reboot": "systemctl reboot",
"cmd-poweroff": "systemctl poweroff",
"gtk-theme": "Adwaita",
"gtk-icon-theme": "",
"gtk-cursor-theme": "",
"prefer-dark-theme": True,
"template-name": "",
"time-format": "%H:%M:%S",
"date-format": "%A, %d. %B",
"lang": "",
"env-vars": []
}
for key in defaults:
if key not in settings:
Expand Down Expand Up @@ -159,14 +166,14 @@
def set_clock():
_now = datetime.now()
for win in windows:
win.update_time(_now)
win.update_time(_now, settings["time-format"], settings["date-format"])
return False


def move_clock():
_now = datetime.now()
for win in windows:
win.update_time(_now)
win.update_time(_now, settings["time-format"], settings["date-format"])
return True


Expand Down
6 changes: 3 additions & 3 deletions nwg_hello/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ def handle_keyboard(self, w, event):

return True

def update_time(self, now):
self.lbl_clock.set_text(f'{now.strftime("%H:%M:%S")}')
self.lbl_date.set_text(f'{now.strftime("%A, %d. %B")}')
def update_time(self, now, time_format, date_format):
self.lbl_clock.set_text(f'{now.strftime(time_format)}')
self.lbl_date.set_text(f'{now.strftime(date_format)}')

def on_session_changed(self, combo):
self.entry_password.grab_focus()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def read(f_name):

setup(
name='nwg-hello',
version='0.2.4',
version='0.2.5',
description='GTK3-based greeter for greetd',
packages=find_packages(),
include_package_data=True,
Expand Down

0 comments on commit 1ec89bb

Please sign in to comment.