def stroke_selected(self, color): doc = self.app.current_doc canvas = doc.canvas if canvas.mode in modes.EDIT_MODES and canvas.controller.target: doc.api.stroke_selected(color, [canvas.controller.target, ]) elif not doc.selection.objs: txt = _('Do you wish to change default stroke color for this document?') txt += '\n' txt += _('This style will be applied to newly created objects.') title = self.app.appdata.app_name if dialogs.yesno_dialog(self.mw, title, txt): new_style = doc.model.get_def_style() if color: if new_style[1]: new_style[1][2] = deepcopy(color) else: new_style[1] = [sk2_const.STROKE_MIDDLE, 0.1 * uc2const.mm_to_pt, deepcopy(color), [], sk2_const.CAP_BUTT, sk2_const.JOIN_MITER, 1.0 / math.sin(45.0 / 2.0), 0, 0, [] ] else: new_style[1] = [] doc.api.set_default_style(new_style) else: doc.api.stroke_selected(color)
def select_stroke_donor(self, objs): if len(objs) == 1 and objs[0].is_primitive() and not objs[0].is_pixmap(): style = self._get_style(objs) if not style is None: stroke_style = deepcopy(style[1]) self.app.current_doc.api.set_stroke_style(stroke_style) return False if not len(objs): txt = _("Source object is not selected to copy stroke property.") else: txt = _("Selected object cannot be source of stroke property.") txt += '\n' + _('Do you want to try again?') return yesno_dialog(self.app.mw, self.app.appdata.app_name, txt)
def select_stroke_donor(self, objs): if len(objs) == 1 and objs[0].is_primitive and not objs[0].is_pixmap: style = self._get_style(objs) if style is not None: stroke_style = deepcopy(style[1]) self.app.current_doc.api.set_stroke_style(stroke_style) return False if not len(objs): txt = _("Source object is not selected to copy stroke property.") else: txt = _("Selected object cannot be source of stroke property.") txt += '\n' + _('Do you want to try again?') return yesno_dialog(self.app.mw, self.app.appdata.app_name, txt)
def select_stroke_donor(self, objs): if len(objs) == 1 and objs[0].cid > sk2_model.PRIMITIVE_CLASS and not \ objs[0].cid == sk2_model.PIXMAP: style = self._get_style(objs) if not style is None: stroke_style = deepcopy(style[1]) self.app.current_doc.api.set_stroke_style(stroke_style) return False if not len(objs): txt = _("There is no selected object.") else: txt = _("Selected object cannot be source of stroke property.") txt += '\n' + _('Do you want to try again?') return yesno_dialog(self.app.mw, self.app.appdata.app_name, txt)
def select_fill_donor(self, objs): if len(objs) == 1 and objs[0].is_primitive and not objs[0].is_pixmap: style = self._get_style(objs) if style is not None: fill_style = deepcopy(style[0]) if fill_style and fill_style[1] == sk2const.FILL_GRADIENT: fill_style[2][1] = [] self.app.current_doc.api.set_fill_style(fill_style) return False if not len(objs): txt = _("Source object is not selected to copy fill property.") else: txt = _("Selected object cannot be source of fill property.") txt += '\n' + _('Do you want to try again?') return yesno_dialog(self.app.mw, self.app.appdata.app_name, txt)
def select_fill_donor(self, objs): if len(objs) == 1 and objs[0].is_primitive() and not objs[0].is_pixmap(): style = self._get_style(objs) if not style is None: fill_style = deepcopy(style[0]) if fill_style and fill_style[1] == sk2_const.FILL_GRADIENT: fill_style[2][1] = [] self.app.current_doc.api.set_fill_style(fill_style) return False if not len(objs): txt = _("Source object is not selected to copy fill property.") else: txt = _("Selected object cannot be source of fill property.") txt += '\n' + _('Do you want to try again?') return yesno_dialog(self.app.mw, self.app.appdata.app_name, txt)
def select_container(self, objs): selection = self.app.current_doc.selection if len(objs) == 1 and objs[0].is_primitive and \ not objs[0] in selection.objs and not objs[0].is_pixmap: self.app.current_doc.api.pack_container(objs[0]) return False if not len(objs): txt = _("There is no selected object.") elif objs[0] in selection.objs: txt = _("Object from current selection cannot be container.") else: txt = _("Selected object cannot be container.") txt += '\n' + _('Do you want to try again?') return yesno_dialog(self.app.mw, self.app.appdata.app_name, txt)
def select_container(self, objs): selection = self.app.current_doc.selection if len(objs) == 1 and objs[0].is_primitive() and not \ objs[0] in selection.objs and not objs[0].is_pixmap(): self.app.current_doc.api.pack_container(objs[0]) return False if not len(objs): txt = _("There is no selected object.") elif objs[0] in selection.objs: txt = _("Object from current selection cannot be container.") else: txt = _("Selected object cannot be container.") txt += '\n' + _('Do you want to try again?') return yesno_dialog(self.app.mw, self.app.appdata.app_name, txt)
def select_container(self, objs): selection = self.app.current_doc.selection if len(objs) == 1 and objs[0].cid > sk2_model.PRIMITIVE_CLASS and not \ objs[0] in selection.objs and not objs[0].cid == sk2_model.PIXMAP: self.app.current_doc.api.pack_container(objs[0]) return False if not len(objs): txt = _("There is no selected object.") elif objs[0] in selection.objs: txt = _("Object from current selection cannot be container.") else: txt = _("Selected object cannot be container.") txt += '\n' + _('Do you want to try again?') return yesno_dialog(self.app.mw, self.app.appdata.app_name, txt)
def select_trim_target(self, selected): if len(selected) == 1 and selected[0].is_primitive(): sel_obj = selected[0] objs = self.get_selection() if sel_obj in objs: objs.remove(sel_obj) if objs: objs = [sel_obj, ] + objs self._action(objs) return False else: selected = [] if not len(selected): txt = _("There is no selected object.") else: txt = _("Selected object cannot be target for trim operation.") txt += '\n' + _('Do you want to try again?') return yesno_dialog(self.app.mw, self.app.appdata.app_name, txt)
def stroke_dialog(self, default_style=False): doc = self.app.current_doc doc.canvas.set_mode() objs = [] if default_style: stroke_style = doc.model.styles['Default Style'][1] default_style = True title = _('Default document stroke') else: stroke_style = None title = _('Stroke') if doc.selection.objs: style = self._get_style(doc.selection.objs) if style is not None: stroke_style = style[1] elif doc.canvas.mode in modes.EDIT_MODES and \ doc.canvas.controller.target: objs.append(doc.canvas.controller.target) style = self._get_style(objs) if style is not None: stroke_style = style[1] if stroke_style is None: txt = _( 'Do you wish to change default stroke style for this document?' ) txt += '\n' txt += _('This style will be applied to newly created objects.') title = self.app.appdata.app_name if dialogs.yesno_dialog(self.mw, title, txt): stroke_style = doc.model.styles['Default Style'][1] default_style = True title = _('Default document stroke') else: return new_stroke_style = dialogs.stroke_dlg(self.mw, doc, stroke_style, title) if new_stroke_style is not None: if default_style: new_style = doc.model.get_def_style() new_style[1] = new_stroke_style doc.api.set_default_style(new_style) else: doc.api.set_stroke_style(new_stroke_style, objs)
def fill_selected(self, color): doc = self.app.current_doc canvas = doc.canvas if canvas.mode in modes.EDIT_MODES and canvas.controller.target: doc.api.fill_selected(color, [canvas.controller.target, ]) elif not doc.selection.objs: txt = _('Do you wish to change default fill color for this document?') txt += '\n' txt += _('This style will be applied to newly created objects.') title = self.app.appdata.app_name if dialogs.yesno_dialog(self.mw, title, txt): new_style = doc.model.get_def_style() if color: fill_style = [sk2_const.FILL_EVENODD, sk2_const.FILL_SOLID, deepcopy(color)] new_style[0] = fill_style else: new_style[0] = [] doc.api.set_default_style(new_style) else: doc.api.fill_selected(color)
def fill_selected(self, color): doc = self.app.current_doc canvas = doc.canvas if canvas.mode in modes.EDIT_MODES and canvas.controller.target: doc.api.fill_selected(color, [canvas.controller.target, ]) elif not doc.selection.objs: txt = _( 'Do you wish to change default fill color for this document?') txt += '\n' txt += _('This style will be applied to newly created objects.') title = self.app.appdata.app_name if dialogs.yesno_dialog(self.mw, title, txt): new_style = doc.model.get_def_style() if color: fill_style = [sk2const.FILL_EVENODD, sk2const.FILL_SOLID, deepcopy(color)] new_style[0] = fill_style else: new_style[0] = [] doc.api.set_default_style(new_style) else: doc.api.fill_selected(color)
def fill_dialog(self, default_style=False): doc = self.app.current_doc objs = [] if default_style: fill_style = doc.model.styles['Default Style'][0] default_style = True title = _('Default document fill') else: fill_style = None title = _('Fill') if doc.selection.objs: style = self._get_style(doc.selection.objs) if not style is None: fill_style = style[0] elif doc.canvas.mode in modes.EDIT_MODES and \ doc.canvas.controller.target: objs.append(doc.canvas.controller.target) style = self._get_style(objs) if not style is None: fill_style = style[0] if fill_style is None: txt = _('Do you wish to change default fill style for this document?') txt += '\n' txt += _('This style will be applied to newly created objects.') title = self.app.appdata.app_name if dialogs.yesno_dialog(self.mw, title, txt): fill_style = doc.model.styles['Default Style'][0] default_style = True title = _('Default document fill') else: return new_fill_style = dialogs.fill_dlg(self.mw, doc, fill_style, title) if not new_fill_style is None: if default_style: new_style = doc.model.get_def_style() new_style[0] = new_fill_style doc.api.set_default_style(new_style) else: doc.api.set_fill_style(new_fill_style, objs)