File: aboutdialog.py

package info (click to toggle)
syncthing-gtk 0.9.4.4%2Bds%2Bgit20221205%2B12a9702d29ab-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,888 kB
  • sloc: python: 8,077; sh: 259; xml: 134; makefile: 6
file content (71 lines) | stat: -rw-r--r-- 2,275 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
"""
Syncthing-GTK - About dialog
"""


import os

from syncthing_gtk.tools import IS_WINDOWS
from syncthing_gtk.uibuilder import UIBuilder


class AboutDialog(object):
    """ Standard looking about dialog """

    def __init__(self, app, uipath, iconpath):
        self.uipath = uipath
        self.iconpath = iconpath
        self.setup_widgets(app)

    def show(self, parent=None):
        if parent is not None:
            self.dialog.set_transient_for(parent)
        self.dialog.show()

    def run(self, *a):
        self.dialog.run()

    def close(self):
        if hasattr(self, "dialog"):
            self.dialog.set_visible(False)
            self.dialog.destroy()

    def setup_widgets(self, app):
        self.builder = UIBuilder()
        # Fix icon path
        self.builder.replace_icon_path("icons/", self.iconpath)
        # Load ui file
        self.builder.add_from_file(os.path.join(self.uipath, "about.ui"))
        self.builder.connect_signals(self)
        self.dialog = self.builder.get_object("dialog")
        # Get app version
        app_ver = "unknown"
        try:
            if IS_WINDOWS:
                # pkg_resources will not work on cx_Frozen package
                from syncthing_gtk.tools import get_install_path
                with open(os.path.join(get_install_path(), "__version__"), "r") as vfile:
                    app_ver = vfile.read().strip(" \t\r\n")
            else:
                import pkg_resources

                import syncthing_gtk
                if syncthing_gtk.__file__.startswith(pkg_resources.require("syncthing-gtk")[0].location):
                    app_ver = pkg_resources.require("syncthing-gtk")[0].version
        except:
            # pkg_resources is not available or __version__ file missing
            # There is no reason to crash on this.
            pass
        # Get daemon version
        try:
            daemon_ver = app.daemon.get_version()
            app_ver = "%s (Daemon %s)" % (app_ver, daemon_ver)
        except:
            # App is None or daemon version is not yet known
            pass
        # Display versions in UI
        self.builder.get_object("lblVersion").set_label(app_ver)

    def on_dialog_response(self, *a):
        self.close()