mintwelcome.py 6.72 KB
Newer Older
Daniel Alley's avatar
Daniel Alley committed
1
#!/usr/bin/python3
2
import apt
3
import gettext
Clement Lefebvre's avatar
Clement Lefebvre committed
4
import gi
5
6
7
import os
import platform
import subprocess
8
import locale
9
import cairo
Daniel Alley's avatar
Daniel Alley committed
10
gi.require_version("Gtk", "3.0")
11
from gi.repository import Gtk, Gio, Gdk, GdkPixbuf
Clement Lefebvre's avatar
Clement Lefebvre committed
12

13
NORUN_FLAG = os.path.expanduser("~/.linuxmint/mintwelcome/norun.flag")
Clement Lefebvre's avatar
Clement Lefebvre committed
14
15

# i18n
16
gettext.install("mintwelcome", "/usr/share/linuxmint/locale")
17
18
19
from locale import gettext as _
locale.bindtextdomain("mintwelcome", "/usr/share/linuxmint/locale")
locale.textdomain("mintwelcome")
Clement Lefebvre's avatar
Clement Lefebvre committed
20

21
22
LAYOUT_STYLE_LEGACY, LAYOUT_STYLE_NEW = range(2)

JosephMcc's avatar
JosephMcc committed
23
24
25
26
27
28
29
30
31
32
33
34
35
class SidebarRow(Gtk.ListBoxRow):

    def __init__(self, page_widget, page_name, icon_name):
        Gtk.ListBoxRow.__init__(self)
        self.page_widget = page_widget
        box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
        box.set_border_width(6)
        image = Gtk.Image.new_from_icon_name(icon_name, Gtk.IconSize.BUTTON)
        box.pack_start(image, False, False, 0)
        label = Gtk.Label()
        label.set_text(page_name)
        box.pack_start(label, False, False, 0)
        self.add(box)
Daniel Alley's avatar
Daniel Alley committed
36

37
class MintWelcome():
Daniel Alley's avatar
Daniel Alley committed
38

Clement Lefebvre's avatar
Clement Lefebvre committed
39
    def __init__(self):
40
        builder = Gtk.Builder()
Butterfly's avatar
Butterfly committed
41
        builder.set_translation_domain("mintwelcome")
42
        builder.add_from_file('/usr/share/linuxmint/mintwelcome/mintwelcome.ui')
JosephMcc's avatar
JosephMcc committed
43

44
45
46
        window = builder.get_object("main_window")
        window.set_icon_name("mintwelcome")
        window.set_position(Gtk.WindowPosition.CENTER)
Clement Lefebvre's avatar
Clement Lefebvre committed
47
        window.connect("destroy", Gtk.main_quit)
Clement Lefebvre's avatar
Clement Lefebvre committed
48

49
        with open("/etc/fuss/info") as f:
Clement Lefebvre's avatar
Clement Lefebvre committed
50
            config = dict([line.strip().split("=") for line in f])
Clement Lefebvre's avatar
Clement Lefebvre committed
51
        codename = config['CODENAME'].capitalize()
Clement Lefebvre's avatar
Clement Lefebvre committed
52
        edition = config['EDITION'].replace('"', '')
Clement Lefebvre's avatar
Clement Lefebvre committed
53
        release = config['RELEASE']
Clement Lefebvre's avatar
Clement Lefebvre committed
54
        desktop = config['DESKTOP']
55
56
        release_notes = config['RELEASE_NOTES_URL']
        new_features = config['NEW_FEATURES_URL']
Clement Lefebvre's avatar
Clement Lefebvre committed
57
58
59
        architecture = "64-bit"
        if platform.machine() != "x86_64":
            architecture = "32-bit"
60

61
        # distro-specific
62
        dist_name = "FUSS"
63
        if os.path.exists("/usr/share/doc/debian-system-adjustments/copyright"):
64
            dist_name = "LMDE"
65

66
67
68
        # Setup the labels in the Mint badge
        builder.get_object("label_version").set_text("%s %s" % (dist_name, release))
        builder.get_object("label_edition").set_text("%s %s" % (edition, architecture))
Clement Lefebvre's avatar
Clement Lefebvre committed
69

JosephMcc's avatar
JosephMcc committed
70
71
        # Setup the main stack
        self.stack = Gtk.Stack()
72
        builder.get_object("center_box").pack_start(self.stack, True, True, 0)
JosephMcc's avatar
JosephMcc committed
73
74
        self.stack.set_transition_type(Gtk.StackTransitionType.CROSSFADE)
        self.stack.set_transition_duration(150)
75

76
        # Action buttons
77
78
79
        builder.get_object("button_forums").connect("clicked", self.visit, "https://www.fuss.bz.it/page/desk/")
        builder.get_object("button_documentation").connect("clicked", self.visit, "https://www.fuss.bz.it/page/doc/")
        builder.get_object("button_contribute").connect("clicked", self.visit, "https://gitlab.fuss.bz.it/explore")
80
81
        builder.get_object("button_new_features").connect("clicked", self.visit, new_features)
        builder.get_object("button_release_notes").connect("clicked", self.visit, release_notes)
