Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP implement edit preferences #204

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/sk1/prefs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import wal
from generic import RootItem
from prefs_canvas import CanvasPrefs
from prefs_edit import EditPrefs
from prefs_cms import CMSPrefs
from prefs_fonts import FontPrefs
from prefs_general import GeneralPrefs
Expand All @@ -31,6 +32,7 @@
PREFS_APP = [GeneralPrefs, CMSPrefs, RulersPrefs,
PalettesPrefs, FontPrefs,
# CanvasPrefs,
EditPrefs,
PrinterPrefs, ]

PREFS_DOC = [GridPrefs, ]
Expand Down
87 changes: 87 additions & 0 deletions src/sk1/prefs/prefs_edit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 Maxim. S. Barabash
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import wal

from sk1 import _, config
from sk1.resources import icons

from generic import PrefPanel


NODE_SIZE_SCHEME = [_('Small'), _('Medium'), _('Large')]
NODE_SIZE = [5, 7, 9]


class EditPrefs(PrefPanel):
pid = 'Edit'
name = _('Edit')
title = _('Edit preferences')
icon_id = icons.PD_PREFS_EDIT

def __init__(self, app, dlg, *args):
PrefPanel.__init__(self, app, dlg)
grid = wal.GridPanel(self, rows=2, cols=3, hgap=5, vgap=5)

grid.pack(wal.Label(grid, _('Constrain angle:')))
self.constrain_angle = wal.IntSpin(
grid, config.curve_fixed_angle, range_val=(1, 90)
)
grid.pack(self.constrain_angle, fill=True)
grid.pack(wal.Label(grid, _('degrees')))

grid.pack(wal.Label(grid, _('Node size:')))
self.node_size = wal.Combolist(grid, items=NODE_SIZE_SCHEME)
try:
node_size_idx = NODE_SIZE.index(config.point_size)
except ValueError:
node_size_idx = 0
self.node_size.set_active(node_size_idx)
grid.pack(self.node_size)

self.pack(grid, align_center=False, fill=True, padding=5)
self.built = True

def apply_changes(self):
config.curve_fixed_angle = self.constrain_angle.get_value()

node_size_idx = self.node_size.get_active()
point_size = NODE_SIZE[node_size_idx]
config.point_size = point_size
config.curve_start_point_size = point_size
config.curve_point_size = point_size
config.curve_last_point_size = point_size
config.control_point_size = point_size
config.rect_midpoint_size = point_size
config.rect_point_size = point_size
config.ellipse_start_point_size = point_size
config.ellipse_end_point_size = point_size
config.polygon_point_size = point_size
config.text_point_size = point_size
config.gradient_vector_point_size = point_size

config.sel_marker_size = point_size + 2
config.curve_new_point_size = point_size + 2
config.curve_active_point_size = point_size + 2

def restore_defaults(self):
defaults = config.get_defaults()
self.constrain_angle.set_value(defaults['curve_fixed_angle'])
self.node_size.set_active(0)

def build(self):
self.built = True
7 changes: 5 additions & 2 deletions src/sk1/prefs/prefs_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,11 @@ def build(self):

grid.pack(wal.Label(grid, _('Language (*):')))
self.lang = wal.Combolist(grid, items=LANGS)
index = 0 if config.language == 'system' \
else LANGS.index(config.language)
try:
index = 0 if config.language == 'system' \
else LANGS.index(config.language)
except ValueError:
index = 0
self.lang.set_active(index)
grid.pack(self.lang)

Expand Down
1 change: 1 addition & 0 deletions src/sk1/resources/icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@

PD_PREFS_CMS = 'prefs-cms'
PD_PREFS_CMS_BANNER = 'prefs-cms-banner'
PD_PREFS_EDIT = 'prefs-edit'
PD_PREFS_PALETTE = 'prefs-palette'
PD_PREFS_RULER = 'prefs-ruler'
PD_PREFS_GRID = 'prefs-grid'
Expand Down