我正在写一篇关于ironpython的gui,我正在尝试创建一个用户可以在文本框中命名的文本文件。文本文件用于从矢量文件中给我一个python脚本。任何建议
答案 0 :(得分:0)
通过以下内容,我可以使用IronPython
创建文件public function get_diseases_records_total() {
$sql = 'SELECT d.id, d.disease_name, m.med_name, d.created_at ';
$sql .= 'FROM diseases d ';
$sql .= 'INNER JOIN diseases_medicines dm ON d.id = dm.disease_id ';
$sql .= 'INNER JOIN medicines m ON dm.medicine_id = m.id ';
$query = $this->db->query($sql);
return $query->num_rows();
}
public function get_diseases_records_filtered($data) {
extract($data);
$params = [];
$sql = 'SELECT d.id, d.disease_name, m.med_name, d.created_at ';
$sql .= 'FROM diseases d ';
$sql .= 'INNER JOIN diseases_medicines dm ON d.id = dm.disease_id ';
$sql .= 'INNER JOIN medicines m ON dm.medicine_id = m.id ';
$sql .= 'WHERE 1 ';
if(!empty($search['value'])){
$sql .= 'AND (d.id = ? ';
$sql .= 'OR d.disease_name LIKE ? ';
$sql .= 'OR m.med_name LIKE ? ';
$sql .= 'OR d.created_at LIKE ?) ';
}
if(!empty($search['value'])){
$params[] = $search['value'];
$params[] = $search['value'];
$params[] = $search['value'];
$params[] = $search['value'];
}
$query = $this->db->query($sql, $params);
return $query->num_rows();
}
public function get_diseases($data, $details = false) {
extract($data);
$params = [];
$sql = 'SELECT d.id, d.disease_name, m.med_name, d.created_at ';
$sql .= 'FROM diseases d ';
$sql .= 'INNER JOIN diseases_medicines dm ON d.id = dm.disease_id ';
$sql .= 'INNER JOIN medicines m ON dm.medicine_id = m.id ';
$sql .= 'WHERE 1 ';
if(!empty($search['value'])){
$sql .= 'AND (d.id = ? ';
$sql .= 'OR d.disease_name LIKE ? ';
$sql .= 'OR m.med_name LIKE ? ';
$sql .= 'OR d.created_at LIKE ?) ';
}
if(isset($order)){
$sql .= 'ORDER BY ' . $columns[$order[0]['column']]['data'] . ' ' . strtoupper($order[0]['dir']) . ' ';//$order[0]['column']
}
$sql .= 'LIMIT ?, ?';
if(!empty($search['value'])){
$params[] = $search['value'];
$params[] = '%' . $search['value'] . '%';
$params[] = '%' . $search['value'] . '%';
$params[] = '%' . $search['value'] . '%';
}
$params[] = (int)$start;
$params[] = (int)$length;
$query = $this->db->query($sql, $params);
return ( $query->num_rows() ) ? $query->result() : FALSE;
}
这里是关于ScriptEngine m_engine = Python.CreateEngine();
ScriptScope m_scope = m_engine.CreateScope();
String code = @"file = open('myfile.txt', 'w+')";
ScriptSource source = m_engine.CreateScriptSourceFromString(code, SourceCodeKind.SingleStatement);
source.Execute(m_scope);
的{{3}}。它会打开文件进行写入,首先截断文件。
所以我想你只需要在脚本中插入文件的名称......
答案 1 :(得分:0)
当我在python中编写时,我正在编写适合我的代码。希望它有所帮助。
def on_save_as(self, sender, e):
dlg = SaveFileDialog()
dlg.Filter = "Text File (*.txt)|*.txt"
dlg.Title = "SaveFile"
if dlg.ShowDialog():
self.save_file(dlg.FileName)
def save_file(self, filename):
sw = StreamWriter(filename)
try:
buf = self.textbox.Text
sw.Write(buf)
self.statusbar_item.Content = Path.GetFileName(filename)
self.openfile = filename
except Exception, ex:
MessageBox.Show(ex.Message)
finally:
sw.Close()