[jokosher-devel] [PATCH] Fixed bug #119700 and removed RecView/MixerStrip control button redundancy



Hello,

Here we go again..:)
I added a new Class called ControlsBox which contains all the code for creating and updating the control buttons(mute,solo etc). This means that it's no
longer necessary to have the same code in both RecordingView and MixerStrip, they both use an instance of the ControlsBox class instead.
So now the buttons in MixView also works.
Additionally, the instrument name label in the MixerStrip now gets updated when the name is changed in the RecordingView (bug #119700).

Let me know if I've messed something up:)

Regards,
Knut Erik Teigen
Index: InstrumentViewer.py
===================================================================
--- InstrumentViewer.py	(revision 1430)
+++ InstrumentViewer.py	(working copy)
@@ -12,8 +12,8 @@
 import pango
 from EventLaneViewer import *
 import Globals
-import InstrumentEffectsDialog
 import AddInstrumentDialog
+from ControlsBox import *
 import Utils
 import gettext
 _ = gettext.gettext
@@ -63,8 +63,6 @@
 		self.projectview = projectview
 		self.mainview = mainview
 		
-		self.effectsDialog = None		#the instrument effects dialog (to make sure more than one is never opened)
-		
 		self.Updating = False
 		
 		#get the default colour for the current theme
@@ -122,60 +120,9 @@
 		self.labelbox.pack_start(self.image, False)
 		self.labelbox.pack_end(self.labeleventbox)
 		self.headerBox.pack_start(self.labelbox)
-		self.controlsBox = gtk.HBox()
+		self.controlsBox = ControlsBox(mainview,instrument,includeEffects=True)
 		self.headerBox.pack_start(self.controlsBox, False)
 		
-		# define the tooltip messages and images for buttons that change states
-		self.recTipDisabled = _("Enable this instrument for recording")
-		self.recTipEnabled = _("Disable this instrument for recording")
-		self.muteTipDisabled = _("Mute - silence this instrument")
-		self.muteTipEnabled = _("Unmute - hear this instrument")
-		self.soloTipDisabled = _("Activate Solo - silence all other instruments")
-		self.soloTipEnabled = _("Deactivate Solo - hear all the instruments")
-		
-		self.recImgDisabled = gtk.gdk.pixbuf_new_from_file(os.path.join(Globals.IMAGE_PATH, "icon_arm.png"))
-		self.recImgEnabled = gtk.gdk.pixbuf_new_from_file(os.path.join(Globals.IMAGE_PATH, "icon_disarm.png"))
-		self.soloImgDisabled = gtk.gdk.pixbuf_new_from_file(os.path.join(Globals.IMAGE_PATH, "icon_solo.png"))
-		self.soloImgEnabled = gtk.gdk.pixbuf_new_from_file(os.path.join(Globals.IMAGE_PATH, "icon_group.png"))
-		self.muteImgDisabled = Utils.GetIconThatMayBeMissing("stock_volume", gtk.ICON_SIZE_BUTTON, False)
-		self.muteImgEnabled = Utils.GetIconThatMayBeMissing("stock_volume-mute", gtk.ICON_SIZE_BUTTON, False)
-		
-		self.recTip = gtk.Tooltips()
-		self.recButton = gtk.ToggleButton("")
-		self.recTip.set_tip(self.recButton, self.recTipEnabled, None)
-		self.recButton.connect("toggled", self.OnArm)
-		
-		self.muteButton = gtk.ToggleButton("")
-		self.muteButton.connect("toggled", self.OnMute)
-		self.muteTip = gtk.Tooltips()
-		self.muteTip.set_tip(self.muteButton, self.muteTipDisabled, None)
-		
-		self.soloButton = gtk.ToggleButton("")
-		self.soloTip = gtk.Tooltips()
-		self.soloTip.set_tip(self.soloButton, self.soloTipDisabled, None)
-		self.soloButton.connect("toggled", self.OnSolo)
-		
-		self.propsButton = gtk.Button()
-		procimg = gtk.Image()
-		procimg.set_from_file(os.path.join(Globals.IMAGE_PATH, "icon_effectsapply.png"))
-		self.propsButton.set_image(procimg)
-
-		self.propsButton.connect("clicked", self.OnEffectsButtonClicked)
-		self.propsTip = gtk.Tooltips()
-		self.propsTip.set_tip(self.propsButton, _("Instrument Effects"), None)
-		
-		self.controlsBox.add(self.recButton)
-		self.controlsBox.add(self.muteButton)
-		self.controlsBox.add(self.soloButton)
-		self.controlsBox.add(self.propsButton)
-		
-		self.instrument.connect("solo", self.OnInstrumentSolo)
-		self.instrument.connect("arm", self.OnInstrumentArm)
-		self.instrument.connect("mute", self.OnInstrumentMute)
-		
-		#initialize the images on the buttons
-		for i in (self.OnInstrumentArm, self.OnInstrumentMute, self.OnInstrumentSolo):
-			i(self.instrument)
 		self.separator = gtk.HSeparator()
 		self.headerBox.pack_end(self.separator, False, True)
 		self.instrument.isSelected = False
@@ -196,7 +143,7 @@
 		self.instrument.connect("name", self.OnInstrumentName)
 		self.instrument.connect("image", self.OnInstrumentImage)
 		self.instrument.connect("selected", self.OnInstrumentSelected)
-		
+
 		#set the appropriate colour if the instrument it already selected.
 		self.OnInstrumentSelected()
 		self.show_all()
@@ -206,42 +153,6 @@
 
 	#_____________________________________________________________________
 
-	def OnMute(self, widget):
-		"""
-		Toggles muting the instrument on/off.
-		It will also update the pressed in/out look of the button.
-		
-		Parameters:
-			widget -- reserved for GTK callbacks, don't use it explicitly.
-		"""
-		if not self.Updating:
-			self.instrument.ToggleMuted(wasSolo=False)
-	
-	#_____________________________________________________________________
-
-	def OnArm(self, widget):
-		"""
-		Toggles arming the instrument on/off.
-		It will also update the pressed in/out look of the button.
-		
-		Parameters:
-			widget -- reserved for GTK callbacks, don't use it explicitly.
-		"""
-		if not self.Updating:
-			self.instrument.ToggleArmed()
-		
-	#_____________________________________________________________________
-	
-	def OnSolo(self, widget):
-		"""
-		Toggles soloing the instrument on/off.
-		It will also update the pressed in/out look of the button.
-		"""
-		if not self.Updating:
-			self.instrument.ToggleSolo(False)
-		
-	#_____________________________________________________________________
-
 	def OnSelect(self, widget, event):
 		"""
 		Called when a button has been pressed anywhere within InstrumentViewer.
@@ -445,6 +356,7 @@
 		Parameters:
 			instrument -- the instrument instance that send the signal.
 		"""
+                self.mainview.workspace.UpdateInstrumentNames()
 		self.instrlabel.set_text(self.instrument.name)
 	
 	#_____________________________________________________________________
@@ -485,36 +397,7 @@
 
 	#______________________________________________________________________
 
-	def OnEffectsButtonClicked(self, widget):
-		"""
-		Creates and shows the instrument effects dialog
-		
-		Parameters:
-			widget -- reserved for GTK callbacks, don't use it explicitly.
-			mouse -- reserved for GTK callbacks, don't use it explicitly.
-		"""
-		Globals.debug("props button pressed")
-		if not self.effectsDialog:
-			self.effectsDialog = InstrumentEffectsDialog.InstrumentEffectsDialog(
-					self.instrument,
-					self.OnEffectsDialogDestroyed,
-					self.mainview.icon)
-		else:
-			self.effectsDialog.BringWindowToFront()
 
-	#______________________________________________________________________
-	
-	def OnEffectsDialogDestroyed(self, window):
-		"""
-		Called when the InstrumentEffectsDialog is destroyed.
-		
-		Parameters:
-			window -- reserved for GTK callbacks, don't use it explicitly.
-		"""
-		self.effectsDialog = None
-		
-	#______________________________________________________________________
-	
 	def OnDragMotion(self, widget, context, x, y, time):
 		"""
 		Called each time the user moves the mouse while dragging.
Index: Workspace.py
===================================================================
--- Workspace.py	(revision 1430)
+++ Workspace.py	(working copy)
@@ -84,6 +84,14 @@
 						self.mainview.compactMixButton,
 						self.mainview.mixingViewDisabledTip)
 	#____________________________________________________________________	
+        def UpdateInstrumentNames(self):
+                """
+                Updates the instrument names in the MixerStrips.
+                """
 
+                for strip in self.mixView.mixerStripList:
+                        strip.Update()
+	#____________________________________________________________________	
+
 #=========================================================================
 		
Index: MixerStrip.py
===================================================================
--- MixerStrip.py	(revision 1430)
+++ MixerStrip.py	(working copy)
@@ -16,6 +16,7 @@
 import os
 import Globals
 import Utils
+from ControlsBox import *
 
 import gettext
 _ = gettext.gettext
@@ -98,45 +99,9 @@
 		self.vbox.pack_start(self.vu, True, True)
 		
 		#Control Buttons
-		hb = gtk.HBox()
+		controlsBox = ControlsBox(mainview,instrument,includeEffects=False)
+		self.vbox.pack_start(controlsBox, False, False)
 		
-		# define the tooltip messages and images for buttons that change states
-		self.recTipDisabled = _("Enable this instrument for recording")
-		self.recTipEnabled = _("Disable this instrument for recording")
-		self.muteTipDisabled = _("Mute - silence this instrument")
-		self.muteTipEnabled = _("Unmute - hear this instrument")
-		self.soloTipDisabled = _("Activate Solo - silence all other instruments")
-		self.soloTipEnabled = _("Deactivate Solo - hear all the instruments")
-		
-		self.recImgDisabled = gtk.gdk.pixbuf_new_from_file(os.path.join(Globals.IMAGE_PATH, "icon_arm.png"))
-		self.recImgEnabled = gtk.gdk.pixbuf_new_from_file(os.path.join(Globals.IMAGE_PATH, "icon_disarm.png"))
-		self.soloImgDisabled = gtk.gdk.pixbuf_new_from_file(os.path.join(Globals.IMAGE_PATH, "icon_solo.png"))
-		self.soloImgEnabled = gtk.gdk.pixbuf_new_from_file(os.path.join(Globals.IMAGE_PATH, "icon_group.png"))
-		self.muteImgDisabled = Utils.GetIconThatMayBeMissing("stock_volume", gtk.ICON_SIZE_BUTTON, False)
-		self.muteImgEnabled = Utils.GetIconThatMayBeMissing("stock_volume-mute", gtk.ICON_SIZE_BUTTON, False)
-		
-		# create the actual buttons and set their initial properties
-		self.recButton = gtk.ToggleButton("")
-		self.recButton.connect("toggled", self.OnArm)
-		self.recTip = gtk.Tooltips()
-		self.recTip.set_tip(self.recButton, self.recTipDisabled, None)
-
-		self.muteButton = gtk.ToggleButton("")
-		self.muteButton.connect("toggled", self.OnMute)
-		self.muteTip = gtk.Tooltips()
-		self.muteTip.set_tip(self.muteButton, self.muteTipDisabled, None)
-		
-		self.soloButton = gtk.ToggleButton("")
-		self.soloTip = gtk.Tooltips()
-		self.soloTip.set_tip(self.soloButton, self.soloTipDisabled, None)
-		self.soloButton.connect("toggled", self.OnSolo)
-		
-		# add the buttons to the hbox
-		hb.add(self.recButton)
-		hb.add(self.muteButton)
-		hb.add(self.soloButton)
-		self.vbox.pack_start(hb, False, False)
-		
 		# Label and icon
 		hb = gtk.HBox()
 		imgsize = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)[0]
@@ -157,42 +122,6 @@
 		
 	#_____________________________________________________________________
 
-	def OnMute(self, widget):
-		"""
-		Toggles muting the instrument on/off.
-		
-		Parameters:
-			widget -- reserved for GTK callbacks, don't use it explicitly.
-		"""
-		if not self.Updating:
-			self.instrument.ToggleMuted(False)
-	
-	#_____________________________________________________________________
-
-	def OnArm(self, widget):
-		"""
-		Toggles arming the instrument on/off.
-		
-		Parameters:
-			widget -- reserved for GTK callbacks, don't use it explicitly.
-		"""
-		if not self.Updating:
-			self.instrument.ToggleArmed()
-		
-	#_____________________________________________________________________
-	
-	def OnSolo(self, widget):
-		"""
-		Toggles soloing the instrument on/off.
-		
-		Parameters:
-			widget -- reserved for GTK callbacks, don't use it explicitly.
-		"""
-		if not self.Updating:
-			self.instrument.ToggleSolo(False)
-		
-	#_____________________________________________________________________
-	
 	def EmitMinimise(self, widget):
 		"""
 		Minimizes the Instrument to the StatusBar.
@@ -206,47 +135,13 @@
 	
 	def Update(self):
 		"""
-		Updates the MixerStrip interface elements according to the actual
-		instrument state (i.e. muted/not muted).
-		"""
+		Updates the MixerStrip tooltip and instrument name
+                """
 		self.Updating = True
 		
 		self.mintip.enable()
 		self.label.set_text(self.instrument.name)
 		
-		# update the mute button image and tooltip
-		image = gtk.Image()
-		if self.instrument.actuallyIsMuted:
-			image.set_from_pixbuf(self.muteImgEnabled)
-			self.muteButton.set_image(image)
-			self.muteTip.set_tip(self.muteButton, self.muteTipEnabled, None)
-		else:
-			image.set_from_pixbuf(self.muteImgDisabled)
-			self.muteButton.set_image(image)
-			self.muteTip.set_tip(self.muteButton, self.muteTipDisabled, None)
-		
-		# update the arm button image and tooltip	
-		image = gtk.Image()
-		if self.instrument.isArmed:
-			image.set_from_pixbuf(self.recImgEnabled)
-			self.recButton.set_image(image)
-			self.recTip.set_tip(self.recButton, self.recTipEnabled, None)
-		else:
-			image.set_from_pixbuf(self.recImgDisabled)
-			self.recButton.set_image(image)
-			self.recTip.set_tip(self.recButton, self.recTipDisabled, None)
-			
-		# update the solo button image and tooltip
-		image = gtk.Image()
-		if self.instrument.isSolo:
-			image.set_from_pixbuf(self.soloImgEnabled)
-			self.soloButton.set_image(image)
-			self.soloTip.set_tip(self.soloButton, self.soloTipEnabled, None)
-		else:
-			image.set_from_pixbuf(self.soloImgDisabled)
-			self.soloButton.set_image(image)
-			self.soloTip.set_tip(self.soloButton, self.soloTipDisabled, None)
-		
 		self.Updating = False
 	
 	#_____________________________________________________________________
Index: ControlsBox.py
===================================================================
--- ControlsBox.py	(revision 0)
+++ ControlsBox.py	(revision 0)
@@ -0,0 +1,221 @@
+import pygtk
+pygtk.require("2.0")
+import gtk
+import os.path
+import Globals
+import Utils
+import InstrumentEffectsDialog
+
+class ControlsBox(gtk.HBox):
+
+	def __init__(self, mainview, instrument, includeEffects=True):
+		gtk.Container.__init__(self)
+		"""
+		Creates a new instance of ControlsBox.
+
+                Parameters:
+                        mainview -- The Main Jokosher window 
+                        instrument -- The instrument that the ControlsBox control.
+                        includeEffects -- Whether the Effects button is included or not.
+                                        This may be extended to include all the buttons.
+                """
+
+                self.mainview = mainview
+                self.instrument = instrument
+
+ 		# define the tooltip messages and images for buttons that change states
+		self.recTipDisabled = _("Enable this instrument for recording")
+		self.recTipEnabled = _("Disable this instrument for recording")
+		self.muteTipDisabled = _("Mute - silence this instrument")
+		self.muteTipEnabled = _("Unmute - hear this instrument")
+		self.soloTipDisabled = _("Activate Solo - silence all other instruments")
+		self.soloTipEnabled = _("Deactivate Solo - hear all the instruments")
+		
+		self.recImgDisabled = gtk.gdk.pixbuf_new_from_file(os.path.join(Globals.IMAGE_PATH, "icon_arm.png"))
+		self.recImgEnabled = gtk.gdk.pixbuf_new_from_file(os.path.join(Globals.IMAGE_PATH, "icon_disarm.png"))
+		self.soloImgDisabled = gtk.gdk.pixbuf_new_from_file(os.path.join(Globals.IMAGE_PATH, "icon_solo.png"))
+		self.soloImgEnabled = gtk.gdk.pixbuf_new_from_file(os.path.join(Globals.IMAGE_PATH, "icon_group.png"))
+		self.muteImgDisabled = Utils.GetIconThatMayBeMissing("stock_volume", gtk.ICON_SIZE_BUTTON, False)
+		self.muteImgEnabled = Utils.GetIconThatMayBeMissing("stock_volume-mute", gtk.ICON_SIZE_BUTTON, False)
+		
+		self.recTip = gtk.Tooltips()
+		self.recButton = gtk.ToggleButton("")
+		self.recTip.set_tip(self.recButton, self.recTipEnabled, None)
+		self.recButton.connect("toggled", self.OnArm)
+		
+		self.muteButton = gtk.ToggleButton("")
+		self.muteButton.connect("toggled", self.OnMute)
+		self.muteTip = gtk.Tooltips()
+		self.muteTip.set_tip(self.muteButton, self.muteTipDisabled, None)
+		
+		self.soloButton = gtk.ToggleButton("")
+		self.soloTip = gtk.Tooltips()
+		self.soloTip.set_tip(self.soloButton, self.soloTipDisabled, None)
+		self.soloButton.connect("toggled", self.OnSolo)
+		
+		self.add(self.recButton)
+		self.add(self.muteButton)
+		self.add(self.soloButton)
+
+                if includeEffects:
+                        self.propsButton = gtk.Button()
+                        procimg = gtk.Image()
+                        procimg.set_from_file(os.path.join(Globals.IMAGE_PATH, "icon_effectsapply.png"))
+                        self.propsButton.set_image(procimg)
+                        self.effectsDialog = None		#the instrument effects dialog (to make sure more than one is never opened)
+
+                        self.propsButton.connect("clicked", self.OnEffectsButtonClicked)
+                        self.propsTip = gtk.Tooltips()
+                        self.propsTip.set_tip(self.propsButton, _("Instrument Effects"), None)
+		        self.add(self.propsButton)
+		
+		self.instrument.connect("solo", self.OnInstrumentSolo)
+		self.instrument.connect("arm", self.OnInstrumentArm)
+		self.instrument.connect("mute", self.OnInstrumentMute)
+		
+		#initialize the images on the buttons
+		for i in (self.OnInstrumentArm, self.OnInstrumentMute, self.OnInstrumentSolo):
+			i(self.instrument)
+               
+
+	#_____________________________________________________________________
+
+	def OnMute(self, widget):
+		"""
+		Toggles muting the instrument on/off.
+		It will also update the pressed in/out look of the button.
+		
+		Parameters:
+			widget -- reserved for GTK callbacks, don't use it explicitly.
+		"""
+		if not self.Updating:
+			self.instrument.ToggleMuted(wasSolo=False)
+	
+	#_____________________________________________________________________
+
+	def OnArm(self, widget):
+		"""
+		Toggles arming the instrument on/off.
+		It will also update the pressed in/out look of the button.
+		
+		Parameters:
+			widget -- reserved for GTK callbacks, don't use it explicitly.
+		"""
+		if not self.Updating:
+			self.instrument.ToggleArmed()
+		
+	#_____________________________________________________________________
+	
+	def OnSolo(self, widget):
+		"""
+		Toggles soloing the instrument on/off.
+		It will also update the pressed in/out look of the button.
+		"""
+		if not self.Updating:
+			self.instrument.ToggleSolo(False)
+		
+	#_____________________________________________________________________
+
+	def OnInstrumentSolo(self, instrument=None):
+		"""
+		Callback for when the instrument's solo status changes.
+		
+		Parameters:
+			instrument -- the instrument instance that send the signal.
+		"""
+		self.Updating = True
+		self.soloButton.set_active(self.instrument.isSolo)
+		self.Updating = False
+		self.soloTip.enable()
+		
+		# update the solo button image and tooltip
+		image = gtk.Image()
+		if self.instrument.isSolo:
+			image.set_from_pixbuf(self.soloImgEnabled)
+			self.soloButton.set_image(image)
+			self.soloTip.set_tip(self.soloButton, self.soloTipEnabled, None)
+		else:
+			image.set_from_pixbuf(self.soloImgDisabled)
+			self.soloButton.set_image(image)
+			self.soloTip.set_tip(self.soloButton, self.soloTipDisabled, None)
+
+	#_____________________________________________________________________
+	
+	def OnInstrumentArm(self, instrument=None):
+		"""
+		Callback for when the instrument's armed status changes.
+		
+		Parameters:
+			instrument -- the instrument instance that send the signal.
+		"""
+		self.Updating = True
+		self.recButton.set_active(self.instrument.isArmed)
+		self.Updating = False
+		self.recTip.enable()
+		
+		# update the arm button image and tooltip	
+		image = gtk.Image()
+		if self.instrument.isArmed:
+			image.set_from_pixbuf(self.recImgEnabled)
+			self.recButton.set_image(image)
+			self.recTip.set_tip(self.recButton, self.recTipEnabled, None)
+		else:
+			image.set_from_pixbuf(self.recImgDisabled)
+			self.recButton.set_image(image)
+			self.recTip.set_tip(self.recButton, self.recTipDisabled, None)
+	
+	#_____________________________________________________________________
+	
+	def OnInstrumentMute(self, instrument=None):
+		"""
+		Callback for when the instrument's muted status changes.
+		
+		Parameters:
+			instrument -- the instrument instance that send the signal.
+		"""
+		self.Updating = True
+		self.muteButton.set_active(self.instrument.actuallyIsMuted)
+		self.Updating = False
+		
+		# update the mute button image and tooltip
+		image = gtk.Image()
+		if self.instrument.actuallyIsMuted:
+			image.set_from_pixbuf(self.muteImgEnabled)
+			self.muteButton.set_image(image)
+			self.muteTip.set_tip(self.muteButton, self.muteTipEnabled, None)
+		else:
+			image.set_from_pixbuf(self.muteImgDisabled)
+			self.muteButton.set_image(image)
+			self.muteTip.set_tip(self.muteButton, self.muteTipDisabled, None)
+	
+	#______________________________________________________________________
+
+	def OnEffectsButtonClicked(self, widget):
+		"""
+		Creates and shows the instrument effects dialog
+		
+		Parameters:
+			widget -- reserved for GTK callbacks, don't use it explicitly.
+			mouse -- reserved for GTK callbacks, don't use it explicitly.
+		"""
+		Globals.debug("props button pressed")
+		if not self.effectsDialog:
+			self.effectsDialog = InstrumentEffectsDialog.InstrumentEffectsDialog(
+					self.instrument,
+					self.OnEffectsDialogDestroyed,
+					self.mainview.icon)
+		else:
+			self.effectsDialog.BringWindowToFront()
+
+	#______________________________________________________________________
+	
+	def OnEffectsDialogDestroyed(self, window):
+		"""
+		Called when the InstrumentEffectsDialog is destroyed.
+		
+		Parameters:
+			window -- reserved for GTK callbacks, don't use it explicitly.
+		"""
+		self.effectsDialog = None
+		
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]