Ejemplo n.º 1
0
def createFileChooserDialog(filters, filename, prefs, prefkey, multiselect):
    """
    Creates a file chooser dialog that remembers its last directory.

    """
    fileChooser = JFileChooser()

    # Add filters
    if not hasattr(filters, '__iter__'):
        filters = (filters, )
    if filters:
        for filter in filters:
            fileChooser.addChoosableFileFilter(filter)
        fileChooser.fileFilter = filters[0]

    # Enable/disable multiple file select
    fileChooser.setMultiSelectionEnabled(multiselect)

    # Restore the last directory
    if prefs and prefkey:
        defaultDirName = prefs.get(prefkey, None)
        if defaultDirName:
            defaultDirectory = File(defaultDirName)
            if defaultDirectory.exists():
                fileChooser.currentDirectory = defaultDirectory

    # Preset the file name
    if filename:
        fileChooser.selectedFile = File(fileChooser.currentDirectory, filename)

    return fileChooser
Ejemplo n.º 2
0
def createFileChooserDialog(filters, filename, prefs, prefkey, multiselect):
    """
    Creates a file chooser dialog that remembers its last directory.
    
    """
    fileChooser = JFileChooser()

    # Add filters
    if not hasattr(filters, '__iter__'):
        filters = (filters,)
    if filters:
        for filter in filters:
            fileChooser.addChoosableFileFilter(filter)
        fileChooser.fileFilter = filters[0]

    # Enable/disable multiple file select
    fileChooser.setMultiSelectionEnabled(multiselect)

    # Restore the last directory
    if prefs and prefkey:
        defaultDirName = prefs.get(prefkey, None)
        if defaultDirName:
            defaultDirectory = File(defaultDirName)
            if defaultDirectory.exists():
                fileChooser.currentDirectory = defaultDirectory

    # Preset the file name
    if filename:
        fileChooser.selectedFile = File(fileChooser.currentDirectory, filename)

    return fileChooser
 def chooseFile(self, event):
     chooseFile = JFileChooser()
     filter = FileNameExtensionFilter("c files", ["c"])
     chooseFile.addChoosableFileFilter(filter)
     chooseFile.showDialog(self.uploadPanel, "Choose File")
     chosenFile = chooseFile.getSelectedFile()
     self.uploadTextField.text = str(chosenFile)
Ejemplo n.º 4
0
 def onClick(self, e):
     chooseFile = JFileChooser()
     filter = FileNameExtensionFilter("c files", ["c"])
     chooseFile.addChoosableFileFilter(filter)
     ret = chooseFile.showDialog(self.panel, "Choose file")
     if ret == JFileChooser.APPROVE_OPTION:
           file = chooseFile.getSelectedFile()
           
           print file
Ejemplo n.º 5
0
 def open(self, e):
     filechooser = JFileChooser()
     filter = FileNameExtensionFilter("c files", ["c"])
     filechooser.addChoosableFileFilter(filter)
     ret = filechooser.showDialog(self.panel, "Elegir fichero")
     if ret == JFileChooser.APPROVE_OPTION:
         file = filechooser.getSelectedFile()
         text = self.readFile(file)
         self.area.setText(text)
Ejemplo n.º 6
0
    def fileButtonClick(self, callbacks):
        fileTypeList = ["csv", "txt", "json"]
        txtFilter = FileNameExtensionFilter("txt", fileTypeList)
        fileChooser = JFileChooser()
        fileChooser.addChoosableFileFilter(txtFilter)
        result = fileChooser.showOpenDialog(self._splitpane)

        if result == JFileChooser.APPROVE_OPTION:
            f = fileChooser.getSelectedFile()
            fileName = f.getPath()
            self.populateTableModel(f)
Ejemplo n.º 7
0
    def fileButtonClick(self, e):

        fileTypeList = ["war", "ear", "zip"]
        warFilter = FileNameExtensionFilter("war", fileTypeList)
        fileChooser = JFileChooser()
        fileChooser.addChoosableFileFilter(warFilter)
        result = fileChooser.showOpenDialog(self._splitpane)

        if result == JFileChooser.APPROVE_OPTION:
            f = fileChooser.getSelectedFile()
            fileName = f.getPath()
            self.populateJTable(f)
    def onClick(self, e):

        chooseFile = JFileChooser()
        filter = FileNameExtensionFilter("SQLite", ["sqlite"])
        chooseFile.addChoosableFileFilter(filter)

        ret = chooseFile.showDialog(self.panel, "Select SQLite")

        if ret == JFileChooser.APPROVE_OPTION:
            file = chooseFile.getSelectedFile()
            text = self.readPath(file)
            self.area.setText(text)
