Source code for mountain_tapir.model

# -*- coding: utf-8 -*-
#
# Mountain Tapir Collage Maker is a tool for combining images into collages.
# Copyright (c) 2016, tttppp
#
# 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 3 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.  If not, see <http://www.gnu.org/licenses/>.

from __future__ import absolute_import

from collections import defaultdict
import os

from mountain_tapir.algorithm import Algorithm
from mountain_tapir.constants import Constants
from mountain_tapir.tool import Tool


[docs]class Model: def __init__(self, config): self.config = config self.selectedTool = Tool.LOAD self.__regionCount = config.get('COLLAGE', 'regionCount', Constants.INITIAL_REGIONS, 'int') self.__width = config.get('COLLAGE', 'width', Constants.INITIAL_WIDTH, 'int') self.__height = config.get('COLLAGE', 'height', Constants.INITIAL_HEIGHT, 'int') self.__algorithm = config.get('COLLAGE', 'algorithm', Algorithm.COLLAGE, 'int') self.__regions = None self.imageFiles = [] self.regionToImageFile = defaultdict(lambda: None) self.regionToCanvas = defaultdict(lambda: None) self.__currentDirectory = config.get('FILE', 'initialdirectory', self._getDefaultDirectory())
[docs] def setCurrentDirectory(self, currentDirectory): """Set the directory to start looking for images in.""" self.__currentDirectory = currentDirectory self.config.update('FILE', 'initialdirectory', currentDirectory)
[docs] def getCurrentDirectory(self): """Get the directory to start looking for images in.""" if not os.path.isdir(self.__currentDirectory): self.__currentDirectory = self._getDefaultDirectory() return self.__currentDirectory
[docs] def setWidth(self, width): """Set the width of the output collage.""" self.__width = width self.config.update('COLLAGE', 'width', width)
[docs] def getWidth(self): """Get the width of the output collage.""" return self.__width
[docs] def setHeight(self, height): """Set the height of the output collage.""" self.__height = height self.config.update('COLLAGE', 'height', height)
[docs] def getHeight(self): """Get the height of the output collage.""" return self.__height
[docs] def setAlgorithm(self, algorithm): """Set the algorithm used to generate the collage.""" self.__algorithm = algorithm self.config.update('COLLAGE', 'algorithm', algorithm)
[docs] def getAlgorithm(self): """Get the algorithm used to generate the collage.""" return self.__algorithm
[docs] def setRegionCount(self, regionCount): """Set the number of regions in the collage.""" self.__regionCount = regionCount self.config.update('COLLAGE', 'regionCount', regionCount)
[docs] def getRegionCount(self): """Get the number of regions in the collage.""" return self.__regionCount
[docs] def setRegions(self, regions): """Set the regions in the collage.""" self.__regions = regions self.setRegionCount(len(regions))
[docs] def getRegions(self): """Get the regions in the collage.""" return self.__regions
def _getDefaultDirectory(self): return os.path.expanduser('~')