Cleanup: minor changes to zoom menu
Updates to refactor from [0].
- Rename "_context" as it's no longer unused.
- Remove call to `iface_` as the string no longer contains text.
- Remove redundant `enumerate(..)`.
- Use ternary operator instead of a tuple lookup.
- Assign a ratio variable for reuse.
[0]: 7e2075b809
This commit is contained in:
@@ -1289,21 +1289,22 @@ class CLIP_PT_tools_grease_pencil_draw(AnnotationDrawingToolsPanel, Panel):
|
||||
class CLIP_MT_view_zoom(Menu):
|
||||
bl_label = "Zoom"
|
||||
|
||||
def draw(self, _context):
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
from math import isclose
|
||||
|
||||
current_zoom = _context.space_data.zoom_percentage
|
||||
current_zoom = context.space_data.zoom_percentage
|
||||
ratios = ((1, 8), (1, 4), (1, 2), (1, 1), (2, 1), (4, 1), (8, 1))
|
||||
|
||||
for i, (a, b) in enumerate(ratios):
|
||||
percent = a / b * 100
|
||||
for (a, b) in ratios:
|
||||
ratio = a / b
|
||||
percent = ratio * 100.0
|
||||
layout.operator(
|
||||
"clip.view_zoom_ratio",
|
||||
text=iface_("%g%% (%d:%d)") % (percent, a, b),
|
||||
text="%g%% (%d:%d)" % (percent, a, b),
|
||||
translate=False,
|
||||
icon=('NONE', 'LAYER_ACTIVE')[isclose(percent, current_zoom, abs_tol=0.5)]
|
||||
).ratio = a / b
|
||||
icon='LAYER_ACTIVE' if isclose(percent, current_zoom, abs_tol=0.5) else 'NONE',
|
||||
).ratio = ratio
|
||||
|
||||
layout.separator()
|
||||
layout.operator("clip.view_zoom_in")
|
||||
|
||||
@@ -115,21 +115,22 @@ class IMAGE_MT_view(Menu):
|
||||
class IMAGE_MT_view_zoom(Menu):
|
||||
bl_label = "Zoom"
|
||||
|
||||
def draw(self, _context):
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
from math import isclose
|
||||
|
||||
current_zoom = _context.space_data.zoom_percentage
|
||||
current_zoom = context.space_data.zoom_percentage
|
||||
ratios = ((1, 8), (1, 4), (1, 2), (1, 1), (2, 1), (4, 1), (8, 1))
|
||||
|
||||
for i, (a, b) in enumerate(ratios):
|
||||
percent = a / b * 100
|
||||
for (a, b) in ratios:
|
||||
ratio = a / b
|
||||
percent = ratio * 100.0
|
||||
layout.operator(
|
||||
"image.view_zoom_ratio",
|
||||
text=iface_("%g%% (%d:%d)") % (percent, a, b),
|
||||
text="%g%% (%d:%d)" % (percent, a, b),
|
||||
translate=False,
|
||||
icon=('NONE', 'LAYER_ACTIVE')[isclose(percent, current_zoom, abs_tol=0.5)]
|
||||
).ratio = a / b
|
||||
icon='LAYER_ACTIVE' if isclose(percent, current_zoom, abs_tol=0.5) else 'NONE',
|
||||
).ratio = ratio
|
||||
|
||||
layout.separator()
|
||||
layout.operator("image.view_zoom_in")
|
||||
|
||||
@@ -368,23 +368,24 @@ class SEQUENCER_MT_range(Menu):
|
||||
class SEQUENCER_MT_preview_zoom(Menu):
|
||||
bl_label = "Zoom"
|
||||
|
||||
def draw(self, _context):
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.operator_context = 'INVOKE_REGION_PREVIEW'
|
||||
from math import isclose
|
||||
|
||||
current_zoom = _context.space_data.zoom_percentage
|
||||
current_zoom = context.space_data.zoom_percentage
|
||||
ratios = ((1, 8), (1, 4), (1, 2), (1, 1), (2, 1), (4, 1), (8, 1))
|
||||
|
||||
for i, (a, b) in enumerate(ratios):
|
||||
percent = a / b * 100
|
||||
for (a, b) in ratios:
|
||||
ratio = a / b
|
||||
percent = ratio * 100.0
|
||||
|
||||
layout.operator(
|
||||
"sequencer.view_zoom_ratio",
|
||||
text=iface_("%g%% (%d:%d)") % (percent, a, b),
|
||||
text="%g%% (%d:%d)" % (percent, a, b),
|
||||
translate=False,
|
||||
icon=('NONE', 'LAYER_ACTIVE')[isclose(percent, current_zoom, abs_tol=0.5)],
|
||||
).ratio = a / b
|
||||
icon='LAYER_ACTIVE' if isclose(percent, current_zoom, abs_tol=0.5) else 'NONE',
|
||||
).ratio = ratio
|
||||
|
||||
layout.separator()
|
||||
layout.operator("view2d.zoom_in")
|
||||
|
||||
Reference in New Issue
Block a user