Ejemplo n.º 9
0
    def onClick(self, e):

        chooseFile = JFileChooser()
        filter = FileNameExtensionFilter("SQLite", ["sqlite"])
        chooseFile.addChoosableFileFilter(filter)

        ret = chooseFile.showDialog(self.panel, "Select SQLite")

        if ret == JFileChooser.APPROVE_OPTION:
            file = chooseFile.getSelectedFile()
            text = self.readPath(file)
            self.area.setText(text)
Ejemplo n.º 10
0
    def Find_Plaso_File(self, e):

       chooseFile = JFileChooser()
       filter = FileNameExtensionFilter("All", ["*.*"])
       chooseFile.addChoosableFileFilter(filter)

       ret = chooseFile.showDialog(self.panel0, "Find Plaso Storage File")

       if ret == JFileChooser.APPROVE_OPTION:
           file = chooseFile.getSelectedFile()
           Canonical_file = file.getCanonicalPath()
           #text = self.readPath(file)
           self.local_settings.setSetting('Plaso_Storage_File', Canonical_file)
           self.Plaso_Storage_File_TF.setText(Canonical_file)
Ejemplo n.º 11
0
    def Find_Plaso_File(self, e):

        chooseFile = JFileChooser()
        filter = FileNameExtensionFilter("All", ["*.*"])
        chooseFile.addChoosableFileFilter(filter)

        ret = chooseFile.showDialog(self.panel0, "Find Plaso Storage File")

        if ret == JFileChooser.APPROVE_OPTION:
            file = chooseFile.getSelectedFile()
            Canonical_file = file.getCanonicalPath()
            #text = self.readPath(file)
            self.local_settings.setPlaso_Storage_File(Canonical_file)
            self.Plaso_Storage_File_TF.setText(Canonical_file)
    def onClick(self, e):

       chooseFile = JFileChooser()
       filter = FileNameExtensionFilter("SQLite", ["sqlite"])
       chooseFile.addChoosableFileFilter(filter)

       ret = chooseFile.showDialog(self.panel0, "Select SQLite")

       if ret == JFileChooser.APPROVE_OPTION:
           file = chooseFile.getSelectedFile()
           Canonical_file = file.getCanonicalPath()
           #text = self.readPath(file)
           self.local_settings.setSetting('ExecFile', Canonical_file)
           self.Program_Executable_TF.setText(Canonical_file)
    def onClick(self, e):

        chooseFile = JFileChooser()
        filter = FileNameExtensionFilter("SQLite", ["sqlite"])
        chooseFile.addChoosableFileFilter(filter)

        ret = chooseFile.showDialog(self.panel0, "Select SQLite")

        if ret == JFileChooser.APPROVE_OPTION:
            file = chooseFile.getSelectedFile()
            Canonical_file = file.getCanonicalPath()
            #text = self.readPath(file)
            self.local_settings.setSetting('ExecFile', Canonical_file)
            self.Program_Executable_TF.setText(Canonical_file)
Ejemplo n.º 14
0
    def Find_Dir(self, e):

        chooseFile = JFileChooser()
        filter = FileNameExtensionFilter("All", ["*.*"])
        chooseFile.addChoosableFileFilter(filter)
        #chooseFile.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)

        ret = chooseFile.showDialog(self.panel0, "Find Volatility Directory")

        if ret == JFileChooser.APPROVE_OPTION:
            file = chooseFile.getSelectedFile()
            Canonical_file = file.getCanonicalPath()
            #text = self.readPath(file)
            self.local_settings.setVolatility_Directory(Canonical_file)
            self.Program_Executable_TF.setText(Canonical_file)
Ejemplo n.º 15
0
    def FindFTKTxtFile(self, e):

       chooseFile = JFileChooser()
       filter = FileNameExtensionFilter("ALL", ["*.*"])
       chooseFile.addChoosableFileFilter(filter)

       ret = chooseFile.showDialog(self.panel0, "Find FTK Log File")
       
       if ret == JFileChooser.APPROVE_OPTION:
           file = chooseFile.getSelectedFile()
           Canonical_file = file.getCanonicalPath()
           #text = self.readPath(file)
           self.local_settings.setSetting('FTKLogFile', Canonical_file)
           setSetting('FTKLogFile', Canonical_file)
           self.FTKLogFile_TF.setText(Canonical_file)
