Package list lightdm-gtk-greeter-settings / 11d787e
Xfce integration, GtkHeadbar Andrew P. 7 years ago
4 changed file(s) with 118 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
5959 <property name="icon_name">lightdm-gtk-greeter-settings</property>
6060 <signal name="destroy" handler="on_destroy" swapped="no"/>
6161 <child>
62 <object class="GtkBox" id="box1">
62 <object class="GtkBox" id="content_box">
6363 <property name="visible">True</property>
6464 <property name="can_focus">False</property>
6565 <property name="margin_left">8</property>
752752 <object class="GtkLabel" id="greeter_clock-format_preview">
753753 <property name="visible">True</property>
754754 <property name="can_focus">False</property>
755 <property name="tooltip_text" translatable="yes" context="option|greeter|clock-format">%H %I - hours, %M - minutes, %S - seconds
756 %d - day, %m - month, %y %Y - year
757 %a %A - day of the week, %b %B - month name</property>
755758 <property name="margin_left">24</property>
756759 <property name="hexpand">True</property>
757760 <property name="label">&lt;preview&gt;</property>
762765 <packing>
763766 <property name="left_attach">0</property>
764767 <property name="top_attach">2</property>
765 <property name="width">2</property>
766 </packing>
767 </child>
768 <child>
769 <object class="GtkLabel" id="greeter_clock-format_help">
770 <property name="visible">True</property>
771 <property name="can_focus">False</property>
772 <property name="halign">start</property>
773 <property name="margin_left">24</property>
774 <property name="hexpand">True</property>
775 <property name="label" translatable="yes" context="option|greeter|clock-format">%H %I - hours, %M - minutes, %S - seconds
776 %d - day, %m - month, %y %Y - year
777 %a %A - day of the week, %b %B - month name</property>
778 <attributes>
779 <attribute name="style" value="oblique"/>
780 </attributes>
781 </object>
782 <packing>
783 <property name="left_attach">0</property>
784 <property name="top_attach">3</property>
785768 <property name="width">2</property>
786769 </packing>
787770 </child>
17901773 </child>
17911774 <child>
17921775 <object class="GtkInfoBar" id="infobar">
1793 <property name="visible">True</property>
17941776 <property name="app_paintable">True</property>
17951777 <property name="can_focus">False</property>
17961778 <property name="message_type">warning</property>
18141796 <property name="can_focus">False</property>
18151797 <property name="border_width">8</property>
18161798 <child>
1817 <object class="GtkLabel" id="label8">
1818 <property name="visible">True</property>
1819 <property name="can_focus">False</property>
1820 <property name="label" translatable="yes">You don't have permissions to change greeter configuration</property>
1799 <object class="GtkLabel" id="infobar_label">
1800 <property name="visible">True</property>
1801 <property name="can_focus">False</property>
1802 <property name="label" translatable="yes">label</property>
18211803 <property name="justify">center</property>
18221804 <property name="wrap">True</property>
18231805 </object>
00 [Desktop Entry]
11 _Name=LightDM GTK+ Greeter settings
2 Categories=GNOME;GTK;Settings;System;Utility;X-XFCE-SettingsDialog;
2 _Comment=Configure LightDM GTK+ Greeter
3 Categories=GNOME;GTK;Settings;System;Utility;X-XFCE-SettingsDialog;X-XFCE-SystemSettings;
34 Keywords=Configuration;Utility;
45 Exec=lightdm-gtk-greeter-settings-pkexec
56 Icon=lightdm-gtk-greeter-settings
4040 from lightdm_gtk_greeter_settings.helpers import (
4141 C_,
4242 string2bool,
43 SimpleEnum,
4344 WidgetsEnum)
4445 from lightdm_gtk_greeter_settings.MonitorsGroup import MonitorsGroup
4546 from lightdm_gtk_greeter_settings.OptionGroup import SimpleGroup
4647
4748
48 __all__ = ['GtkGreeterSettingsWindow']
49 __all__ = ['GtkGreeterSettingsWindow',
50 'WindowMode']
51
52
53 class WindowMode(SimpleEnum):
54 Default = 'default'
55 Embedded = 'embedded'
56 GtkHeader = 'gtk-header'
4957
5058
5159 InitialValue = collections.namedtuple('InitialValue', ('value', 'enabled'))
5765
5866 class Widgets(WidgetsEnum):
5967 apply = 'apply_button'
68 reload = 'reset_button'
69 close = 'close_button'
70 buttons = 'dialog_buttons'
71 content = 'content_box'
6072 infobar = 'infobar'
61
62 def __new__(cls):
73 infobar_label = 'infobar_label'
74
75 def __new__(cls, mode=WindowMode.Default):
6376 builder = Gtk.Builder()
6477 builder.add_from_file(helpers.get_data_path('%s.ui' % cls.__name__))
6578 window = builder.get_object('settings_window')
6679 window.builder = builder
80 window.mode = mode
6781 builder.connect_signals(window)
6882 window.init_window()
6983 return window
7084
7185 builder = None
86 mode = WindowMode.Default
7287
7388 entries_setup = {
7489 ('greeter', 'allow-debugging'): ('changed',),
121136
122137 self._config_path = helpers.get_config_path()
123138 self._allow_edit = self._has_access_to_write(self._config_path)
124 self._widgets.infobar.props.visible = not self._allow_edit
125139 self._widgets.apply.props.visible = self._allow_edit
126140
127141 if not self._allow_edit:
128 helpers.show_message(
129 text=_('No permissions to save configuration'),
130 secondary_text=_(
131 'It seems that you don\'t have permissions to write to '
132 'file:\n{path}\n\nTry to run this program using "sudo" '
133 'or "pkexec"').format(path=self._config_path),
134 message_type=Gtk.MessageType.WARNING)
142 self._set_message(_('You don\'t have permissions to change greeter configuration'),
143 Gtk.MessageType.WARNING)
144 if self.mode != WindowMode.Embedded:
145 helpers.show_message(
146 text=_('No permissions to save configuration'),
147 secondary_text=_(
148 'It seems that you don\'t have permissions to write to '
149 'file:\n{path}\n\nTry to run this program using "sudo" '
150 'or "pkexec"').format(path=self._config_path),
151 message_type=Gtk.MessageType.WARNING)
152
153 if self.mode == WindowMode.Embedded:
154 self._widgets.buttons.hide()
155 self.on_entry_changed = self.on_entry_changed_embedded
156 self._widgets.content.reorder_child(self._widgets.infobar, 0)
157 elif self.mode == WindowMode.GtkHeader:
158 self._widgets.buttons.remove(self._widgets.apply)
159 self._widgets.buttons.remove(self._widgets.reload)
160 self._widgets.buttons.hide()
161 self._widgets.apply.set_label('')
162 self._widgets.reload.set_label('')
163
164 header = Gtk.HeaderBar()
165 header.set_show_close_button(True)
166 header.props.title = self.get_title()
167 header.pack_start(self._widgets.reload)
168 header.pack_start(self._widgets.apply)
169 header.show_all()
170
171 self.set_titlebar(header)
135172
136173 self._config = configparser.RawConfigParser(strict=False)
137174 self._read()
141178 return True
142179 return os.access(os.path.dirname(self._config_path), os.W_OK | os.X_OK)
143180
181 def _set_message(self, message, type_=Gtk.MessageType.INFO):
182 if not message:
183 self._widgets.infobar.hide()
184
185 self._widgets.infobar.props.message_type = type_
186 self._widgets.infobar_label.props.label = message
187 self._widgets.infobar.show()
188
144189 def _read(self):
145190 self._config.clear()
146191 try:
147 if not self._config.read(self._config_path):
148 helpers.show_message(text=_('Failed to read configuration '
149 'file: {path}')
192 if not self._config.read(self._config_path) and \
193 self.mode != WindowMode.Embedded:
194 helpers.show_message(text=_('Failed to read configuration file: {path}')
150195 .format(path=self._config_path),
151196 message_type=Gtk.MessageType.ERROR)
152197 except (configparser.DuplicateSectionError,
167212 for group in self._groups:
168213 group.write(self._config)
169214
170 for entry in self._changed_entries:
171 self._initial_values[entry] = InitialValue(entry.value, entry.enabled)
172
173 self._changed_entries.clear()
174 self._widgets.apply.props.sensitive = False
215 if self.mode != WindowMode.Embedded:
216 for entry in self._changed_entries:
217 self._initial_values[entry] = InitialValue(entry.value, entry.enabled)
218
219 self._changed_entries.clear()
220 self._widgets.apply.props.sensitive = False
175221
176222 try:
177223 with open(self._config_path, 'w') as file:
219265 self._changed_entries.discard(entry)
220266
221267 self._widgets.apply.props.sensitive = self._allow_edit and self._changed_entries
268
269 def on_entry_changed_embedded(self, entry, force=False):
270 if self._changed_entries is None:
271 return
272
273 initial = self._initial_values[entry]
274 if force or entry.enabled != initial.enabled or \
275 (entry.enabled and entry.value != initial.value):
276 self._changed_entries.add(entry)
277 else:
278 self._changed_entries.discard(entry)
279
280 if self._allow_edit:
281 self._write()
222282
223283 def on_entry_reset_clicked(self, item):
224284 entry, value, enabled = item._reset_entry_data
1717
1818 def main():
1919 from gi.repository import Gtk
20 from lightdm_gtk_greeter_settings import helpers
2021 from lightdm_gtk_greeter_settings import GtkGreeterSettingsWindow
22 from lightdm_gtk_greeter_settings.GtkGreeterSettingsWindow import WindowMode
2123
24 import argparse
2225 import locale
2326 locale.textdomain('lightdm-gtk-greeter-settings')
2427
25 window = GtkGreeterSettingsWindow.GtkGreeterSettingsWindow()
26 window.show()
27 Gtk.main()
28 parser = argparse.ArgumentParser(description='LightDM Gtk+ Greeter settings editor')
29 parser.add_argument('-s', '--socket-id', action='store', help='Settings manager socket')
30 parser.add_argument('--use-gtk-header', action='store_const', const=True,
31 help='Use GtkHeaderBar')
32 args = parser.parse_args()
33
34 try:
35 socket_id = int(args.socket_id or '')
36 except ValueError:
37 socket_id = None
38
39 if socket_id:
40 window = GtkGreeterSettingsWindow.GtkGreeterSettingsWindow(WindowMode.Embedded)
41 plug = Gtk.Plug.new(socket_id)
42 plug.connect('delete-event', Gtk.main_quit)
43 plug.show()
44 content = window.builder.get_object('content_box')
45 content.reparent(plug)
46 Gtk.main()
47 else:
48 if args.use_gtk_header:
49 window = GtkGreeterSettingsWindow.GtkGreeterSettingsWindow(mode=WindowMode.GtkHeader)
50 else:
51 window = GtkGreeterSettingsWindow.GtkGreeterSettingsWindow()
52 window.show()
53 Gtk.main()
2854
2955
3056 if __name__ == '__main__':