1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

Option to select image scaling method, as discussed in issue #275.

This commit is contained in:
Joe R 2022-09-19 22:26:44 -04:00
parent 02e68785ee
commit 3fd823b2f5
8 changed files with 85 additions and 17 deletions

View file

@ -599,8 +599,10 @@ class Application:
return d
return self._getImagesDir('toolbar', 'default', size, check=False)
def setTile(self, i, force=0):
if self.scrolled_canvas.setTile(self, i, force):
def setTile(self, i, scaling=-1, force=0):
if scaling == -1:
scaling = self.opt.tabletile_scale_method
if self.scrolled_canvas.setTile(self, i, scaling, force):
tile = self.tabletile_manager.get(i)
if i == 0:
self.opt.colors['table'] = tile.color

View file

@ -417,7 +417,7 @@ class MfxScrolledCanvas(object):
#
#
def setTile(self, app, i, force=False):
def setTile(self, app, i, scale_method, force=False):
logging.info('MfxRoot: setTitle app=%s' % app)
tile = app.tabletile_manager.get(i)

View file

@ -120,6 +120,7 @@ sound_sample_volume = integer(0, 128)
sound_sample_buffer_size = integer(1, 4)
music = boolean
tabletile_name = string
tabletile_scale_method = integer
center_layout = boolean
recent_gameid = int_list
favorite_gameid = int_list
@ -274,6 +275,7 @@ class Options:
('sound_sample_buffer_size', 'int'),
('music', 'bool'),
('tabletile_name', 'str'),
('tabletile_scale_method', 'int'),
('center_layout', 'bool'),
('translate_game_names', 'bool'),
('solver_presets', 'list'),
@ -461,6 +463,7 @@ class Options:
self.spread_stacks = False
self.center_layout = True
self.preserve_aspect_ratio = True
self.tabletile_scale_method = 0
self.resampling = 0
if USE_PIL:
self.resampling = int(Image.ANTIALIAS)

View file

@ -685,8 +685,11 @@ class PysolMenubarTk:
tile = self.app.tabletile_manager.get(0)
tile.color = d.key
self.app.setTile(0)
elif d.key > 0 and d.key != self.app.tabletile_index:
self.app.setTile(d.key)
elif d.key > 0 and (d.key != self.app.tabletile_index or
d.preview_scaling !=
self.app.opt.tabletile_scale_method):
self.app.setTile(d.key, scaling=d.preview_scaling)
self.app.opt.tabletile_scale_method = d.preview_scaling
def mSelectCardsetDialog(self, *event):
if self._cancelDrag(break_pause=False):

View file

@ -417,7 +417,7 @@ class MfxCanvas(gnomecanvas.Canvas):
item._item.set(fill_color=self._text_color)
# PySol extension - set a tiled background image
def setTile(self, app, i, force=False):
def setTile(self, app, i, scale_method, force=False):
# print 'setTile:', i
tile = app.tabletile_manager.get(i)
if tile is None or tile.error:

View file

