示例#1
0
class VadCheckModuleSettingsPanel(IngestModuleIngestJobSettingsPanel):
    # Note, we can't use a self.settings instance variable.
    # Rather, self.local_settings is used.
    # https://wiki.python.org/jython/UserGuide#javabean-properties
    # Jython Introspector generates a property - 'settings' on the basis
    # of getSettings() defined in this class. Since only getter function
    # is present, it creates a read-only 'settings' property. This auto-
    # generated read-only property overshadows the instance-variable -
    # 'settings'

    # We get passed in a previous version of the settings so that we can
    # prepopulate the UI
    # TODO: Update this for your UI
    def __init__(self, settings):
        #print("init: " + settings.getSetting("runVadTranscriber") + " " + settings.getSetting("minPercVoiced") + " " + settings.getSetting("minTotalVoiced"))
        #print("init local_settings: " + self.local_settings.getSetting("vadAggressivness") + " " + self.local_settings.getSetting("minPercVoiced") + " " + self.local_settings.getSetting("minTotalVoiced"))
        self.local_settings = GenericIngestModuleJobSettings()
        #initComponents will initialize sliders which will call lambdas for updating settings using current values in sliders
        #which would overwrite settings.
        self.initComponents()
        #print("init local_settings 2: " + self.local_settings.getSetting("vadAggressivness") + " " + self.local_settings.getSetting("minPercVoiced") + " " + self.local_settings.getSetting("minTotalVoiced"))
        #now safe to set settings
        self.local_settings = settings
        #print("init 2: " + self.local_settings.getSetting("runVadTranscriber") + " " + self.local_settings.getSetting("minPercVoiced") + " " + self.local_settings.getSetting("minTotalVoiced"))
        self.customizeComponents()
    
    _logger = Logger.getLogger(VadCheckModuleFactory.moduleName)

    def log(self, level, msg):
        self._logger.logp(level, self.__class__.__name__, inspect.stack()[1][3], msg)

    # def makeGuiCallback(self, key, guiGetAction):
    #     def callback(event):
    #         #self.log(Level.INFO, "setting key = " + key + " val =" + str(event.getSource().getValue()))
    #         value = str(guiGetAction(event.getSource()))
    #         print("setting key = " + key + " val =" + value)
    #         self.local_settings.setSetting(key, value)
    #         print("test in settings key = " + key + " val =" + self.local_settings.getSetting(key))
    #     return callback    

    def initComponents(self):
        #print("initComponents 1: " + self.local_settings.getSetting("vadAggressivness") + " " + self.local_settings.getSetting("minPercVoiced") + " " + self.local_settings.getSetting("minTotalVoiced"))
        self.setLayout(BoxLayout(self, BoxLayout.Y_AXIS))

        self.label2 = JLabel()
        self.label2.setText("Minimum percentage of segments with speech")
        self.label3 = JLabel()
        self.label3.setText("Minimum total duration of segment with speech (s)")

        #sliderGetAction = lambda slider: slider.getValue()
        self.minPercVoiced = JSlider()#stateChanged=self.makeGuiCallback("minPercVoiced", sliderGetAction))
        self.minPercVoiced.setMajorTickSpacing(20)
        self.minPercVoiced.setMinorTickSpacing(5)
        self.minPercVoiced.setPaintLabels(True)
        self.minPercVoiced.setPaintTicks(True)

        self.minTotalVoiced = JSlider()#stateChanged=self.makeGuiCallback("minTotalVoiced", sliderGetAction))
        self.minTotalVoiced.setMajorTickSpacing(60)
        self.minTotalVoiced.setMaximum(180)
        self.minTotalVoiced.setMinorTickSpacing(10)
        self.minTotalVoiced.setPaintLabels(True)
        self.minTotalVoiced.setPaintTicks(True)
        #print("initComponents 2: " + self.local_settings.getSetting("vadAggressivness") + " " + self.local_settings.getSetting("minPercVoiced") + " " + self.local_settings.getSetting("minTotalVoiced"))

        #checkboxGetAction = lambda checkbox: checkbox.isSelected()
        self.runVadTranscriber = JCheckBox("Transcribe files with speech detected ? (slow)")#,
            #actionPerformed=self.makeGuiCallback("runVadTranscriber", checkboxGetAction))
        self.showTextSegmentStartTime = JCheckBox("Show text segment start time ?")

        self.add(self.label2)
        self.add(self.minPercVoiced)
        self.add(self.label3)
        self.add(self.minTotalVoiced)
        self.add(self.showTextSegmentStartTime)
        self.add(self.runVadTranscriber)

        self.vadTranscriberLanguage = makeLanguageSelectionComboBox(self, "english")
        #this is needed because of https://bugs.jython.org/issue1749824
        #class ComboActionListener(ActionListener):
        #    def actionPerformed(self, e):
        #        value = e.getSource().getSelectedItem()
        #        self.local_settings.setSetting(key, value)

        #self.vadTranscriberLanguage.actionListener = ComboActionListener()

    #local_settings is of type https://github.com/sleuthkit/autopsy/blob/bbdea786db487c781edf2cf9032a2ba3166e97e0/Core/src/org/sleuthkit/autopsy/ingest/GenericIngestModuleJobSettings.java
    def customizeComponents(self):
        def setValue(key, default, stringToPythonObj, guiSetAction):
            string = self.local_settings.getSetting(key)
            #print("customizeComponents " + key + " stored value was " + str(string))
            #print("string is None " + str(string is None) + " stringToPythonObj(string) " + str(stringToPythonObj(string)))
            checkedValue = default if string is None else stringToPythonObj(string)
            obj = getattr(self, key)
            guiSetAction(obj, checkedValue)
            #self.log(Level.INFO, "setValue for key " + key + " " + str(checkedValue))
        
        sliderSetAction = lambda obj, val: obj.setValue(val)
        checkBoxSetAction = lambda obj, val: obj.setSelected(val)
        comboBoxSetAction = lambda obj, val: obj.setSelectedItem(val)

        setValue("minPercVoiced", minPercVoicedDefault, int, sliderSetAction)
        setValue("minTotalVoiced", minTotalVoicedDefault, int, sliderSetAction)
        setValue("runVadTranscriber", runVadTranscriberDefault, eval, checkBoxSetAction)
        setValue("showTextSegmentStartTime", showTextSegmentStartTimeDefault, eval, checkBoxSetAction)
        setValue("vadTranscriberLanguage", runVadTranscriberDefault, lambda x: x, comboBoxSetAction)

    # Return the settings used
    #note: exceptions thrown here will be caught and not logged.
    def getSettings(self):
        #print("getSettings: " + self.local_settings.getSetting("runVadTranscriber") + " " + self.local_settings.getSetting("minPercVoiced") + " " + self.local_settings.getSetting("minTotalVoiced"))
        
        self.local_settings.setSetting("minPercVoiced", str(self.minPercVoiced.getValue()))
        self.local_settings.setSetting("minTotalVoiced", str(self.minTotalVoiced.getValue()))
        self.local_settings.setSetting("runVadTranscriber", str(self.runVadTranscriber.isSelected()))
        self.local_settings.setSetting("showTextSegmentStartTime", str(self.showTextSegmentStartTime.isSelected()))
        self.local_settings.setSetting("vadTranscriberLanguage", str(self.vadTranscriberLanguage.getSelectedItem()))
 
        return self.local_settings
