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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013-14 Stephane Galland <galland@arakhne.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#---------------------------------
# IMPORTS
#---------------------------------
# Include the Gtk libraries
from gi.repository import Gtk
#---------------------------------
# INTERNATIONALIZATION
#---------------------------------
import gettext
_T = gettext.gettext
#---------------------------------
# CLASS Panel
#---------------------------------
# Gtk panel that is managing the configuration of the plugin
class Panel(Gtk.Grid):
def __init__(self, settings, window):
Gtk.Grid.__init__(self)
self.set_row_homogeneous(False)
self.set_column_homogeneous(False)
self.set_row_spacing(5)
self.set_property('orientation', Gtk.Orientation.VERTICAL)
self.set_property('margin', 5)
self.set_property('vexpand', False)
self._settings = settings
self.window = window
# Create the components
# Row 1: Paths
ui_frame = Gtk.Frame()
ui_frame.set_label(_T("Paths of the tools"));
ui_frame.set_property('margin', 5)
self.add(ui_frame)
ui_table = Gtk.Grid()
ui_table.set_row_homogeneous(True)
ui_table.set_column_homogeneous(False)
ui_table.set_row_spacing(5)
ui_table.set_column_spacing(5)
ui_table.set_property('margin', 5)
ui_frame.add(ui_table)
label = _T("Path of 'autolatex'")
ui_label = Gtk.Label(label)
ui_label.set_property('hexpand', False)
ui_label.set_property('vexpand', False)
ui_label.set_property('halign', Gtk.Align.START)
ui_label.set_property('valign', Gtk.Align.CENTER)
ui_table.attach(ui_label,
0,0,1,1) # left, top, width, height
self._ui_edit_autolatex_cmd = Gtk.FileChooserButton()
self._ui_edit_autolatex_cmd.set_width_chars(40)
self._ui_edit_autolatex_cmd.set_title(label)
self._ui_edit_autolatex_cmd.set_create_folders(False)
self._ui_edit_autolatex_cmd.set_property('hexpand', True)
self._ui_edit_autolatex_cmd.set_property('vexpand', False)
ui_table.attach(self._ui_edit_autolatex_cmd,
1,0,1,1) # left, top, width, height
label = _T("Path to 'autolatex-backend'")
ui_label = Gtk.Label(label)
ui_label.set_property('hexpand', False)
ui_label.set_property('vexpand', False)
ui_label.set_property('halign', Gtk.Align.START)
ui_label.set_property('valign', Gtk.Align.CENTER)
ui_table.attach(ui_label,
0,1,1,1) # left, right, top and bottom columns
self._ui_edit_autolatex_backend_cmd = Gtk.FileChooserButton()
self._ui_edit_autolatex_backend_cmd.set_width_chars(40)
self._ui_edit_autolatex_backend_cmd.set_title(label)
self._ui_edit_autolatex_backend_cmd.set_create_folders(False)
self._ui_edit_autolatex_backend_cmd.set_property('hexpand', True)
self._ui_edit_autolatex_backend_cmd.set_property('vexpand', False)
ui_table.attach(self._ui_edit_autolatex_backend_cmd,
1,1,1,1) # left, top, width, height
# Row 2: SyncTex
ui_frame = Gtk.Frame()
ui_frame.set_label(_T("SyncTeX"));
ui_frame.set_property('margin', 5)
self.add(ui_frame)
ui_table = Gtk.Grid()
ui_table.set_row_homogeneous(True)
ui_table.set_column_homogeneous(False)
ui_table.set_row_spacing(5)
ui_table.set_column_spacing(5)
ui_table.set_property('margin', 5)
ui_frame.add(ui_table)
ui_label = Gtk.Label(_T("Enable SyncTeX (overriding the configurations)"))
ui_label.set_property('hexpand', True)
ui_label.set_property('vexpand', False)
ui_label.set_property('halign', Gtk.Align.START)
ui_label.set_property('valign', Gtk.Align.CENTER)
ui_table.attach(ui_label,
0,0,1,1) # left, right, width, height
self._ui_use_synctex = Gtk.Switch()
self._ui_use_synctex.set_property('hexpand', False)
self._ui_use_synctex.set_property('vexpand', False)
self._ui_use_synctex.set_property('halign', Gtk.Align.END)
self._ui_use_synctex.set_property('valign', Gtk.Align.CENTER)
ui_table.attach(self._ui_use_synctex,
1,0,1,1) # left, top, width, height
# Row 3: UI parameters
ui_frame = Gtk.Frame()
ui_frame.set_label(_T("Configuration of the UI"));
ui_frame.set_property('margin', 5)
self.add(ui_frame)
ui_table = Gtk.Grid()
ui_table.set_row_homogeneous(True)
ui_table.set_column_homogeneous(False)
ui_table.set_row_spacing(5)
ui_table.set_column_spacing(5)
ui_table.set_property('margin', 5)
ui_frame.add(ui_table)
ui_label = Gtk.Label(_T("Show the progress info bar"))
ui_label.set_property('hexpand', True)
ui_label.set_property('vexpand', False)
ui_label.set_property('halign', Gtk.Align.START)
ui_label.set_property('valign', Gtk.Align.CENTER)
ui_table.attach(ui_label,
0,0,1,1) # left, right, width, height
self._ui_show_progress_info_bar = Gtk.Switch()
self._ui_show_progress_info_bar.set_property('hexpand', False)
self._ui_show_progress_info_bar.set_property('vexpand', False)
self._ui_show_progress_info_bar.set_property('halign', Gtk.Align.END)
self._ui_show_progress_info_bar.set_property('valign', Gtk.Align.CENTER)
ui_table.attach(self._ui_show_progress_info_bar,
1,0,1,1) # left, top, width, height
# Row 4: Document parameters
ui_frame = Gtk.Frame()
ui_frame.set_label(_T("Configuration of the documents"));
ui_frame.set_property('margin', 5)
self.add(ui_frame)
ui_table = Gtk.Grid()
ui_table.set_row_homogeneous(True)
ui_table.set_column_homogeneous(False)
ui_table.set_row_spacing(5)
ui_table.set_column_spacing(5)
ui_table.set_property('margin', 5)
ui_frame.add(ui_table)
ui_label = Gtk.Label(_T("Save before running AutoLaTeX"))
ui_label.set_property('hexpand', True)
ui_label.set_property('vexpand', False)
ui_label.set_property('halign', Gtk.Align.START)
ui_label.set_property('valign', Gtk.Align.CENTER)
ui_table.attach(ui_label,
0,0,1,1) # left, right, width, height
self._ui_save_before_run = Gtk.Switch()
self._ui_save_before_run.set_property('hexpand', False)
self._ui_save_before_run.set_property('vexpand', False)
self._ui_save_before_run.set_property('halign', Gtk.Align.END)
self._ui_save_before_run.set_property('valign', Gtk.Align.CENTER)
ui_table.attach(self._ui_save_before_run,
1,0,1,1) # left, top, width, height
# Set the initial values
self.on_initialize_fields()
# Attach signals
self._ui_hierarchy_connect_id = self.connect('hierarchy-changed', self.on_hierarchy_changed)
def on_hierarchy_changed(self, widget, previous_toplevel, data=None):
if previous_toplevel:
self._settings.disconnect('autolatex-cmd')
self._settings.disconnect('autolatex-backend-cmd')
self._settings.disconnect('force-synctex')
self._settings.disconnect('show-progress-info')
self._settings.disconnect('save-before-run-autolatex')
self.disconnect(self._ui_hierarchy_connect_id)
self.on_save_changes()
else:
self._settings.connect('autolatex-cmd', self.on_gsettings_changed)
self._settings.connect('autolatex-backend-cmd', self.on_gsettings_changed)
self._settings.connect('force-synctex', self.on_gsettings_changed)
self._settings.connect('show-progress-info', self.on_gsettings_changed)
self._settings.connect('save-before-run-autolatex', self.on_gsettings_changed)
# Invoked when the different fields in the preference box must be initialized
def on_initialize_fields(self):
cmd = self._settings.get_autolatex_cmd()
if cmd: self._ui_edit_autolatex_cmd.set_filename(cmd)
else: self._ui_edit_autolatex_cmd.unselect_all()
cmd = self._settings.get_autolatex_backend_cmd()
if cmd: self._ui_edit_autolatex_backend_cmd.set_filename(cmd)
else: self._ui_edit_autolatex_backend_cmd.unselect_all()
flag = self._settings.get_force_synctex()
self._ui_use_synctex.set_active(flag)
flag = self._settings.get_progress_info_visibility()
self._ui_show_progress_info_bar.set_active(flag)
flag = self._settings.get_save_before_run_autolatex()
self._ui_save_before_run.set_active(flag)
# Invoked when the changes in the preference dialog box should be saved
def on_save_changes(self):
filename = self._ui_edit_autolatex_cmd.get_filename()
self._settings.set_autolatex_cmd(filename)
filename = self._ui_edit_autolatex_backend_cmd.get_filename()
self._settings.set_autolatex_backend_cmd(filename)
force_synctex = self._ui_use_synctex.get_active()
self._settings.set_force_synctex(force_synctex)
show_info_bar = self._ui_show_progress_info_bar.get_active()
self._settings.set_progress_info_visibility(show_info_bar)
save_before_run = self._ui_save_before_run.get_active()
self._settings.set_save_before_run_autolatex(save_before_run)
def on_gsettings_changed(self, settings, key, data=None):
if key == 'autolatex-cmd':
gsettings_cmd = self._settings.get_autolatex_cmd()
window_cmd = self._ui_edit_autolatex_cmd.get_filename()
if gsettings_cmd != window_cmd:
dialog = Gtk.MessageDialog(self.window, Gtk.DialogFlags.MODAL, Gtk.MessageType.WARNING, Gtk.ButtonsType.YES_NO, _T("The path of AutoLaTeX has been changed by an external software. The new path is different from the one you have entered. Do you want to use the new path?"))
answer = dialog.run()
dialog.destroy()
if answer == Gtk.ResponseType.YES:
if gsettings_cmd: self._ui_edit_autolatex_cmd.set_filename(gsettings_cmd)
else: self._ui_edit_autolatex_cmd.unselect_all()
elif key == 'autolatex-backend-cmd':
gsettings_cmd = self._settings.get_autolatex_backend_cmd()
window_cmd = self._ui_edit_autolatex_backend_cmd.get_filename()
if gsettings_cmd != window_cmd:
dialog = Gtk.MessageDialog(self.window, Gtk.DialogFlags.MODAL, Gtk.MessageType.WARNING, Gtk.ButtonsType.YES_NO, _T("The path of AutoLaTeX Backend has been changed by an external software. The new path is different from the one you have entered. Do you want to use the new path?"))
answer = dialog.run()
dialog.destroy()
if answer == Gtk.ResponseType.YES:
if gsettings_cmd: self._ui_edit_autolatex_backend_cmd.set_filename(gsettings_cmd)
else: self._ui_edit_autolatex_backend_cmd.unselect_all()
elif key == 'force-synctex':
gsettings_flag = self._settings.get_force_synctex()
window_flag = self._ui_use_synctex.get_active()
if gsettings_flag != window_flag:
dialog = Gtk.MessageDialog(self.window, Gtk.DialogFlags.MODAL, Gtk.MessageType.WARNING, Gtk.ButtonsType.YES_NO, _T("The enabling flag for SyncTeX has been changed by an external software. The new flag is different from the one inside the preference dialog box. Do you want to use the new flag?"))
answer = dialog.run()
dialog.destroy()
if answer == Gtk.ResponseType.YES:
self._ui_use_synctex.set_active(gsettings_flag)
elif key == 'show-progress-info':
gsettings_flag = self._settings.get_progress_info_visibility()
window_flag = self._ui_show_progress_info_bar.get_active()
if gsettings_flag != window_flag:
dialog = Gtk.MessageDialog(self.window, Gtk.DialogFlags.MODAL, Gtk.MessageType.WARNING, Gtk.ButtonsType.YES_NO, _T("The enabling flag for the progress info bar has been changed by an external software. The new flag is different from the one inside the preference dialog box. Do you want to use the new flag?"))
answer = dialog.run()
dialog.destroy()
if answer == Gtk.ResponseType.YES:
self._ui_show_progress_info_bar.set_active(gsettings_flag)
elif key == 'save-before-run-autolatex':
gsettings_flag = self._settings.get_save_before_run_autolatex()
window_flag = self._ui_save_before_run.get_active()
if gsettings_flag != window_flag:
dialog = Gtk.MessageDialog(self.window, Gtk.DialogFlags.MODAL, Gtk.MessageType.WARNING, Gtk.ButtonsType.YES_NO, _T("The flag to save before running AutoLaTeX has been changed by an external software. The new flag is different from the one inside the preference dialog box. Do you want to use the new flag?"))
answer = dialog.run()
dialog.destroy()
if answer == Gtk.ResponseType.YES:
self._ui_show_progress_info_bar.set_active(gsettings_flag)
|