Created
February 23, 2013 19:29
-
-
Save ernado/5020991 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf8 | |
import logging | |
__ch = logging.StreamHandler() | |
__ch.setLevel(logging.DEBUG) | |
__formatter = logging.Formatter('%(asctime)s.%(msecs)d [%(levelname)s] %(message)s', r'%d.%m.%y %H:%M:%S') | |
__ch.setFormatter(__formatter) | |
logger = logging.getLogger(__name__) | |
logger.setLevel(logging.DEBUG) | |
logger.addHandler(__ch) | |
from abc import ABCMeta, abstractmethod | |
VERSION = 'v0.02' | |
class APresentationObject: | |
@abstractmethod | |
def show(self): | |
raise NotImplementedError | |
__metaclass__ = ABCMeta | |
class Presentation(APresentationObject): | |
title = '' | |
description = '' | |
slides = [] | |
def show(self): | |
print self.__str__() | |
def get_slides_count(self): | |
return len(self.slides) | |
def add_slide(self, slide): | |
if type(slide) == Slide: | |
logger.info('Слайд добавлен в презентацию') | |
self.slides.append(slide) | |
def __init__(self, t, d=''): | |
self.description = d | |
def __str__(self): | |
return "Презентация, количество слайдов: %s" % self.get_slides_count() | |
def rename(self, title): | |
self.title = title | |
class Glyph(APresentationObject): | |
gtype = None | |
x = 0 | |
y = 0 | |
z = 0 | |
def move_up(self): | |
logger.info('Глиф типа <%s> был перемещен вперед (x=%s;y=%s)' % self.gtype) | |
self.z += 1 | |
def move_down(self): | |
logger.info('Глиф типа <%s> был перемещен назад (x=%s;y=%s)' % self.gtype) | |
self.z -= 1 | |
def move(self, dx, dy): | |
logger.info('Глиф типа <%s> был перемещен на вектор с координатами (x=%s;y=%s)' % (self.gtype, dx, dy)) | |
self.x += dx | |
self.y += dy | |
def move_to(self, x, y): | |
logger.info('Глиф типа <%s> был перемещет в (x=%s;y=%s)' % (self.gtype, x, y)) | |
self.x, self.y = x,y | |
class Slide(APresentationObject): | |
glyphs = [] | |
description = "" | |
def __init__(self, description=""): | |
logger.info('Создан слайд с описанием "%s"' % description) | |
self.description = description | |
def show(self): | |
print "Количество глифов: %s" % self.get_glyphs_count() | |
def get_glyphs_count(self): | |
return len(self.glyphs) | |
def __getitem__(self, item): | |
return self.glyphs[item] | |
def set_description(self, d): | |
logger.info('Описание слайда изменено с "%s" на "%s"' % (self.description, d)) | |
self.description = d | |
def __str__(self): | |
return 'Слайд, количество глифов: %s, описание: "%s"' % (self.get_glyphs_count(), self.description) | |
def add_glyph(self, t): | |
if issubclass(type(t), Glyph): | |
logger.info('В слайд добавлен глиф <%s>' % t) | |
self.glyphs.append(t) | |
else: | |
raise TypeError | |
def __getitem__(self, item): | |
return self.glyphs[item] | |
class Image(Glyph): | |
gtype = 'изображение' | |
path = '' | |
description = '' | |
def set_path(self, p): | |
logger.info('Путь изобраения изменеи с "%s" на "%s"' % (self.path, p)) | |
self.path = p | |
def set_description(self, d): | |
logger.info('Описание изобраения изменено с "%s" на "%s"' % (self.description, d)) | |
self.d = d | |
def __str__(self): | |
return 'Изорбажение (x=%s,y=%s,z=%s); описание: "%s"; имя файла: "%s"' % \ | |
(self.x,self.y,self.z, self.description, self.path) | |
def show(self): | |
print self.__str__() | |
def __init__(self, path, description=''): | |
logger.info('Изображение создано; путь=%s; описание="%s"' % (path, description)) | |
self.path = path | |
self.description = description | |
class Text(Glyph): | |
gtype = 'надпись' | |
text = '' | |
def set_text(self, t): | |
logger.info('Текст надписи был изменен с "%s" на "%s"' % (self.text, t)) | |
self.text = t | |
if __name__ == '__main__': | |
logger.debug('Запуск программы') | |
print 'Прототип системы СЛАЙДЫ - версия %s' % VERSION | |
p = Presentation('Новая презентация') | |
print p | |
slide = Slide() | |
slide.set_description('Описание') | |
print slide | |
image = Image('noway.jpg', 'No way') | |
slide.add_glyph(image) | |
print slide | |
print slide[0] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment