1#!/usr/bin/env python3 2# coding: utf-8 3 4# Copyright (C) 2017, 2018 Robert Griesel 5# This program is free software: you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation, either version 3 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program. If not, see <http://www.gnu.org/licenses/> 17 18from setzer.app.service_locator import ServiceLocator 19 20 21class PreviewPanelPresenter(object): 22 23 def __init__(self, workspace): 24 self.workspace = workspace 25 self.main_window = ServiceLocator.get_main_window() 26 self.notebook = self.main_window.preview_panel.notebook 27 28 self.workspace.register_observer(self) 29 self.activate_blank_page() 30 31 def change_notification(self, change_code, notifying_object, parameter): 32 33 if change_code == 'new_document': 34 document = parameter 35 if document.is_latex_document(): 36 self.notebook.append_page(document.preview.view, None) 37 38 if change_code == 'document_removed': 39 document = parameter 40 if document.is_latex_document(): 41 self.notebook.remove(document.preview.view) 42 43 if change_code == 'new_active_document': 44 self.set_preview_document() 45 46 if change_code == 'root_state_change': 47 self.set_preview_document() 48 49 def activate_blank_page(self): 50 self.notebook.set_current_page(0) 51 52 def set_preview_document(self): 53 if self.workspace.get_active_document() == None: 54 self.activate_blank_page() 55 else: 56 if self.workspace.root_document != None: 57 document = self.workspace.root_document 58 self.notebook.set_current_page(self.notebook.page_num(document.preview.view)) 59 elif self.workspace.active_document.is_latex_document(): 60 document = self.workspace.active_document 61 self.notebook.set_current_page(self.notebook.page_num(document.preview.view)) 62 else: 63 self.activate_blank_page() 64 65 66