示例#2
0
class DebugControlPanel(JPanel):
    BUTTON_SIZE = (50, 50)

    def __init__(self, interpreter, debugger, debugPanel):
        self.interpreter = interpreter
        self.debugger = debugger
        self.debugPanel = debugPanel

        # Build our slider!
        self.slider = JSlider(JSlider.HORIZONTAL,
            debugger.MIN_SPEED, debugger.MAX_SPEED, debugger.speed,
            stateChanged=self._sliderSpeedChanged
        )

        # Label the slider!
        self.sliderLabels = labels = Hashtable()
        labels.put(debugger.MIN_SPEED, JLabel("Slow"))
        labels.put(debugger.MAX_SPEED, JLabel("Fast"))
        self.slider.labelTable = labels
        self.slider.paintLabels = True

        # Build some buttons!
        self.buttonInsets = Insets(0, 0, 0, 0)
        self.watchButton = self.makeDebuggerButton(
            self.debugPanel.watchVariable, 'images/plus.jpg'
        )
        self.unwatchButton = self.makeDebuggerButton(
            self.debugPanel.unwatchVariable, 'images/minus.jpg'
        )
        self.fullspeedButton = self.makeDebuggerButton(
            self.debugPanel.fullSpeed, 'images/fullspeed.jpg'
        )
        self.stopButton = self.makeDebuggerButton(
            self.interpreter.stopAction, 'images/stop.jpg'
        )

        # Display them all!
        self.setLayout(BoxLayout(self, BoxLayout.X_AXIS))
        self.add(self.slider)
        self.add(self.watchButton)
        self.add(self.unwatchButton)
        self.add(self.fullspeedButton)
        self.add(self.stopButton)

        # Connect the slider to the debugger!
        self.debugger.onSpeedSet.connect(self._showSpeedSetting)
        self.debugger.onStart.connect(self._lockControls)
        self.debugger.onStop.connect(self._unlockControls)

    def makeDebuggerButton(self, action, icon):
        imageIcon = JESResources.makeIcon(icon)
        return JButton(action, text=None, icon=imageIcon, margin=self.buttonInsets)

    @threadsafe
    def _sliderSpeedChanged(self, event):
        # These two event listeners could hypothetically go into
        # mutual recursion. To keep them from doing so, neither of them
        # trigger the other event unless the value actually changed.
        # This ensures they stop recursing after a single round.
        value = self.slider.getValue()
        if self.debugger.speed != value:
            self.debugger.setSpeed(value)

    @threadsafe
    def _showSpeedSetting(self, debugger, newSpeed, **_):
        if self.slider.getValue() != newSpeed:
            self.slider.setValue(newSpeed)

    @threadsafe
    def _lockControls(self, debugger, **_):
        self.debugPanel.watchVariable.enabled = False
        self.debugPanel.unwatchVariable.enabled = False
        self.debugPanel.fullSpeed.enabled = True

    @threadsafe
    def _unlockControls(self, debugger, **_):
        self.debugPanel.watchVariable.enabled = True
        self.debugPanel.unwatchVariable.enabled = True
        self.debugPanel.fullSpeed.enabled = False
