| ... |
... |
@@ -49,7 +49,7 @@ def __init__(self, workspace_id=None): |
|
49
|
49
|
|
|
50
|
50
|
name = _('My Workspace')
|
|
51
|
51
|
color = None
|
|
52
|
|
- avatar_sha = None
|
|
|
52
|
+ self._avatar_sha = None
|
|
53
|
53
|
|
|
54
|
54
|
if workspace_id is None:
|
|
55
|
55
|
self._ui.remove_workspace_button.set_sensitive(False)
|
| ... |
... |
@@ -58,8 +58,15 @@ def __init__(self, workspace_id=None): |
|
58
|
58
|
workspace_id, 'name')
|
|
59
|
59
|
color = app.settings.get_workspace_setting(
|
|
60
|
60
|
workspace_id, 'color')
|
|
|
61
|
+ self._avatar_sha = app.settings.get_workspace_setting(
|
|
|
62
|
+ workspace_id, 'avatar_sha')
|
|
|
63
|
+ if self._avatar_sha == '':
|
|
|
64
|
+ self._avatar_sha = None
|
|
61
|
65
|
|
|
62
|
66
|
rgba = make_rgba(color or DEFAULT_WORKSPACE_COLOR)
|
|
|
67
|
+ if self._avatar_sha is not None:
|
|
|
68
|
+ self._ui.image_switch.set_state(True)
|
|
|
69
|
+ self._ui.style_stack.set_visible_child_name('image')
|
|
63
|
70
|
|
|
64
|
71
|
self._ui.entry.set_text(name)
|
|
65
|
72
|
self._ui.color_chooser.set_rgba(rgba)
|
| ... |
... |
@@ -92,25 +99,36 @@ def _on_text_changed(self, entry, _param): |
|
92
|
99
|
def _on_image_switch_toggled(self, switch, *args):
|
|
93
|
100
|
if switch.get_active():
|
|
94
|
101
|
self._ui.style_stack.set_visible_child_name('image')
|
|
|
102
|
+ if self._workspace_id is not None:
|
|
|
103
|
+ self._avatar_sha = app.settings.get_workspace_setting(
|
|
|
104
|
+ self._workspace_id, 'avatar_sha')
|
|
95
|
105
|
else:
|
|
96
|
106
|
self._ui.style_stack.set_visible_child_name('color')
|
|
|
107
|
+ self._avatar_sha = None
|
|
|
108
|
+ self._update_avatar()
|
|
97
|
109
|
|
|
98
|
110
|
def _update_avatar(self):
|
|
99
|
111
|
name = self._ui.entry.get_text()
|
|
100
|
112
|
rgba = self._ui.color_chooser.get_rgba()
|
|
101
|
113
|
scale = self.get_scale_factor()
|
|
102
|
|
- surface = make_workspace_avatar(
|
|
103
|
|
- name[:1].upper(),
|
|
104
|
|
- rgba_to_float(rgba),
|
|
105
|
|
- AvatarSize.WORKSPACE_EDIT,
|
|
106
|
|
- scale)
|
|
|
114
|
+ if self._avatar_sha is not None:
|
|
|
115
|
+ surface = app.interface.avatar_storage.get_workspace_surface(
|
|
|
116
|
+ self._workspace_id,
|
|
|
117
|
+ AvatarSize.WORKSPACE_EDIT,
|
|
|
118
|
+ scale)
|
|
|
119
|
+ else:
|
|
|
120
|
+ surface = make_workspace_avatar(
|
|
|
121
|
+ name[:1].upper(),
|
|
|
122
|
+ rgba_to_float(rgba),
|
|
|
123
|
+ AvatarSize.WORKSPACE_EDIT,
|
|
|
124
|
+ scale)
|
|
107
|
125
|
self._ui.preview.set_from_surface(surface)
|
|
108
|
126
|
|
|
109
|
127
|
def _get_avatar_data(self):
|
|
110
|
128
|
if not self._avatar_selector.get_prepared():
|
|
111
|
129
|
return None
|
|
112
|
130
|
|
|
113
|
|
- success, data, width, height = self._avatar_selector.get_avatar_bytes()
|
|
|
131
|
+ success, data, _wid, _hei = self._avatar_selector.get_avatar_bytes()
|
|
114
|
132
|
if not success:
|
|
115
|
133
|
return None
|
|
116
|
134
|
|
| ... |
... |
@@ -119,15 +137,23 @@ def _get_avatar_data(self): |
|
119
|
137
|
def _on_save(self, _button):
|
|
120
|
138
|
name = self._ui.entry.get_text()
|
|
121
|
139
|
rgba = self._ui.color_chooser.get_rgba()
|
|
122
|
|
- # use_image = self._ui.image_switch.get_active()
|
|
123
|
|
- # if use_image:
|
|
124
|
|
- # avatar = self._get_avatar_data()
|
|
|
140
|
+ use_image = self._ui.image_switch.get_active()
|
|
|
141
|
+ if use_image:
|
|
|
142
|
+ data = self._get_avatar_data()
|
|
|
143
|
+ if data is not None:
|
|
|
144
|
+ self._avatar_sha = app.interface.save_avatar(data)
|
|
125
|
145
|
|
|
126
|
146
|
if self._workspace_id is not None:
|
|
127
|
147
|
app.settings.set_workspace_setting(
|
|
128
|
148
|
self._workspace_id, 'name', name)
|
|
129
|
149
|
app.settings.set_workspace_setting(
|
|
130
|
150
|
self._workspace_id, 'color', rgba.to_string())
|
|
|
151
|
+ if self._avatar_sha is None:
|
|
|
152
|
+ app.settings.set_workspace_setting(
|
|
|
153
|
+ self._workspace_id, 'avatar_sha', '')
|
|
|
154
|
+ else:
|
|
|
155
|
+ app.settings.set_workspace_setting(
|
|
|
156
|
+ self._workspace_id, 'avatar_sha', self._avatar_sha)
|
|
131
|
157
|
|
|
132
|
158
|
app.window.update_workspace(self._workspace_id)
|
|
133
|
159
|
self.destroy()
|
| ... |
... |
@@ -136,6 +162,9 @@ def _on_save(self, _button): |
|
136
|
162
|
workspace_id = app.settings.add_workspace(name)
|
|
137
|
163
|
app.settings.set_workspace_setting(
|
|
138
|
164
|
workspace_id, 'color', rgba.to_string())
|
|
|
165
|
+ if self._avatar_sha is not None:
|
|
|
166
|
+ app.settings.set_workspace_setting(
|
|
|
167
|
+ workspace_id, 'avatar_sha', self._avatar_sha)
|
|
139
|
168
|
|
|
140
|
169
|
app.window.add_workspace(workspace_id)
|
|
141
|
170
|
self.destroy()
|