예제 #1
0
    def __init__(self, toolbar, activity, fill_color_button):

        self._activity = activity
        self.properties = self._activity.area.tool
        self._fill_color_button = fill_color_button
        self._selected_tool_name = self._TOOL_BRUSH_NAME

        self._tool_brush = DrawToolButton('tool-brush', activity.tool_group,
                                          _('Brush'))
        activity.tool_group = self._tool_brush
        toolbar.insert(self._tool_brush, -1)

        add_menu('tool-brush', _('Brush'), self._TOOL_BRUSH_NAME,
                 self._tool_brush, self.set_tool)

        add_menu('tool-eraser', _('Eraser'), self._TOOL_ERASER_NAME,
                 self._tool_brush, self.set_tool)

        add_menu('tool-bucket', _('Bucket'), self._TOOL_BUCKET_NAME,
                 self._tool_brush, self.set_tool)

        add_menu('tool-picker', _('Picker'), self._TOOL_PICKER_NAME,
                 self._tool_brush, self.set_tool)

        self._tool_stamp = add_menu('tool-stamp', _('Stamp'),
                                    self._TOOL_STAMP_NAME, self._tool_brush,
                                    self.set_tool)

        is_selected = self._activity.area.is_selected()
        self._tool_stamp.set_sensitive(is_selected)

        add_menu('tool-stamp', _('Load stamp'), 'load-stamp', self._tool_brush,
                 self.set_tool)

        self._activity.area.connect('undo', self._on_signal_undo_cb)
        self._activity.area.connect('redo', self._on_signal_redo_cb)
        self._activity.area.connect('select', self._on_signal_select_cb)
        self._activity.area.connect('action-saved',
                                    self._on_signal_action_saved_cb)

        self._tool_marquee_rectangular = add_menu('tool-marquee-rectangular',
                                                  _('Select Area'),
                                                  self._TOOL_MARQUEE_RECT_NAME,
                                                  self._tool_brush,
                                                  self.set_tool)

        self._tool_brush.connect('clicked', self._tool_button_clicked_cb)

        self._stroke_color = ButtonStrokeColor(activity)
        self.set_tool(self._tool_brush, self._TOOL_BRUSH_NAME)
        self._stroke_color.connect('notify::color', self._color_button_cb)
        toolbar.insert(self._stroke_color, -1)
예제 #2
0
    def __init__(self, toolbar, activity, fill_color_button):

        self._activity = activity
        self.properties = self._activity.area.tool
        self._fill_color_button = fill_color_button
        self._selected_tool_name = self._TOOL_BRUSH_NAME

        self._tool_brush = DrawToolButton('tool-brush',
                                          activity.tool_group, _('Brush'))
        activity.tool_group = self._tool_brush
        toolbar.insert(self._tool_brush, -1)

        add_menu('tool-brush', _('Brush'), self._TOOL_BRUSH_NAME,
                 self._tool_brush, self.set_tool)

        add_menu('tool-eraser', _('Eraser'), self._TOOL_ERASER_NAME,
                 self._tool_brush, self.set_tool)

        add_menu('tool-bucket', _('Bucket'), self._TOOL_BUCKET_NAME,
                 self._tool_brush, self.set_tool)

        add_menu('tool-picker', _('Picker'), self._TOOL_PICKER_NAME,
                 self._tool_brush, self.set_tool)

        self._tool_stamp = add_menu('tool-stamp', _('Stamp'),
                                    self._TOOL_STAMP_NAME, self._tool_brush,
                                    self.set_tool)

        is_selected = self._activity.area.is_selected()
        self._tool_stamp.set_sensitive(is_selected)

        add_menu('tool-stamp', _('Load stamp'), 'load-stamp', self._tool_brush,
                 self.set_tool)

        self._activity.area.connect('undo', self._on_signal_undo_cb)
        self._activity.area.connect('redo', self._on_signal_redo_cb)
        self._activity.area.connect('select', self._on_signal_select_cb)
        self._activity.area.connect('action-saved',
                                    self._on_signal_action_saved_cb)

        self._tool_marquee_rectangular = add_menu('tool-marquee-rectangular',
                                                  _('Select Area'),
                                                  self._TOOL_MARQUEE_RECT_NAME,
                                                  self._tool_brush,
                                                  self.set_tool)

        self._tool_brush.connect('clicked', self._tool_button_clicked_cb)

        self._stroke_color = ButtonStrokeColor(activity)
        self.set_tool(self._tool_brush, self._TOOL_BRUSH_NAME)
        self._stroke_color.connect('notify::color', self._color_button_cb)
        toolbar.insert(self._stroke_color, -1)