Ejemplo n.º 16
0
    def Find_Dir(self, e):

       chooseFile = JFileChooser()
       filter = FileNameExtensionFilter("All", ["*.*"])
       chooseFile.addChoosableFileFilter(filter)
       #chooseFile.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)

       ret = chooseFile.showDialog(self.panel0, "Find Volatility Directory")

       if ret == JFileChooser.APPROVE_OPTION:
           file = chooseFile.getSelectedFile()
           Canonical_file = file.getCanonicalPath()
           #text = self.readPath(file)
           self.local_settings.setSetting('Volatility_Directory', Canonical_file)
           self.Program_Executable_TF.setText(Canonical_file)
Ejemplo n.º 17
0
 def onOpenFile(self, event):
     ''' remember to change the path'''
     chooseFile = JFileChooser()
     chooseFile.setCurrentDirectory(File('C:\Users\fragom\PhD_CIM\Modelica\Models')) 
     filtro = FileNameExtensionFilter("mo files", ["mo"])
     chooseFile.addChoosableFileFilter(filtro)
     ret = chooseFile.showDialog(self, "Choose file")
     if ret == JFileChooser.APPROVE_OPTION:
         self.faile= chooseFile.getSelectedFile()
         if event.getActionCommand() == "Load Model":
             self.cbMoFile.addItem(self.faile.getPath())
             self.cbMoFile.selectedItem= self.faile.getPath()
         if event.getActionCommand() == "Load Library":
             self.cbMoLib.addItem(self.faile.getPath())
             self.cbMoLib.selectedItem= self.faile.getPath()
Ejemplo n.º 18
0
 def init():
     canvas = RayTracePanel(w, h, aa, threads)
     self.add(canvas)
     
     #Save FileChooser
     fcS = JFileChooser()
     fcS.addChoosableFileFilter(FileNameExtensionFilter('Windows Bitmap (*.bmp)', ['bmp']))
     fcS.addChoosableFileFilter(FileNameExtensionFilter('JPEG / JFIF (*.jpg)', ['jpg']))
     fcS.addChoosableFileFilter(FileNameExtensionFilter('Portable Network Graphics (*.png)', ['png']))
     def saveFile(event):
         '''Performed when the save button is pressed'''
         result = fcS.showSaveDialog(frame)
         if result == JFileChooser.APPROVE_OPTION:
             file = fcS.getSelectedFile()
             fname = file.getPath()
             ext = fcS.getFileFilter().getExtensions()[0]
             if not fname.endswith('.' + ext):
                 file = File(fname + '.' + ext)
             canvas.saveToFile(file, ext)
     
     #Open FileChooser
     fcO = JFileChooser()
     fcO.addChoosableFileFilter(FileNameExtensionFilter('RayTrace Scene File (*.rts)', ['rts']))
     def openFile(event):
         '''Performed when the open button is pressed'''
         result = fcO.showOpenDialog(frame)
         if result == JFileChooser.APPROVE_OPTION:
             fname = fcO.getSelectedFile().getPath()
             if fname.endswith('.rts'):
                 f = open(fname, 'rb')
                 newScene = SceneFactory().buildScene(f)
                 f.close()
                 Painter(canvas, newScene, openButton, saveButton, stopButton).start()
         
     def stop(event):
         '''Peformed when the stop button is pressed'''
         canvas.stopRendering()
         
     #Setup Menu
     menuBar = JMenuBar()
     menu = JMenu("File")
     menuBar.add(menu)
     openButton = JMenuItem("Open...", actionPerformed=openFile)
     openButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK))
     menu.add(openButton)
     saveButton = JMenuItem("Save as...", actionPerformed=saveFile)
     saveButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK))
     menu.add(saveButton)
     menu.addSeparator()
     stopButton = JMenuItem('Stop Render', actionPerformed=stop)
     stopButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0));
     stopButton.setEnabled(False)
     menu.add(stopButton)
     menu.addSeparator()
     closeButton = JMenuItem('Close', actionPerformed=exit)
     closeButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK))
     menu.add(closeButton)
     self.setJMenuBar(menuBar)
