Skip to content

Commit

Permalink
feature: add option to enable/disable sound notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Mar 20, 2024
1 parent 2b05c54 commit 5760b40
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 7 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
recursive-include dicogis/locale *
recursive-include dicogis/bin/img *
recursive-include dicogis/bin/audio *
1 change: 1 addition & 0 deletions dicogis/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
__icon_path__ = Path("bin/img/DicoGIS_logo_200px.png")
__keywords__ = ["GIS", "metadata", "INSPIRE", "GDAL", "OGR", "data management"]
__license__ = "Apache-2.0"
__notification_sound_path__ = Path("bin/audio/notification_sound_microwave_bell.wav")
__summary__ = (
"Create Excel spreadsheet describing geographical data from a PostGIS "
"Database or a file tree structure."
Expand Down
Binary file not shown.
27 changes: 25 additions & 2 deletions dicogis/cli/cmd_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from dicogis.georeaders.read_postgis import ReadPostGIS
from dicogis.listing.geodata_listing import check_usable_pg_services, find_geodata_files
from dicogis.utils.environment import get_gdal_version, get_proj_version
from dicogis.utils.notifier import send_system_notify
from dicogis.utils.texts import TextsManager
from dicogis.utils.utils import Utilities

Expand Down Expand Up @@ -96,9 +97,18 @@ def inventory(
"supported. Here for the future!",
),
] = "excel",
out_prettify_size: Annotated[
opt_notify_sound: Annotated[
bool,
typer.Option(
envvar="DICOGIS_ENABLE_NOTIFICATION_SOUND",
is_flag=True,
help="Enable/disable notification's sound at the end of processing.",
),
] = True,
opt_prettify_size: Annotated[
bool,
typer.Option(
envvar="DICOGIS_EXPORT_SIZE_PRETTIFY",
is_flag=True,
help="Enable prettified files size in output. "
"Example: 1 ko instead of 1024.",
Expand Down Expand Up @@ -165,7 +175,7 @@ def inventory(
# creating the Excel workbook
xl_workbook = MetadataToXlsx(
texts=localized_strings,
opt_size_prettify=out_prettify_size,
opt_size_prettify=opt_prettify_size,
)
else:
logger.error(
Expand Down Expand Up @@ -278,6 +288,11 @@ def inventory(
gui=False,
)
logger.info(f"Workbook saved: {saved[1]}")
send_system_notify(
notification_title="DicoGIS analysis ended",
notification_message=f"DicoGIS successfully processed {total_files} files.",
notification_sound=opt_notify_sound,
)

# look for geographic database
if pg_services:
Expand Down Expand Up @@ -339,6 +354,14 @@ def inventory(
if output_path is None:
output_path = f"DicoGIS_database_{date.today()}.xlsx"

send_system_notify(
notification_title="DicoGIS analysis ended",
notification_message="DicoGIS successfully processed "
f"{sgbd_reader.conn.GetLayerCount()} PostGIS tables. "
"\nOpen the application to save the workbook.",
notification_sound=opt_notify_sound,
)


# ############################################################################
# #### Stand alone program ########
Expand Down
11 changes: 8 additions & 3 deletions dicogis/ui/main_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,6 @@ def ligeofiles(self, target_folder: str) -> tuple[list[str]]:
Returns:
tuple[list[str]]: tuple of list of paths by formats
"""

# disable related UI items in the meanwhile
self.tab_files.btn_browse.config(state=DISABLED)

Expand Down Expand Up @@ -602,8 +601,8 @@ def process_files(self):
notification_title="DicoGIS analysis ended",
notification_message=f"DicoGIS successfully processed {total_files} files. "
"\nOpen the application to save the workbook.",
notification_sound=self.tab_options.opt_end_process_notification_sound.get(),
)
self.bell()
self.val.config(state=ACTIVE)
self.xl_workbook.tunning_worksheets()
saved = utils_global.safe_save(
Expand Down Expand Up @@ -662,7 +661,13 @@ def process_db(self, sgbd_reader: ReadPostGIS):
self.update()

# saving dictionary
self.bell()
send_system_notify(
notification_title="DicoGIS analysis ended",
notification_message="DicoGIS successfully processed "
f"{sgbd_reader.conn.GetLayerCount()} PostGIS tables. "
"\nOpen the application to save the workbook.",
notification_sound=self.tab_options.opt_end_process_notification_sound.get(),
)
self.val.config(state=ACTIVE)
self.xl_workbook.tunning_worksheets()
saved = utils_global.safe_save(
Expand Down
12 changes: 12 additions & 0 deletions dicogis/ui/tab_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ def __init__(self, parent, txt: dict, switcher: Callable = None):
row=2, column=0, sticky="NSWE", padx=2, pady=2
)

self.opt_end_process_notification_sound = BooleanVar(
master=self, value=getenv("DICOGIS_ENABLE_NOTIFICATION_SOUND", True)
)
caz_opt_end_process_notification_sound = Checkbutton(
self.FrOptExport,
text="Play a notification sound when processing has finished.",
variable=self.opt_end_process_notification_sound,
)
caz_opt_end_process_notification_sound.grid(
row=3, column=0, sticky="NSWE", padx=2, pady=2
)

# positionning frames

self.FrOptExport.grid(row=1, column=0, sticky="NSWE", padx=2, pady=2)
Expand Down
12 changes: 10 additions & 2 deletions dicogis/utils/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from notifypy import Notify

# package
from dicogis.__about__ import __icon_path__, __title__
from dicogis.__about__ import __icon_path__, __notification_sound_path__, __title__
from dicogis.utils.utils import Utilities

# ##############################################################################
Expand All @@ -37,14 +37,22 @@
# ##############################################################################
# ############ Functions ##########
# #################################
def send_system_notify(notification_message: str, notification_title: str):
def send_system_notify(
notification_message: str, notification_title: str, notification_sound: bool = True
):
"""Send a notification to the system.
Args:
notification_message (str): notification message
notification_title (str): notification title
"""
notification.message = notification_message
if notification_sound:
notification.audio = str(
dicogis_utils.resolve_internal_path(
internal_path=__notification_sound_path__
).resolve()
)

try:
notification.send()
Expand Down
6 changes: 6 additions & 0 deletions docs/misc/credits.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Credits

## Audio

The notification sound is a work of [Joseph SARDIN](https://josephsardin.fr/) under [Creative Commons CC0 1.0 Universal](https://bigsoundbank.com/right.html): [Microwave Bell](https://bigsoundbank.com/sound-1631-microwave-bell.html).

----

## Dependencies

> Generated with [pipdeptree](https://pypi.org/project/pipdeptree/).
Expand Down
1 change: 1 addition & 0 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Some options and arguments can be set with environment variables.
| Variable name | Corresponding CLI argument | Default value |
| :----------------------------- | :------------------------: | :----------------: |
| `DICOGIS_DEFAULT_LANGUAGE` | `--language` | `None` |
| `DICOGIS_ENABLE_NOTIFICATION_SOUND` | `--notify-sound` / `--no-notify-sound` | `--notify-sound` |
| `DICOGIS_EXPORT_SIZE_PRETTIFY` | `--out-prettify-size` / `--no-out-prettify-size` | `--no-out-prettify-size` |
| `DICOGIS_FORMATS_LIST` | `--formats` | `dxf,esri_shapefile,geojson,gml,kml,mapinfo_tab,sqlite,ecw,geotiff,jpeg` |
| `DICOGIS_OUTPUT_FILEPATH` | `--output-path` | `None` |
Expand Down

0 comments on commit 5760b40

Please sign in to comment.