예제 #3
0
class ToolsToolbarBuilder():

    # Tool default definitions
    # _TOOL_PENCIL_NAME = 'pencil'
    _TOOL_BRUSH_NAME = 'brush'
    _TOOL_ERASER_NAME = 'eraser'
    _TOOL_BUCKET_NAME = 'bucket'
    _TOOL_PICKER_NAME = 'picker'
    _TOOL_STAMP_NAME = 'stamp'
    _TOOL_MARQUEE_RECT_NAME = 'marquee-rectangular'

    def __init__(self, toolbar, activity, fill_color_button):

        self._activity = activity
        self.properties = self._activity.area.tool
        self._fill_color_button = fill_color_button
        self._selected_tool_name = self._TOOL_BRUSH_NAME

        self._tool_brush = DrawToolButton('tool-brush', activity.tool_group,
                                          _('Brush'))
        activity.tool_group = self._tool_brush
        toolbar.insert(self._tool_brush, -1)

        add_menu('tool-brush', _('Brush'), self._TOOL_BRUSH_NAME,
                 self._tool_brush, self.set_tool)

        add_menu('tool-eraser', _('Eraser'), self._TOOL_ERASER_NAME,
                 self._tool_brush, self.set_tool)

        add_menu('tool-bucket', _('Bucket'), self._TOOL_BUCKET_NAME,
                 self._tool_brush, self.set_tool)

        add_menu('tool-picker', _('Picker'), self._TOOL_PICKER_NAME,
                 self._tool_brush, self.set_tool)

        self._tool_stamp = add_menu('tool-stamp', _('Stamp'),
                                    self._TOOL_STAMP_NAME, self._tool_brush,
                                    self.set_tool)

        is_selected = self._activity.area.is_selected()
        self._tool_stamp.set_sensitive(is_selected)

        add_menu('tool-stamp', _('Load stamp'), 'load-stamp', self._tool_brush,
                 self.set_tool)

        self._activity.area.connect('undo', self._on_signal_undo_cb)
        self._activity.area.connect('redo', self._on_signal_redo_cb)
        self._activity.area.connect('select', self._on_signal_select_cb)
        self._activity.area.connect('action-saved',
                                    self._on_signal_action_saved_cb)

        self._tool_marquee_rectangular = add_menu('tool-marquee-rectangular',
                                                  _('Select Area'),
                                                  self._TOOL_MARQUEE_RECT_NAME,
                                                  self._tool_brush,
                                                  self.set_tool)

        self._tool_brush.connect('clicked', self._tool_button_clicked_cb)

        self._stroke_color = ButtonStrokeColor(activity)
        self.set_tool(self._tool_brush, self._TOOL_BRUSH_NAME)
        self._stroke_color.connect('notify::color', self._color_button_cb)
        toolbar.insert(self._stroke_color, -1)

    def set_tool(self, widget, tool_name):
        """
        Set tool to the Area object. Configures tool's color and size.

            @param self -- Gtk.Toolbar
            @param widget -- The connected widget, if any;
                          necessary in case this method is used in a connect()
            @param tool_name --The name of the selected tool
        """

        if widget != self._tool_brush:
            self._tool_brush.set_icon_name(widget.icon_name)
            self._stroke_color.set_selected_tool(tool_name)

        if tool_name == self._TOOL_STAMP_NAME:
            resized_stamp = self._activity.area.setup_stamp()
            self._stroke_color.color_button.set_resized_stamp(resized_stamp)
        else:
            self._stroke_color.color_button.stop_stamping()
        if tool_name != self._TOOL_MARQUEE_RECT_NAME:
            self._activity.area.end_selection()

        if tool_name == 'load-stamp':
            dialog = TuxStampDialog(self._activity)
            dialog.set_transient_for(self._activity)
            dialog.connect('stamp-selected', self._load_stamp)
            dialog.show_all()
        else:
            self._do_setup_tool(tool_name)

    def _do_setup_tool(self, tool_name):
        self._stroke_color.update_stamping()
        self.properties['name'] = tool_name
        self._activity.area.set_tool(self.properties)
        self._fill_color_button.set_sensitive(False)
        self._selected_tool_name = tool_name

    def _tool_button_clicked_cb(self, button):
        if self._selected_tool_name == 'load-stamp':
            # do not open the load stamp dialog when the button is pressed
            return
        self.set_tool(button, self._selected_tool_name)

    def _color_button_cb(self, widget, pspec):
        new_color = widget.get_color()
        self._activity.area.set_stroke_color(new_color)

    def _on_signal_undo_cb(self, widget, data=None):
        self._verify_sensitive_buttons()

    def _on_signal_redo_cb(self, widget, data=None):
        self._verify_sensitive_buttons()

    def _on_signal_select_cb(self, widget, data=None):
        self._verify_sensitive_buttons()

    def _on_signal_action_saved_cb(self, widget, data=None):
        self._verify_sensitive_buttons()

    def _verify_sensitive_buttons(self):
        # Check if there is an area selected or if the "stamp" tool is
        # being used
        sensitive = self._activity.area.is_selected() or \
            self.properties['name'] == 'stamp'
        self._tool_stamp.set_sensitive(sensitive)

    def _load_stamp(self, widget, filepath):
        resized_stamp = self._activity.area.setup_stamp(stamp=filepath)
        self._stroke_color.color_button.set_resized_stamp(resized_stamp)
        self._do_setup_tool('load-stamp')