Ejemplo n.º 19
0
    def loadSimOut(self, event):
        chooseFile = JFileChooser()
        filtro = FileNameExtensionFilter("Output files (.h5)", ['h5'])
        chooseFile.addChoosableFileFilter(filtro)
        ret = chooseFile.showDialog(self.frame, "Choose simulation result")
        if ret == JFileChooser.APPROVE_OPTION:
            faile= chooseFile.getSelectedFile()
            self.cbfilesimOut.addItem(faile.getPath())
            self.cbfilesimOut.selectedItem(faile.getPath())

        h5pmu= PhasorMeasH5.PhasorMeasH5(faile)
        h5pmu.open_h5()
        h5pmu.load_h5('pwLine4', 'V')
        # result: 2 vectors per variable, work with pwLine4.n.vr, pwLine4.n.vi
        senyal= h5pmu.get_senyal()
        print senyal
Ejemplo n.º 20
0
    def _select_sql_file(self, e):
        """ Shows a JFileChooser dialog to select the SQL file to use for creating
        the model. """
        try:
            chooseFile = JFileChooser()
            filter_ = FileNameExtensionFilter("txt files", ["txt"])
            chooseFile.addChoosableFileFilter(filter_)

            ret = chooseFile.showDialog(self._panel, "Choose file")

            if ret == JFileChooser.APPROVE_OPTION:
                self._sql_file = chooseFile.getSelectedFile().getPath()
            else:
                self._sql_file = None
            self._text_field_sql_file.setText("" + self._sql_file)
        except Exception as e:
            print(e)
Ejemplo n.º 21
0
def saveFileDialog(parent, startingDir=None, title=None, extension=None):
    # type: (java.awt.Component, str, str, str) -> (java.io.File, str)
    """Creates a fileChooser.showSaveDialog and returns the selected file.
    
    Args:
    
    * parent (java.awt.Component): Parent component.
    * startingDir (str): Starting directory.
    * title (str): Title of the dialog.
    * fileFilter (str): Extension (without the dot) of the file to look for. E.g., "json"
    
    Returns java.io.File and a string containing the last used directory."""

    fileChooser = JFileChooser()
    if startingDir is not None:
        startingPath = File(startingDir)
        fileChooser.setCurrentDirectory(startingPath)
    if title is not None:
        fileChooser.dialogTitle = title

    # FileNameExtensionFilter
    # https://docs.oracle.com/javase/8/docs/api/javax/swing/filechooser/FileNameExtensionFilter.html
    if extension is not None:
        extensionFilterString = "%s Files (*.%s)" % (extension.upper(),
                                                     extension)
        extensionFilterList = [extension]
        fil = FileNameExtensionFilter(extensionFilterString,
                                      extensionFilterList)
        fileChooser.fileFilter = fil
        fileChooser.addChoosableFileFilter(fil)

    fileChooser.fileSelectionMode = JFileChooser.FILES_ONLY
    returnVal = fileChooser.showSaveDialog(parent)
    if returnVal != JFileChooser.APPROVE_OPTION:
        # export cancelled or there was an error
        return None, ""

    # store the used directory
    lastDir = fileChooser.getCurrentDirectory().toString()
    # get file path
    selectedFile = fileChooser.getSelectedFile()
    return selectedFile, lastDir
Ejemplo n.º 22
0
 def go(self, fileTypes=None, default=None, directoryAllowed=False):
     fileChooser = JFileChooser()
     if self.title:
         fileChooser.setDialogTitle(self.title)
     if default:
         fileChooser.setSelectedFile(java.io.File(default))
     fileChooser.setCurrentDirectory(java.io.File("."))
     if fileTypes:
         for extension, description in fileTypes:
            fileChooser.addChoosableFileFilter(FileFilterForExtension(extension, description))            
     if self.loadOrSave == "load":
         result = fileChooser.showOpenDialog(self.parent)
     else:
         result = fileChooser.showSaveDialog(self.parent)
     if (result == JFileChooser.APPROVE_OPTION):
         fileResult = None
         fileAndMaybeDir = fileChooser.getSelectedFile().getAbsoluteFile()
         if directoryAllowed or not fileAndMaybeDir.isDirectory():
             fileResult = str(fileAndMaybeDir)
         return fileResult
     else:
         return None
