wrap button callbacks with {cls}.pause_updates()

This commit is contained in:
onyx-and-iris 2023-07-11 01:26:46 +01:00
parent 3e68488231
commit 82cf0e914b
4 changed files with 62 additions and 16 deletions

View File

@ -249,7 +249,13 @@ class ChannelLabelFrameBuilder(AbstractBuilder):
self.scale.bind("<Double-Button-1>", self.labelframe.reset_gain)
self.scale.bind("<Button-1>", self.labelframe.scale_press)
self.scale.bind("<ButtonRelease-1>", self.labelframe.scale_release)
self.scale.bind("<MouseWheel>", self.labelframe._on_mousewheel)
self.scale.bind(
"<MouseWheel>",
partial(
self.labelframe.pause_updates,
self.labelframe._on_mousewheel,
),
)
def add_gain_label(self):
self.labelframe.gain_label = ttk.Label(
@ -263,7 +269,7 @@ class ChannelLabelFrameBuilder(AbstractBuilder):
self.button_mute = ttk.Checkbutton(
self.labelframe,
text="MUTE",
command=partial(self.labelframe.toggle_mute, "mute"),
command=partial(self.labelframe.pause_updates, self.labelframe.toggle_mute),
style=f"{'Toggle.TButton' if _configuration.themes_enabled else f'{self.identifier}Mute{self.index}.TButton'}",
variable=self.labelframe.mute,
)
@ -283,7 +289,7 @@ class ChannelLabelFrameBuilder(AbstractBuilder):
self.button_on = ttk.Checkbutton(
self.labelframe,
text="ON",
command=self.labelframe.set_on,
command=partial(self.labelframe.pause_updates, self.labelframe.set_on),
style=f"{'Toggle.TButton' if _configuration.themes_enabled else f'{self.identifier}On{self.index}.TButton'}",
variable=self.labelframe.on,
)
@ -486,7 +492,9 @@ class StripConfigFrameBuilder(ChannelConfigFrameBuilder):
ttk.Checkbutton(
self.configframe,
text=param,
command=partial(self.configframe.toggle_a, param),
command=partial(
self.configframe.pause_updates, self.configframe.toggle_a, param
),
style=f"{'Toggle.TButton' if _configuration.themes_enabled else f'{param}.TButton'}",
variable=self.configframe.phys_out_params_vars[
self.configframe.phys_out_params.index(param)
@ -507,7 +515,9 @@ class StripConfigFrameBuilder(ChannelConfigFrameBuilder):
ttk.Checkbutton(
self.configframe,
text=param,
command=partial(self.configframe.toggle_b, param),
command=partial(
self.configframe.pause_updates, self.configframe.toggle_b, param
),
style=f"{'Toggle.TButton' if _configuration.themes_enabled else f'{param}.TButton'}",
variable=self.configframe.virt_out_params_vars[
self.configframe.virt_out_params.index(param)
@ -528,7 +538,9 @@ class StripConfigFrameBuilder(ChannelConfigFrameBuilder):
ttk.Checkbutton(
self.configframe,
text=param,
command=partial(self.configframe.toggle_p, param),
command=partial(
self.configframe.pause_updates, self.configframe.toggle_p, param
),
style=f"{'Toggle.TButton' if _configuration.themes_enabled else f'{param}.TButton'}",
variable=self.configframe.param_vars[i],
)
@ -578,10 +590,16 @@ class BusConfigFrameBuilder(ChannelConfigFrameBuilder):
column=0, row=0, columnspan=2, sticky=(tk.W)
)
self.configframe.busmode_button.bind(
"<Button-1>", self.configframe.rotate_bus_modes_right
"<Button-1>",
partial(
self.configframe.pause_updates, self.configframe.rotate_bus_modes_right
),
)
self.configframe.busmode_button.bind(
"<Button-3>", self.configframe.rotate_bus_modes_left
"<Button-3>",
partial(
self.configframe.pause_updates, self.configframe.rotate_bus_modes_left
),
)
def create_param_buttons(self):
@ -589,7 +607,9 @@ class BusConfigFrameBuilder(ChannelConfigFrameBuilder):
ttk.Checkbutton(
self.configframe,
text=param,
command=partial(self.configframe.toggle_p, param),
command=partial(
self.configframe.pause_updates, self.configframe.toggle_p, param
),
style=f"{'Toggle.TButton' if _configuration.themes_enabled else f'{param}.TButton'}",
variable=self.configframe.param_vars[i],
)

View File

@ -88,17 +88,27 @@ class ChannelLabelFrame(ttk.LabelFrame):
self.parent.target.event.add("ldirty")
self.after(500, self.resume_updates)
def pause_updates(self, func, *args):
"""function wrapper, adds a 50ms delay on updates"""
_base_values.run_update = False
func(*args)
self.after(50, self.resume_updates)
def resume_updates(self):
_base_values.run_update = True
def _on_mousewheel(self, event):
_base_values.run_update = False
self.gain.set(
self.gain.get()
+ (
_configuration.mwscroll_step
if event.delta > 0
else -_configuration.mwscroll_step
round(
self.gain.get()
+ (
_configuration.mwscroll_step
if event.delta > 0
else -_configuration.mwscroll_step
),
1,
)
)
if self.gain.get() > 12:
@ -106,7 +116,7 @@ class ChannelLabelFrame(ttk.LabelFrame):
elif self.gain.get() < -60:
self.gain.set(-60)
self.setter("gain", self.gain.get())
self.after(1, self.resume_updates)
self.gainlabel.set(round(self.gain.get(), 1))
def open_config(self):
if self.conf.get():

View File

@ -68,6 +68,14 @@ class Config(ttk.Frame):
self.parent.target.event.add("ldirty")
self.after(350, self.resume_updates)
def pause_updates(self, func, *args):
"""function wrapper, adds a 50ms delay on updates"""
_base_values.run_update = False
func(*args)
self.after(50, self.resume_updates)
def resume_updates(self):
_base_values.run_update = True

View File

@ -78,6 +78,14 @@ class GainLayer(ttk.LabelFrame):
self.parent.target.event.add("ldirty")
self.after(500, self.resume_updates)
def pause_updates(self, func, *args):
"""function wrapper, adds a 50ms delay on updates"""
_base_values.run_update = False
func(*args)
self.after(50, self.resume_updates)
def resume_updates(self):
_base_values.run_update = True