示例#1
0
 def getDefaultIngestJobSettings(self):
     s = GenericIngestModuleJobSettings()
     s.setSetting("minPercVoiced", str(minPercVoicedDefault))
     s.setSetting("minTotalVoiced", str(minTotalVoicedDefault))
     s.setSetting("runVadTranscriber", str(runVadTranscriberDefault))
     s.setSetting("showTextSegmentStartTime", str(showTextSegmentStartTimeDefault))
     return s
示例#2
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