Ejemplo n.º 23
0
    def actionPerformed(self, actionEvent):
        global yara_rules
        global yara_path

        if actionEvent.getSource() is self.menuItem:
            yara_path = self._yara_exe_txtField.getText()
            yara_rules = self._yara_rules_files
            t = Thread(self)
            t.start()
        elif actionEvent.getSource() is self._yara_clear_button:
            # Delete the LogEntry objects from the log
            row = self._log.size()
            self._lock.acquire()
            self._log.clear()

            # Update the Table
            self.fireTableRowsDeleted(0, row)

            # Clear data regarding any selected LogEntry objects from the request / response viewers
            self._requestViewer.setMessage([], True)
            self._responseViewer.setMessage([], False)
            self._currentlyDisplayedItem = None
            self._lock.release()
        elif actionEvent.getSource() is self._yara_rules_select_files_button:
            fileChooser = JFileChooser()
            yarFilter = FileNameExtensionFilter("Yara Rules", ["yar"])
            fileChooser.addChoosableFileFilter(yarFilter)
            fileChooser.setFileFilter(yarFilter)
            fileChooser.setMultiSelectionEnabled(True)
            fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY)
            ret = fileChooser.showOpenDialog(None)
            if ret == JFileChooser.APPROVE_OPTION:
                self._yara_rules_files.clear()
                for file in fileChooser.getSelectedFiles():
                    self._yara_rules_files.add(file.getPath())
                self._yara_rules_fileList.setListData(self._yara_rules_files)
        else:
            stdout.println("Unknown Event Received.")
Ejemplo n.º 24
0
    def _save_model(self, e):
        """ Saves the current Aslan++ model and concretization file. """
        try:
            chooseFile = JFileChooser()
            filter_ = FileNameExtensionFilter("txt files", ["txt"])
            chooseFile.addChoosableFileFilter(filter_)

            ret = chooseFile.showDialog(self._panel, "Choose file")

            if ret == JFileChooser.APPROVE_OPTION:
                self._model_name = chooseFile.getSelectedFile().getPath()
                with open("{}.aslan++".format(self._model_name), "w") as f:
                    skeleton = self._jfxp_aslanpp._editor.getText()
                    skeleton = skeleton.replace("@filename",
                                                basename(self._model_name))
                    f.write(skeleton)
                print("model created")

                with open("{}.txt".format(self._model_name), "w") as f:
                    f.write(self._jfxp_concretization._editor.getText())

        except Exception as e:
            print(e)
Ejemplo n.º 25
0
 def showFC(self, event):
     fc = JFileChooser(RestrictedFileSystemView(File(r'C:\IBM\WebSphere')))
     fc.addChoosableFileFilter(FileNameExtensionFilter(
         'XML files', ['xml']))
     fc.addChoosableFileFilter(
         FileNameExtensionFilter('Image files',
                                 'bmp,jpg,jpeg,gif,png'.split(',')))
     fc.addChoosableFileFilter(
         FileNameExtensionFilter('Text files', ['txt']))
     result = fc.showOpenDialog(None)
     if result == JFileChooser.APPROVE_OPTION:
         message = 'result = "%s"' % fc.getSelectedFile()
     else:
         message = 'Request canceled by user'
     self.label.setText(message)
Ejemplo n.º 26
0
def run(scene, w=512, h=512, aa=1, threads=1):
    '''Create GUI and perform ray-tracing.'''
    #Make Swing not look like garbage (so much)
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
    #Setup frame
    frame = JFrame("RayTracer",
                   defaultCloseOperation=JFrame.EXIT_ON_CLOSE,
                   size=(w, h))
    frame.setIconImage(ImageIcon('resources/icon.png').getImage())
    canvas = RayTracePanel(w, h, aa, threads)
    frame.getContentPane().add(JScrollPane(canvas))

    #Save FileChooser
    fcS = JFileChooser()
    fcS.addChoosableFileFilter(
        FileNameExtensionFilter('Windows Bitmap (*.bmp)', ['bmp']))
    fcS.addChoosableFileFilter(
        FileNameExtensionFilter('JPEG / JFIF (*.jpg)', ['jpg']))
    fcS.addChoosableFileFilter(
        FileNameExtensionFilter('Portable Network Graphics (*.png)', ['png']))

    def saveFile(event):
        '''Performed when the save button is pressed'''
        result = fcS.showSaveDialog(frame)
        if result == JFileChooser.APPROVE_OPTION:
            file = fcS.getSelectedFile()
            fname = file.getPath()
            ext = fcS.getFileFilter().getExtensions()[0]
            if not fname.endswith('.' + ext):
                file = File(fname + '.' + ext)
            canvas.saveToFile(file, ext)

    #Open FileChooser
    fcO = JFileChooser()
    fcO.addChoosableFileFilter(
        FileNameExtensionFilter('RayTrace Scene File (*.rts)', ['rts']))

    def openFile(event):
        '''Performed when the open button is pressed'''
        result = fcO.showOpenDialog(frame)
        if result == JFileChooser.APPROVE_OPTION:
            fname = fcO.getSelectedFile().getPath()
            if fname.endswith('.rts'):
                f = open(fname, 'rb')
                newScene = SceneFactory().buildScene(f)
                f.close()
                Painter(canvas, newScene, openButton, saveButton).start()

    def exit(event):
        '''Performed when the exit button is pressed'''
        import sys
        sys.exit(0)

    #Setup Menu
    menuBar = JMenuBar()
    menu = JMenu("File")
    menuBar.add(menu)
    openButton = JMenuItem("Open...", actionPerformed=openFile)
    openButton.setAccelerator(
        KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK))
    menu.add(openButton)
    saveButton = JMenuItem("Save as...", actionPerformed=saveFile)
    saveButton.setAccelerator(
        KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK))
    menu.add(saveButton)
    menu.addSeparator()
    closeButton = JMenuItem('Close', actionPerformed=exit)
    closeButton.setAccelerator(
        KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK))
    menu.add(closeButton)
    frame.setJMenuBar(menuBar)

    #Finish initializing GUI
    frame.pack()
    #frame.setLocationRelativeTo(None)
    frame.setVisible(True)

    #Perform ray-tracing
    if scene is not None:
        Thread(Painter(canvas, scene, openButton, saveButton)).start()
Ejemplo n.º 27
0
class BurpExtender(IBurpExtender, IMessageEditorTabFactory, ITab, IExtensionStateListener):
    EXTENSION_NAME = "Protobuf Editor"

    def __init__(self):
        self.descriptors = OrderedDict()

        self.chooser = JFileChooser()
        self.chooser.addChoosableFileFilter(PROTO_FILENAME_EXTENSION_FILTER)
        self.chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES)
        self.chooser.setMultiSelectionEnabled(True)

    def registerExtenderCallbacks(self, callbacks):
        self.callbacks = callbacks
        self.helpers = callbacks.getHelpers()

        self.enabled = False

        try:
            process = subprocess.Popen(['protoc', '--version'],
                                       stdin=subprocess.PIPE,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE)
            output, error = process.communicate()
            self.enabled = output.startswith('libprotoc')

            if error:
                raise RuntimeError(error)

        except (OSError, RuntimeError) as error:
            self.callbacks.getStderr().write(
                    "Error calling protoc: %s\n" % (error.message, ))

        if not self.enabled:
            return

        rules = []
        saved_rules = callbacks.loadExtensionSetting('rules')

        if saved_rules:
            rules = json.loads(base64.b64decode(saved_rules))

            # For checkboxes to be rendered in a table model, the
            # type has to be java.lang.Boolean, not a Python bool.

            for rule in rules:
                rule[-1] = Boolean(rule[-1])

        self.table = ParameterProcessingRulesTable(self, *rules)

        callbacks.setExtensionName(self.EXTENSION_NAME)
        callbacks.registerExtensionStateListener(self)
        callbacks.registerMessageEditorTabFactory(self)
        callbacks.addSuiteTab(self)
        return

    def createNewInstance(self, controller, editable):
        return ProtobufEditorTab(self, controller, editable)

    def getTabCaption(self):
        return self.EXTENSION_NAME

    def getUiComponent(self):
        return self.table

    def extensionUnloaded(self):
        if not self.table.rules:
            return

        rules = self.table.rules

        # The default JSONENcoder cannot dump a java.lang.Boolean type,
        # so convert it to a Python bool. (We'll have to change it back
        # when loading the rules again.

        for rule in rules:
            rule[-1] = bool(rule[-1])

        self.callbacks.saveExtensionSetting(
                'rules', base64.b64encode(json.dumps(rules)))
        return
