Example #1
0
 def actionPerformed(self, actionEvent):
     chooser = JFileChooser()
     #chooser.setCurrentDirectory(".")
     chooser.setDialogTitle("Choose file")
     chooser.setFileSelectionMode(JFileChooser.FILES_ONLY)
     chooser.setAcceptAllFileFilterUsed(False)
     if chooser.showOpenDialog(self) == JFileChooser.APPROVE_OPTION:
         print chooser.getCurrentDirectory()
         print chooser.getSelectedFile()
         self.field.setText(str(chooser.getSelectedFile()))
     else:
         print "No file selected"
def searchFile2(event):
    label3.text = "Isi pesan terenkripsi"
    label4.text = "Isi pesan asli"
    myFileChooser = JFileChooser()
    rVal = int(myFileChooser.showOpenDialog(None))
    print rVal
    if (rVal == JFileChooser.APPROVE_OPTION):
        encryptedTextFile.text = myFileChooser.getSelectedFile().getName()
        encryptedTextPath.text = myFileChooser.getCurrentDirectory().toString()
        try:
            myPath = encryptedTextPath.text + "/" + encryptedTextFile.text
            fileReaderX = FileReader(myPath)
            bufferedReaderX = BufferedReader(fileReaderX)
            inputFile = ""
            textFieldReadable = bufferedReaderX.readLine()
            while (textFieldReadable != None):
                inputFile += textFieldReadable
                inputFile += "\n"
                textFieldReadable = bufferedReaderX.readLine()
            pesanAsli.text = inputFile

            import myGUI.saveToFile as convertThis

            return convertThis.convertBackToInt(inputFile)

        except (RuntimeError, TypeError, NameError):
            print "eror gan"
Example #3
0
    def createDialogBoxForImportExport(self, dialogTitle, extensionFilter, buttonText):

        # create frame
        frameImportExportDialogBox = JFrame()

        # try to load the last used directory
        try:
            # load the directory for future imports/exports
            fileChooserDirectory = self._callbacks.loadExtensionSetting("fileChooserDirectory")

        # there is not a last used directory
        except:
            # set the last used directory to blank
            fileChooserDirectory = ""

        # create file chooser
        fileChooserImportExportDialogBox = JFileChooser(fileChooserDirectory)

        # set dialog title
        fileChooserImportExportDialogBox.setDialogTitle(dialogTitle)

        # create extension filter
        filterImportExportDialogBox = FileNameExtensionFilter(extensionFilter[0], extensionFilter[1])

        # set extension filter
        fileChooserImportExportDialogBox.setFileFilter(filterImportExportDialogBox)

        # show dialog box and get value
        valueFileChooserImportExportDialogBox = fileChooserImportExportDialogBox.showDialog(frameImportExportDialogBox, buttonText)

        # check if a file was not selected
        if valueFileChooserImportExportDialogBox != JFileChooser.APPROVE_OPTION:
        
            # return no path/file selected
            return False, "No Path/File"

        # get the directory
        fileChooserDirectory = fileChooserImportExportDialogBox.getCurrentDirectory()

        # store the directory for future imports/exports
        self._callbacks.saveExtensionSetting("fileChooserDirectory", str(fileChooserDirectory))

        # get absolute path of file
        fileChosenImportExportDialogBox = fileChooserImportExportDialogBox.getSelectedFile().getAbsolutePath()

        # split name and extension
        fileNameImportExportDialogBox, fileExtensionImportExportDialogBox = os.path.splitext(fileChosenImportExportDialogBox)

        # check if file does not have an extention
        if fileExtensionImportExportDialogBox == "":

            # add extension to file
            fileChosenImportExportDialogBox = fileChosenImportExportDialogBox + extensionFilter[2]

        # return dialog box value and path/file
        return True, fileChosenImportExportDialogBox
