summaryrefslogtreecommitdiff
path: root/support/autolatex/plugins/gedit2/autolatex/config/cli/window.py
blob: 6b75cd6407c725add01ea302c6b12c7701d7b28f (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
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# autolatex/config/cli/window.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 Gtk, GdkPixbuf
# AutoLaTeX internal libs
from ...utils import utils
from . import generator_panel, figure_panel, figure_assignment_panel, translator_panel, viewer_panel

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

import gettext
_T = gettext.gettext

#---------------------------------
# Global function to open the dialog
#---------------------------------

def open_configuration_dialog(parent, is_document_level, directory):
	dialog = _Window(parent, is_document_level, directory)
	dialog.run()
	dialog.destroy()

#---------------------------------
# CLASS NotbookTab
#---------------------------------

class _NotebookTab(Gtk.Box):
	__gtype_name__ = "AutoLaTeXConfigurationNotebookTab"

	def __init__(self, label, icon):
		Gtk.Box.__init__(self,False,2)
		self.set_property('orientation', Gtk.Orientation.HORIZONTAL)
		self.set_property('expand', False)
		self._label = label
		pixbuf = GdkPixbuf.Pixbuf.new_from_file(utils.make_notebook_icon_path(icon))
		iconwgt = Gtk.Image.new_from_pixbuf(pixbuf)
		self.add(iconwgt)
		labelwgt = Gtk.Label(self._label)
		labelwgt.set_alignment(0, 0.5)
		self.add(labelwgt)
		self.show_all()

	def get_text(self):
		return self._label

#---------------------------------
# CLASS AutoLaTeXConfigurationWindow
#---------------------------------

# Gtk window that is displaying the configuration panels
class _Window(Gtk.Dialog):
	__gtype_name__ = "AutoLaTeXConfigurationWindow"

	def __init__(self, parent, is_document_level, directory):
		Gtk.Dialog.__init__(self,
			(_T("Document Configuration") if is_document_level else _T("User Configuration")),
			parent, 0,
			( Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_APPLY, Gtk.ResponseType.APPLY))
		self.set_default_size(600, 500)
		# Notebook
		self._ui_notebook = Gtk.Notebook()
		self.get_content_area().add(self._ui_notebook);
		# Tab for translators
		tab = generator_panel.Panel(is_document_level, directory, self)
		self._ui_notebook.append_page(
				tab,
				_NotebookTab(
					_T("Generator"), "autolatex-compile.png"))
		tab = figure_panel.Panel(is_document_level, directory, self)
		self._ui_notebook.append_page(
				tab,
				_NotebookTab(
					_T("Figures"), "autolatex-images.png"))
		if is_document_level:
			tab = figure_assignment_panel.Panel(is_document_level, directory, self)
			self._ui_notebook.append_page(
					tab,
					_NotebookTab(
						_T("List of figures"), "autolatex-images.png"))
		tab = translator_panel.Panel(is_document_level, directory, self)
		self._ui_notebook.append_page(
				tab,
				_NotebookTab(
					_T("Translators"), "autolatex-images.png"))
		tab = viewer_panel.Panel(is_document_level, directory, self)
		self._ui_notebook.append_page(
				tab,
				_NotebookTab(
					_T("Viewer"), "autolatex-view.png"))
		self.show_all()
		# Listening the response signal
		self.connect('response', self.on_response_signal);

	# Callback for response in the dialog
	def on_response_signal(self, action, data=None):
		if data == Gtk.ResponseType.APPLY:
			for i in range(self._ui_notebook.get_n_pages()):
				page = self._ui_notebook.get_nth_page(i)
				result = page.save()
				if not result:
					tab_label = self._ui_notebook.get_tab_label(page)
					dialog = Gtk.MessageDialog(self, Gtk.DialogFlags.MODAL, Gtk.MessageType.WARNING, Gtk.ButtonsType.OK, _T("The page '%s' cannot save its fields.\n You will loose the changes on this pages.") % tab_label.get_text())
					answer = dialog.run()
					dialog.destroy()