Ejemplo n.º 28
0
    def init():
        canvas = RayTracePanel(w, h, aa, threads)
        self.add(canvas)

        #Save FileChooser
        fcS = JFileChooser()
        fcS.addChoosableFileFilter(
            FileNameExtensionFilter('Windows Bitmap (*.bmp)', ['bmp']))
        fcS.addChoosableFileFilter(
            FileNameExtensionFilter('JPEG / JFIF (*.jpg)', ['jpg']))
        fcS.addChoosableFileFilter(
            FileNameExtensionFilter('Portable Network Graphics (*.png)',
                                    ['png']))

        def saveFile(event):
            '''Performed when the save button is pressed'''
            result = fcS.showSaveDialog(frame)
            if result == JFileChooser.APPROVE_OPTION:
                file = fcS.getSelectedFile()
                fname = file.getPath()
                ext = fcS.getFileFilter().getExtensions()[0]
                if not fname.endswith('.' + ext):
                    file = File(fname + '.' + ext)
                canvas.saveToFile(file, ext)

        #Open FileChooser
        fcO = JFileChooser()
        fcO.addChoosableFileFilter(
            FileNameExtensionFilter('RayTrace Scene File (*.rts)', ['rts']))

        def openFile(event):
            '''Performed when the open button is pressed'''
            result = fcO.showOpenDialog(frame)
            if result == JFileChooser.APPROVE_OPTION:
                fname = fcO.getSelectedFile().getPath()
                if fname.endswith('.rts'):
                    f = open(fname, 'rb')
                    newScene = SceneFactory().buildScene(f)
                    f.close()
                    Painter(canvas, newScene, openButton, saveButton,
                            stopButton).start()

        def stop(event):
            '''Peformed when the stop button is pressed'''
            canvas.stopRendering()

        #Setup Menu
        menuBar = JMenuBar()
        menu = JMenu("File")
        menuBar.add(menu)
        openButton = JMenuItem("Open...", actionPerformed=openFile)
        openButton.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK))
        menu.add(openButton)
        saveButton = JMenuItem("Save as...", actionPerformed=saveFile)
        saveButton.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK))
        menu.add(saveButton)
        menu.addSeparator()
        stopButton = JMenuItem('Stop Render', actionPerformed=stop)
        stopButton.setAccelerator(KeyStroke.getKeyStroke(
            KeyEvent.VK_ESCAPE, 0))
        stopButton.setEnabled(False)
        menu.add(stopButton)
        menu.addSeparator()
        closeButton = JMenuItem('Close', actionPerformed=exit)
        closeButton.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK))
        menu.add(closeButton)
        self.setJMenuBar(menuBar)
Ejemplo n.º 29
0
def run(scene, w=512, h=512, aa=1, threads=1):
    """Create GUI and perform ray-tracing."""
    # Make Swing not look like garbage (so much)
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
    # Setup frame
    frame = JFrame("RayTracer", defaultCloseOperation=JFrame.EXIT_ON_CLOSE, size=(w, h))
    frame.setIconImage(ImageIcon("resources/icon.png").getImage())
    canvas = RayTracePanel(w, h, aa, threads)
    frame.getContentPane().add(JScrollPane(canvas))

    # Save FileChooser
    fcS = JFileChooser()
    fcS.addChoosableFileFilter(FileNameExtensionFilter("Windows Bitmap (*.bmp)", ["bmp"]))
    fcS.addChoosableFileFilter(FileNameExtensionFilter("JPEG / JFIF (*.jpg)", ["jpg"]))
    fcS.addChoosableFileFilter(FileNameExtensionFilter("Portable Network Graphics (*.png)", ["png"]))

    def saveFile(event):
        """Performed when the save button is pressed"""
        result = fcS.showSaveDialog(frame)
        if result == JFileChooser.APPROVE_OPTION:
            file = fcS.getSelectedFile()
            fname = file.getPath()
            ext = fcS.getFileFilter().getExtensions()[0]
            if not fname.endswith("." + ext):
                file = File(fname + "." + ext)
            canvas.saveToFile(file, ext)

    # Open FileChooser
    fcO = JFileChooser()
    fcO.addChoosableFileFilter(FileNameExtensionFilter("RayTrace Scene File (*.rts)", ["rts"]))

    def openFile(event):
        """Performed when the open button is pressed"""
        result = fcO.showOpenDialog(frame)
        if result == JFileChooser.APPROVE_OPTION:
            fname = fcO.getSelectedFile().getPath()
            if fname.endswith(".rts"):
                f = open(fname, "rb")
                newScene = SceneFactory().buildScene(f)
                f.close()
                Painter(canvas, newScene, openButton, saveButton, stopButton).start()

    def exit(event):
        """Performed when the exit button is pressed"""
        import sys

        sys.exit(0)

    def stop(event):
        """Peformed when the stop button is pressed"""
        canvas.stopRendering()

    # Setup Menu
    menuBar = JMenuBar()
    menu = JMenu("File")
    menuBar.add(menu)
    openButton = JMenuItem("Open...", actionPerformed=openFile)
    openButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK))
    menu.add(openButton)
    saveButton = JMenuItem("Save as...", actionPerformed=saveFile)
    saveButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK))
    menu.add(saveButton)
    menu.addSeparator()
    stopButton = JMenuItem("Stop Render", actionPerformed=stop)
    stopButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0))
    stopButton.setEnabled(False)
    menu.add(stopButton)
    menu.addSeparator()
    closeButton = JMenuItem("Close", actionPerformed=exit)
    closeButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK))
    menu.add(closeButton)
    frame.setJMenuBar(menuBar)

    # Finish initializing GUI
    self.pack()