def f2_clic_browse1(event):
   print("Click browse 1")
   fc = JFileChooser()
   fc.setCurrentDirectory(gvars['path_JFileChooser'])
   fc.setDialogTitle('Open original image')
   result = fc.showOpenDialog( None )
   if result == JFileChooser.APPROVE_OPTION :
      message = 'Path to original image %s' % fc.getSelectedFile()
      gvars['path_original_image'] = str(fc.getSelectedFile())
      f2_txt1.setText(gvars['path_original_image'])
      gvars['path_JFileChooser'] = fc.getCurrentDirectory()

   else :
      message = 'Request canceled by user'
   print( message )
Example #5
0
    def menuItemClicked(self, menuItemCaption, messageInfo):
        if menuItemCaption == 'Save PoC':

            if self.dir:
                fc = JFileChooser(self.dir)
            else:
                fc = JFileChooser()

            returnVal = fc.showSaveDialog(None)

            if returnVal == JFileChooser.APPROVE_OPTION:
                file = fc.getSelectedFile()

                try:
                    mode = 'w'
                    if file.exists():
                        res = JOptionPane.showConfirmDialog(
                            None, "File exists. Append?")
                        mode = {
                            JOptionPane.YES_OPTION: 'a',
                            JOptionPane.NO_OPTION: 'w',
                            JOptionPane.CANCEL_OPTION: None,
                        }[res]

                    if not mode:
                        return
                    fp = open(str(file.getAbsolutePath()), mode)
                    for req_resp in messageInfo:
                        req = req_resp.getRequest()
                        resp = req_resp.getResponse()
                        fp.write(req.tostring())
                        fp.write('\r\n\r\n')
                        fp.write(resp.tostring())
                        fp.write('\r\n\r\n')
                    fp.close()
                except Exception, e:
                    JOptionPane.showMessageDialog(
                        None, "Error during save: " + str(e), "Error",
                        JOptionPane.ERROR_MESSAGE)
                    raise

                JOptionPane.showMessageDialog(None,
                                              "File was successfully saved",
                                              "Ok",
                                              JOptionPane.INFORMATION_MESSAGE)
                self.dir = fc.getCurrentDirectory()
Example #6
0
    def menuItemClicked(self, menuItemCaption, messageInfo):
        if menuItemCaption == 'Save PoC':

            if self.dir:
                fc = JFileChooser(self.dir)
            else:
                fc = JFileChooser()

            returnVal = fc.showSaveDialog(None)

            if returnVal == JFileChooser.APPROVE_OPTION:
                file = fc.getSelectedFile()

                try:
                    mode = 'w'
                    if file.exists():
                        res = JOptionPane.showConfirmDialog(None, 
                                "File exists. Append?")
                        mode = {
                                JOptionPane.YES_OPTION : 'a',
                                JOptionPane.NO_OPTION : 'w',
                                JOptionPane.CANCEL_OPTION : None,
                                }[res]

                    if not mode:
                        return
                    fp = open(str(file.getAbsolutePath()), mode)
                    for req_resp in messageInfo:
                        req = req_resp.getRequest()
                        resp = req_resp.getResponse()
                        fp.write(req.tostring())
                        fp.write('\r\n\r\n')
                        fp.write(resp.tostring())
                        fp.write('\r\n\r\n')
                    fp.close()
                except Exception, e:
                    JOptionPane.showMessageDialog(None, 
                            "Error during save: " + str(e), "Error",  
                            JOptionPane.ERROR_MESSAGE)
                    raise

                JOptionPane.showMessageDialog(None, 
                            "File was successfully saved", "Ok",  
                            JOptionPane.INFORMATION_MESSAGE)
                self.dir = fc.getCurrentDirectory()
Example #7
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
def searchFile(event):
    myFileChooser = JFileChooser()
    rVal = int(myFileChooser.showOpenDialog(None))
    print rVal
    if (rVal == JFileChooser.APPROVE_OPTION):
        plainTextFile.text = myFileChooser.getSelectedFile().getName()
        plainTextPath.text = myFileChooser.getCurrentDirectory().toString()
        try:

            myPath = plainTextPath.text + "/" + plainTextFile.text
            fileReader = FileReader(myPath)
            bufferedReader = BufferedReader(fileReader)
            inputFile = ""
            textFieldReadable = bufferedReader.readLine()
            while (textFieldReadable != None):
                inputFile += textFieldReadable
                inputFile += "\n"
                textFieldReadable = bufferedReader.readLine()
            pesanAsli.text = inputFile

        except (RuntimeError, TypeError, NameError):
            print "eror gan"
