|
| 1 | +# |
| 2 | +# DVR-Scan: Video Motion Event Detection & Extraction Tool |
| 3 | +# -------------------------------------------------------------- |
| 4 | +# [ Site: https://www.dvr-scan.com/ ] |
| 5 | +# [ Repo: https://github.com/Breakthrough/DVR-Scan ] |
| 6 | +# |
| 7 | +# Copyright (C) 2014-2024 Brandon Castellano <http://www.bcastell.com>. |
| 8 | +# DVR-Scan is licensed under the BSD 2-Clause License; see the included |
| 9 | +# LICENSE file, or visit one of the above pages for details. |
| 10 | +# |
| 11 | +"""DVR-Scan Region Editor handles detection region input and processing. |
| 12 | +
|
| 13 | +Regions are represented as a set of closed polygons defined by lists of points. |
| 14 | +
|
| 15 | +*NOTE*: The region editor is being transitioned to an offical GUI for DVR-Scan. |
| 16 | +During this period, there may still be some keyboard/CLI interaction required to |
| 17 | +run the program. Usability and accessibility bugs will be prioritized over feature |
| 18 | +development. |
| 19 | +
|
| 20 | +The code in this module covers *all* the current UI logic, and consequently is not |
| 21 | +well organized. This should be resolved as we develop the UI further and start to |
| 22 | +better separate the CLI from the GUI. To facilitate this, a separate entry-point |
| 23 | +for the GUI will be developed, and the region editor functionality will be deprecated. |
| 24 | +""" |
| 25 | + |
| 26 | +import os |
| 27 | +import os.path |
| 28 | +import tkinter as tk |
| 29 | +import tkinter.filedialog |
| 30 | +import tkinter.messagebox |
| 31 | +import tkinter.scrolledtext |
| 32 | +import tkinter.ttk as ttk |
| 33 | +import typing as ty |
| 34 | +import webbrowser |
| 35 | + |
| 36 | +import PIL |
| 37 | +import PIL.Image |
| 38 | +import PIL.ImageTk |
| 39 | + |
| 40 | +import dvr_scan |
| 41 | +from dvr_scan.app.common import SUPPORTS_RESOURCES |
| 42 | +from dvr_scan.platform import get_system_version_info |
| 43 | + |
| 44 | +if SUPPORTS_RESOURCES: |
| 45 | + import importlib.resources as resources |
| 46 | + |
| 47 | +TITLE = "About DVR-Scan" |
| 48 | +COPYRIGHT = ( |
| 49 | + f"DVR-Scan {dvr_scan.__version__}\n\nCopyright © Brandon Castellano.\nAll rights reserved." |
| 50 | +) |
| 51 | + |
| 52 | + |
| 53 | +class AboutWindow: |
| 54 | + def __init__(self): |
| 55 | + self._version_info: ty.Optional[str] = None |
| 56 | + self._about_image: PIL.Image = None |
| 57 | + self._about_image_tk: PIL.ImageTk.PhotoImage = None |
| 58 | + |
| 59 | + def show(self, root: tk.Tk): |
| 60 | + window = tk.Toplevel(master=root) |
| 61 | + window.withdraw() |
| 62 | + window.title(TITLE) |
| 63 | + window.resizable(True, True) |
| 64 | + |
| 65 | + if SUPPORTS_RESOURCES: |
| 66 | + app_logo = PIL.Image.open(resources.open_binary(dvr_scan, "dvr-scan-logo.png")) |
| 67 | + self._about_image = app_logo.crop((8, 8, app_logo.width - 132, app_logo.height - 8)) |
| 68 | + self._about_image_tk = PIL.ImageTk.PhotoImage(self._about_image) |
| 69 | + canvas = tk.Canvas( |
| 70 | + window, width=self._about_image.width, height=self._about_image.height |
| 71 | + ) |
| 72 | + canvas.grid() |
| 73 | + canvas.create_image(0, 0, anchor=tk.NW, image=self._about_image_tk) |
| 74 | + |
| 75 | + ttk.Separator(window, orient=tk.HORIZONTAL).grid(row=1, sticky="ew", padx=16.0) |
| 76 | + ttk.Label( |
| 77 | + window, |
| 78 | + text=COPYRIGHT, |
| 79 | + ).grid(row=2, sticky="nw", padx=24.0, pady=24.0) |
| 80 | + |
| 81 | + # TODO: These should be buttons not labels. |
| 82 | + website_link = ttk.Label( |
| 83 | + window, text="www.dvr-scan.com", cursor="hand2", foreground="medium blue" |
| 84 | + ) |
| 85 | + website_link.grid(row=2, sticky="ne", padx=24.0, pady=24.0) |
| 86 | + website_link.bind("<Button-1>", lambda _: webbrowser.open_new_tab("www.dvr-scan.com")) |
| 87 | + |
| 88 | + about_tabs = ttk.Notebook(window) |
| 89 | + version_tab = ttk.Frame(about_tabs) |
| 90 | + version_area = tkinter.scrolledtext.ScrolledText( |
| 91 | + version_tab, wrap=tk.NONE, width=40, height=1 |
| 92 | + ) |
| 93 | + # TODO: See if we can add another button that will copy debug logs. |
| 94 | + if not self._version_info: |
| 95 | + self._version_info = get_system_version_info() |
| 96 | + version_area.insert(tk.INSERT, self._version_info) |
| 97 | + version_area.grid(sticky="nsew") |
| 98 | + version_area.config(state="disabled") |
| 99 | + version_tab.columnconfigure(0, weight=1) |
| 100 | + version_tab.rowconfigure(0, weight=1) |
| 101 | + tk.Button( |
| 102 | + version_tab, |
| 103 | + text="Copy to Clipboard", |
| 104 | + command=lambda: root.clipboard_append(self._version_info), |
| 105 | + ).grid(row=1, column=0) |
| 106 | + |
| 107 | + license_tab = ttk.Frame(about_tabs) |
| 108 | + scrollbar = tk.Scrollbar(license_tab, orient=tk.HORIZONTAL) |
| 109 | + license_area = tkinter.scrolledtext.ScrolledText( |
| 110 | + license_tab, wrap=tk.NONE, width=40, xscrollcommand=scrollbar.set, height=1 |
| 111 | + ) |
| 112 | + license_area.insert(tk.INSERT, dvr_scan.get_license_info()) |
| 113 | + license_area.grid(sticky="nsew") |
| 114 | + scrollbar.config(command=license_area.xview) |
| 115 | + scrollbar.grid(row=1, sticky="swe") |
| 116 | + license_area.config(state="disabled") |
| 117 | + license_tab.columnconfigure(0, weight=1) |
| 118 | + license_tab.rowconfigure(0, weight=1) |
| 119 | + |
| 120 | + # TODO: Add tab that has some useful links like submitting bug report, etc |
| 121 | + about_tabs.add(version_tab, text="Version Info") |
| 122 | + about_tabs.add(license_tab, text="License Info") |
| 123 | + |
| 124 | + about_tabs.grid( |
| 125 | + row=0, column=1, rowspan=4, padx=(0.0, 16.0), pady=(16.0, 16.0), sticky="nsew" |
| 126 | + ) |
| 127 | + window.update() |
| 128 | + if self._about_image is not None: |
| 129 | + window.columnconfigure(0, minsize=self._about_image.width) |
| 130 | + window.rowconfigure(0, minsize=self._about_image.height) |
| 131 | + else: |
| 132 | + window.columnconfigure(0, minsize=200) |
| 133 | + window.rowconfigure(0, minsize=100) |
| 134 | + # minsize includes padding |
| 135 | + window.columnconfigure(1, weight=1, minsize=100) |
| 136 | + window.rowconfigure(3, weight=1) |
| 137 | + |
| 138 | + window.minsize(width=window.winfo_reqwidth(), height=window.winfo_reqheight()) |
| 139 | + # can we query widget height? |
| 140 | + |
| 141 | + root.grab_release() |
| 142 | + if os == "nt": |
| 143 | + root.attributes("-disabled", True) |
| 144 | + |
| 145 | + window.transient(root) |
| 146 | + window.focus() |
| 147 | + window.grab_set() |
| 148 | + |
| 149 | + def dismiss(): |
| 150 | + window.grab_release() |
| 151 | + window.destroy() |
| 152 | + if os == "nt": |
| 153 | + root.attributes("-disabled", False) |
| 154 | + root.grab_set() |
| 155 | + root.focus() |
| 156 | + |
| 157 | + window.protocol("WM_DELETE_WINDOW", dismiss) |
| 158 | + window.attributes("-topmost", True) |
| 159 | + window.bind("<Escape>", lambda _: window.destroy()) |
| 160 | + window.bind("<Destroy>", lambda _: dismiss()) |
| 161 | + |
| 162 | + window.deiconify() |
| 163 | + window.wait_window() |
0 commit comments