emmental/emmental/gsetup.py
Anna Schumaker deb4f3d252 db: Create a base Connection manager
This is a wrapper around the sqlite3.Connection objct that adds some
nice functionality to make working with SQL easier.

I defined the following magic methods:
  * __enter__() to manually begin a transaction
  * __exit__() to commit or rollback a manual transaction
  * __call__() to execute a SQL statement with either positional or
    keyword arguments.

Additionally:
  * I define a "CASEFOLD" function that can be used in queries
    to lowercase unicode text when searching.
  * I set foreign_keys = ON so foreign keys checking is always enabled
  * I provide an executemany() function for running running the same
    statement multiple times with different arguments.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2023-04-12 09:23:14 -04:00

57 lines
2.1 KiB
Python

# Copyright 2022 (c) Anna Schumaker.
"""Set up GObject Introspection, and custom styling, and icons."""
import pathlib
import sys
import sqlite3
import gi
import xdg.BaseDirectory
gi.require_version("Gdk", "4.0")
gi.require_version("Gtk", "4.0")
gi.require_version("Adw", "1")
gi.importlib.import_module("gi.repository.Gio")
gi.importlib.import_module("gi.repository.Gtk")
DEBUG_STR = "-debug" if __debug__ else ""
APPLICATION_ID = f"com.nowheycreamery.emmental{'-debug' if __debug__ else ''}"
CSS_FILE = pathlib.Path(__file__).parent / "emmental.css"
CSS_PRIORITY = gi.repository.Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
CSS_PROVIDER = gi.repository.Gtk.CssProvider()
CSS_PROVIDER.load_from_path(str(CSS_FILE))
DATA_DIR = pathlib.Path(xdg.BaseDirectory.save_data_path("emmental"))
RESOURCE_PATH = "/com/nowheycreamery/emmental"
RESOURCE_ICONS = f"{RESOURCE_PATH}/icons/scalable/apps"
RESOURCE_FILE = pathlib.Path(__file__).parent.parent / "emmental.gresource"
RESOURCE = gi.repository.Gio.Resource.load(str(RESOURCE_FILE))
gi.repository.Gio.resources_register(RESOURCE)
def add_style():
"""Add our stylesheet to the default display."""
style = gi.repository.Gtk.StyleContext
style.add_provider_for_display(gi.repository.Gdk.Display.get_default(),
CSS_PROVIDER, CSS_PRIORITY)
def __print_version(subsystem, major, minor, micro):
print(f"{subsystem} {major}.{minor}.{micro}")
def print_versions():
"""Print version information for libraries we use."""
__print_version("Python", sys.version_info.major, sys.version_info.minor,
sys.version_info.micro)
__print_version("Gtk", gi.repository.Gtk.MAJOR_VERSION,
gi.repository.Gtk.MINOR_VERSION,
gi.repository.Gtk.MICRO_VERSION)
__print_version("Libadwaita", gi.repository.Adw.MAJOR_VERSION,
gi.repository.Adw.MINOR_VERSION,
gi.repository.Adw.MICRO_VERSION)
__print_version("SQLite", sqlite3.sqlite_version_info[0],
sqlite3.sqlite_version_info[1],
sqlite3.sqlite_version_info[2])