示例#3
0
class DebugControlPanel(JPanel):
    BUTTON_SIZE = (50, 50)

    def __init__(self, interpreter, debugger, debugPanel):
        self.interpreter = interpreter
        self.debugger = debugger
        self.debugPanel = debugPanel

        # Build our slider!
        self.slider = JSlider(JSlider.HORIZONTAL,
                              debugger.MIN_SPEED,
                              debugger.MAX_SPEED,
                              debugger.speed,
                              stateChanged=self._sliderSpeedChanged)

        # Label the slider!
        self.sliderLabels = labels = Hashtable()
        labels.put(debugger.MIN_SPEED, JLabel("Slow"))
        labels.put(debugger.MAX_SPEED, JLabel("Fast"))
        self.slider.labelTable = labels
        self.slider.paintLabels = True

        # Build some buttons!
        self.buttonInsets = Insets(0, 0, 0, 0)
        self.watchButton = self.makeDebuggerButton(
            self.debugPanel.watchVariable, 'images/plus.jpg')
        self.unwatchButton = self.makeDebuggerButton(
            self.debugPanel.unwatchVariable, 'images/minus.jpg')
        self.fullspeedButton = self.makeDebuggerButton(
            self.debugPanel.fullSpeed, 'images/fullspeed.jpg')
        self.stopButton = self.makeDebuggerButton(self.interpreter.stopAction,
                                                  'images/stop.jpg')

        # Display them all!
        self.setLayout(BoxLayout(self, BoxLayout.X_AXIS))
        self.add(self.slider)
        self.add(self.watchButton)
        self.add(self.unwatchButton)
        self.add(self.fullspeedButton)
        self.add(self.stopButton)

        # Connect the slider to the debugger!
        self.debugger.onSpeedSet.connect(self._showSpeedSetting)
        self.debugger.onStart.connect(self._lockControls)
        self.debugger.onStop.connect(self._unlockControls)

    def makeDebuggerButton(self, action, icon):
        imageIcon = JESResources.makeIcon(icon)
        return JButton(action,
                       text=None,
                       icon=imageIcon,
                       margin=self.buttonInsets)

    @threadsafe
    def _sliderSpeedChanged(self, event):
        # These two event listeners could hypothetically go into
        # mutual recursion. To keep them from doing so, neither of them
        # trigger the other event unless the value actually changed.
        # This ensures they stop recursing after a single round.
        value = self.slider.getValue()
        if self.debugger.speed != value:
            self.debugger.setSpeed(value)

    @threadsafe
    def _showSpeedSetting(self, debugger, newSpeed, **_):
        if self.slider.getValue() != newSpeed:
            self.slider.setValue(newSpeed)

    @threadsafe
    def _lockControls(self, debugger, **_):
        self.debugPanel.watchVariable.enabled = False
        self.debugPanel.unwatchVariable.enabled = False
        self.debugPanel.fullSpeed.enabled = True

    @threadsafe
    def _unlockControls(self, debugger, **_):
        self.debugPanel.watchVariable.enabled = True
        self.debugPanel.unwatchVariable.enabled = True
        self.debugPanel.fullSpeed.enabled = False