예제 #4
0
class ToolsToolbarBuilder():

    # Tool default definitions
    # _TOOL_PENCIL_NAME = 'pencil'
    _TOOL_BRUSH_NAME = 'brush'
    _TOOL_ERASER_NAME = 'eraser'
    _TOOL_BUCKET_NAME = 'bucket'
    _TOOL_PICKER_NAME = 'picker'
    _TOOL_STAMP_NAME = 'stamp'
    _TOOL_MARQUEE_RECT_NAME = 'marquee-rectangular'

    def __init__(self, toolbar, activity, fill_color_button):

        self._activity = activity
        self.properties = self._activity.area.tool
        self._fill_color_button = fill_color_button
        self._selected_tool_name = self._TOOL_BRUSH_NAME

        self._tool_brush = DrawToolButton('tool-brush',
                                          activity.tool_group, _('Brush'))
        activity.tool_group = self._tool_brush
        toolbar.insert(self._tool_brush, -1)

        add_menu('tool-brush', _('Brush'), self._TOOL_BRUSH_NAME,
                 self._tool_brush, self.set_tool)

        add_menu('tool-eraser', _('Eraser'), self._TOOL_ERASER_NAME,
                 self._tool_brush, self.set_tool)

        add_menu('tool-bucket', _('Bucket'), self._TOOL_BUCKET_NAME,
                 self._tool_brush, self.set_tool)

        add_menu('tool-picker', _('Picker'), self._TOOL_PICKER_NAME,
                 self._tool_brush, self.set_tool)

        self._tool_stamp = add_menu('tool-stamp', _('Stamp'),
                                    self._TOOL_STAMP_NAME, self._tool_brush,
                                    self.set_tool)

        is_selected = self._activity.area.is_selected()
        self._tool_stamp.set_sensitive(is_selected)

        add_menu('tool-stamp', _('Load stamp'), 'load-stamp', self._tool_brush,
                 self.set_tool)

        self._activity.area.connect('undo', self._on_signal_undo_cb)
        self._activity.area.connect('redo', self._on_signal_redo_cb)
        self._activity.area.connect('select', self._on_signal_select_cb)
        self._activity.area.connect('action-saved',
                                    self._on_signal_action_saved_cb)

        self._tool_marquee_rectangular = add_menu('tool-marquee-rectangular',
                                                  _('Select Area'),
                                                  self._TOOL_MARQUEE_RECT_NAME,
                                                  self._tool_brush,
                                                  self.set_tool)

        self._tool_brush.connect('clicked', self._tool_button_clicked_cb)

        self._stroke_color = ButtonStrokeColor(activity)
        self.set_tool(self._tool_brush, self._TOOL_BRUSH_NAME)
        self._stroke_color.connect('notify::color', self._color_button_cb)
        toolbar.insert(self._stroke_color, -1)

    def set_tool(self, widget, tool_name):
        """
        Set tool to the Area object. Configures tool's color and size.

            @param self -- Gtk.Toolbar
            @param widget -- The connected widget, if any;
                          necessary in case this method is used in a connect()
            @param tool_name --The name of the selected tool
        """

        if widget != self._tool_brush:
            self._tool_brush.set_icon_name(widget.icon_name)
            self._stroke_color.set_selected_tool(tool_name)

        if tool_name == self._TOOL_STAMP_NAME:
            resized_stamp = self._activity.area.setup_stamp()
            self._stroke_color.color_button.set_resized_stamp(resized_stamp)
        else:
            self._stroke_color.color_button.stop_stamping()
        if tool_name != self._TOOL_MARQUEE_RECT_NAME:
            self._activity.area.end_selection()

        if tool_name == 'load-stamp':
            dialog = TuxStampDialog(self._activity)
            dialog.set_transient_for(self._activity)
            dialog.connect('stamp-selected', self._load_stamp)
            dialog.show_all()
        else:
            self._do_setup_tool(tool_name)

    def _do_setup_tool(self, tool_name):
        self._stroke_color.update_stamping()
        self.properties['name'] = tool_name
        self._activity.area.set_tool(self.properties)
        self._fill_color_button.set_sensitive(False)
        self._selected_tool_name = tool_name

    def _tool_button_clicked_cb(self, button):
        if self._selected_tool_name == 'load-stamp':
            # do not open the load stamp dialog when the button is pressed
            return
        self.set_tool(button, self._selected_tool_name)

    def _color_button_cb(self, widget, pspec):
        new_color = widget.get_color()
        self._activity.area.set_stroke_color(new_color)

    def _on_signal_undo_cb(self, widget, data=None):
        self._verify_sensitive_buttons()

    def _on_signal_redo_cb(self, widget, data=None):
        self._verify_sensitive_buttons()

    def _on_signal_select_cb(self, widget, data=None):
        self._verify_sensitive_buttons()

    def _on_signal_action_saved_cb(self, widget, data=None):
        self._verify_sensitive_buttons()

    def _verify_sensitive_buttons(self):
        # Check if there is an area selected or if the "stamp" tool is
        # being used
        sensitive = self._activity.area.is_selected() or \
            self.properties['name'] == 'stamp'
        self._tool_stamp.set_sensitive(sensitive)

    def _load_stamp(self, widget, filepath):
        resized_stamp = self._activity.area.setup_stamp(stamp=filepath)
        self._stroke_color.color_button.set_resized_stamp(resized_stamp)
        self._do_setup_tool('load-stamp')