Ejemplo n.º 30
0
def run(scene, w=512, h=512, aa=1, threads=1):
        '''Create GUI and perform ray-tracing.'''
        #Make Swing not look like garbage (so much)
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
        #Setup frame
        frame = JFrame(
            "RayTracer",
            defaultCloseOperation=JFrame.EXIT_ON_CLOSE,
            size=(w, h)
        )
        frame.setIconImage(ImageIcon('resources/icon.png').getImage())
        canvas = RayTracePanel(w, h, aa, threads)
        frame.getContentPane().add(JScrollPane(canvas))
        
        #Save FileChooser
        fcS = JFileChooser()
        fcS.addChoosableFileFilter(FileNameExtensionFilter('Windows Bitmap (*.bmp)', ['bmp']))
        fcS.addChoosableFileFilter(FileNameExtensionFilter('JPEG / JFIF (*.jpg)', ['jpg']))
        fcS.addChoosableFileFilter(FileNameExtensionFilter('Portable Network Graphics (*.png)', ['png']))
        def saveFile(event):
            '''Performed when the save button is pressed'''
            result = fcS.showSaveDialog(frame)
            if result == JFileChooser.APPROVE_OPTION:
                file = fcS.getSelectedFile()
                fname = file.getPath()
                ext = fcS.getFileFilter().getExtensions()[0]
                if not fname.endswith('.' + ext):
                    file = File(fname + '.' + ext)
                canvas.saveToFile(file, ext)
        
        #Open FileChooser
        fcO = JFileChooser()
        fcO.addChoosableFileFilter(FileNameExtensionFilter('RayTrace Scene File (*.rts)', ['rts']))
        def openFile(event):
            '''Performed when the open button is pressed'''
            result = fcO.showOpenDialog(frame)
            if result == JFileChooser.APPROVE_OPTION:
                fname = fcO.getSelectedFile().getPath()
                if fname.endswith('.rts'):
                    f = open(fname, 'rb')
                    newScene = SceneFactory().buildScene(f)
                    f.close()
                    Painter(canvas, newScene, openButton, saveButton).start()
                    
        def exit(event):
            '''Performed when the exit button is pressed'''
            import sys
            sys.exit(0)
        
        #Setup Menu
        menuBar = JMenuBar()
        menu = JMenu("File")
        menuBar.add(menu)
        openButton = JMenuItem("Open...", actionPerformed=openFile)
        openButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK))
        menu.add(openButton)
        saveButton = JMenuItem("Save as...", actionPerformed=saveFile)
        saveButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK))
        menu.add(saveButton)
        menu.addSeparator()
        closeButton = JMenuItem('Close', actionPerformed=exit)
        closeButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK))
        menu.add(closeButton)
        frame.setJMenuBar(menuBar)
        
        #Finish initializing GUI
        frame.pack()
        #frame.setLocationRelativeTo(None)
        frame.setVisible(True)
        
        #Perform ray-tracing
        if scene is not None:
            Thread(Painter(canvas, scene, openButton, saveButton)).start()