# -*- coding: utf-8 -*- # # Copyright 2012 Manuel QuiƱones # # 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; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import sys sys.path.append('mypaint') from gettext import gettext as _ import logging import gtk import gobject from mypaint.gui.tileddrawwidget import TiledDrawWidget from mypaint.lib.brush import BrushInfo from mypaint.lib.document import Document from mypaint.brushlib import brushsettings from toolbar import SETTING_NAMES class Drawing(gtk.HBox): __gsignals__ = {'setting-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_STRING, gobject.TYPE_FLOAT)), 'color-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_STRING,)), 'brush-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_STRING,)), } def __init__(self): super(Drawing, self).__init__() self._brush = BrushInfo() self.brush_name = None self._brush.load_defaults() self._document = Document(self._brush) self._tiled = TiledDrawWidget(document=self._document) self.add(self._tiled) self._tiled.show() self._color = (0.0, 0.0, 0.0) # The settings of our brush: self._settings = {} for setting_name in SETTING_NAMES: setting = brushsettings.settings_dict[setting_name] self._settings[setting_name] = setting.default self.set_brush('brush') def load_ora(self, file_path): return self._document.load_ora(file_path) def save_ora(self, file_path): return self._document.save_ora(file_path) def set_stroke_color(self, color): if isinstance(color, str) or isinstance(color, unicode): color = gtk.gdk.Color(color) self._color = (color.red_float, color.green_float, color.blue_float) self._brush.set_color_hsv((color.hue, color.saturation, color.value)) self.emit('color-changed', self.get_stroke_color()) def get_stroke_color(self): return gtk.gdk.Color(*self._color).to_string() def set_setting(self, setting_name, value): self.update_settings({setting_name: value}) def get_setting(self, setting_name): return self._settings[setting_name] def get_settings(self): return self._settings def update_settings(self, new_settings): self._settings.update(new_settings) for setting_name, value in new_settings.items(): self._brush.set_base_value(setting_name, value) self.emit('setting-changed', setting_name, value) def set_brush(self, brush_name): self.brush_name = brush_name string = open('brushes/%s.myb' % brush_name).read() self._brush.load_from_string(string) self.set_stroke_color(self.get_stroke_color()) self.update_settings(self._settings) self.emit('brush-changed', brush_name)