Codebase list lightdm-gtk-greeter-settings / 564f908
New option: "hide-user-image"; adding PositionEntry.py Andrew P. 9 years ago
4 changed file(s) with 267 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
308308 <object class="GtkSwitch" id="greeter_xft-antialias_value">
309309 <property name="visible">True</property>
310310 <property name="can_focus">False</property>
311 <property name="halign">end</property>
311 <property name="halign">start</property>
312312 </object>
313313 <packing>
314314 <property name="left_attach">1</property>
529529 <property name="can_focus">False</property>
530530 <property name="halign">start</property>
531531 <property name="valign">start</property>
532 <property name="margin_left">24</property>
532533 <property name="label" translatable="yes" context="option|greeter|default-user-image">Default user image</property>
533 <attributes>
534 <attribute name="weight" value="semibold"/>
535 </attributes>
536 </object>
537 <packing>
538 <property name="left_attach">0</property>
539 <property name="top_attach">8</property>
534 </object>
535 <packing>
536 <property name="left_attach">0</property>
537 <property name="top_attach">9</property>
540538 </packing>
541539 </child>
542540 <child>
589587 </object>
590588 <packing>
591589 <property name="left_attach">1</property>
592 <property name="top_attach">8</property>
590 <property name="top_attach">9</property>
593591 </packing>
594592 </child>
595593 <child>
633631 <object class="GtkLabel" id="multihead_label">
634632 <property name="visible">True</property>
635633 <property name="can_focus">True</property>
636 <property name="label" translatable="yes" context="option|multihead"> &lt;i&gt;(or you can use &lt;a href=""&gt;multihead setup for individual monitors&lt;/a&gt;)&lt;/i&gt;</property>
634 <property name="label" translatable="yes" context="option|multihead"> &lt;i&gt;(or use &lt;a href=""&gt;multihead setup&lt;/a&gt; for individual monitors)&lt;/i&gt;</property>
637635 <property name="use_markup">True</property>
638636 <property name="angle">0.029999999999999999</property>
639637 </object>
648646 <property name="left_attach">0</property>
649647 <property name="top_attach">4</property>
650648 <property name="width">2</property>
649 </packing>
650 </child>
651 <child>
652 <object class="GtkLabel" id="greeter_hide-user-image_label">
653 <property name="visible">True</property>
654 <property name="can_focus">False</property>
655 <property name="halign">start</property>
656 <property name="label" translatable="yes" context="option|greeter|hide-user-image">User image</property>
657 <attributes>
658 <attribute name="weight" value="semibold"/>
659 </attributes>
660 </object>
661 <packing>
662 <property name="left_attach">0</property>
663 <property name="top_attach">8</property>
664 </packing>
665 </child>
666 <child>
667 <object class="GtkSwitch" id="greeter_hide-user-image_value">
668 <property name="visible">True</property>
669 <property name="can_focus">True</property>
670 <property name="halign">start</property>
671 </object>
672 <packing>
673 <property name="left_attach">1</property>
674 <property name="top_attach">8</property>
651675 </packing>
652676 </child>
653677 </object>
8383 'xft-hintstyle': (OptionEntry.ChoiceEntry, None),
8484 'background': (OptionEntry.BackgroundEntry, '#000000'),
8585 'user-background': (OptionEntry.BooleanEntry, 'true'),
86 'hide-user-image': (OptionEntry.InvertedBooleanEntry, 'false'),
8687 'default-user-image': (OptionEntry.IconEntry, '#avatar-default'),
8788 # Panel
8889 'clock-format': (OptionEntry.ClockFormatEntry, '%a, %H:%M'),
2929 from lightdm_gtk_greeter_settings.helpers import string2bool, bool2string
3030
3131
32 __all__ = ['BaseEntry', 'BooleanEntry', 'StringEntry', 'StringPathEntry', 'ClockFormatEntry',
32 __all__ = ['BaseEntry', 'BooleanEntry', 'InvertedBooleanEntry',
33 'StringEntry', 'StringPathEntry', 'ClockFormatEntry',
3334 'BackgroundEntry', 'IconEntry', 'IndicatorsEntry',
3435 'AdjustmentEntry', 'ChoiceEntry']
3536
135136
136137 def _set_enabled(self, value):
137138 self._value.props.sensitive = value
139
140
141 class InvertedBooleanEntry(BooleanEntry):
142
143 def __init__(self, widgets):
144 super().__init__(widgets)
145
146 def _get_value(self):
147 return bool2string(not self._value.props.active)
148
149 def _set_value(self, value):
150 self._value.props.active = not string2bool(value)
138151
139152
140153 class StringEntry(BaseEntry):
336349 self._path_dialog_preview = widgets['path_dialog_preview']
337350 self._icon_dialog = None
338351
339 #self._icon_item.set_ic
340
341352 self._button.connect('toggled', self._on_button_toggled)
342353 self._menu.connect('hide', self._on_menu_hide)
343354 self._icon_item.connect('activate', self._on_select_icon)
0 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
1 # LightDM GTK Greeter Settings
2 # Copyright (C) 2014 Andrew P. <pan.pav.7c5@gmail.com>
3 #
4 # This program is free software: you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License version 3, as published
6 # by the Free Software Foundation.
7 #
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranties of
10 # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 # PURPOSE. See the GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License along
14 # with this program. If not, see <http://www.gnu.org/licenses/>.
15
16
17 from gi.repository import Gtk
18 from itertools import product
19 from lightdm_gtk_greeter_settings.OptionEntry import BaseEntry
20 from lightdm_gtk_greeter_settings.helpers import WidgetsWrapper
21
22
23 __all__ = ['PositionEntry']
24
25
26 class PositionEntry(BaseEntry):
27
28 class Dimension:
29 def __init__(self, widgets, on_changed):
30 self._entry = widgets['entry']
31 self._percents = widgets['percents']
32 self._mirror = widgets['mirror']
33 self._adjustment = widgets['adjustment']
34 self._on_changed = on_changed
35
36 self._anchor = None
37
38 self._percents.connect('toggled', self._on_percents_toggled)
39 self._mirror.connect('toggled', self._on_mirror_toggled)
40 self._on_value_changed_id = self._adjustment.connect('value-changed',
41 self._on_value_changed)
42
43 @property
44 def value(self):
45 return '%s%d%s,%s' % ('-' if self._mirror.props.active else '',
46 int(self._entry.props.value),
47 '%' if self._percents.props.active else '',
48 self._anchor)
49
50 @value.setter
51 def value(self, s):
52 value, _, anchor = s.partition(',')
53
54 percents = value and value[-1] == '%'
55 if percents:
56 value = value[:-1]
57
58 try:
59 p = int(value)
60 except ValueError:
61 p = 0
62
63 negative = (p < 0) or (p == 0 and value and value[0] == '-')
64
65 if not anchor or anchor not in ('start', 'center', 'end'):
66 if negative:
67 anchor = 'end'
68 else:
69 anchor = 'start'
70 self._anchor = anchor
71
72 self._percents.props.active = percents
73 self._adjustment.props.upper = 100 if self._percents.props.active else 10000
74 self._mirror.props.active = negative
75 with self._adjustment.handler_block(self._on_value_changed_id):
76 self._adjustment.props.value = -p if negative else p
77
78 @property
79 def anchor(self):
80 return self._anchor
81
82 @anchor.setter
83 def anchor(self, value):
84 self._anchor = value
85
86 def get_value_for_screen(self, screen: int):
87 p = int(self._adjustment.props.value)
88
89 if self._percents.props.active:
90 p = screen * p / 100
91 if self._mirror.props.active:
92 p = screen - p
93
94 return int(p)
95
96 def _on_percents_toggled(self, toggle):
97 self._adjustment.props.upper = 100 if toggle.props.active \
98 else 10000
99 self._on_changed(self)
100
101 def _on_mirror_toggled(self, toggle):
102 self._on_changed(self)
103
104 def _on_value_changed(self, widget):
105 self._on_changed(self)
106
107
108 ASSUMED_WINDOW_SIZE = 430, 240
109
110 def __init__(self, widgets):
111 super().__init__(widgets)
112
113 self._screen_size = None
114 self._last_overlay_size = None
115 self._last_window_allocation = None
116
117 self._screen_frame = widgets['screen_frame']
118 self._screen_overlay = widgets['screen_overlay']
119 self._window_frame = widgets['window_frame']
120 self._grid = widgets['window_grid']
121
122 # Creating points grid
123 anchors_align = (Gtk.Align.START, Gtk.Align.CENTER, Gtk.Align.END)
124 anchors = [(x, y, Gtk.RadioButton())
125 for x, y in product(enumerate(('start', 'center', 'end')), repeat=2)]
126
127 self._anchors = {}
128 for (left, x_anchor), (top, y_anchor), w in anchors:
129 w.props.halign = anchors_align[left]
130 w.props.valign = anchors_align[top]
131 w.props.group = anchors[0][-1]
132 w.connect('toggled', self._on_anchor_toggled, x_anchor, y_anchor)
133 self._grid.attach(w, left, top, 1, 1)
134 self._anchors[x_anchor, y_anchor] = w
135
136 self._grid.show_all()
137
138 self._x = PositionEntry.Dimension(WidgetsWrapper(widgets, 'x'), self._on_dimension_changed)
139 self._y = PositionEntry.Dimension(WidgetsWrapper(widgets, 'y'), self._on_dimension_changed)
140
141 self._on_gdk_screen_changed()
142
143 self._screen_overlay.connect('get-child-position', self._on_screen_overlay_get_child_position)
144 self._screen_overlay.connect('screen-changed', self._on_gdk_screen_changed)
145
146 def _get_value(self):
147 return self._x.value + ' ' + self._y.value
148
149 def _set_value(self, value):
150 if value:
151 x, _, y = value.partition(' ')
152 self._x.value = x
153 self._y.value = y or x
154 self._anchors[self._x.anchor, self._y.anchor].props.active = True
155
156 def _get_corrected_position(self, p, screen, window, anchor):
157 if anchor == 'center':
158 p -= window / 2
159 elif anchor == 'end':
160 p -= window
161
162 if p + window > screen:
163 p = screen - window
164 if p < 0:
165 p = 0
166
167 return int(p)
168
169 def _on_dimension_changed(self, dimension):
170 self._last_window_allocation = None
171 self._screen_overlay.queue_resize()
172 self._emit_changed()
173
174 def _on_screen_overlay_get_child_position(self, overlay, child, allocation):
175 screen = overlay.get_allocation()
176
177 if self._last_window_allocation and self._last_overlay_size == (screen.width, screen.height):
178 allocation.x, allocation.y, allocation.width, allocation.height = self._last_window_allocation
179 return True
180 self._last_overlay_size = screen.width, screen.height
181
182 scale = screen.width / self._screen_size[0]
183
184 width = int(self.ASSUMED_WINDOW_SIZE[0] * scale)
185 height = int(self.ASSUMED_WINDOW_SIZE[1] * scale)
186
187 # Set desired size
188 child.set_size_request(width, height)
189 # And check what actually we have now
190 width, height = child.size_request().width, child.size_request().height
191
192 x = self._get_corrected_position(int(self._x.get_value_for_screen(self._screen_size[0]) * scale),
193 screen.width, width, self._x.anchor)
194 y = self._get_corrected_position(int(self._y.get_value_for_screen(self._screen_size[1]) * scale),
195 screen.height, height, self._y.anchor)
196
197 self._last_window_allocation = x, y, width, height
198 allocation.x, allocation.y, allocation.width, allocation.height = x, y, width, height
199
200 return True
201
202 def _on_anchor_toggled(self, toggle, x, y):
203 if not toggle.props.active:
204 return
205 self._x.anchor = x
206 self._y.anchor = y
207 self._last_window_allocation = None
208 self._screen_overlay.queue_resize()
209 self._emit_changed()
210
211 def _on_gdk_screen_changed(self, widget = None, prev_screen = None):
212 screen = self._screen_overlay.get_toplevel().get_screen()
213 geometry = screen.get_monitor_geometry(screen.get_primary_monitor())
214 self._screen_size = geometry.width, geometry.height
215 self._screen_frame.props.ratio = geometry.width / geometry.height
216
217