82
        builder.get_object("button_mintinstall").connect("clicked", self.launch, "gnome-software")
83
84
85
# button to launch timeshift, commented out
#        builder.get_object("button_timeshift").connect("clicked", self.pkexec, "timeshift-gtk")
# button to launch gufw, commented out
86
#builder.get_object("button_gufw").connect("clicked", self.launch, "gufw")
87
88

        # Settings button depends on DE
89
        de_is_cinnamon = False
90
        self.theme = None
91
92
        if os.getenv("XDG_CURRENT_DESKTOP") in ["Cinnamon", "X-Cinnamon"]:
            builder.get_object("button_settings").connect("clicked", self.launch, "cinnamon-settings")
93
            de_is_cinnamon = True
94
            self.theme = Gio.Settings(schema="org.cinnamon.desktop.interface").get_string("gtk-theme")
95
96
97
98
99
100
101
        elif os.getenv("XDG_CURRENT_DESKTOP") == "MATE":
            builder.get_object("button_settings").connect("clicked", self.launch, "mate-control-center")
        elif os.getenv("XDG_CURRENT_DESKTOP") == "XFCE":
            builder.get_object("button_settings").connect("clicked", self.launch, "xfce4-settings-manager")
        else:
            # Hide settings
            builder.get_object("box_first_steps").remove(builder.get_object("box_settings"))
102

103
104
105
106
        # Hide new features page for LMDE
        if dist_name == "LMDE":
            builder.get_object("box_documentation").remove(builder.get_object("box_new_features"))

107
108
        # Construct the stack switcher
        list_box = builder.get_object("list_navigation")
109

110
111
112
113
        page = builder.get_object("page_home")
        self.stack.add_named(page, "page_home")
        list_box.add(SidebarRow(page, _("Welcome"), "go-home-symbolic"))
        self.stack.set_visible_child(page)
114

115
116
117
        page = builder.get_object("page_first_steps")
        self.stack.add_named(page, "page_first_steps")
        list_box.add(SidebarRow(page, _("First Steps"), "dialog-information-symbolic"))
JosephMcc's avatar
JosephMcc committed
118

119
120
121
        page = builder.get_object("page_documentation")
        self.stack.add_named(page, "page_documentation")
        list_box.add(SidebarRow(page, _("Documentation"), "accessories-dictionary-symbolic"))
JosephMcc's avatar
JosephMcc committed
122

123
124
125
        page = builder.get_object("page_help")
        self.stack.add_named(page, "page_help")
        list_box.add(SidebarRow(page, _("Help"), "help-browser-symbolic"))
JosephMcc's avatar
JosephMcc committed
126

127
128
129
        page = builder.get_object("page_contribute")
        self.stack.add_named(page, "page_contribute")
        list_box.add(SidebarRow(page, _("Contribute"), "starred-symbolic"))
JosephMcc's avatar
JosephMcc committed
130
131
132
133

        list_box.connect("row-activated", self.sidebar_row_selected_cb)

        # Construct the bottom toolbar
134
        box = builder.get_object("toolbar_bottom")
Clement Lefebvre's avatar
Clement Lefebvre committed
135
136
        checkbox = Gtk.CheckButton()
        checkbox.set_label(_("Show this dialog at startup"))
137
        if not os.path.exists(NORUN_FLAG):
Clement Lefebvre's avatar
Clement Lefebvre committed
138
139
            checkbox.set_active(True)
        checkbox.connect("toggled", self.on_button_toggled)
JosephMcc's avatar
JosephMcc committed
140
141
        box.pack_end(checkbox)
        window.set_default_size(800, 500)
Clement Lefebvre's avatar
Clement Lefebvre committed
142
        window.show_all()
143
        
JosephMcc's avatar
JosephMcc committed
144
145
    def sidebar_row_selected_cb(self, list_box, row):
        self.stack.set_visible_child(row.page_widget)
Clement Lefebvre's avatar
Clement Lefebvre committed
146

Clement Lefebvre's avatar
Clement Lefebvre committed
147
148
    def on_button_toggled(self, button):
        if button.get_active():
149
150
            if os.path.exists(NORUN_FLAG):
                os.system("rm -rf %s" % NORUN_FLAG)
151
        else:
152
            os.system("mkdir -p ~/.linuxmint/mintwelcome")
153
            os.system("touch %s" % NORUN_FLAG)
Clement Lefebvre's avatar
Clement Lefebvre committed
154

155
156
    def visit(self, button, url):
        subprocess.Popen(["xdg-open", url])
JosephMcc's avatar
JosephMcc committed
157

158
159
    def launch(self, button, command):
        subprocess.Popen([command])
JosephMcc's avatar
JosephMcc committed
160

161
162
    def pkexec(self, button, command):
        subprocess.Popen(["pkexec", command])
JosephMcc's avatar
JosephMcc committed
163

164
if __name__ == "__main__":
Clement Lefebvre's avatar
Clement Lefebvre committed
165
    MintWelcome()
166
    Gtk.main()