@ -23,7 +23,7 @@
import os
from pysollib.mfxutil import KwStruct
from pysollib.mfxutil import KwStruct, USE_PIL
from pysollib.mygettext import _
from pysollib.ui.tktile.selecttree import SelectDialogTreeData
from pysollib.ui.tktile.tkutil import bind
@ -152,7 +152,8 @@ class SelectTileDialogWithPreview(MfxDialog):
paned_window.add(right_frame)
notebook = ttk.Notebook(left_frame)
notebook.pack(expand=True, fill='both')
notebook.grid(row=0, column=0, sticky='nsew',
padx=padx, pady=pady, columnspan=2)
tree_frame = ttk.Frame(notebook)
notebook.add(tree_frame, text=_('Tree View'))
search_frame = ttk.Frame(notebook)
@ -199,6 +200,33 @@ class SelectTileDialogWithPreview(MfxDialog):
self.list.config(yscrollcommand=self.list_scrollbar.set)
self.list_scrollbar.config(command=self.list.yview)
if USE_PIL:
self.scaleOptions = {"Default": 0,
"Tile": 1,
"Stretch": 2,
"Preserve Aspect Ratio": 3}
scaleValues = list(self.scaleOptions.keys())
self.scaling = tkinter.StringVar()
self.scaling.set(next(key for key, value in
self.scaleOptions.items()
if value == app.opt.tabletile_scale_method))
self.labelScale = tkinter.Label(left_frame, text="Image scaling:",
anchor="w")
self.textScale = PysolCombo(left_frame, values=scaleValues,
state='readonly',
textvariable=self.scaling,
selectcommand=self.updateScaling)
self.labelScale.grid(row=4, column=0, sticky='ew',
padx=padx, pady=pady)
self.textScale.grid(row=4, column=1, sticky='ew',
padx=padx, pady=pady)
left_frame.rowconfigure(0, weight=1)
left_frame.columnconfigure(0, weight=1)
left_frame.columnconfigure(1, weight=1)
self.preview = MfxScrolledCanvas(right_frame, hbar=0, vbar=0)
self.preview.pack(side="right", fill='both', expand=True,
padx=padx, pady=pady)
@ -206,7 +234,9 @@ class SelectTileDialogWithPreview(MfxDialog):
self.preview.canvas.preview = 1
# create a preview of the current state
self.preview_key = -1
self.updatePreview(key)
self.preview_scaling = -1
self.current_key = -1
self.updatePreview(key, app.opt.tabletile_scale_method)
#
focus = self.createButtons(bottom_frame, kw)
focus = self.tree.frame
@ -258,6 +288,10 @@ class SelectTileDialogWithPreview(MfxDialog):
def basicSearch(self, *args):
self.updateSearchList(self.list_searchtext.get())
def updateScaling(self, *args):
self.updatePreview(self.preview_key,
self.scaleOptions[self.scaling.get()])
def updateSearchList(self, searchString):
self.criteria.name = searchString
self.performSearch()
@ -316,12 +350,18 @@ class SelectTileDialogWithPreview(MfxDialog):
self.updatePreview(cardset)
self.list["cursor"] = oldcur
def updatePreview(self, key):
if key == self.preview_key:
def updatePreview(self, key, scaling=-1):
if scaling < 0:
scaling = self.preview_scaling
if key == self.preview_key and scaling == self.preview_scaling:
return
canvas = self.preview.canvas
canvas.deleteAllItems()
self.preview_scaling = scaling
if isinstance(key, six.string_types):
if USE_PIL:
self.textScale['state'] = 'disabled'
# solid color
canvas.config(bg=key)
canvas.setTile(None)
@ -332,7 +372,13 @@ class SelectTileDialogWithPreview(MfxDialog):
# image
tile = self.manager.get(key)
if tile:
if self.preview.setTile(self.app, key):
if USE_PIL:
if tile.stretch:
self.textScale['state'] = 'normal'
else:
self.textScale['state'] = 'disabled'
if self.preview.setTile(self.app, key, scaling):
self.preview_key = key
return
self.preview_key = -1

View file

@ -510,7 +510,7 @@ class MfxScrolledCanvas:
#
#
def setTile(self, app, i, force=False):
def setTile(self, app, i, scale_method, force=False):
tile = app.tabletile_manager.get(i)
if tile is None or tile.error:
return False
@ -527,8 +527,19 @@ class MfxScrolledCanvas:
tile.color == app.opt.colors['table']):
return False
#
if not self.canvas.setTile(tile.filename, tile.stretch,
tile.save_aspect):
stretch = tile.stretch
save_aspect = tile.save_aspect
if scale_method < 0 and stretch:
scale_method = app.opt.tabletile_scale_method
elif not stretch:
scale_method = 0
if scale_method > 0:
stretch = scale_method > 1
save_aspect = scale_method > 2
if not self.canvas.setTile(tile.filename, stretch, save_aspect):
tile.error = True
return False

View file

@ -1759,9 +1759,12 @@ Unsupported game for import.
tile.color = d.key
if self.app.setTile(0):
self.tkopt.tabletile.set(0)
elif d.key > 0 and d.key != self.app.tabletile_index:
if self.app.setTile(d.key):
elif d.key > 0 and (d.key != self.app.tabletile_index or
d.preview_scaling !=
self.app.opt.tabletile_scale_method):
if self.app.setTile(d.key, d.preview_scaling):
self.tkopt.tabletile.set(d.key)
self.app.opt.tabletile_scale_method = d.preview_scaling
def mOptToolbar(self, *event):
# if self._cancelDrag(break_pause=False): return