Skip to content

Commit ef66293

Browse files
authored
cocoavlc example - zoom fix (#239)
One minor change for Zoom in, -Out and Normal 1X.
1 parent f99827b commit ef66293

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

examples/cocoavlc.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _PyPI(package):
4646
return 'see <https://PyPI.org/project/%s>' % (package,)
4747

4848
__all__ = ('AppVLC',) # PYCHOK expected
49-
__version__ = '22.12.12'
49+
__version__ = '22.12.14'
5050

5151
try:
5252
import vlc
@@ -165,21 +165,20 @@ class AppVLC(App):
165165
'''
166166
adjustr = ''
167167
marquee = None
168+
media = None
168169
logostr = ''
169170
player = None
170171
raiser = False
171172
rate = 0.0 # rate vs normal
172-
rate1X = 1.0 # rate 1X, fixed
173173
scale = 0.0 # video size / window size
174-
scale_1X = 0.0 # video scale 1X
175174
sized = None # video (width, height)
176175
Snapshot = Item('Snapshot', key='s', alt=True)
177176
snapshot = _PNG # default: .png, .jpg or .tiff
178177
snapshots = 0
179178
Toggle = None
180179
video = None
181180
window = None
182-
zoomX = 1.0 # zoom factor
181+
zoomX = 1.0 # zoom factor, >= 1.0
183182

184183
def __init__(self, video=None, # video file name
185184
adjustr='', # vlc.VideoAdjustOption
@@ -192,7 +191,7 @@ def __init__(self, video=None, # video file name
192191
self.adjustr = adjustr
193192
self.logostr = logostr
194193
self.marquee = marquee
195-
self.media = None
194+
# self.media = None
196195
self.raiser = raiser
197196
self.Toggle = Item('Play', self.menuToggle_, key='p', ctrl=True)
198197
self.video = video
@@ -509,12 +508,12 @@ def _hue(self, unused, fraction=0): # change hue
509508
def _rate(self, unused, factor=0): # change the video rate
510509
p = self.player
511510
r = p.get_rate() * factor
512-
r = max(0.2, min(10.0, r)) if r > 0 else self.rate1X
511+
r = max(0.2, min(10.0, r)) if r > 0 else 1.0
513512
p.set_rate(r)
514513
self.rate = r
515514

516515
def _reset(self, resize=False):
517-
self.scale_1X = 0.0 # 1X zoom
516+
self.zoomX = 1
518517
self.sized = None
519518
if resize:
520519
Thread(target=self._sizer).start()
@@ -538,8 +537,8 @@ def _sizer(self, secs=0.25): # asynchronously
538537
w = self.window
539538
# set window's contents' aspect ratio
540539
w.ratio = self.sized = a, b
541-
# get video scale for 1X zoom
542-
self.scale_1X = float(w.frame.width) / a
540+
# get video scale factor
541+
self.scale = float(w.frame.width) / a
543542
self._wiggle()
544543
break
545544
elif secs > 0.001:
@@ -597,22 +596,20 @@ def _wiggle(self):
597596
# wiggle the video to fill the window
598597
p = self.player
599598
s = p.video_get_scale()
600-
p.video_set_scale(0.0 if s else self.scale_1X)
599+
p.video_set_scale(0.0 if s else self.scale)
601600
p.video_set_scale(s)
602601

603602
def _zoom(self, unused, factor=0):
604603
# zoom the video in/out, see tkvlc.py
605-
X = self.scale_1X
606604
p = self.player
607-
c = p.video_get_scale()
608-
s = (c or X) * factor
609-
if s < X:
610-
s = 0.0 # 1X
611-
# wiggle the video to fill the window
612-
p.video_set_scale(0.0 if c else X)
605+
x = self.zoomX * factor
606+
if x > 1:
607+
s = x
608+
else: # not below 1X
609+
s, x = 0.0, 1.0
613610
p.video_set_scale(s)
614-
self.scale = s
615-
self.zoomX = (s / (X or 1.0)) or 1.0
611+
self.scale = s
612+
self.zoomX = x
616613

617614

618615
if __name__ == '__main__': # MCCABE 24

0 commit comments

Comments
 (0)