summaryrefslogtreecommitdiff
path: root/support/autolatex/plugins/gedit2/autolatex/config/cli/viewer_panel.py
blob: 3a7708bca40d8953ab0de14149aa8874f004ac95 (plain)
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# autolatex/config/cli/viewer_panel.py
# Copyright (C) 2013  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 Glib, Gtk and Gedit libraries
from gi.repository import GObject, Gdk, Gtk, GdkPixbuf
# AutoLaTeX internal libs
from ...utils import utils
from . import abstract_panel

#---------------------------------
# INTERNATIONALIZATION
#---------------------------------

import gettext
_T = gettext.gettext

#---------------------------------
# CLASS Panel
#---------------------------------

# Gtk panel that is managing the configuration of the viewer
class Panel(abstract_panel.AbstractPanel):
	__gtype_name__ = "AutoLaTeXViewerPanel"

	def __init__(self, is_document_level, directory, window):
		abstract_panel.AbstractPanel.__init__(self, is_document_level, directory, window)

	#
	# Fill the grid
	#
	def _init_widgets(self):
		# Launch the viewer
		self._ui_launch_viewer_checkbox = self._create_switch(
				_T("Launch a viewer after compilation"))[1]
		# Viewer command line
		self._ui_viewer_command_field = self._create_entry(
				_T("Command for launching the viewer (optional)"))[1]


	#
	# Initialize the content
	#
	def _init_content(self):
		self._read_settings('viewer')
		#
		inh = self._get_settings_bool_inh('view')
		cur = self._get_settings_bool('view')
		self._init_overriding(self._ui_launch_viewer_checkbox, cur is not None)
		self._ui_launch_viewer_checkbox.set_active(utils.first_of(cur, inh, False))
		#
		inh = self._get_settings_str_inh('viewer')
		cur = self._get_settings_str('viewer')
		self._init_overriding(self._ui_viewer_command_field, cur is not None)
		self._ui_viewer_command_field.set_text(utils.first_of(cur, inh, ''))


	#
	# Connect signals
	#
	def _connect_signals(self):
		self._ui_launch_viewer_checkbox.connect('notify::active',self.on_launch_viewer_toggled)




	# Change the state of the widgets according to the state of other widgets
	def update_widget_states(self):
		is_active = self._ui_launch_viewer_checkbox.get_active()
		if not self._get_overriding(self._ui_launch_viewer_checkbox):
			inh = self._get_settings_bool_inh('view', False)
			if (inh!=is_active):
				GObject.idle_add(self._ui_launch_viewer_checkbox.set_active, inh)
				is_active = inh
		self._update_sentitivity(self._ui_viewer_command_field, is_active)
			

	# Invoke when the flag 'launch viewer' has changed
	def on_launch_viewer_toggled(self, widget, data=None):
		self.update_widget_states()

	# Invoked when the changes in the panel must be saved
	def save(self):
		self._reset_settings_section()
		#
		if self._get_sentitivity(self._ui_launch_viewer_checkbox):
			v = self._ui_launch_viewer_checkbox.get_active()
		else:
			v = None
		self._set_settings_bool('view', v)
		#
		if self._get_sentitivity(self._ui_viewer_command_field):
			v = self._ui_viewer_command_field.get_text()
		else:
			v = None
		self._set_settings_str('viewer', v)
		#
		return utils.backend_set_configuration(self._directory,
			'project' if self._is_document_level else 'user', self._settings)