def __init__(self, parent, printer): self.printer = printer wal.LabeledPanel.__init__(self, parent, _('Print mode')) grid = wal.GridPanel(self, 2, 2, 5, 5) self.mono_opt = wal.Radiobutton(grid, _('Monochrome'), group=True, onclick=self.update) icon = get_icon(icons.PD_PRINTMODE_MONO, size=wal.DEF_SIZE) self.mono_bmp = wal.Bitmap(grid, icon) grid.pack(self.mono_bmp) grid.pack(self.mono_opt) self.color_opt = wal.Radiobutton(grid, _('Color'), onclick=self.update) icon = get_icon(icons.PD_PRINTMODE_COLOR, size=wal.DEF_SIZE) self.color_bmp = wal.Bitmap(grid, icon) grid.pack(self.color_bmp) grid.pack(self.color_opt) self.color_opt.set_value(True) self.pack(grid, padding_all=10, align_center=False) hpanel = wal.HPanel(self) self.cs_lbl = wal.Label(hpanel, _('Color space:')) hpanel.pack(self.cs_lbl, padding=5) self.cs_combo = wal.Combolist(hpanel, items=CS) hpanel.pack(self.cs_combo) self.pack(hpanel) self.pack((5, 5)) self.set_data()
def __init__(self, parent, printer, app): self.app = app self.printer = printer wal.LabeledPanel.__init__(self, parent, _('Paper')) grid = wal.GridPanel(self, 2, 2, 5, 5) grid.add_growable_col(1) grid.pack(wal.Label(grid, _('Page size:'))) self.size_combo = wal.Combolist(grid, onchange=self.on_change) grid.pack(self.size_combo, fill=True) grid.pack(wal.Label(grid, _('Width:'))) hpanel = wal.HPanel(grid) self.wspin = StaticUnitSpin(self.app, hpanel) hpanel.pack(self.wspin) hpanel.pack(StaticUnitLabel(self.app, hpanel), padding=5) hpanel.pack((5, 5)) hpanel.pack(wal.Label(grid, _('Height:')), padding=5) self.hspin = StaticUnitSpin(self.app, hpanel) hpanel.pack(self.hspin) hpanel.pack(StaticUnitLabel(self.app, hpanel), padding=5) grid.pack(hpanel) self.pack(grid, fill=True, expand=True, padding_all=10) self.set_data()
def __init__(self, parent, printer, app): self.app = app self.printer = printer wal.LabeledPanel.__init__(self, parent, _('Orientation')) hpanel = wal.HPanel(self) vpanel = wal.VPanel(hpanel) self.port_opt = wal.Radiobutton(vpanel, _('Portrait'), group=True, onclick=self.update) vpanel.pack(self.port_opt, align_center=False) vpanel.pack((5, 5)) self.land_opt = wal.Radiobutton(vpanel, _('Landscape'), onclick=self.update) vpanel.pack(self.land_opt, align_center=False) hpanel.pack(vpanel) icon_name = icons.PD_PRINTORIENT_PORTRAIT if self.printer.page_orientation == uc2const.LANDSCAPE: icon_name = icons.PD_PRINTORIENT_LANDSCAPE self.land_opt.set_value(True) icon = get_icon(icon_name, size=wal.DEF_SIZE) self.orient_icon = wal.Bitmap(hpanel, icon) hpanel.pack(self.orient_icon, padding=10) self.pack(hpanel, fill=True, expand=True, padding_all=10)
def __init__(self, parent, printer, app): self.printer = printer self.app = app wal.LabeledPanel.__init__(self, parent, _('Document metainfo')) grid = wal.GridPanel(self, 4, 2, 2, 5) grid.add_growable_col(1) grid.pack(wal.Label(grid, _('Title:'))) self.title = wal.Entry(grid, self.printer.meta_title) grid.pack(self.title, fill=True) grid.pack(wal.Label(grid, _('Subject:'))) self.subject = wal.Entry(grid, self.printer.meta_subject) grid.pack(self.subject, fill=True) grid.pack(wal.Label(grid, _('Author:'))) self.author = wal.Entry(grid, self.printer.meta_author) grid.pack(self.author, fill=True) grid.pack(wal.Label(grid, _('Keywords:'))) self.keywords = wal.Entry(grid, self.printer.meta_keywords) grid.pack(self.keywords, fill=True) self.pack(grid, fill=True, expand=True, padding_all=7)
def set_dialog_buttons(self): PrnProsDialog.set_dialog_buttons(self) self.import_btn = wal.Button(self.left_button_box, _('Set metainfo'), tooltip=_('Set metainfo from current document'), onclick=self.main_panel.doc_info.import_data) self.left_button_box.pack(self.import_btn) self.import_btn.set_enable(self.main_panel.doc_info.is_metadata())
def __init__(self, parent, dlg, cms, stops, sel_stop=0, onposition=None, oncolor=None): self.dlg = dlg self.cms = cms self.stops = stops self.selected_stop = sel_stop self.pos_callback = onposition self.color_callback = oncolor wal.LabeledPanel.__init__(self, parent, text=_("Gradient stop")) grid = wal.GridPanel(self, cols=3, vgap=5, hgap=5) grid.pack(wal.Label(grid, _("Color value:"))) clr = self.stops[self.selected_stop][1] txt = _("Change stop color") self.swatch = PDColorButton(grid, self.dlg, self.cms, clr, txt, onchange=self.edit_color) grid.pack(self.swatch) grid.pack((1, 1)) grid.pack(wal.Label(grid, _("Position:"))) self.position = wal.FloatSpin( grid, range_val=(0.0, 100.0), step=1.0, onchange=self.pos_changed, onenter=self.pos_changed ) grid.pack(self.position) grid.pack(wal.Label(grid, "%")) self.pack(grid, align_center=False, padding_all=10)
def set_selected_nodes(self, points=[], add_flag=False): if points: self.new_node = None if not add_flag: for item in self.selected_nodes: item.selected = False self.selected_nodes = [] for item in points: if item.is_start() and item.path.is_closed(): continue if item.selected and item in self.selected_nodes: item.selected = False self.selected_nodes.remove(item) else: item.selected = True self.selected_nodes.append(item) if len(self.selected_nodes) == 1: self.create_control_points() else: self.clear_control_points() events.emit(events.SELECTION_CHANGED, self.presenter) msg = _('No selected nodes') if self.selected_nodes: msg = _('Selected %d node(s)') % len(self.selected_nodes) events.emit(events.APP_STATUS, msg) self.canvas.selection_redraw()
def _get_open_filters(items=[]): wildcard = '' descr = uc2const.FORMAT_DESCRIPTION ext = uc2const.FORMAT_EXTENSION if not items: items = [] + data.LOADER_FORMATS wildcard += _('All supported formats') + '|' for item in items: for extension in ext[item]: wildcard += '*.' + extension + ';' wildcard += '*.' + extension.upper() + ';' if is_mac():return wildcard wildcard += '|' wildcard += _('All files (*.*)') + '|' wildcard += '*;*.*|' for item in items: wildcard += descr[item] + '|' for extension in ext[item]: wildcard += '*.' + extension + ';' wildcard += '*.' + extension.upper() + ';' if not item == items[-1]: wildcard += '|' return wildcard
def update_val(self): text = _('Fill:') if self.non_solid: pass elif self.colorspace is None: text += ' ' + _('None') else: if self.colorspace == uc2const.COLOR_CMYK: c, m, y, k = self.color text += ' C-%d%% M-%d%% Y-%d%% K-%d%%' % (c * 100, m * 100, y * 100, k * 100) elif self.colorspace == uc2const.COLOR_RGB: r, g, b = self.color text += ' R-%d G-%d B-%d' % (r * 255, g * 255, b * 255) elif self.colorspace == uc2const.COLOR_LAB: l, a, b = self.color text += ' L-%d a-%d b-%d' % (l * 255, a * 255, b * 255) elif self.colorspace == uc2const.COLOR_GRAY: gray, = self.color text += ' gray-%d' % (gray * 255) elif self.colorspace == uc2const.COLOR_SPOT: text += ' %s' % (self.color_name) else: pass if self.alpha < 1.0: if self.colorspace == uc2const.COLOR_CMYK: alpha = int(round(self.alpha * 100)) text += ' A-%d%%' % (alpha) else: alpha = int(round(self.alpha * 255)) text += ' A-%d' % (alpha) self.set_text(text)
def build(self): self.set_profiles() self.update_list() self.viewer = ProfileList(self, self.pf_list) self.pack_start(self.viewer, False, True, 5) box = gtk.VBox() self.add_button = wal.ImgButton(box, wal.STOCK_ADD, tooltip=_('Import profile'), cmd=self.import_profile) box.pack_start(self.add_button, False, False, 5) self.remove_button = wal.ImgButton(box, wal.STOCK_REMOVE, tooltip=_('Remove profile'), cmd=self.remove_profile) box.pack_start(self.remove_button, False, False, 5) self.remove_button.set_sensitive(False) self.info_button = wal.ImgButton(box, wal.STOCK_INFO, tooltip=_('Profile info'), cmd=self.inspect_profile) box.pack_start(self.info_button, False, False, 5) self.pack_start(box, False, False, 0)
def save(self): try: if config.make_backup: if os.path.lexists(self.doc_file): if os.path.lexists(self.doc_file + '~'): os.remove(self.doc_file + '~') os.rename(self.doc_file, self.doc_file + '~') saver = get_saver(self.doc_file) if saver is None: raise IOError(_('Unknown file format is requested for saving!'), self.doc_file) pd = ProgressDialog(_('Saving file...'), self.app.mw) ret = pd.run(saver, [self.doc_presenter, self.doc_file]) if ret == gtk.RESPONSE_OK: if not pd.error_info is None: pd.destroy() raise IOError(*pd.error_info) pd.destroy() else: pd.destroy() raise IOError(_('Error while saving'), self.doc_file) except IOError: raise IOError(*sys.exc_info()) self.reflect_saving()
def export_as(self): doc_file = '' + self.current_doc.doc_file if not doc_file: doc_file = '' + self.current_doc.doc_name if os.path.splitext(doc_file)[1] == "." + \ uc2const.FORMAT_EXTENSION[uc2const.SK2][0]: doc_file = os.path.splitext(doc_file)[0] + "." + \ uc2const.FORMAT_EXTENSION[uc2const.PNG][0] doc_file = os.path.join(config.export_dir, os.path.basename(doc_file)) doc_file = dialogs.get_save_file_name(self.mw, self, doc_file, _('Export document As...'), file_types=data.SAVER_FORMATS[1:])[0] if doc_file: try: self.make_backup(doc_file, True) self.current_doc.export_as(doc_file) except: first = _('Cannot save document') msg = ("%s '%s'.") % (first, self.current_doc.doc_name) + '\n' msg += _('Please check file name and write permissions') dialogs.error_dialog(self.mw, self.appdata.app_name, msg) self.print_stacktrace() return config.export_dir = str(os.path.dirname(doc_file)) events.emit(events.APP_STATUS, _('Document is successfully exported'))
def build(self): grid = wal.GridPanel(self.panel, rows=4, cols=2, vgap=5, hgap=5) self.panel.pack(grid, expand=True, fill=True, padding_all=5) grid.add_growable_col(1) grid.add_growable_row(3) grid.pack(wal.Label(grid, _('Palette name:'))) self.name_entry = wal.Entry(grid, value=self.palette.model.name) grid.pack(self.name_entry, fill=True) grid.pack(wal.Label(grid, _('Palette source:'))) self.source_entry = wal.Entry(grid, value=self.palette.model.source) grid.pack(self.source_entry, fill=True) grid.pack(wal.Label(grid, _('Columns:'))) cols = self.palette.model.columns size = len(self.palette.model.colors) self.cols = wal.IntSpin(grid, value=cols, range_val=(1, size), spin_overlay=config.spin_overlay) grid.pack(self.cols) grid.pack(wal.Label(grid, _('Description:'))) self.comm_entry = wal.Entry(grid, value=self.palette.model.comments, multiline=True) grid.pack(self.comm_entry, fill=True)
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 save_as(self): doc_file = '' + self.current_doc.doc_file if not doc_file: doc_file = '' + self.current_doc.doc_name if not os.path.splitext(doc_file)[1] == "." + \ uc2const.FORMAT_EXTENSION[uc2const.SK2][0]: doc_file = os.path.splitext(doc_file)[0] + "." + \ uc2const.FORMAT_EXTENSION[uc2const.SK2][0] if not os.path.lexists(os.path.dirname(doc_file)): doc_file = os.path.join(config.save_dir, os.path.basename(doc_file)) doc_file = dialogs.get_save_file_name(self.mw, self, doc_file)[0] if doc_file: old_file = self.current_doc.doc_file old_name = self.current_doc.doc_name self.current_doc.set_doc_file(doc_file) try: self.make_backup(doc_file) self.current_doc.save() except: self.current_doc.set_doc_file(old_file, old_name) first = _('Cannot save document') msg = ("%s '%s'.") % (first, self.current_doc.doc_name) + '\n' msg += _('Please check file name and write permissions') dialogs.error_dialog(self.mw, self.appdata.app_name, msg) self.print_stacktrace() return False config.save_dir = str(os.path.dirname(doc_file)) self.history.add_entry(doc_file, appconst.SAVED) events.emit(events.DOC_SAVED, self.current_doc) events.emit(events.APP_STATUS, _('Document saved')) return True else: return False
def close(self, doc=None): if not self.docs: return if doc is None: doc = self.current_doc if not doc == self.current_doc: self.set_current_doc(doc) if self.insp.is_doc_not_saved(doc): msg = _("Document '%s' has been modified.") % (doc.doc_name) + '\n' msg += _('Do you want to save your changes?') ret = dialogs.ync_dialog(self.mw, self.appdata.app_name, msg) if ret is None: return False if ret: if not self.save(): return False if doc in self.docs: self.docs.remove(doc) doc.close() events.emit(events.DOC_CLOSED) if not len(self.docs): self.current_doc = None events.emit(events.NO_DOCS) msg = _('To start create new or open existing document') events.emit(events.APP_STATUS, msg) self.mw.set_title() else: self.set_current_doc(self.docs[-1]) return True
def _action(self, objs): doc = self.app.current_doc paths = self.get_paths_list(objs) doc.canvas.set_temp_mode(modes.WAIT_MODE) try: result = self.do_action(paths) except: doc.canvas.restore_mode() result = [] msg = _('Error occurred during this operation.') msg += '\n' + _('Perhaps this was due to the imperfection of the algorithm.') error_dialog(self.app.mw, self.app.appdata.app_name, msg) return doc.canvas.restore_mode() if result: style = deepcopy(objs[0].style) doc.api.create_curve(result, style) elif not result and self.pid == INTERSECTION_MODE: msg = _('Selected objects cannot be intersected.') msg_dialog(self.app.mw, self.app.appdata.app_name, msg) return if self.del_check.get_value(): objs_list = [] for obj in objs: index = obj.parent.childs.index(obj) objs_list.append([obj, obj.parent, index]) doc.api.delete_objects(objs_list)
def save(self, doc=''): if not doc: doc = self.current_doc if not doc.doc_file: return self.save_as() ext = os.path.splitext(self.current_doc.doc_file)[1] if not ext == "." + uc2const.FORMAT_EXTENSION[uc2const.SK2][0]: return self.save_as() if not os.path.lexists(os.path.dirname(self.current_doc.doc_file)): return self.save_as() try: self.make_backup(self.current_doc.doc_file) doc.save() self.history.add_entry(self.current_doc.doc_file, appconst.SAVED) events.emit(events.DOC_SAVED, doc) except: msg = _('Cannot save file') msg = "%s '%s'" % (msg, self.current_doc.doc_file) + '\n' msg += _('Please check file write permissions') dialogs.error_dialog(self.mw, self.appdata.app_name, msg) self.print_stacktrace() return False events.emit(events.APP_STATUS, _('Document saved')) return True
def build(self): self.pack((5, 5)) vpanel = wal.VPanel(self) hpanel = wal.HPanel(vpanel) hpanel.pack(wal.Label(hpanel, _('Guide color:'))) hpanel.pack((10, 5)) self.color = self.doc.methods.get_guide_rgb_color() self.guide_color_btn = wal.ColorButton(hpanel, self.color[:3], onchange=self.on_change) hpanel.pack(self.guide_color_btn) hpanel.pack((10, 5)) hpanel.pack(CBMiniPalette(hpanel, colors=GUIDE_COLORS, onclick=self.change_color)) vpanel.pack(hpanel, fill=True, align_center=False) val = self.doc.methods.is_guide_visible() self.show_guide_check = wal.Checkbox(vpanel, _('Show grid on canvas'), val) vpanel.pack(self.show_guide_check, align_center=False, padding=5) self.pack((10, 10)) self.preview = GuidePreview(vpanel, deepcopy(self.color)) vpanel.pack(self.preview, fill=True, expand=True) self.pack(vpanel, fill=True, expand=True, padding_all=5)
def __init__(self, parent, app): self.app = app wal.LabeledPanel.__init__(self, parent, _('Align')) self.pack((5, 5)) self.pack(wal.Label(self, _('Relative to:'))) self.source = wal.Combolist(self, items=SOURCE_NAMES, onchange=self.update) self.pack(self.source, padding_all=5, fill=True) self.pack((5, 5)) self.halign = wal.HToggleKeeper(self, H_ALIGN_MODES, H_ALIGN_MODE_ICONS, H_ALIGN_MODE_NAMES, on_change=self.update, allow_none=True) self.pack(self.halign) self.halign.set_mode(ALIGN_CENTER) self.valign = wal.HToggleKeeper(self, V_ALIGN_MODES, V_ALIGN_MODE_ICONS, V_ALIGN_MODE_NAMES, on_change=self.update, allow_none=True) self.pack(self.valign, padding_all=5) self.valign.set_mode(ALIGN_CENTER) self.group = wal.Checkbox(self, _('Selection as group'), True, onclick=self.update) self.pack(self.group, padding_all=5) self.apply_btn = wal.Button(self, _('Apply'), onclick=self.action) self.pack(self.apply_btn, padding_all=5, fill=True)
def build(self): self.pack((5, 5)) hpanel = wal.HPanel(self) hpanel.pack(wal.Label(hpanel, _('Document units') + ':')) names = [] for item in unit_names: names.append(unit_full_names[item]) self.units_combo = wal.Combolist(hpanel, items=names) self.units = self.doc.methods.get_doc_units() self.units_combo.set_active(unit_names.index(self.units)) hpanel.pack(self.units_combo, padding=5) self.pack(hpanel) data = [[_('Unit'), _('Value in points')]] for item in uc2const.unit_names: name = uc2const.unit_full_names[item] value = _('%s points') % str(uc2const.unit_dict[item]) data.append([name, value]) slist = wal.ReportList(self, data) self.pack(slist, expand=True, fill=True, padding_all=5) self.origin = self.doc.methods.get_doc_origin() self.pack(wal.Label(self, _('Document origin:')), padding_all=5) self.origin_keeper = wal.HToggleKeeper(self, ORIGINS, ORIGIN_ICONS, ORIGIN_NAMES) self.origin_keeper.set_mode(self.origin) self.pack(self.origin_keeper) self.pack((5, 5))
def build(self): self.metainfo = deepcopy(self.doc.model.metainfo) if self.metainfo[3]: self.metainfo[3] = b64decode(self.metainfo[3]) grid = wal.GridPanel(self, 4, 2, 5, 5) grid.add_growable_col(1) grid.add_growable_row(3) grid.pack(wal.Label(grid, _('Author:'))) self.author_field = wal.Entry(grid, '' + self.metainfo[0]) grid.pack(self.author_field, fill=True) grid.pack(wal.Label(grid, _('License:'))) self.license_field = wal.Entry(grid, '' + self.metainfo[1]) grid.pack(self.license_field, fill=True) grid.pack(wal.Label(grid, _('Keywords:'))) self.keys_field = wal.Entry(grid, '' + self.metainfo[2]) grid.pack(self.keys_field, fill=True) grid.pack(wal.Label(grid, _('Notes:'))) self.notes_field = wal.Entry(grid, '' + self.metainfo[3], multiline=True) grid.pack(self.notes_field, fill=True) self.pack(grid, fill=True, expand=True, padding_all=5)
def __init__(self, master, owner, app, dlg): self.owner = owner PrefsTab.__init__(self, master, app, dlg) self.set_border_width(0) self.use_cms = config.cms_use hbox = wal.HBox(self) txt = _('Activate Color Management') self.cms_check = wal.CheckButton(hbox, txt, self.use_cms, self.changes) hbox.pack(self.cms_check, padding=10) self.pack(hbox, padding=5) self.container = wal.HidableVBox(hbox) self.splash = wal.ImgPlate(self.container, rc.IMG_PREFS_CMS_BANNER, bg=wal.DARK_GRAY) self.container.pack(self.splash, True, True) self.container.set_visible(self.use_cms) self.pack(self.container) hbox = wal.HBox(self) txt = _('Note: If Color Management is not activated all colors ' 'will be processed using simple calculation procedures. Therefore ' 'resulted color values will be not accurate.') note = wal.DecorLabel(hbox, txt, -1, enabled=False, wrap=True) note.set_width(450) hbox.pack(note, padding=10) self.pack(hbox, padding=5)
def __init__(self, parent, prefpanel): CMS_Tab.__init__(self, parent, prefpanel) txt = _('Activate Color Management') panel = wal.VPanel(self) hp = wal.HPanel(panel) self.cms_check = wal.Checkbox(hp, txt, config.cms_use, onclick=self.activate_cms) hp.pack(self.cms_check) panel.pack(hp, fill=True, padding_all=3) self.banner = wal.VPanel(panel) self.banner.set_bg(wal.DARK_GRAY) bmp = get_bmp(self.banner, icons.PD_PREFS_CMS_BANNER) self.banner.pack(bmp, padding=2) panel.pack(self.banner, expand=True, fill=True) txt = _('Note: If Color Management is not activated all colors ' 'will be processed using simple calculation procedures. Therefore ' 'resulted color values will be not accurate.') fontsize = -3 if wal.is_msw(): fontsize = -1 label = wal.Label(self, txt, fontsize=fontsize) label.set_enable(False) if wal.is_msw():label.wrap(430) panel.pack(label, fill=True, padding_all=5) self.pack(panel, fill=True, expand=True)
def build(self): grid = wal.GridPanel(self, 1, 3, 2, 2) grid.pack(wal.Label(grid, _('Angle:'))) self.angle = AngleSpin(grid, val_range=(-360.0, 360.0), check_focus=True) grid.pack(self.angle) grid.pack(wal.Label(grid, _('degrees'))) self.pack(grid, align_center=False, padding=5) self.pack(wal.Label(grid, _('Center:')), align_center=False, padding=5) grid = wal.GridPanel(self, 2, 3, 2, 2) grid.pack(get_bmp(grid, make_artid('h-sign'))) self.h_spin = UnitSpin(self.app, grid, can_be_negative=True) grid.pack(self.h_spin) grid.pack(UnitLabel(self.app, grid)) grid.pack(get_bmp(grid, make_artid('v-sign'))) self.v_spin = UnitSpin(self.app, grid, can_be_negative=True) grid.pack(self.v_spin) grid.pack(UnitLabel(self.app, grid)) self.pack(grid, align_center=False, padding_all=5) self.center = wal.Checkbox(self, _('Relative center'), onclick=self.on_click) self.pack(self.center, align_center=False, padding=5) self.active_widgets = [self.angle, self.center] self.on_click()
def save_selected(self, doc_file): doc = SK2_Presenter(self.app.appdata) origin = self.doc_presenter.model.doc_origin doc.methods.set_doc_origin(origin) doc_units = self.doc_presenter.model.doc_units doc.methods.set_doc_units(doc_units) page = doc.methods.get_page() page_format = deepcopy(self.active_page.page_format) doc.methods.set_page_format(page, page_format) objs = [] for item in self.selection.objs: objs.append(item.copy()) layer = doc.methods.get_layer(page) layer.childs = objs saver = get_saver(doc_file) if saver is None: doc.close() raise IOError(_('Unknown file format is requested for saving!'), doc_file) pd = ProgressDialog(_('Saving file...'), self.app.mw) ret = pd.run(saver, [doc, doc_file], False) if ret: if not pd.error_info is None: pd.destroy() doc.close() raise IOError(*pd.error_info) pd.destroy() doc.close() else: pd.destroy() doc.close() raise IOError(_('Error while saving'), doc_file)
def __init__(self, app, parent): wal.VPanel.__init__(self, parent) data = [[_('Component'), _('Version')]] + app.appdata.components slist = wal.ReportList(self, data, border=False, odd_color=wal.YELLOW_ODD_COLOR) self.pack(slist, expand=True, fill=True) slist.set_column_width(0, const.LIST_AUTOSIZE)
def save_selected(self): doc_file = '' + self.current_doc.doc_file if not doc_file: doc_file = '' + self.current_doc.doc_name if not os.path.splitext(doc_file)[1] == "." + \ uc2const.FORMAT_EXTENSION[uc2const.SK2][0]: doc_file = os.path.splitext(doc_file)[0] + "." + \ uc2const.FORMAT_EXTENSION[uc2const.SK2][0] if not os.path.lexists(os.path.dirname(doc_file)): doc_file = os.path.join(config.save_dir, os.path.basename(doc_file)) doc_file = dialogs.get_save_file_name(self.mw, self, doc_file, _('Save selected objects only as...'), path_only=True) if doc_file: try: self.make_backup(doc_file) self.current_doc.save_selected(doc_file) self.history.add_entry(doc_file, appconst.SAVED) except: first = _('Cannot save document:') msg = ("%s\n'%s'.") % (first, doc_file) + '\n' msg += _('Please check requested file format and write permissions') dialogs.error_dialog(self.mw, self.appdata.app_name, msg) self.print_stacktrace()
def __init__(self, parent, dlg, cms, pattern_def, onchange=None): self.dlg = dlg self.app = dlg.app self.cms = cms self.pattern_def = deepcopy(pattern_def) self.callback = onchange wal.HPanel.__init__(self, parent) left_panel = wal.VPanel(self) self.pattern_swatch = PatternSwatch(left_panel, self.cms, pattern_def) left_panel.pack(self.pattern_swatch) button_panel = wal.HPanel(left_panel) txt = _('Load pattern from file') button_panel.pack(wal.ImageButton(self, icons.PD_OPEN, wal.SIZE_16, tooltip=txt, flat=False, onclick=self.load_pattern), padding=1) txt = _('Save pattern into file') button_panel.pack(wal.ImageButton(self, icons.PD_FILE_SAVE, wal.SIZE_16, tooltip=txt, flat=False, onclick=self.save_pattern), padding=1) left_panel.pack(button_panel, padding=2) self.pack(left_panel, fill=True) right_panel = wal.VPanel(self) self.pattern_color_editor = PatternColorEditor(right_panel, dlg, cms, pattern_def[2], onchange=self.color_changed) right_panel.pack(self.pattern_color_editor, padding=5) self.trafo_editor = PatternTrafoEditor(right_panel, dlg.app, onchange=self.trafo_changed) right_panel.pack(self.trafo_editor, padding=5) self.pack(right_panel, fill=True, expand=True)
def build(self): grid = wal.GridPanel(self, 2, 5, 2, 2) grid.pack(get_bmp(grid, make_artid('h-sign'))) self.h_spin = wal.FloatSpin(grid, 100.0, (0.01, 10000.0), 1.0, onchange=self.on_reset) grid.pack(self.h_spin) grid.pack(wal.Label(grid, '%')) grid.pack((5, 5)) self.h_mirror = wal.ImageToggleButton(grid, False, make_artid('h-mirror'), tooltip=_('Horizontal mirror'), flat=False) grid.pack(self.h_mirror) grid.pack(get_bmp(grid, make_artid('v-sign'))) self.v_spin = wal.FloatSpin(grid, 100.0, (0.01, 10000.0), 1.0, onchange=self.height_changed) grid.pack(self.v_spin) grid.pack(wal.Label(grid, '%')) grid.pack((5, 5)) self.v_mirror = wal.ImageToggleButton(grid, False, make_artid('v-mirror'), tooltip=_('Vertical mirror'), flat=False) grid.pack(self.v_mirror) self.pack(grid, align_center=False, padding=5) self.proportion = wal.Checkbox(self, _('Keep ratio'), True) self.pack(self.proportion, align_center=False, padding=5) self.active_widgets = [self.h_spin, self.h_mirror, self.v_spin, self.v_mirror, self.proportion]
def update_points(self): self.start_point = ControlPoint(self.canvas, self.target, True) self.end_point = ControlPoint(self.canvas, self.target) msg = _('Ellipse in editing') events.emit(events.APP_STATUS, msg)
def open_url(self, url): webbrowser.open(url, new=1, autoraise=True) msg = _('Requested page was opened in the default browser') events.emit(events.APP_STATUS, msg)
def new(self): doc = SK1Presenter(self) self.docs.append(doc) self.set_current_doc(doc) events.emit(events.APP_STATUS, _('New document created'))
def get_new_docname(self): self.doc_counter += 1 doc_name = '%s %d' % (_('Untitled'), self.doc_counter) return doc_name
class LayersPlugin(RsPlugin): pid = 'LayersPlugin' name = _('Layers') active_panel = None panels = {} select_idx = None layer_new = None layer_to_bottom = None layer_lower = None layer_raise = None layer_to_top = None layer_delete = None layer_edit = None viewer = None def build_ui(self): self.icon = get_icon(PLUGIN_ICON) self.panel.pack(wal.Label(self.panel, _('Layers'), fontbold=True), padding=3) self.panel.pack(wal.HLine(self.panel), fill=True) pnl = wal.HPanel(self.panel) self.layer_new = wal.ImageButton(pnl, icons.PD_LAYER_NEW, tooltip=_('Create new layer'), onclick=self.new_layer) self.layer_to_bottom = wal.ImageButton( pnl, icons.PD_LOWER_TO_BOTTOM, tooltip=_('Layer to bottom'), onclick=self.lower_layer_to_bottom) self.layer_lower = wal.ImageButton(pnl, icons.PD_LOWER, tooltip=_('Lower layer'), onclick=self.lower_layer) self.layer_raise = wal.ImageButton(pnl, icons.PD_RAISE, tooltip=_('Raise layer'), onclick=self.raise_layer) self.layer_to_top = wal.ImageButton(pnl, icons.PD_RAISE_TO_TOP, tooltip=_('Layer to top'), onclick=self.raise_layer_to_top) self.layer_delete = wal.ImageButton(pnl, icons.PD_LAYER_DELETE, tooltip=_('Delete layer'), onclick=self.delete_layer) self.layer_edit = wal.ImageButton(pnl, icons.PD_EDIT, tooltip=_('Rename layer'), onclick=self.rename_layer) pnl.pack(self.layer_new) pnl.pack(self.layer_to_bottom) pnl.pack(self.layer_lower) pnl.pack(self.layer_raise) pnl.pack(self.layer_to_top) pnl.pack(self.layer_delete) pnl.pack(self.layer_edit) self.panel.pack(pnl) bmp = [make_artid(item) for item in BITMAPS] pnl = wal.VPanel(self.panel, border=True) self.viewer = wal.LayerList(pnl, self.get_data(), bmp, on_select=self.update, on_change=self.changed, on_double_click=self.rename_layer) pnl.pack(self.viewer, fill=True, expand=True) self.panel.pack(pnl, padding_all=3, fill=True, expand=True) events.connect(events.DOC_CHANGED, self.update) events.connect(events.DOC_MODIFIED, self.update) self.update() def get_data(self): doc = self.app.current_doc if not doc: return [] result = [] for layer in doc.get_layers(): props = [] if doc.active_layer == layer: props.append(1) else: props.append(0) for item in layer.properties: props.append(item) props.append(layer.name) result.append(props) result.reverse() return result def get_selected_index(self): doc = self.app.current_doc layers = doc.get_layers() return len(layers) - self.viewer.get_selected() - 1 def get_selected_layer(self): doc = self.app.current_doc layers = doc.get_layers() index = len(layers) - self.viewer.get_selected() - 1 return layers[index] def get_layer_index(self, layer): doc = self.app.current_doc layers = doc.get_layers() index = layers.index(layer) return len(layers) - index - 1 def changed(self, item, col): doc = self.app.current_doc layers = doc.get_layers() index = self.get_selected_index() if not col: if not layers[index] == doc.active_layer: doc.api.set_active_layer(layers[index]) elif col < 5: layer = layers[index] if col < 3 and layer == doc.active_layer: flag = False for item in layers: if item.properties[0] and item.properties[1] and not \ layer == item: doc.api.set_active_layer(item) flag = True if not flag: return props = [] + layer.properties props[col - 1] = abs(props[col - 1] - 1) doc.api.set_layer_properties(layer, props) def new_layer(self): self.app.current_doc.api.create_layer() def delete_layer(self): doc = self.app.current_doc layers = doc.get_layers() indx = self.get_selected_index() doc.api.delete_layer(layers[indx]) self.viewer.set_selected(0) def raise_layer(self): layer = self.get_selected_layer() self.app.current_doc.api.layer_raise(layer) self.viewer.set_selected(self.get_layer_index(layer)) self.update() def raise_layer_to_top(self): layer = self.get_selected_layer() self.app.current_doc.api.layer_to_top(layer) self.viewer.set_selected(self.get_layer_index(layer)) self.update() def lower_layer(self): layer = self.get_selected_layer() self.app.current_doc.api.layer_lower(layer) self.viewer.set_selected(self.get_layer_index(layer)) self.update() def lower_layer_to_bottom(self): layer = self.get_selected_layer() self.app.current_doc.api.layer_to_bottom(layer) self.viewer.set_selected(self.get_layer_index(layer)) self.update() def rename_layer(self): layer = self.get_selected_layer() txt = edit_dlg(self.app.mw, _('Rename layer'), layer.name) if txt is not None and not layer.name == txt: self.app.current_doc.api.set_layer_name(layer, txt) def update(self, *args): doc = self.app.current_doc if doc: layers = doc.get_layers() lnums = len(layers) self.viewer.update(self.get_data()) sel_idx = self.viewer.get_selected() if sel_idx is None: self.viewer.set_selected(0) sel_idx = 0 sel_layer = self.get_selected_layer() self.layer_to_bottom.set_enable(sel_idx < lnums - 1) self.layer_lower.set_enable(sel_idx < lnums - 1) self.layer_raise.set_enable(sel_idx > 0) self.layer_to_top.set_enable(sel_idx > 0) self.layer_delete.set_enable(not sel_layer == doc.active_layer) def show_signal(self, *args): self.update()
class CmsProfiles(CmsTab): name = _('Color profiles') def __init__(self, parent, prefpanel): CmsTab.__init__(self, parent, prefpanel) txt = _('Color space profiles') self.pack(wal.Label(self, txt, fontbold=True), padding=2) self.pack(wal.HLine(self), fill=True, padding_all=2) grid = wal.GridPanel(self, rows=10, cols=3, hgap=5, vgap=5) grid.add_growable_col(1) self.cs_widgets = {} self.cs_profiles = {} self.cs_config_profiles = {} self.cs_config = {COLOR_RGB: config.cms_rgb_profile, COLOR_CMYK: config.cms_cmyk_profile, COLOR_LAB: config.cms_lab_profile, COLOR_GRAY: config.cms_gray_profile, COLOR_DISPLAY: config.cms_display_profile} for colorspace in COLORSPACES[:-1]: txt = _('%s profile:') % colorspace grid.pack(wal.Label(grid, txt)) combo = wal.Combolist(grid, items=[]) self.cs_widgets[colorspace] = combo grid.pack(combo, fill=True) self.update_combo(colorspace) grid.pack(ManageButton(grid, self, colorspace)) self.pack(grid, fill=True, padding_all=5) txt = _('Hardware profiles') self.pack(wal.Label(self, txt, fontbold=True), padding=2) self.pack(wal.HLine(self), fill=True, padding_all=2) grid = wal.GridPanel(self, cols=3, hgap=5, vgap=5) grid.add_growable_col(1) txt = _('Display profile:') grid.pack(wal.Label(grid, txt)) combo = wal.Combolist(grid, items=[]) self.cs_widgets[COLOR_DISPLAY] = combo grid.pack(combo, fill=True) self.update_combo(COLOR_DISPLAY) grid.pack(ManageButton(grid, self, COLOR_DISPLAY)) self.pack(grid, fill=True, padding_all=5) txt = _('Use display profile') self.display_check = wal.Checkbox(self, txt, config.cms_use_display_profile, onclick=self.activate_display) self.pack(self.display_check, align_center=False) self.pack(wal.HLine(self), fill=True, padding_all=2) txt = _('Note: Display profile for your hardware can be found here:') label = wal.Label(self, txt, fontsize=-1) self.pack(label, fill=True, padding_all=5) self.pack(wal.HyperlinkLabel(self, 'https://icc.opensuse.org/')) self.activate_display() def activate_display(self): combo = self.cs_widgets[COLOR_DISPLAY] combo.set_enable(self.display_check.get_value()) def update_config_data(self, colorspace): if colorspace == COLOR_RGB: self.cs_config_profiles[colorspace] = config.cms_rgb_profiles.copy() elif colorspace == COLOR_CMYK: self.cs_config_profiles[ colorspace] = config.cms_cmyk_profiles.copy() elif colorspace == COLOR_LAB: self.cs_config_profiles[colorspace] = config.cms_lab_profiles.copy() elif colorspace == COLOR_GRAY: self.cs_config_profiles[ colorspace] = config.cms_gray_profiles.copy() else: self.cs_config_profiles[ colorspace] = config.cms_display_profiles.copy() self.cs_profiles[colorspace] = self.get_profile_names(colorspace) def update_combo(self, colorspace, set_active=True): self.update_config_data(colorspace) combo = self.cs_widgets[colorspace] combo.set_items(self.cs_profiles[colorspace]) if not set_active: return self.set_active_profile(combo, self.cs_config[colorspace], colorspace) def set_active_profile(self, widget, name, colorspace): profiles = self.get_profile_names(colorspace) if not name: widget.set_active(0) elif name not in profiles: widget.set_active(0) if colorspace == COLOR_RGB: config.cms_rgb_profile = '' elif colorspace == COLOR_CMYK: config.cms_cmyk_profile = '' elif colorspace == COLOR_LAB: config.cms_lab_profile = '' elif colorspace == COLOR_GRAY: config.cms_gray_profile = '' else: config.cms_display_profile = '' else: widget.set_active(profiles.index(name)) def get_profile_names(self, colorspace): names = [] default = _('Built-in %s profile') % colorspace names.append(default) names += self.cs_config_profiles[colorspace].keys() return names def apply_changes(self): for colorspace in COLORSPACES: profiles = self.get_profile_names(colorspace) combo = self.cs_widgets[colorspace] index = combo.get_active() profile_name = '' if index: profile_name = profiles[index] if colorspace == COLOR_RGB: config.cms_rgb_profile = profile_name elif colorspace == COLOR_CMYK: config.cms_cmyk_profile = profile_name elif colorspace == COLOR_LAB: config.cms_lab_profile = profile_name elif colorspace == COLOR_GRAY: config.cms_gray_profile = profile_name else: config.cms_display_profile = profile_name config.cms_use_display_profile = self.display_check.get_value() def restore_defaults(self): for item in COLORSPACES: self.cs_config[item] = '' self.update_combo(item) defaults = config.get_defaults() self.display_check.set_value(defaults['cms_use_display_profile'])
def docprops_dlg(app, parent): title = _('Document properties') DocPropertiesDialog(app, parent, title).show()
def build(self): self.printsys = self.get_printsys() self.prn_list = self.printsys.get_printer_names() if self.prn_list: self.active_printer = self.printsys.get_default_printer() hpanel = wal.HPanel(self) hpanel.pack(wal.Label(hpanel, _('Printer:'))) hpanel.pack((5, 5)) self.prn_combo = wal.Combolist(hpanel, items=self.prn_list, onchange=self.set_data) hpanel.pack(self.prn_combo, fill=True, expand=True) index = self.prn_list.index(self.active_printer.get_name()) self.prn_combo.set_active(index) self.pack(hpanel, fill=True, padding_all=5) self.pack((10, 10)) # ---Panels self.insp = self.app.insp units = uc2const.UNIT_MM if self.insp.is_doc(): units = self.app.current_doc.model.doc_units units_text = uc2const.unit_short_names[units] # ---Shift panel shifts = self.active_printer.shifts hpanel = wal.HPanel(self) txt = _('Printing shift') + ' (%s)' % units_text spanel = wal.LabeledPanel(hpanel, text=txt) spanel.pack((1, 1), expand=True) grid = wal.GridPanel(spanel, 2, 2, 5, 5) grid.pack(wal.Label(grid, _('Horizontal shift:'))) self.hshift = StaticUnitSpin(self.app, grid, shifts[0], can_be_negative=True, onchange=self.save_data, onenter=self.save_data) grid.pack(self.hshift) grid.pack(wal.Label(grid, _('Vertical shift:'))) self.vshift = StaticUnitSpin(self.app, grid, shifts[1], can_be_negative=True, onchange=self.save_data, onenter=self.save_data) grid.pack(self.vshift) spanel.pack(grid, padding_all=5) spanel.pack((1, 1), expand=True) hpanel.pack(spanel, fill=True, expand=True) hpanel.pack((5, 5)) # ---Margin panel txt = _('Printing margins') + ' (%s)' % units_text mpanel = wal.LabeledPanel(hpanel, text=txt) mpanel.pack((5, 5)) mrgs = self.active_printer.margins self.top_spin = StaticUnitSpin(self.app, mpanel, mrgs[0], onchange=self.save_data, onenter=self.save_data) mpanel.pack(self.top_spin) mpanel.pack((5, 5)) hp = wal.HPanel(self) self.left_spin = StaticUnitSpin(self.app, hp, mrgs[3], onchange=self.save_data, onenter=self.save_data) hp.pack(self.left_spin) hp.pack((5, 5)) self.right_spin = StaticUnitSpin(self.app, hp, mrgs[1], onchange=self.save_data, onenter=self.save_data) hp.pack(self.right_spin) mpanel.pack(hp) mpanel.pack((5, 5)) self.bottom_spin = StaticUnitSpin(self.app, mpanel, mrgs[2], onchange=self.save_data, onenter=self.save_data) mpanel.pack(self.bottom_spin) mpanel.pack((10, 10)) # --- hpanel.pack(mpanel, fill=True, expand=True) self.pack(hpanel, fill=True) self.pack((10, 10)) # ---Calibration page text = _("To measure real print area and vertical/horizontal " "printing shift just print calibration page on the " "A4/Letter sheet.") label = wal.Label(self, text) label.wrap(470) self.pack(label, fill=True, padding_all=5, align_center=False) self.a4_calibrate_btn = wal.Button( self, _('Print A4 calibration page'), onclick=self.print_calibration_a4) self.pack(self.a4_calibrate_btn) self.pack((5, 5)) self.letter_calibrate_btn = wal.Button( self, _('Print Letter calibration page'), onclick=self.print_calibration_letter) self.pack(self.letter_calibrate_btn) self.pack((5, 5)) else: self.pack((5, 5), expand=True) self.pack(get_bmp(self, icons.PD_NO_PRINTERS), padding=10) self.pack(wal.Label(self, _('Cannot found installed printers!'))) self.pack((10, 10)) self.pack((5, 5), expand=True) self.built = True
class PrinterPrefs(PrefPanel): pid = 'Printers' name = _('Printers') title = _('Printer preferences') icon_id = icons.PD_PREFS_PRINTERS printsys = None active_printer = None prn_list = [] prn_combo = None insp = None hshift = None vshift = None top_spin = None left_spin = None right_spin = None bottom_spin = None a4_calibrate_btn = None letter_calibrate_btn = None def __init__(self, app, dlg, *args): PrefPanel.__init__(self, app, dlg) def get_printsys(self): if wal.IS_MSW: from sk1.printing.msw_print import MSW_PS return MSW_PS(self.app, physical_only=True) else: from sk1.printing.cups_print import CUPS_PS return CUPS_PS(physical_only=True) def build(self): self.printsys = self.get_printsys() self.prn_list = self.printsys.get_printer_names() if self.prn_list: self.active_printer = self.printsys.get_default_printer() hpanel = wal.HPanel(self) hpanel.pack(wal.Label(hpanel, _('Printer:'))) hpanel.pack((5, 5)) self.prn_combo = wal.Combolist(hpanel, items=self.prn_list, onchange=self.set_data) hpanel.pack(self.prn_combo, fill=True, expand=True) index = self.prn_list.index(self.active_printer.get_name()) self.prn_combo.set_active(index) self.pack(hpanel, fill=True, padding_all=5) self.pack((10, 10)) # ---Panels self.insp = self.app.insp units = uc2const.UNIT_MM if self.insp.is_doc(): units = self.app.current_doc.model.doc_units units_text = uc2const.unit_short_names[units] # ---Shift panel shifts = self.active_printer.shifts hpanel = wal.HPanel(self) txt = _('Printing shift') + ' (%s)' % units_text spanel = wal.LabeledPanel(hpanel, text=txt) spanel.pack((1, 1), expand=True) grid = wal.GridPanel(spanel, 2, 2, 5, 5) grid.pack(wal.Label(grid, _('Horizontal shift:'))) self.hshift = StaticUnitSpin(self.app, grid, shifts[0], can_be_negative=True, onchange=self.save_data, onenter=self.save_data) grid.pack(self.hshift) grid.pack(wal.Label(grid, _('Vertical shift:'))) self.vshift = StaticUnitSpin(self.app, grid, shifts[1], can_be_negative=True, onchange=self.save_data, onenter=self.save_data) grid.pack(self.vshift) spanel.pack(grid, padding_all=5) spanel.pack((1, 1), expand=True) hpanel.pack(spanel, fill=True, expand=True) hpanel.pack((5, 5)) # ---Margin panel txt = _('Printing margins') + ' (%s)' % units_text mpanel = wal.LabeledPanel(hpanel, text=txt) mpanel.pack((5, 5)) mrgs = self.active_printer.margins self.top_spin = StaticUnitSpin(self.app, mpanel, mrgs[0], onchange=self.save_data, onenter=self.save_data) mpanel.pack(self.top_spin) mpanel.pack((5, 5)) hp = wal.HPanel(self) self.left_spin = StaticUnitSpin(self.app, hp, mrgs[3], onchange=self.save_data, onenter=self.save_data) hp.pack(self.left_spin) hp.pack((5, 5)) self.right_spin = StaticUnitSpin(self.app, hp, mrgs[1], onchange=self.save_data, onenter=self.save_data) hp.pack(self.right_spin) mpanel.pack(hp) mpanel.pack((5, 5)) self.bottom_spin = StaticUnitSpin(self.app, mpanel, mrgs[2], onchange=self.save_data, onenter=self.save_data) mpanel.pack(self.bottom_spin) mpanel.pack((10, 10)) # --- hpanel.pack(mpanel, fill=True, expand=True) self.pack(hpanel, fill=True) self.pack((10, 10)) # ---Calibration page text = _("To measure real print area and vertical/horizontal " "printing shift just print calibration page on the " "A4/Letter sheet.") label = wal.Label(self, text) label.wrap(470) self.pack(label, fill=True, padding_all=5, align_center=False) self.a4_calibrate_btn = wal.Button( self, _('Print A4 calibration page'), onclick=self.print_calibration_a4) self.pack(self.a4_calibrate_btn) self.pack((5, 5)) self.letter_calibrate_btn = wal.Button( self, _('Print Letter calibration page'), onclick=self.print_calibration_letter) self.pack(self.letter_calibrate_btn) self.pack((5, 5)) else: self.pack((5, 5), expand=True) self.pack(get_bmp(self, icons.PD_NO_PRINTERS), padding=10) self.pack(wal.Label(self, _('Cannot found installed printers!'))) self.pack((10, 10)) self.pack((5, 5), expand=True) self.built = True def set_data(self): name = self.prn_combo.get_active_value() self.active_printer = self.printsys.get_printer_by_name(name) shifts = self.active_printer.shifts mrgs = self.active_printer.margins self.hshift.set_point_value(shifts[0]) self.vshift.set_point_value(shifts[1]) self.top_spin.set_point_value(mrgs[0]) self.right_spin.set_point_value(mrgs[1]) self.bottom_spin.set_point_value(mrgs[2]) self.left_spin.set_point_value(mrgs[3]) def save_data(self): self.active_printer.shifts = (self.hshift.get_point_value(), self.vshift.get_point_value()) self.active_printer.margins = (self.top_spin.get_point_value(), self.right_spin.get_point_value(), self.bottom_spin.get_point_value(), self.left_spin.get_point_value()) def apply_changes(self): if not self.prn_list: return config.printer_config = {} for name in self.prn_list: printer = self.printsys.get_printer_by_name(name) if printer: printer.save_config() def restore_defaults(self): if not self.prn_list: return self.active_printer.shifts = STD_SHIFTS self.active_printer.margins = STD_MARGINS self.set_data() def print_calibration_a4(self): self.active_printer.print_test_page_a4(self.app, self.dlg) def print_calibration_letter(self): self.active_printer.print_test_page_letter(self.app, self.dlg)
class GeneralPrefs(PrefPanel): pid = 'General' name = _('General') title = _('General application preferences') icon_id = icons.PD_PREFS_GENERAL newdoc = None backup = None expbackup = None hist_size = None hist_menu_size = None log_level = None fcache = None server = None def __init__(self, app, dlg, *_args): PrefPanel.__init__(self, app, dlg) def build(self): table = wal.GridPanel(self, rows=8, cols=2, hgap=25, vgap=7) txt = _('New document on start') table.pack(wal.Label(table, txt)) self.newdoc = wal.Switch(table, config.new_doc_on_start) table.pack(self.newdoc) txt = _('Backup on document save') table.pack(wal.Label(table, txt)) self.backup = wal.Switch(table, config.make_backup) table.pack(self.backup) txt = _('Backup on export') table.pack(wal.Label(table, txt)) self.expbackup = wal.Switch(table, config.make_export_backup) table.pack(self.expbackup) txt = _('Make font cache on start') table.pack(wal.Label(table, txt)) self.fcache = wal.Switch(table, config.make_font_cache_on_start) table.pack(self.fcache) txt = _('Run as server') table.pack(wal.Label(table, txt)) self.server = wal.Switch(table, config.app_server) table.pack(self.server) txt = _('History log size:') table.pack(wal.Label(table, txt)) self.hist_size = wal.IntSpin(table, config.history_size, (10, 1000)) table.pack(self.hist_size) txt = _('History menu size:') table.pack(wal.Label(table, txt)) self.hist_menu_size = wal.IntSpin( table, config.history_list_size, (5, 20)) table.pack(self.hist_menu_size) txt = _('Logging level (*):') table.pack(wal.Label(table, txt)) self.log_level = wal.Combolist(table, items=LEVELS) self.log_level.set_active(LEVELS.index(config.log_level)) table.pack(self.log_level) self.pack(table) self.pack((1, 1), expand=True) txt = _('(*) - Application restart is required to apply these options') self.pack(wal.Label(self, txt, fontsize=-1)) self.built = True def apply_changes(self): config.new_doc_on_start = self.newdoc.get_value() config.make_backup = self.backup.get_value() config.make_export_backup = self.expbackup.get_value() config.app_server = self.server.get_value() config.history_size = self.hist_size.get_value() config.history_list_size = self.hist_menu_size.get_value() config.log_level = self.log_level.get_active_value() config.make_font_cache_on_start = self.fcache.get_value() def restore_defaults(self): defaults = config.get_defaults() self.newdoc.set_value(defaults['new_doc_on_start']) self.backup.set_value(defaults['make_backup']) self.expbackup.set_value(defaults['make_export_backup']) self.server.set_value(defaults['app_server']) self.hist_size.set_value(defaults['history_size']) self.hist_menu_size.set_value(defaults['history_list_size']) self.log_level.set_active(LEVELS.index(defaults['log_level'])) self.fcache.set_value(defaults['make_font_cache_on_start'])
def __init__(self, parent, app, onchange=None): self.app = app self.callback = onchange wal.VPanel.__init__(self, parent) self.pack(wal.Label(self, _('Transformation matrix:')), padding=5) grid = wal.GridPanel(self, 3, 5, 3, 1) # ---M11 grid.pack(wal.Label(grid, 'm11:')) self.m11 = wal.FloatSpin(grid, range_val=(-1000000.0, 1000000.0), step=0.01, onchange=self.changes, onenter=self.changes) grid.pack(self.m11) grid.pack((5, 5)) # ---M12 grid.pack(wal.Label(grid, 'm12:')) self.m12 = wal.FloatSpin(grid, range_val=(-1000000.0, 1000000.0), step=0.01, onchange=self.changes, onenter=self.changes) grid.pack(self.m12) # ---M21 grid.pack(wal.Label(grid, 'm21:')) self.m21 = wal.FloatSpin(grid, range_val=(-1000000.0, 1000000.0), step=0.01, onchange=self.changes, onenter=self.changes) grid.pack(self.m21) grid.pack((5, 5)) # ---M22 grid.pack(wal.Label(grid, 'm22:')) self.m22 = wal.FloatSpin(grid, range_val=(-1000000.0, 1000000.0), step=0.01, onchange=self.changes, onenter=self.changes) grid.pack(self.m22) # ---dx grid.pack(wal.Label(grid, 'dx:')) self.dx = wal.FloatSpin(grid, range_val=(-1000000.0, 1000000.0), step=0.01, onchange=self.changes, onenter=self.changes) grid.pack(self.dx) grid.pack((5, 5)) # ---dy grid.pack(wal.Label(grid, 'dy:')) self.dy = wal.FloatSpin(grid, range_val=(-1000000.0, 1000000.0), step=0.01, onchange=self.changes, onenter=self.changes) grid.pack(self.dy) self.pack(grid)
def __init__(self, parent, app, trafo=[] + sk2const.NORMAL_TRAFO, transforms=[] + sk2const.PATTERN_TRANSFORMS, onchange=None): self.app = app self.callback = onchange wal.VPanel.__init__(self, parent) grid = wal.GridPanel(self, 3, 7, 3, 2) # ---Origin X txt = _('Horizontal origin shift') grid.pack(get_bmp(grid, icons.PD_PATTERN_ORIGIN_X, txt)) self.origin_x = UnitSpin(app, grid, can_be_negative=True, onchange=self.changes, onenter=self.changes) grid.pack(self.origin_x) grid.pack(StaticUnitLabel(app, grid)) grid.pack((10, 5)) # ---Origin Y txt = _('Vertical origin shift') grid.pack(get_bmp(grid, icons.PD_PATTERN_ORIGIN_Y, txt)) self.origin_y = UnitSpin(app, grid, can_be_negative=True, onchange=self.changes, onenter=self.changes) grid.pack(self.origin_y) grid.pack(StaticUnitLabel(app, grid)) # ---Scale X txt = _('Scale horizontally') grid.pack(get_bmp(grid, icons.PD_PATTERN_SCALE_X, txt)) self.scale_x = wal.FloatSpin(grid, range_val=(-1000000.0, 1000000.0), step=1.0, onchange=self.changes, onenter=self.changes) grid.pack(self.scale_x) grid.pack(wal.Label(grid, '%')) grid.pack((10, 5)) # ---Scale Y txt = _('Scale vertically') grid.pack(get_bmp(grid, icons.PD_PATTERN_SCALE_Y, txt)) self.scale_y = wal.FloatSpin(grid, range_val=(-1000000.0, 1000000.0), step=1.0, onchange=self.changes, onenter=self.changes) grid.pack(self.scale_y) grid.pack(wal.Label(grid, '%')) # ---Shear X txt = _('Shear horizontally') grid.pack(get_bmp(grid, icons.PD_PATTERN_SHEAR_X, txt)) self.shear_x = wal.FloatSpin(grid, range_val=(0.0, 85.0), step=1.0, onchange=self.changes, onenter=self.changes) grid.pack(self.shear_x) grid.pack(wal.Label(grid, u'°')) grid.pack((10, 5)) # ---Shear X txt = _('Shear vertically') grid.pack(get_bmp(grid, icons.PD_PATTERN_SHEAR_Y, txt)) self.shear_y = wal.FloatSpin(grid, range_val=(0.0, 85.0), step=1.0, onchange=self.changes, onenter=self.changes) grid.pack(self.shear_y) grid.pack(wal.Label(grid, u'°')) self.pack(grid) # ---Rotate rot_panel = wal.HPanel(self) txt = _('Rotate pattern') rot_panel.pack(get_bmp(rot_panel, icons.PD_PATTERN_ROTATE, txt)) self.rotate = wal.FloatSpin(rot_panel, range_val=(-360.0, 360.0), step=1.0, onchange=self.changes, onenter=self.changes) rot_panel.pack(self.rotate, padding=3) rot_panel.pack(wal.Label(rot_panel, u'°')) self.pack(rot_panel, padding=5) self.set_trafo(trafo, transforms)
class GridProps(DP_Panel): name = _('Grid') geom = [] color = [] def build(self): self.pack((5, 5)) self.geom = self.doc.methods.get_grid_values() hpanel = wal.HPanel(self) txt = _('Grid origin') origin_panel = wal.LabeledPanel(hpanel, text=txt) grid = wal.GridPanel(origin_panel, 2, 3, 5, 5) grid.pack(wal.Label(grid, 'X:')) self.x_val = UnitSpin(self.app, grid, self.geom[0]) grid.pack(self.x_val) grid.pack(StaticUnitLabel(self.app, grid)) grid.pack(wal.Label(grid, 'Y:')) self.y_val = UnitSpin(self.app, grid, self.geom[1]) grid.pack(self.y_val) grid.pack(StaticUnitLabel(self.app, grid)) origin_panel.pack(grid, padding_all=5) hpanel.pack(origin_panel, padding_all=5, fill=True, expand=True) txt = _('Grid frequency') freq_panel = wal.LabeledPanel(hpanel, text=txt) grid = wal.GridPanel(origin_panel, 2, 3, 5, 5) grid.pack(wal.Label(grid, 'dX:')) self.dx_val = UnitSpin(self.app, grid, self.geom[2]) grid.pack(self.dx_val) grid.pack(StaticUnitLabel(self.app, grid)) grid.pack(wal.Label(grid, 'dY:')) self.dy_val = UnitSpin(self.app, grid, self.geom[3]) grid.pack(self.dy_val) grid.pack(StaticUnitLabel(self.app, grid)) freq_panel.pack(grid, padding_all=5) hpanel.pack(freq_panel, padding_all=5, fill=True, expand=True) self.pack(hpanel, fill=True) self.pack((5, 5)) color_panel = wal.HPanel(self) color_panel.pack((10, 10)) vpanel = wal.VPanel(color_panel) hpanel = wal.HPanel(vpanel) hpanel.pack(wal.Label(hpanel, _('Grid color:'))) hpanel.pack((10, 5)) self.color = self.doc.methods.get_grid_rgba_color() self.grid_color_btn = wal.ColorButton(hpanel, self.color[:3], onchange=self.on_change) hpanel.pack(self.grid_color_btn) vpanel.pack(hpanel, fill=True) hpanel = wal.HPanel(vpanel) hpanel.pack(wal.Label(hpanel, _('Grid opacity:'))) hpanel.pack((10, 5)) self.alpha_spin = wal.FloatSpin(hpanel, self.color[3] * 100.0, range_val=(0.0, 100.0), width=5, onchange=self.on_spin_change, onenter=self.on_spin_change) hpanel.pack(self.alpha_spin) hpanel.pack(wal.Label(hpanel, '%'), padding=3) vpanel.pack(hpanel, fill=True, padding=5) self.alpha_slider = wal.Slider(vpanel, int(self.color[3] * 100.0), range_val=(0, 100), onchange=self.on_slider_change) vpanel.pack(self.alpha_slider, fill=True, padding=5) val = self.doc.methods.is_grid_visible() self.show_grid_check = wal.Checkbox(vpanel, _('Show grid on canvas'), val) vpanel.pack(self.show_grid_check, fill=True, padding=5) color_panel.pack(vpanel) color_panel.pack((10, 10)) preview_panel = wal.VPanel(color_panel) preview_panel.pack(wal.Label(hpanel, _('Grid preview:'))) preview_panel.pack((5, 5)) self.grid_preview = GridPreview(preview_panel, self.color) preview_panel.pack(self.grid_preview, fill=True, expand=True) color_panel.pack(preview_panel, fill=True, expand=True) color_panel.pack((10, 10)) self.pack(color_panel, fill=True) def on_slider_change(self): self.alpha_spin.set_value(float(self.alpha_slider.get_value())) self.on_change() def on_spin_change(self): self.alpha_slider.set_value(int(self.alpha_spin.get_value())) self.on_change() def on_change(self): color = list(self.grid_color_btn.get_value()) color.append(self.alpha_spin.get_value() / 100.0) self.grid_preview.set_color(color) def save(self): geom = [ self.x_val.get_point_value(), self.y_val.get_point_value(), self.dx_val.get_point_value(), self.dy_val.get_point_value() ] if not self.geom == geom: self.api.set_grid_values(geom) color = list(self.grid_color_btn.get_value()) color.append(self.alpha_spin.get_value() / 100.0) if not self.color == color: self.api.set_grid_color(color) visibility = self.doc.methods.is_grid_visible() if not visibility == self.show_grid_check.get_value(): grid = self.doc.methods.get_grid_layer() props = self.doc.methods.get_grid_properties() props[0] = 0 if self.show_grid_check.get_value(): props[0] = 1 self.api.set_layer_properties(grid, props)
def build(self): self.pack((5, 5)) self.geom = self.doc.methods.get_grid_values() hpanel = wal.HPanel(self) txt = _('Grid origin') origin_panel = wal.LabeledPanel(hpanel, text=txt) grid = wal.GridPanel(origin_panel, 2, 3, 5, 5) grid.pack(wal.Label(grid, 'X:')) self.x_val = UnitSpin(self.app, grid, self.geom[0]) grid.pack(self.x_val) grid.pack(StaticUnitLabel(self.app, grid)) grid.pack(wal.Label(grid, 'Y:')) self.y_val = UnitSpin(self.app, grid, self.geom[1]) grid.pack(self.y_val) grid.pack(StaticUnitLabel(self.app, grid)) origin_panel.pack(grid, padding_all=5) hpanel.pack(origin_panel, padding_all=5, fill=True, expand=True) txt = _('Grid frequency') freq_panel = wal.LabeledPanel(hpanel, text=txt) grid = wal.GridPanel(origin_panel, 2, 3, 5, 5) grid.pack(wal.Label(grid, 'dX:')) self.dx_val = UnitSpin(self.app, grid, self.geom[2]) grid.pack(self.dx_val) grid.pack(StaticUnitLabel(self.app, grid)) grid.pack(wal.Label(grid, 'dY:')) self.dy_val = UnitSpin(self.app, grid, self.geom[3]) grid.pack(self.dy_val) grid.pack(StaticUnitLabel(self.app, grid)) freq_panel.pack(grid, padding_all=5) hpanel.pack(freq_panel, padding_all=5, fill=True, expand=True) self.pack(hpanel, fill=True) self.pack((5, 5)) color_panel = wal.HPanel(self) color_panel.pack((10, 10)) vpanel = wal.VPanel(color_panel) hpanel = wal.HPanel(vpanel) hpanel.pack(wal.Label(hpanel, _('Grid color:'))) hpanel.pack((10, 5)) self.color = self.doc.methods.get_grid_rgba_color() self.grid_color_btn = wal.ColorButton(hpanel, self.color[:3], onchange=self.on_change) hpanel.pack(self.grid_color_btn) vpanel.pack(hpanel, fill=True) hpanel = wal.HPanel(vpanel) hpanel.pack(wal.Label(hpanel, _('Grid opacity:'))) hpanel.pack((10, 5)) self.alpha_spin = wal.FloatSpin(hpanel, self.color[3] * 100.0, range_val=(0.0, 100.0), width=5, onchange=self.on_spin_change, onenter=self.on_spin_change) hpanel.pack(self.alpha_spin) hpanel.pack(wal.Label(hpanel, '%'), padding=3) vpanel.pack(hpanel, fill=True, padding=5) self.alpha_slider = wal.Slider(vpanel, int(self.color[3] * 100.0), range_val=(0, 100), onchange=self.on_slider_change) vpanel.pack(self.alpha_slider, fill=True, padding=5) val = self.doc.methods.is_grid_visible() self.show_grid_check = wal.Checkbox(vpanel, _('Show grid on canvas'), val) vpanel.pack(self.show_grid_check, fill=True, padding=5) color_panel.pack(vpanel) color_panel.pack((10, 10)) preview_panel = wal.VPanel(color_panel) preview_panel.pack(wal.Label(hpanel, _('Grid preview:'))) preview_panel.pack((5, 5)) self.grid_preview = GridPreview(preview_panel, self.color) preview_panel.pack(self.grid_preview, fill=True, expand=True) color_panel.pack(preview_panel, fill=True, expand=True) color_panel.pack((10, 10)) self.pack(color_panel, fill=True)
def save(self): metainfo = [ self.author_field.get_value(), self.license_field.get_value(), self.keys_field.get_value(), self.notes_field.get_value() ] if not self.metainfo == metainfo: if metainfo[3]: metainfo[3] = b64encode(metainfo[3]) self.api.set_doc_metainfo(metainfo) ORIENTS = [uc2const.PORTRAIT, uc2const.LANDSCAPE] ORIENTS_ICONS = [icons.CTX_PAGE_PORTRAIT, icons.CTX_PAGE_LANDSCAPE] ORIENTS_NAMES = [_('Portrait'), _('Landscape')] class PageProps(DP_Panel): name = _('Page') page_format = None desktop_bg = None page_fill = None border_flag = False def build(self): self.page_format = self.doc.methods.get_default_page_format() self.formats = [ _('Custom'), ] + uc2const.PAGE_FORMAT_NAMES
def build(self): self.page_format = self.doc.methods.get_default_page_format() self.formats = [ _('Custom'), ] + uc2const.PAGE_FORMAT_NAMES self.pack((5, 10)) #--- hpanel = wal.HPanel(self) hpanel.pack((5, 5)) label = wal.Label(hpanel, _('Default page:')) hpanel.pack(label) hpanel.pack((5, 5)) self.page_combo = wal.Combolist(self, items=self.formats, onchange=self.page_combo_changed) index = 0 state = True if self.page_format[0] in uc2const.PAGE_FORMAT_NAMES: index = self.formats.index(self.page_format[0]) state = False self.page_combo.set_active(index) hpanel.pack(self.page_combo) hpanel.pack((15, 5)) self.orient_keeper = wal.HToggleKeeper(self, ORIENTS, ORIENTS_ICONS, ORIENTS_NAMES, on_change=self.orient_changed) self.orient_keeper.set_mode(self.page_format[2]) hpanel.pack(self.orient_keeper) self.pack(hpanel, fill=True) self.pack((5, 5)) #--- w, h = self.page_format[1] hpanel = wal.HPanel(self) dx = label.get_size()[0] + 10 hpanel.pack((dx, 5)) self.page_width = UnitSpin(self.app, hpanel, w, onchange=self.page_spin_changed) hpanel.pack(self.page_width) hpanel.pack(get_bmp(self, icons.CTX_W_ON_H), padding=5) self.page_height = UnitSpin(self.app, hpanel, h, onchange=self.page_spin_changed) hpanel.pack(self.page_height) hpanel.pack(StaticUnitLabel(self.app, hpanel), padding=5) self.page_width.set_enable(state) self.page_height.set_enable(state) self.pack(hpanel, fill=True) self.pack(wal.HLine(self), padding_all=5, fill=True) #--- hpanel = wal.HPanel(self) hpanel.pack((5, 5)) self.desktop_bg = self.doc.methods.get_desktop_bg() grid = wal.GridPanel(hpanel, 3, 3, 5, 5) grid.add_growable_col(2) grid.pack(wal.Label(hpanel, _('Desktop:'))) self.desktop_color_btn = wal.ColorButton(hpanel, self.desktop_bg) grid.pack(self.desktop_color_btn) grid.pack(CBMiniPalette(grid, onclick=self.desktop_color_btn.set_value)) self.page_fill = self.doc.methods.get_page_fill() if self.page_fill[0] == FILL_SOLID: color1 = self.page_fill[1] color2 = [1.0, 1.0, 1.0] else: color1 = self.page_fill[1][0] color2 = self.page_fill[1][1] grid.pack(wal.Label(hpanel, _('Page:'))) self.page_color1_btn = wal.ColorButton(hpanel, color1) grid.pack(self.page_color1_btn) grid.pack(CBMiniPalette(grid, onclick=self.page_color1_btn.set_value)) grid.pack((5, 5)) self.page_color2_btn = wal.ColorButton(hpanel, color2) grid.pack(self.page_color2_btn) self.colors2 = CBMiniPalette(grid, onclick=self.page_color2_btn.set_value) grid.pack(self.colors2) if not self.page_fill[0] == FILL_PATTERN: self.page_color2_btn.set_enable(False) self.colors2.set_enable(False) hpanel.pack(grid, fill=True) hpanel.pack((5, 5)) self.pack(hpanel, fill=True) #--- vpanel = wal.VPanel(self) if wal.is_msw(): vpanel.pack((5, 5)) self.pattern_check = wal.Checkbox(vpanel, _('Use pattern for page fill'), self.page_fill[0] == FILL_PATTERN, onclick=self.pattern_check_changed) vpanel.pack(self.pattern_check, align_center=False) if wal.is_msw(): vpanel.pack((5, 5)) self.border_flag = self.doc.methods.get_page_border() self.border_check = wal.Checkbox(vpanel, _('Show page border'), self.border_flag) vpanel.pack(self.border_check, align_center=False) self.pack(vpanel, fill=True, padding_all=5)
# # 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/>. import wal from sk1 import _ TXT = _( """Dash pattern is a sequence (stroke-space-stroke-space- etc.) of integer or float values separated by space which describes size of pattern elements. The values are relative to line width. Example: '2 1' or '5 1 1 1'. Empty value means no dash, i.e. solid line.""") class DashEditorDialog(wal.OkCancelDialog): dash = None editor = None def __init__(self, parent, title, dash=None): dash = dash or [] self.dash = dash wal.OkCancelDialog.__init__(self, parent, title, style=wal.VERTICAL) def build(self): self.pack(wal.Label(self, TXT), align_center=False, padding_all=5)
def dash_editor_dlg(parent, dash): dlg = DashEditorDialog(parent, _('Edit dash pattern'), dash) return dlg.show()
def get_prefs_dialog(parent, pid=''): dlg = PrefsDialog(parent, _("sK1 Preferences"), pid) dlg.show() # PREFS_DATA.remove(PREFS_DATA[1]) PREFS_DATA.remove(PREFS_DATA[0])
class IconizerPlugin(RsPlugin): pid = 'IconizerPlugin' name = _('Iconizer') active_transform = None transforms = {} picture = None config = None bg_color_btn = None pallete = None viewer = None border_check = None sel_check = None apply_btn = None def build_ui(self): self.icon = get_icon(PLUGIN_ICON) self.config = IconizerConfig() config_dir = self.app.appdata.app_config_dir config_file = os.path.join(config_dir, 'iconizer_config.xml') self.config.load(config_file) self.panel.pack((5, 5)) hpanel = wal.HPanel(self.panel) hpanel.pack(wal.Label(hpanel, _('Background:'))) self.bg_color_btn = wal.ColorButton(hpanel, self.config.bg_color, onchange=self.update, silent=False) hpanel.pack((5, 5)) hpanel.pack(self.bg_color_btn) self.panel.pack(hpanel, padding=5) self.pallete = CBMiniPalette(self.panel, COLORS, onclick=self.bg_color_btn.set_value) self.panel.pack(self.pallete) self.panel.pack((10, 10)) self.viewer = ImageViewer(self.panel, self.config.bg_color) self.panel.pack(self.viewer) self.panel.pack((10, 10)) check_panel = wal.VPanel(self.panel) self.border_check = wal.Checkbox(check_panel, _('Show image border'), value=self.config.draw_border, onclick=self.update) check_panel.pack(self.border_check, align_center=False) self.sel_check = wal.Checkbox(check_panel, _('Draw selected only'), value=self.config.draw_selected, onclick=self.update) check_panel.pack(self.sel_check, align_center=False) self.panel.pack(check_panel) self.apply_btn = wal.Button(self.panel, _('Save image'), onclick=self.apply_action) self.panel.pack(self.apply_btn, fill=True, padding_all=5) self.panel.pack((5, 5)) self.panel.pack(wal.HLine(self.panel), fill=True) events.connect(events.DOC_CHANGED, self.update) events.connect(events.SELECTION_CHANGED, self.update) events.connect(events.DOC_MODIFIED, self.update) def show_signal(self, *args): self.update() def save_config(self): config_dir = self.app.appdata.app_config_dir config_file = os.path.join(config_dir, 'iconizer_config.xml') self.config.save(config_file) def render(self, sel_flag=False): doc = self.app.current_doc if not doc: return if sel_flag: if not doc.selection.objs: return None w, h = libgeom.bbox_size(doc.selection.bbox) x, y = libgeom.bbox_center(doc.selection.bbox) trafo = (1.0, 0, 0, -1.0, w / 2.0 - x, h / 2.0 + y) else: page = doc.active_page w, h = page.page_format[1] trafo = (1.0, 0, 0, -1.0, w / 2.0, h / 2.0) canvas_matrix = cairo.Matrix(*trafo) surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(w), int(h)) ctx = cairo.Context(surface) ctx.set_matrix(canvas_matrix) rend = crenderer.CairoRenderer(doc.cms) if sel_flag: objs = doc.selection.objs for obj in objs: layer = doc.methods.get_parent_layer(obj) rend.antialias_flag = layer.properties[3] == 1 rend.render(ctx, [ obj, ]) else: page = doc.active_page layers = doc.methods.get_visible_layers(page) for item in layers: rend.antialias_flag = item.properties[3] == 1 rend.render(ctx, item.childs) image_stream = StringIO() surface.write_to_png(image_stream) return image_stream def update(self, *args): if self.is_shown(): color = self.bg_color_btn.get_value() if not color == self.config.bg_color: self.config.bg_color = color self.save_config() self.viewer.set_canvas_bg(self.config.bg_color) if not self.sel_check.get_value() == self.config.draw_selected: self.config.draw_selected = not self.config.draw_selected self.save_config() if not self.border_check.get_value() == self.config.draw_border: self.config.draw_border = not self.config.draw_border self.save_config() self.viewer.set_border(self.config.draw_border) self.picture = self.render(self.config.draw_selected) self.viewer.set_picture(self.picture) self.apply_btn.set_enable(self.picture is not None) def apply_action(self): if not self.picture: return doc_file = 'image' doc_file = os.path.join(config.save_dir, doc_file) doc_file = dialogs.get_save_file_name(self.app.mw, doc_file, _('Save image as...'), file_types=[uc2const.PNG], path_only=True) if doc_file: try: fileptr = open(doc_file, 'wb') fileptr.write(self.picture.getvalue()) fileptr.close() except Exception: first = _('Cannot save image:') msg = "%s\n'%s'." % (first, doc_file) + '\n' msg += _('Please check file name and write permissions') dialogs.error_dialog(self.app.mw, self.app.appdata.app_name, msg) return config.save_dir = str(os.path.dirname(doc_file)) events.emit(events.APP_STATUS, _('Image is successfully saved'))
def __init__(self, parent, filepath): self.filepath = filepath size = (400, 250) title = _('Profile info') wal.CloseDialog.__init__(self, parent, title, size, wal.HORIZONTAL)
def __init__(self, parent, prefpanel): CmsTab.__init__(self, parent, prefpanel) self.intents = INTENTS.keys() self.intents.sort() self.intents_names = [] for item in self.intents: self.intents_names.append(INTENTS[item]) panel = wal.VPanel(self.panel) # Intents panel int_panel = wal.LabeledPanel(panel, _('Rendering intents')) grid = wal.GridPanel(int_panel, vgap=5, hgap=5) grid.pack(wal.Label(grid, _('Display/RGB intent:'))) self.display = wal.Combolist(grid, items=self.intents_names) self.display.set_active(self.intents.index(config.cms_rgb_intent)) grid.pack(self.display) grid.pack(wal.Label(grid, _('Printer/CMYK intent:'))) self.printer = wal.Combolist(grid, items=self.intents_names) self.printer.set_active(self.intents.index(config.cms_cmyk_intent)) grid.pack(self.printer) int_panel.pack(grid, align_center=False, padding_all=10) panel.pack(int_panel, fill=True) # Simulate printer panel txt = _('Simulate printer on the screen') self.simulate_check = wal.Checkbox(panel, txt, config.cms_proofing, onclick=self.activate_simulation) sm_panel = wal.LabeledPanel(panel, widget=self.simulate_check) txt = _("Highlight colors that are outside of the printer's gamut") self.outcolors_check = wal.Checkbox(sm_panel, txt, config.cms_gamutcheck, onclick=self.activate_outcolors) sm_panel.pack(self.outcolors_check, align_center=False, padding_all=5) clrpanel = wal.HPanel(sm_panel) clrpanel.pack((20, 1)) self.alarm_label = wal.Label(clrpanel, _('Highlight color:')) clrpanel.pack(self.alarm_label, padding=5) self.color_btn = wal.ColorButton(clrpanel, config.cms_alarmcodes) clrpanel.pack(self.color_btn) sm_panel.pack(clrpanel, align_center=False, padding_all=2) txt = _('Separation for SPOT colors') self.separation_check = wal.Checkbox(sm_panel, txt, config.cms_proof_for_spot, onclick=self.activate_outcolors) sm_panel.pack(self.separation_check, align_center=False, padding_all=5) panel.pack(sm_panel, fill=True, padding=5) # Bottom checks txt = _('Use Blackpoint Compensation') self.bpc_check = wal.Checkbox(panel, txt, config.cms_bpc_flag) panel.pack(self.bpc_check, align_center=False) if wal.IS_MSW: panel.pack((5, 5)) txt = _('Use Black preserving transforms') self.bpt_check = wal.Checkbox(panel, txt, config.cms_bpt_flag) panel.pack(self.bpt_check, align_center=False) self.panel.pack(panel, fill=True, padding_all=5) self.activate_simulation()
def __init__(self, app, parent, colorspace): self.app = app self.colorspace = colorspace size = (400, 250) title = _('%s profiles') % colorspace wal.CloseDialog.__init__(self, parent, title, size, wal.HORIZONTAL)
def update_list(self): keys = self.profiles.keys() keys.sort() default = _('Built-in %s profile') % self.colorspace self.pf_list = [default, ] + keys
def log_viewer_dlg(parent): dlg = LogViewerDialog(parent, _("Recent documents")) ret = dlg.show() if ret: parent.app.open(ret)
def get_profile_names(self, colorspace): names = [] default = _('Built-in %s profile') % colorspace names.append(default) names += self.cs_config_profiles[colorspace].keys() return names
def set_dialog_buttons(self): wal.OkCancelDialog.set_dialog_buttons(self) self.clear_btn = wal.Button(self.left_button_box, _('Clear log'), onclick=self.clear_history) self.left_button_box.pack(self.clear_btn)
def rename_layer(self): layer = self.get_selected_layer() txt = edit_dlg(self.app.mw, _('Rename layer'), layer.name) if txt is not None and not layer.name == txt: self.app.current_doc.api.set_layer_name(layer, txt)
from palette_viewer import PaletteViewer FILL_MODES = [sk2_const.FILL_ANY, sk2_const.FILL_CLOSED_ONLY] RULE_MODES = [sk2_const.FILL_EVENODD, sk2_const.FILL_NONZERO] FILL_MODE_ICONS = { sk2_const.FILL_ANY: icons.PD_FILL_ANY, sk2_const.FILL_CLOSED_ONLY: icons.PD_FILL_CLOSED_ONLY, } RULE_MODE_ICONS = { sk2_const.FILL_EVENODD: icons.PD_EVENODD, sk2_const.FILL_NONZERO: icons.PD_NONZERO, } FILL_MODE_NAMES = { sk2_const.FILL_ANY: _('Fill any contour'), sk2_const.FILL_CLOSED_ONLY: _('Fill closed only'), } RULE_MODE_NAMES = { sk2_const.FILL_EVENODD: _('Evenodd fill'), sk2_const.FILL_NONZERO: _('Nonzero fill'), } class FillRuleKeeper(wal.HPanel): mode = 0 fill_keeper = None rule_keeper = None def __init__(self, parent, mode=sk2_const.FILL_EVENODD): self.mode = mode
def update_points(self): self.points = [] self.midpoints = [] mps = self.target.get_midpoints() for item in mps: self.midpoints.append(MidPoint(self.canvas, self.target, item)) corner_points = self.target.get_corner_points() stops = self.target.get_stops() for index in range(4): if not self.target.corners[index]: start = corner_points[index] stop = stops[index][0] stop2 = stops[index - 1] if len(stop2) == 2: stop2 = stop2[1] else: stop2 = stop2[0] coef = self.target.corners[index] self.points.append(ControlPoint(self.canvas, self.target, start, stop, stop2=stop2, coef=coef, index=index)) elif self.target.corners[index] == 1.0: start = corner_points[index] stop = stops[index - 1] if len(stop) == 2: stop = stop[1] coef = self.target.corners[index] self.points.append(ControlPoint(self.canvas, self.target, start, stop, coef=coef, index=index)) elif not self.target.corners[index - 1] == 1.0: stop = stop[0] coef = self.target.corners[index] self.points.append(ControlPoint(self.canvas, self.target, start, stop, coef=coef, index=index)) stop = stops[index][0] start2 = [] if len(stops[index]) == 1 and \ self.target.corners[index - 3] == 1.0: start2 = corner_points[index - 3] coef = self.target.corners[index] self.points.append(ControlPoint(self.canvas, self.target, start, stop, start2=start2, coef=coef, index=index, subindex=1)) else: start = corner_points[index] stop = stops[index - 1] if len(stop) == 2: stop = stop[1] else: stop = stop[0] coef = self.target.corners[index] self.points.append(ControlPoint(self.canvas, self.target, start, stop, coef=coef, index=index)) stop = stops[index][0] self.points.append(ControlPoint(self.canvas, self.target, start, stop, coef=coef, index=index, subindex=1)) msg = _('Rectangle in editing') events.emit(events.APP_STATUS, msg)