Example #9
0
def fileBrowser():
    myFileChooser = JFileChooser()
    rVal = int(myFileChooser.showOpenDialog(None))
    print rVal
    if (rVal == JFileChooser.APPROVE_OPTION):
        theName = myFileChooser.getSelectedFile().getName()
        thePath = myFileChooser.getCurrentDirectory().toString()
        try:
            myPath = theName + "/" + thePath

            fileReader = FileReader(myPath)
            bufferedReader = BufferedReader(fileReader)
            inputFile = ""
            textFieldReadable = bufferedReader.readLine()
            while (textFieldReadable != None):
                inputFile += textFieldReadable
                inputFile += "\n"
            #    textFieldReadable = bufferedReader.readLine()
            #pesanAsli.text = inputFile
            return inputFile

        except (RuntimeError, TypeError, NameError):
            print "eror gan"
Example #10
0
def fileBrowser(event):
    myFileChooserX = JFileChooser()
    rValX = int(myFileChooserX.showOpenDialog(None))
    print "rVal =", rValX
    if (rValX == JFileChooser.APPROVE_OPTION):
        namaFile.text = myFileChooserX.getSelectedFile().getName()
        alamatFile.text = myFileChooserX.getCurrentDirectory().toString()
        try:
            myPath = alamatFile.text + "/" + namaFile.text
            fileReader = FileReader(myPath)
            print "mypath =", myPath
            bufferedReader = BufferedReader(fileReader)
            inputFile = ""
            textFieldReadable = bufferedReader.readLine()
            while (textFieldReadable != None):
                inputFile += textFieldReadable
                inputFile += "\n"
                textFieldReadable = bufferedReader.readLine()
            print textFieldReadable
            #    textFieldReadable = bufferedReader.readLine()
            plainText.text = inputFile
            return inputFile
        except ():  #RuntimeError, TypeError, NameError):
            print "gagal mengembalikan pesan"
Example #11
0


###########################################################
####################  Before we begin #####################
###########################################################

gvars = {} # Create dictionary to store variables created within functions
gvars['eroded_pixels'] = 0 # initialize

myTempFile = NamedTemporaryFile(suffix='.zip')
gvars['tempFile'] = myTempFile.name

#Set the original directory of the filechooser to the home folder
fc = JFileChooser()
gvars['original_JFileChooser'] = fc.getCurrentDirectory()
gvars['path_JFileChooser'] = gvars['original_JFileChooser']

###########################################################
########## Single Image Labels to ROIs Class ##############
###########################################################

class LabelToRoi_Task(SwingWorker):

    def __init__(self, imp):
        SwingWorker.__init__(self)
        self.imp = imp

    def doInBackground(self):
        imp = self.imp
        print "started"
argvs = sys.argv
argc = len(argvs)
defaultpath = '/'
frontoutputpath2 = '/'

xmlfil = XMLFilter('kike')
print xmlfil.getDescription()
chooser = JFileChooser()
fakefile = File(defaultpath)
chooser.setCurrentDirectory(fakefile)
chooser.setDialogTitle("Select xml file")
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES)
chooser.setAcceptAllFileFilterUsed(False)
InputFolderPath = ''
if (chooser.showOpenDialog(None) == JFileChooser.APPROVE_OPTION):
    IJ.log("getCrrentDirectory(): " + chooser.getCurrentDirectory().toString())
    InputFolderPath = chooser.getSelectedFile().toString()
else:
    IJ.log("No selection")
file = File(InputFolderPath)

# We have to feed a logger to the reader.
logger = Logger.IJ_LOGGER

#-------------------
# Instantiate reader
#-------------------

reader = TmXmlReader(file)
if not reader.isReadingOk():
    sys.exit(reader.getErrorMessage())