本文整理汇总了Python中javax.swing.JFileChooser.setSelectedFile方法的典型用法代码示例。如果您正苦于以下问题:Python JFileChooser.setSelectedFile方法的具体用法?Python JFileChooser.setSelectedFile怎么用?Python JFileChooser.setSelectedFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFileChooser
的用法示例。
在下文中一共展示了JFileChooser.setSelectedFile方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_pdf
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import setSelectedFile [as 别名]
def save_pdf(self, event):
from com.itextpdf.text.pdf import PdfWriter
from com.itextpdf.text import Document
fileChooser = JFileChooser()
fileChooser.setSelectedFile(java.io.File('%s.pdf' % self.view.network.name))
if fileChooser.showSaveDialog(self) == JFileChooser.APPROVE_OPTION:
f = fileChooser.getSelectedFile()
doc = Document()
writer = PdfWriter.getInstance(doc, java.io.FileOutputStream(f))
doc.open()
cb = writer.getDirectContent()
w = self.view.area.size.width
h = self.view.area.size.height
pw = 550
ph = 800
tp = cb.createTemplate(pw, ph)
g2 = tp.createGraphicsShapes(pw, ph)
at = java.awt.geom.AffineTransform()
s = min(float(pw) / w, float(ph) / h)
at.scale(s, s)
g2.transform(at)
self.view.area.pdftemplate = tp, s
self.view.area.paint(g2)
self.view.area.pdftemplate = None
g2.dispose()
cb.addTemplate(tp, 20, 0)
doc.close()
示例2: exportToHTML
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import setSelectedFile [as 别名]
def exportToHTML(self, event):
parentFrame = JFrame()
fileChooser = JFileChooser()
fileChooser.setSelectedFile(File("AutorizeReprort.html"));
fileChooser.setDialogTitle("Save Autorize Report")
userSelection = fileChooser.showSaveDialog(parentFrame)
if userSelection == JFileChooser.APPROVE_OPTION:
fileToSave = fileChooser.getSelectedFile()
enforcementStatusFilter = self.exportES.getSelectedItem()
htmlContent = """<html><title>Autorize Report by Barak Tawily</title>
<style>
.datagrid table { border-collapse: collapse; text-align: left; width: 100%; }
.datagrid {font: normal 12px/150% Arial, Helvetica, sans-serif; background: #fff; overflow: hidden; border: 1px solid #006699; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; }
.datagrid table td, .datagrid table th { padding: 3px 10px; }
.datagrid table thead th {background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #006699), color-stop(1, #00557F) );background:-moz-linear-gradient( center top, #006699 5%, #00557F 100% );filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#006699', endColorstr='#00557F');background-color:#006699; color:#FFFFFF; font-size: 15px; font-weight: bold; border-left: 1px solid #0070A8; } .datagrid table thead th:first-child { border: none; }.datagrid table tbody td { color: #00496B; border-left: 1px solid #E1EEF4;font-size: 12px;font-weight: normal; }.datagrid table tbody .alt td { background: #E1EEF4; color: #00496B; }.datagrid table tbody td:first-child { border-left: none; }.datagrid table tbody tr:last-child td { border-bottom: none; }.datagrid table tfoot td div { border-top: 1px solid #006699;background: #E1EEF4;} .datagrid table tfoot td { padding: 0; font-size: 12px } .datagrid table tfoot td div{ padding: 2px; }.datagrid table tfoot td ul { margin: 0; padding:0; list-style: none; text-align: right; }.datagrid table tfoot li { display: inline; }.datagrid table tfoot li a { text-decoration: none; display: inline-block; padding: 2px 8px; margin: 1px;color: #FFFFFF;border: 1px solid #006699;-webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #006699), color-stop(1, #00557F) );background:-moz-linear-gradient( center top, #006699 5%, #00557F 100% );filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#006699', endColorstr='#00557F');background-color:#006699; }.datagrid table tfoot ul.active, .datagrid table tfoot ul a:hover { text-decoration: none;border-color: #006699; color: #FFFFFF; background: none; background-color:#00557F;}div.dhtmlx_window_active, div.dhx_modal_cover_dv { position: fixed !important; }
table {
width: 100%;
table-layout: fixed;
}
td {
border: 1px solid #35f;
overflow: hidden;
text-overflow: ellipsis;
}
td.a {
width: 13%;
white-space: nowrap;
}
td.b {
width: 9%;
word-wrap: break-word;
}
</style>
<body>
<h1>Autorize Report<h1>
<div class="datagrid"><table>
<thead><tr><th>URL</th><th>Authorization Enforcement Status</th></tr></thead>
<tbody>"""
for i in range(0,self._log.size()):
color = ""
if self._log.get(i)._enfocementStatus == self._enfocementStatuses[0]:
color = "red"
if self._log.get(i)._enfocementStatus == self._enfocementStatuses[1]:
color = "yellow"
if self._log.get(i)._enfocementStatus == self._enfocementStatuses[2]:
color = "LawnGreen"
if enforcementStatusFilter == "All Statuses":
htmlContent += "<tr bgcolor=\"%s\"><td><a href=\"%s\">%s</a></td><td>%s</td></tr>" % (color,self._log.get(i)._url,self._log.get(i)._url, self._log.get(i)._enfocementStatus)
else:
if enforcementStatusFilter == self._log.get(i)._enfocementStatus:
htmlContent += "<tr bgcolor=\"%s\"><td><a href=\"%s\">%s</a></td><td>%s</td></tr>" % (color,self._log.get(i)._url,self._log.get(i)._url, self._log.get(i)._enfocementStatus)
htmlContent += "</tbody></table></div></body></html>"
f = open(fileToSave.getAbsolutePath(), 'w')
f.writelines(htmlContent)
f.close()
示例3: set_from_file
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import setSelectedFile [as 别名]
def set_from_file(self, event):
fileChooser = JFileChooser()
if self.filename is not None:
fileChooser.setSelectedFile(java.io.File(self.filename))
if fileChooser.showOpenDialog(self) == JFileChooser.APPROVE_OPTION:
self.filename = fileChooser.selectedFile.absolutePath
#TODO: this doesn't for for nested FunctionInputs
input = self.view.network.getNode(self.name)
from nef.functions import Interpolator
interp = Interpolator(self.filename)
interp.load_into_function(input)
示例4: go
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import setSelectedFile [as 别名]
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
示例5: exportToCSV
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import setSelectedFile [as 别名]
def exportToCSV(self):
parentFrame = JFrame()
fileChooser = JFileChooser()
fileChooser.setSelectedFile(File("AutorizeReprort.csv"));
fileChooser.setDialogTitle("Save Autorize Report")
userSelection = fileChooser.showSaveDialog(parentFrame)
if userSelection == JFileChooser.APPROVE_OPTION:
fileToSave = fileChooser.getSelectedFile()
enforcementStatusFilter = self.exportES.getSelectedItem()
csvContent = "id\tURL\tOriginal length\tModified length\tUnauthorized length\tAuthorization Enforcement Status\tAuthorization Unauthenticated Status\n"
for i in range(0,self._log.size()):
if enforcementStatusFilter == "All Statuses":
csvContent += "%d\t%s\t%d\t%d\t%d\t%s\t%s\n" % (self._log.get(i)._id,self._log.get(i)._url, len(self._log.get(i)._originalrequestResponse.getResponse()) if self._log.get(i)._originalrequestResponse != None else 0, len(self._log.get(i)._requestResponse.getResponse()) if self._log.get(i)._requestResponse != None else 0, len(self._log.get(i)._unauthorizedRequestResponse.getResponse()) if self._log.get(i)._unauthorizedRequestResponse != None else 0, self._log.get(i)._enfocementStatus, self._log.get(i)._enfocementStatusUnauthorized)
else:
if (enforcementStatusFilter == self._log.get(i)._enfocementStatus) or (enforcementStatusFilter == self._log.get(i)._enfocementStatusUnauthorized):
csvContent += "%d\t%s\t%d\t%d\t%d\t%s\t%s\n" % (self._log.get(i)._id,self._log.get(i)._url, len(self._log.get(i)._originalrequestResponse.getResponse()) if self._log.get(i)._originalrequestResponse != None else 0, len(self._log.get(i)._requestResponse.getResponse()) if self._log.get(i)._requestResponse != None else 0, len(self._log.get(i)._unauthorizedRequestResponse.getResponse()) if self._log.get(i)._unauthorizedRequestResponse != None else 0, self._log.get(i)._enfocementStatus, self._log.get(i)._enfocementStatusUnauthorized)
f = open(fileToSave.getAbsolutePath(), 'w')
f.writelines(csvContent)
f.close()
示例6: DataPanel
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import setSelectedFile [as 别名]
class DataPanel(JPanel,MouseListener):
def __init__(self,view):
JPanel.__init__(self)
self.view=view
self.background=Color.white
self.layout=BorderLayout()
self.popup=JPopupMenu()
self.popup_items={}
self.add(self.make_controls(),BorderLayout.SOUTH)
data,title=self.extract_data()
self.table=JTable(DefaultTableModel(data,title))
scroll=JScrollPane(self.table)
self.add(scroll)
scroll.addMouseListener(self)
self.table.tableHeader.addMouseListener(self)
self.table.addMouseListener(self)
self.fileChooser=JFileChooser()
self.fileChooser.setFileFilter(CSVFilter())
self.fileChooser.setSelectedFile(File('%s.csv'%self.view.network.name))
def make_controls(self):
from timeview.components.timecontrol import Icon, ShadedIcon
panel=JPanel(background=self.background)
panel.add(JButton(Icon.refresh,actionPerformed=self.refresh,rolloverIcon=ShadedIcon.refresh,toolTipText='refresh',borderPainted=False,focusPainted=False,contentAreaFilled=False))
filter=JPanel(layout=BorderLayout(),opaque=False)
self.filter = JSpinner(SpinnerNumberModel(self.view.tau_filter,0,0.5,0.01),stateChanged=self.refresh)
filter.add(self.filter)
filter.add(JLabel('filter'),BorderLayout.NORTH)
filter.maximumSize=filter.preferredSize
panel.add(filter)
decimals=JPanel(layout=BorderLayout(),opaque=False)
self.decimals = JSpinner(SpinnerNumberModel(3,0,10,1),stateChanged=self.refresh)
decimals.add(self.decimals)
decimals.add(JLabel('decimal places'),BorderLayout.NORTH)
decimals.maximumSize=decimals.preferredSize
panel.add(decimals)
panel.add(JButton(Icon.save,actionPerformed=self.save,rolloverIcon=ShadedIcon.save,toolTipText='save',borderPainted=False,focusPainted=False,contentAreaFilled=False))
return panel
def extract_data(self):
pause_state=self.view.paused
self.view.paused=True
while self.view.simulating:
java.lang.Thread.sleep(10)
tau=float(self.filter.value)
dt=self.view.dt
if tau<dt: dt_tau=None
else: dt_tau=dt/tau
decimals=int(self.decimals.value)
format='%%1.%df'%decimals
start_index=max(0,self.view.timelog.tick_count-self.view.timelog.tick_limit+1)
count=min(self.view.timelog.tick_limit,self.view.timelog.tick_count)
start_time=start_index*self.view.dt
data=None
title=['t']
keys = self.view.watcher.active.keys()
keys.sort()
for key in keys:
watch = self.view.watcher.active[key]
name,func,args=key
code='%s.%s%s'%(name,func.__name__,args)
if code not in self.popup_items:
state=True
if 'spike' in func.__name__: state=False
if 'voltage' in func.__name__: state=False
self.popup_items[code]=JCheckBoxMenuItem(code,state,stateChanged=self.refresh)
self.popup.add(self.popup_items[code])
if self.popup_items[code].state is False: continue
d=watch.get(dt_tau=dt_tau,start=start_index,count=count)
n=len(watch.get_first())
if data is None:
data=[]
while len(data)<len(d):
data.append(['%0.4f'%(start_time+(len(data)+0)*self.view.dt)])
for i in range(n):
title.append('%s[%d]'%(code,i))
for j in range(len(data)):
dd=d[j]
#.........这里部分代码省略.........
示例7: JFileChooser
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import setSelectedFile [as 别名]
else:
csvFile.write("Off")
# Notify the writer of the end of this detail record
csvFile.endRecord()
csvFile.flush()
print "Entry", entry.getId(), "written"
# Now do the actual work here
# Create output file.
# Unless modified here, this will create the output file in the same
# location as the roster itself.
# Default behaviour is for this to be in the user preferences directory
fc = JFileChooser()
fc.setSelectedFile(java.io.File(outFile))
ret = fc.showSaveDialog(None)
if ret == JFileChooser.APPROVE_OPTION:
# We've got a valid filename
outFile = fc.getSelectedFile().toString()
print "Output file:", outFile
csvFile = com.csvreader.CsvWriter(java.io.BufferedOutputStream(java.io.FileOutputStream(outFile)),',',java.nio.charset.Charset.defaultCharset())
# Output the header if required
if outputHeader==True:
writeHeader(csvFile)
# Output details
writeDetails(csvFile)
# Flush the write buffer and close the file
示例8: JythonGui
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import setSelectedFile [as 别名]
#.........这里部分代码省略.........
self.top_panel.add(getStageLabel("Run SASI: (this might take a while)"))
self.run_button = JButton("Run...", actionPerformed=self.runSASI)
self.top_panel.add(self.run_button)
SpringUtilities.makeCompactGrid(
self.top_panel, self.stageCounter - 1, 2, 6, 6, 6, 6)
# Progress bar.
self.progressBar = JProgressBar(0, 100)
self.main_panel.add(self.progressBar)
# Log panel.
self.log_panel = JPanel()
self.log_panel.alignmentX = Component.CENTER_ALIGNMENT
self.log_panel.setBorder(EmptyBorder(10,10,10,10))
self.main_panel.add(self.log_panel)
self.log_panel.setLayout(BorderLayout())
self.log = JTextArea()
self.log.editable = False
self.logScrollPane = JScrollPane(self.log)
self.logScrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS)
self.logScrollBar = self.logScrollPane.getVerticalScrollBar()
self.log_panel.add(self.logScrollPane, BorderLayout.CENTER)
# File selectors
self.inputChooser = JFileChooser()
self.inputChooser.fileSelectionMode = JFileChooser.FILES_AND_DIRECTORIES
self.outputChooser = JFileChooser()
defaultOutputFile = os.path.join(System.getProperty("user.home"),
"sasi_project.zip")
self.outputChooser.setSelectedFile(File(defaultOutputFile));
self.outputChooser.fileSelectionMode = JFileChooser.FILES_ONLY
self.frame.setLocationRelativeTo(None)
self.frame.visible = True
def browseInstructions(self, event):
""" Open a browser to the instructions page. """
browseURI(self.instructionsURI)
def itemStateChanged(self, event):
""" Listen for checkbox changes. """
checkBox = event.getItemSelectable()
is_selected = (event.getStateChange() == ItemEvent.SELECTED)
result_field = self.resultFieldCheckBoxes[checkBox]
self.selected_result_fields[result_field['id']] = is_selected
def log_msg(self, msg):
""" Print message to log and scroll to bottom. """
self.log.append(msg + "\n")
self.log.setCaretPosition(self.log.getDocument().getLength())
def openInputChooser(self, event):
ret = self.inputChooser.showOpenDialog(self.frame)
if ret == JFileChooser.APPROVE_OPTION:
self.selected_input_file = self.inputChooser.selectedFile
self.log_msg("Selected '%s' as input." % self.selected_input_file.path)
def openOutputChooser(self, event):
ret = self.outputChooser.showSaveDialog(self.frame)
if ret == JFileChooser.APPROVE_OPTION:
selectedPath = self.outputChooser.selectedFile.path
if not selectedPath.endswith('.zip'):
示例9: JythonGui
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import setSelectedFile [as 别名]
class JythonGui(object):
def __init__(self, instructionsURI=""):
self.instructionsURI = instructionsURI
self.logger = logging.getLogger("sasi_gridder_gui")
self.logger.addHandler(logging.StreamHandler())
def log_fn(msg):
self.log_msg(msg)
self.logger.addHandler(FnLogHandler(log_fn))
self.logger.setLevel(logging.DEBUG)
self.selected_input_file = None
self.selected_output_file = None
self.frame = JFrame("SASI Gridder", defaultCloseOperation=WindowConstants.EXIT_ON_CLOSE)
self.frame.size = (650, 600)
self.main_panel = JPanel()
self.main_panel.layout = BoxLayout(self.main_panel, BoxLayout.Y_AXIS)
self.frame.add(self.main_panel)
self.top_panel = JPanel(SpringLayout())
self.top_panel.alignmentX = Component.CENTER_ALIGNMENT
self.main_panel.add(self.top_panel)
self.stageCounter = 1
def getStageLabel(txt):
label = JLabel("%s. %s" % (self.stageCounter, txt))
self.stageCounter += 1
return label
# Instructions link.
self.top_panel.add(getStageLabel("Read the instructions:"))
instructionsButton = JButton(
('<HTML><FONT color="#000099">' "<U>open instructions</U></FONT><HTML>"),
actionPerformed=self.browseInstructions,
)
instructionsButton.setHorizontalAlignment(SwingConstants.LEFT)
instructionsButton.setBorderPainted(False)
instructionsButton.setOpaque(False)
instructionsButton.setBackground(Color.WHITE)
instructionsButton.setToolTipText(self.instructionsURI)
self.top_panel.add(instructionsButton)
# Select input elements.
self.top_panel.add(getStageLabel("Select an input data folder:"))
self.top_panel.add(JButton("Select input...", actionPerformed=self.openInputChooser))
# Select output elements.
self.top_panel.add(getStageLabel("Specify an output file:"))
self.top_panel.add(JButton("Specify output...", actionPerformed=self.openOutputChooser))
# Run elements.
self.top_panel.add(getStageLabel("Run SASI Gridder: (this might take a hwile"))
self.run_button = JButton("Run...", actionPerformed=self.runSASIGridder)
self.top_panel.add(self.run_button)
SpringUtilities.makeCompactGrid(self.top_panel, self.stageCounter - 1, 2, 6, 6, 6, 6)
# Progress bar.
self.progressBar = JProgressBar(0, 100)
self.main_panel.add(self.progressBar)
# Log panel.
self.log_panel = JPanel()
self.log_panel.alignmentX = Component.CENTER_ALIGNMENT
self.log_panel.setBorder(EmptyBorder(10, 10, 10, 10))
self.main_panel.add(self.log_panel)
self.log_panel.setLayout(BorderLayout())
self.log = JTextArea()
self.log.editable = False
self.logScrollPane = JScrollPane(self.log)
self.logScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS)
self.log_panel.add(self.logScrollPane, BorderLayout.CENTER)
# File selectors
self.inputChooser = JFileChooser()
self.inputChooser.fileSelectionMode = JFileChooser.FILES_AND_DIRECTORIES
self.outputChooser = JFileChooser()
self.outputChooser.fileSelectionMode = JFileChooser.FILES_ONLY
defaultOutputFile = os.path.join(System.getProperty("user.home"), "gridded_efforts.csv")
self.outputChooser.setSelectedFile(File(defaultOutputFile))
self.frame.setLocationRelativeTo(None)
self.frame.visible = True
def browseInstructions(self, event):
""" Open a browser to the instructions page. """
browseURI(self.instructionsURI)
return
def log_msg(self, msg):
self.log.append(msg + "\n")
self.log.setCaretPosition(self.log.getDocument().getLength())
def openInputChooser(self, event):
ret = self.inputChooser.showOpenDialog(self.frame)
#.........这里部分代码省略.........