📄 wximportdialog.py
字号:
#Boa:Dialog:wxImportDialog
"""
A dialog for import ASCII files for PyChem
$Id: wxImportDialog.py Copyright (C) 2005 Roger Jarvis
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
from wxPython.wx import *
from StaticTextCtrl import *
from fileIO import *
def create(parent):
return wxImportDialog(parent)
[wxID_WXIMPORTDIALOG, wxID_WXIMPORTDIALOGBTNBROWSEARRAY,
wxID_WXIMPORTDIALOGBTNCANCEL, wxID_WXIMPORTDIALOGBTNOK,
wxID_WXIMPORTDIALOGCBCOMMADELIM, wxID_WXIMPORTDIALOGCBOTHER,
wxID_WXIMPORTDIALOGCBSEMIDELIM, wxID_WXIMPORTDIALOGCBSPACEDELIM,
wxID_WXIMPORTDIALOGCBTABDELIM, wxID_WXIMPORTDIALOGCBTRANSPOSE,
wxID_WXIMPORTDIALOGSTARRAY, wxID_WXIMPORTDIALOGSWLOADX,
wxID_WXIMPORTDIALOGTXTOTHER,
] = map(lambda _init_ctrls: wxNewId(), range(13))
class wxImportDialog(wxDialog):
def _init_ctrls(self, prnt):
# generated method, don't edit
wxDialog.__init__(self, id=wxID_WXIMPORTDIALOG, name='wxImportDialog',
parent=prnt, pos=wxPoint(355, 218), size=wxSize(287, 232),
style=wxDEFAULT_DIALOG_STYLE, title='Import X-data File')
self.SetClientSize(wxSize(279, 198))
self.SetToolTipString('')
self.swLoadX = wxSashWindow(id=wxID_WXIMPORTDIALOGSWLOADX,
name='swLoadX', parent=self, pos=wxPoint(0, 0), size=wxSize(279,
198), style=wxCLIP_CHILDREN | wxSW_3D)
self.swLoadX.SetToolTipString('')
self.btnBrowseArray = wxButton(id=wxID_WXIMPORTDIALOGBTNBROWSEARRAY,
label='Browse...', name='btnBrowseArray', parent=self.swLoadX,
pos=wxPoint(192, 24), size=wxSize(75, 23), style=0)
EVT_BUTTON(self.btnBrowseArray, wxID_WXIMPORTDIALOGBTNBROWSEARRAY,
self.OnBtnbrowsearrayButton)
self.stArray = wxStaticTextCtrl(caption='',
id=wxID_WXIMPORTDIALOGSTARRAY, name='stArray',
parent=self.swLoadX, pos=wxPoint(16, 24), size=wxSize(160, 21),
style=0, value='')
self.btnOK = wxButton(id=wxID_WXIMPORTDIALOGBTNOK, label='OK',
name='btnOK', parent=self.swLoadX, pos=wxPoint(16, 160),
size=wxSize(104, 23), style=0)
EVT_BUTTON(self.btnOK, wxID_WXIMPORTDIALOGBTNOK, self.OnBtnOKButton)
self.btnCancel = wxButton(id=wxID_WXIMPORTDIALOGBTNCANCEL,
label='Cancel', name='btnCancel', parent=self.swLoadX,
pos=wxPoint(160, 160), size=wxSize(107, 23), style=0)
EVT_BUTTON(self.btnCancel, wxID_WXIMPORTDIALOGBTNCANCEL,
self.OnBtnCancelButton)
self.cbTabDelim = wxCheckBox(id=wxID_WXIMPORTDIALOGCBTABDELIM,
label='Tab delimited', name='cbTabDelim', parent=self.swLoadX,
pos=wxPoint(16, 64), size=wxSize(96, 13), style=0)
self.cbTabDelim.SetValue(True)
self.cbTabDelim.SetToolTipString('')
EVT_CHECKBOX(self.cbTabDelim, wxID_WXIMPORTDIALOGCBTABDELIM,
self.OnCbTabDelimCheckbox)
self.cbSpaceDelim = wxCheckBox(id=wxID_WXIMPORTDIALOGCBSPACEDELIM,
label='Space delimited', name='cbSpaceDelim', parent=self.swLoadX,
pos=wxPoint(160, 64), size=wxSize(96, 13), style=0)
self.cbSpaceDelim.SetValue(False)
self.cbSpaceDelim.SetToolTipString('')
EVT_CHECKBOX(self.cbSpaceDelim, wxID_WXIMPORTDIALOGCBSPACEDELIM,
self.OnCbSpaceDelimCheckbox)
self.cbCommaDelim = wxCheckBox(id=wxID_WXIMPORTDIALOGCBCOMMADELIM,
label='Comma delimited', name='cbCommaDelim', parent=self.swLoadX,
pos=wxPoint(160, 96), size=wxSize(104, 13), style=0)
self.cbCommaDelim.SetValue(False)
self.cbCommaDelim.SetToolTipString('')
EVT_CHECKBOX(self.cbCommaDelim, wxID_WXIMPORTDIALOGCBCOMMADELIM,
self.OnCbCommaDelimCheckbox)
self.cbOther = wxCheckBox(id=wxID_WXIMPORTDIALOGCBOTHER, label='Other',
name='cbOther', parent=self.swLoadX, pos=wxPoint(16, 128),
size=wxSize(56, 13), style=0)
self.cbOther.SetValue(False)
self.cbOther.SetToolTipString('')
EVT_CHECKBOX(self.cbOther, wxID_WXIMPORTDIALOGCBOTHER,
self.OnCbOtherCheckbox)
self.cbSemiDelim = wxCheckBox(id=wxID_WXIMPORTDIALOGCBSEMIDELIM,
label='Semicolon delimited', name='cbSemiDelim',
parent=self.swLoadX, pos=wxPoint(16, 96), size=wxSize(112, 13),
style=0)
self.cbSemiDelim.SetValue(False)
self.cbSemiDelim.SetToolTipString('')
EVT_CHECKBOX(self.cbSemiDelim, wxID_WXIMPORTDIALOGCBSEMIDELIM,
self.OnCbSemiDelimCheckbox)
self.txtOther = wxTextCtrl(id=wxID_WXIMPORTDIALOGTXTOTHER,
name='txtOther', parent=self.swLoadX, pos=wxPoint(72, 126),
size=wxSize(40, 21), style=0, value='')
self.txtOther.SetToolTipString('')
self.cbTranspose = wxCheckBox(id=wxID_WXIMPORTDIALOGCBTRANSPOSE,
label='Transpose', name='cbTranspose', parent=self.swLoadX,
pos=wxPoint(160, 128), size=wxSize(73, 13), style=0)
self.cbTranspose.SetValue(False)
self.cbTranspose.SetToolTipString('')
EVT_CHECKBOX(self.cbTranspose, wxID_WXIMPORTDIALOGCBTRANSPOSE,
self.OnCbTransposeCheckbox)
def __init__(self, parent):
self._init_ctrls(parent)
self.UpdateFlag = 0
self.ClassFile,self.ArrayFile = '',''
def OnBtnbrowsearrayButton(self, event):
self.ArrayFile = wxFileSelector('Choose X-Data File')
self.stArray.SetValue(self.ArrayFile)
return self.ArrayFile
def OnBtnOKButton(self, event):
if '' in [self.ArrayFile]:
dlg = wxMessageDialog(self, 'Please enter all of the fields',
'Error!', wxOK | wxICON_INFORMATION)
try:
dlg.ShowModal()
finally:
dlg.Destroy()
else:
self.ButtonPress = 1
self.Close()
def OnBtnCancelButton(self, event):
self.ButtonPress = 0
self.Close()
def GetRawData(self):
return self.ArrayFile
def GetButtonPress(self):
return self.ButtonPress
def GetDelim(self):
#set delimiter
if self.cbTabDelim.GetValue() == 1:
return '\t'
elif self.cbSpaceDelim.GetValue() == 1:
return ' '
elif self.cbCommaDelim.GetValue() == 1:
return ','
elif self.cbSemiDelim.GetValue() == 1:
return ';'
elif self.cbOther.GetValue() == 1:
return self.txtOther.GetValue()
def Transpose(self):
#flag to indicate whether to transpose the array
if self.cbTranspose.GetValue() == 1:
return 1
else:
return 0
def OnCbTabDelimCheckbox(self, event):
self.cbSpaceDelim.SetValue(0)
self.cbCommaDelim.SetValue(0)
self.cbSemiDelim.SetValue(0)
self.cbOther.SetValue(0)
def OnCbSpaceDelimCheckbox(self, event):
self.cbTabDelim.SetValue(0)
self.cbCommaDelim.SetValue(0)
self.cbSemiDelim.SetValue(0)
self.cbOther.SetValue(0)
def OnCbCommaDelimCheckbox(self, event):
self.cbTabDelim.SetValue(0)
self.cbSpaceDelim.SetValue(0)
self.cbSemiDelim.SetValue(0)
self.cbOther.SetValue(0)
def OnCbOtherCheckbox(self, event):
self.cbTabDelim.SetValue(0)
self.cbSpaceDelim.SetValue(0)
self.cbCommaDelim.SetValue(0)
self.cbSemiDelim.SetValue(0)
def OnCbSemiDelimCheckbox(self, event):
self.cbTabDelim.SetValue(0)
self.cbSpaceDelim.SetValue(0)
self.cbCommaDelim.SetValue(0)
self.cbOther.SetValue(0)
def OnCbTransposeCheckbox(self, event):
event.Skip()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -