def __initializeSourceCombobox(self, row): col = 0; sourceLabel = tk.Label(self, anchor = tk.E, text = 'Source :'); sourceLabel.grid(row = row, column = col); col += 1; self.sourceCombo = FluidFolderCombobox(self, command = self.__onSourceValueChanged, folder = 'audios', extension = '.mp3'); self.sourceCombo.grid(row = row, column = col, rowspan = 1, columnspan = 4, sticky = self.NSEW);
def __initializeContentCombobox(self, row): col = 0 sourceLabel = tk.Label(self, anchor=tk.E, text='Source :') sourceLabel.grid(row=row, column=col) col += 1 self.sourceCombo = FluidFolderCombobox( self, command=self.__onTextSourceValueChanged, folder='texts', extension='.txt') self.sourceCombo.grid(row=row, column=col, rowspan=1, columnspan=4, sticky=self.NSEW)
class MusicPanel(FluidPanel): def __init__(self, parent, **options): super(FluidPanel, self).__init__(parent, options); self.__onAudioSourceChangedCallback = None; self.__onPlayButtonClickedCallback = None; self.__onPauseButtonClickedCallback = None; hWeights = [0, 1, 0, 0, 1]; vWeights = [1, 0, 0, 1]; row = 0; self.__initializePlaceHolderRow(row); row += 1; self.__initializeSourceCombobox(row); row += 1; self.__initializeButtonsRow(row); row += 1; self.__initializePlaceHolderRow(row); self._setupGrid(hWeights, vWeights); self._setControlsPadding(self._childPaddingX, self._childPaddingY); def OnAudioSourceChangedCallback(self, callback): self._funcCheck(callback); self.__onAudioSourceChangedCallback = callback; def OnPlayButtonClickedCallback(self, callback): self._funcCheck(callback); self.__onPlayButtonClickedCallback = callback; def OnPauseButtonClickedCallback(self, callback): self._funcCheck(callback); self.__onPauseButtonClickedCallback = callback; def __initializeSourceCombobox(self, row): col = 0; sourceLabel = tk.Label(self, anchor = tk.E, text = 'Source :'); sourceLabel.grid(row = row, column = col); col += 1; self.sourceCombo = FluidFolderCombobox(self, command = self.__onSourceValueChanged, folder = 'audios', extension = '.mp3'); self.sourceCombo.grid(row = row, column = col, rowspan = 1, columnspan = 4, sticky = self.NSEW); def __initializeButtonsRow(self, row): col = 2; playButton = tk.Button(self, text = 'Jouer', width = self._buttonWidth, height = self._widgetHeight, command = self.__onPlayButtonClicked); playButton.grid(row = row, column = col); col += 1; pauseButton = tk.Button(self, text = 'Arrêter', width = self._buttonWidth, height = self._widgetHeight, command = self.__onPauseButtonClicked); pauseButton.grid(row = row, column = col); def __initializePlaceHolderRow(self, row): placeHolder = tk.Frame(self); placeHolder.grid(row = row, column = 0, rowspan = 1, columnspan = 3, sticky = self.NSEW); def __onSourceValueChanged(self, *args): if self.__onAudioSourceChangedCallback is not None: source = self.sourceCombo.get(); self.__onAudioSourceChangedCallback(source); def __onPlayButtonClicked(self, *args): if self.__onPlayButtonClickedCallback is not None: self.__onPlayButtonClickedCallback(); def __onPauseButtonClicked(self, *args): if self.__onPauseButtonClickedCallback is not None: self.__onPauseButtonClickedCallback();
class TextPanel(FluidPanel): def __init__(self, parent, **options): super(FluidPanel, self).__init__(parent, options) self.__onTextSizeSliderValueChangedCallback = None self.__onFadeTimeSliderValueChangedCallback = None self.__onShowButtonClickedCallback = None self.__onHideButtonClickedCallback = None hWeights = [0, 1, 0, 0, 1] vWeights = [1, 0, 0, 0, 0] row = 0 self.__initializeTextAreaRow(row) row += 1 self.__initializeContentCombobox(row) row += 1 self.__initializeTextSizeSliderRow(row) row += 1 self.__initializeTextFadeTimeSliderRow(row) row += 1 self.__initializeControlButtonsRow(row) self._setupGrid(hWeights, vWeights) self._setControlsPadding(self._childPaddingX, self._childPaddingY) def OnTextSizeSliderValueChangedCallback(self, callback): self._funcCheck(callback) self.__onTextSizeSliderValueChangedCallback = callback def OnTextFadeTimeSliderValueChangedCallback(self, callback): self._funcCheck(callback) self.__onFadeTimeSliderValueChangedCallback = callback def OnShowButtonClickedCallback(self, callback): self._funcCheck(callback) self.__onShowButtonClickedCallback = callback def OnHideButtonClickedCallback(self, callback): self._funcCheck(callback) self.__onHideButtonClickedCallback = callback def __initializeTextAreaRow(self, row): col = 0 textLabel = tk.Label(self, anchor=tk.E, text='Saisissez un texte à afficher :') textLabel.grid(row=row, column=col) col += 1 self.textEntry = tk.Text(self, width=0) self.textEntry.grid(row=row, column=col, rowspan=1, columnspan=4, sticky=self.NSEW) def __initializeContentCombobox(self, row): col = 0 sourceLabel = tk.Label(self, anchor=tk.E, text='Source :') sourceLabel.grid(row=row, column=col) col += 1 self.sourceCombo = FluidFolderCombobox( self, command=self.__onTextSourceValueChanged, folder='texts', extension='.txt') self.sourceCombo.grid(row=row, column=col, rowspan=1, columnspan=4, sticky=self.NSEW) def __initializeTextSizeSliderRow(self, row): col = 0 textSizeLabel = tk.Label(self, anchor=tk.E, text='Taille du texte :') textSizeLabel.grid(row=row, column=col) col += 1 self.textSizeSlider = FluidSlider( self, minValue=100, maxValue=400, initialValue=300, valueFormat='Taille du texte : {0:0g}', labelFormat='{0:0g}', command=self.__onTextSizeSliderValueChanged) self.textSizeSlider.grid(row=row, column=col, rowspan=1, columnspan=4, sticky=self.NSEW) def __initializeTextFadeTimeSliderRow(self, row): col = 0 textSizeLabel = tk.Label(self, anchor=tk.E, text='Transition du texte :') textSizeLabel.grid(row=row, column=col) col += 1 self.fadeTimeSlider = FluidSlider( self, minValue=0, maxValue=2000, initialValue=400, resolution=50, valueFormat='Transition : {0:0g} ms', labelFormat='{0:0g} ms', command=self.__onFadeTimeSliderValueChanged) self.fadeTimeSlider.grid(row=row, column=col, rowspan=1, columnspan=4, sticky=self.NSEW) def __initializeControlButtonsRow(self, row): col = 2 showButton = tk.Button(self, text='Afficher', width=self._buttonWidth, height=self._widgetHeight, command=self.__onShowButtonClicked) showButton.grid(row=row, column=col) col += 1 cancelButton = tk.Button(self, text='Cacher', width=self._buttonWidth, height=self._widgetHeight, command=self.__onHideButtonClicked) cancelButton.grid(row=row, column=col) def __readFromFile(self, filename): with io.open(filename, 'r', encoding='utf8') as fstream: text = fstream.read() return text def __onTextSizeSliderValueChanged(self, *args): if self.__onTextSizeSliderValueChangedCallback is not None: textSize = self.textSizeSlider.get() self.__onTextSizeSliderValueChangedCallback(textSize) def __onTextSourceValueChanged(self, *args): filename = self.sourceCombo.getFullValue() text = self.__readFromFile(filename) self.textEntry.delete('1.0', tk.END) self.textEntry.insert(tk.END, text) def __onFadeTimeSliderValueChanged(self, *args): if self.__onFadeTimeSliderValueChangedCallback is not None: fadeTime = self.fadeTimeSlider.get() self.__onFadeTimeSliderValueChangedCallback(fadeTime) def __onShowButtonClicked(self, *args): if self.__onShowButtonClickedCallback is not None: text = self.textEntry.get('1.0', 'end-1c') self.__onShowButtonClickedCallback(text) def __onHideButtonClicked(self, *args): if self.__onHideButtonClickedCallback is not None: self.__onHideButtonClickedCallback()
class VideoPanel(FluidPanel): def __init__(self, parent, **options): super(FluidPanel, self).__init__(parent, options) self.__onVideoSourceChangedCallback = None self.__onFadeDurationSliderValueChangedCallback = None self.__onPlayButtonClickedCallback = None self.__onPauseButtonClickedCallback = None hWeights = [0, 1, 0, 0, 1] vWeights = [1, 0, 0, 0, 1] row = 0 self.__initializePlaceHolderRow(row) row += 1 self.__initializeSourceCombobox(row) row += 1 self.__initializeFadeDurationSlider(row) row += 1 self.__initializeButtonsRow(row) row += 1 self.__initializePlaceHolderRow(row) self._setupGrid(hWeights, vWeights) self._setControlsPadding(self._childPaddingX, self._childPaddingY) def OnVideoSourceChangedCallback(self, callback): self._funcCheck(callback) self.__onVideoSourceChangedCallback = callback def OnFadeDurationSliderValueChangedCallback(self, callback): self._funcCheck(callback) self.__onFadeDurationSliderValueChangedCallback = callback def OnPlayButtonClickedCallback(self, callback): self._funcCheck(callback) self.__onPlayButtonClickedCallback = callback def OnPauseButtonClickedCallback(self, callback): self._funcCheck(callback) self.__onPauseButtonClickedCallback = callback def __initializeSourceCombobox(self, row): col = 0 sourceLabel = tk.Label(self, anchor=tk.E, text='Source :') sourceLabel.grid(row=row, column=col) col += 1 self.sourceCombo = FluidFolderCombobox( self, command=self.__onSourceValueChanged, folder='videos', extension='.mp4') self.sourceCombo.grid(row=row, column=col, rowspan=1, columnspan=4, sticky=self.NSEW) def __initializeFadeDurationSlider(self, row): col = 0 fadeDurationLabel = tk.Label(self, anchor=tk.E, text='Transition de la vidéo :') fadeDurationLabel.grid(row=row, column=col) col += 1 self.fadeDurationSlider = FluidSlider( self, command=self.__onFadeDurationSliderValueChanged, minValue=0, initialValue=2500, maxValue=4000, valueFormat='Transition : {0:0g} ms', labelFormat='{0:0g}') self.fadeDurationSlider.grid(row=row, column=col, rowspan=1, columnspan=4, sticky=self.NSEW) def __initializeButtonsRow(self, row): col = 2 playButton = tk.Button(self, text='Afficher', width=self._buttonWidth, height=self._widgetHeight, command=self.__onPlayButtonClicked) playButton.grid(row=row, column=col) col += 1 pauseButton = tk.Button(self, text='Arrêter', width=self._buttonWidth, height=self._widgetHeight, command=self.__onPauseButtonClicked) pauseButton.grid(row=row, column=col) def __initializePlaceHolderRow(self, row): placeHolder = tk.Frame(self) placeHolder.grid(row=row, column=0, rowspan=1, columnspan=3, sticky=self.NSEW) def __onSourceValueChanged(self, *args): if self.__onVideoSourceChangedCallback is not None: source = self.sourceCombo.get() self.__onVideoSourceChangedCallback(source) def __onFadeDurationSliderValueChanged(self, *args): if self.__onFadeDurationSliderValueChangedCallback is not None: fadeTime = self.fadeDurationSlider.get() self.__onFadeDurationSliderValueChangedCallback(fadeTime) def __onPlayButtonClicked(self, *args): if self.__onPlayButtonClickedCallback is not None: self.__onPlayButtonClickedCallback() def __onPauseButtonClicked(self, *args): if self.__onPauseButtonClickedCallback is not None: self.__onPauseButtonClickedCallback()
class SpeechPanel(FluidPanel): def __init__(self, parent, **options): super(FluidPanel, self).__init__(parent, options) self.__speechSubmittedCallback = None self.__rateSliderValueChangedCallback = None self.__pitchSliderValueChangedCallback = None self.__cancelButtonClickedCallback = None hWeights = [0, 1, 0, 0, 1] vWeights = [1, 0, 0, 0, 0] row = 0 self.__initializeSpeechTextRow(row) row += 1 self.__initializeSourceCombobox(row) row += 1 self.__initializeRateScaleRow(row) row += 1 self.__initializePitchScaleRow(row) row += 1 self.__initializeButtonsRow(row) self._setupGrid(hWeights, vWeights) self._setControlsPadding(self._childPaddingX, self._childPaddingY) def OnSpeechSubmittedCallback(self, callback): self._funcCheck(callback) self.__speechSubmittedCallback = callback def OnRateSliderValueChangedCallback(self, callback): self._funcCheck(callback) self.__rateSliderValueChangedCallback = callback def OnPitchSliderValueChangedCallback(self, callback): self._funcCheck(callback) self.__pitchSliderValueChangedCallback = callback def OnCancelButtonClickedCallback(self, callback): self._funcCheck(callback) self.__cancelButtonClickedCallback = callback def __initializeSpeechTextRow(self, row): col = 0 speechTextLabel = tk.Label(self, anchor=tk.E, text='Saisissez un texte à énoncer :') speechTextLabel.grid(row=row, column=col) col += 1 self.speechTextEntry = tk.Text(self, width=0) self.speechTextEntry.grid(row=row, column=col, rowspan=1, columnspan=4, sticky=self.NSEW) def __initializeSourceCombobox(self, row): col = 0 sourceLabel = tk.Label(self, anchor=tk.E, text='Source :') sourceLabel.grid(row=row, column=col) col += 1 self.sourceCombo = FluidFolderCombobox( self, command=self.__onSpeechSourceValueChanged, folder='speeches', extension='.txt') self.sourceCombo.grid(row=row, column=col, rowspan=1, columnspan=4, sticky=self.NSEW) def __initializeRateScaleRow(self, row): col = 0 rateTextLabel = tk.Label(self, anchor=tk.E, text='Vitesse du texte :') rateTextLabel.grid(row=row, column=col) col += 1 self.textRateSlider = FluidSlider( self, command=self.__onRateSliderChanged, minValue=0, initialValue=10, maxValue=20, valueFormat='Vitesse x {0:.2f}', labelFormat='x {0:.2f}', valueTransform=lambda v: 0.1 * 10**(v / 10.0)) self.textRateSlider.grid(row=row, column=col, rowspan=1, columnspan=4, sticky=self.NSEW) def __initializePitchScaleRow(self, row): col = 0 pitchTextLabel = tk.Label(self, anchor=tk.E, text='Hauteur de la voix :') pitchTextLabel.grid(row=row, column=col) col += 1 self.textPitchSlider = FluidSlider(self, command=self.__onPitchSliderChanged, minValue=0.0, initialValue=1.0, maxValue=2.0, valueFormat='Hauteur : {0:.2f}', labelFormat='{0:.2f}', resolution=0.05) self.textPitchSlider.grid(row=row, column=col, rowspan=1, columnspan=4, sticky=self.NSEW) def __initializeButtonsRow(self, row): col = 2 speechTextBtn = tk.Button(self, text='Énoncer', width=self._buttonWidth, height=self._widgetHeight, command=self.__onSpeechTextClick) speechTextBtn.grid(row=row, column=col) col += 1 cancelButton = tk.Button(self, text='Annuler', width=self._buttonWidth, height=self._widgetHeight, command=self.__onCancelButtonClick) cancelButton.grid(row=row, column=col) def __readFromFile(self, filename): with io.open(filename, 'r', encoding='utf8') as fstream: text = fstream.read() return text def __onSpeechTextClick(self, *args): if self.__speechSubmittedCallback is not None: text = self.speechTextEntry.get('1.0', 'end-1c') self.__speechSubmittedCallback(text) def __onSpeechSourceValueChanged(self, *args): filename = self.sourceCombo.getFullValue() text = self.__readFromFile(filename) self.speechTextEntry.delete('1.0', tk.END) self.speechTextEntry.insert(tk.END, text) def __onRateSliderChanged(self, *args): if self.__rateSliderValueChangedCallback is not None: rate = self.textRateSlider.get() self.__rateSliderValueChangedCallback(rate) def __onPitchSliderChanged(self, *args): if self.__pitchSliderValueChangedCallback is not None: pitch = self.textPitchSlider.get() self.__pitchSliderValueChangedCallback(pitch) def __onCancelButtonClick(self, *args): if self.__cancelButtonClickedCallback is not None: self.__cancelButtonClickedCallback()