我必须使用错误的术语进行谷歌搜索,因为我找不到我要找的东西。任何帮助表示赞赏。
如何写入 textctrl 中的特定行?
目前我的程序处理文件,处理后的文件列在文本 ctrl 中。我想要达到的就是这个。列出 textctrl 中的文件,并在其名称后进行文字处理。处理后,我需要重新写入完全相同的位置,但这次用完成的单词替换文字处理。我还需要记住哪个文件打印在哪一行。我正在线程化,因此文件不一定按照打开的顺序完成,因为它们的大小不同。
谢谢你的帮助!
# This function opens files for processing.
def Encrypt(self, event):
"""
Runs the thread
"""
self.file2process = ""
dlg = wx.FileDialog(self, "Select files", self.file2process, "", "*.*", wx.OPEN |wx.MULTIPLE | wx.CHANGE_DIR)
if dlg.ShowModal() == wx.ID_OK:
self.file2process = dlg.GetPaths()
for fname in self.file2process:
EncryptThread(fname)
# This is one of two functions that I would need to modify but same prociple would apply to both so only including this one.
def run(self):
"""Run Worker Thread."""
# This is the code executing in the new thread.
keys = {char: chr(i) for i, char in enumerate(self.key)}
with open(self.fname,'r') as f:
with open(self.fname + '.tmp', 'w') as temp:
for data in f:
match = ''.join([keys[char] for char in data if char in keys])
temp.write(match)
os.remove(self.fname)
os.rename(self.fname + '.tmp', self.fname)
msg = self.fname
wx.CallAfter(Publisher().sendMessage, "update", msg)
# This function updates the textctrl.
def updateDisplay(self, msg):
"""
Receives data from thread and updates the display
"""
data = msg.data + "\n"
self.updateText.WriteText(data)