def deleteHosts(self, event): u"""删除 hosts""" fn = DEFAULT_HOSTS_FN.encode() if self.current_selected_hosts_fn: folder, fn = os.path.split(self.current_selected_hosts_fn) # fn = co.decode(fn) ohosts = self.getOHostsFromFn(fn) # print(self.current_selected_hosts_fn, self.taskbar_icon.current_hosts) if not self.current_selected_hosts_fn or \ self.current_selected_hosts_fn == self.taskbar_icon.current_hosts or \ (self.taskbar_icon.current_hosts is None and fn == DEFAULT_HOSTS_FN): self.alert(u"不可删除", u"当前 hosts 正在使用中,不可删除!") return dlg = wx.MessageDialog(None, u"确定要删除 hosts '%s'?" % ohosts.getTitle(), u"删除 hosts", wx.YES_NO | wx.ICON_QUESTION ) ret_code = dlg.ShowModal() if ret_code == wx.ID_YES: # 删除当前 hosts try: os.remove(ohosts.path) except Exception: pass self.updateHostsList() dlg.Destroy()
def deleteHosts(self, event): u"""删除 hosts""" fn = DEFAULT_HOSTS_FN.encode() if self.current_selected_hosts_fn: folder, fn = os.path.split(self.current_selected_hosts_fn) # fn = co.decode(fn) ohosts = self.getOHostsFromFn(fn) # print(self.current_selected_hosts_fn, self.taskbar_icon.current_hosts) if not self.current_selected_hosts_fn or \ self.current_selected_hosts_fn == self.taskbar_icon.current_hosts or \ (self.taskbar_icon.current_hosts is None and fn == DEFAULT_HOSTS_FN): self.alert(u"不可删除", u"当前 hosts 正在使用中,不可删除!") return dlg = wx.MessageDialog(None, u"确定要删除 hosts '%s'?" % ohosts.getTitle(), u"删除 hosts", wx.YES_NO | wx.ICON_QUESTION) ret_code = dlg.ShowModal() if ret_code == wx.ID_YES: # 删除当前 hosts try: os.remove(ohosts.path) except Exception: pass self.updateHostsList() dlg.Destroy()
def getOHostsFromFn(self, fn=None): u"""从 hosts 的文件名取得它的 id""" if not fn: fn = self.current_selected_hosts_fn or DEFAULT_HOSTS_FN.encode() fn = co.decode(fn) for oh in self.hosts_objects: if oh.fn == fn or oh.dc_path == fn: return oh return None