Exemple #1
0
    def showDetail(self, hosts=None):

        dlg = ui.Dlg_addHosts(self)

        if hosts:
            # 初始化值
            dlg.m_radioBtn_local.SetValue(not hosts.is_online)
            dlg.m_radioBtn_online.SetValue(hosts.is_online)
            dlg.m_radioBtn_local.Enable(False)
            dlg.m_radioBtn_online.Enable(False)
            dlg.m_textCtrl_title.SetValue(hosts.title)
            if hosts.url:
                dlg.m_textCtrl_url.SetValue(hosts.url)
                dlg.m_textCtrl_url.Enable(True)

        if dlg.ShowModal() != wx.ID_OK:
            dlg.Destroy()
            return

        dlg.Destroy()

        is_online = dlg.m_radioBtn_online.GetValue()
        title = dlg.m_textCtrl_title.GetValue().strip()
        url = dlg.m_textCtrl_url.GetValue().strip()

        if not title:
            wx.MessageBox(u"方案名不能为空!", caption=u"出错啦!")
            return

        for h in self.hostses:
            if h != hosts and h.title == title:
                wx.MessageBox(u"已经有名为 '%s' 的方案了!" % title, caption=u"出错啦!")
                return

        if not hosts:
            # 新建 hosts
            fn = self.makeNewHostsFileName()
            if not fn:
                wx.MessageBox(u"hosts 文件数超出限制,无法再创建新 hosts 了!", caption=u"出错啦!")
                return

            path = os.path.join(self.hosts_path, fn)

            hosts = Hosts(path, title=title, url=url if is_online else None)
            hosts.content = u"# %s" % title

            if hosts.is_online:
                self.getHostsContent(hosts)

            self.addHosts(hosts, show_after_add=True)

        else:
            # 修改 hosts
            hosts.is_online = is_online
            hosts.title = title
            hosts.url = url if is_online else None
            self.updateHostsTitle(hosts)

        self.saveHosts(hosts)
Exemple #2
0
 def getForeverHosts(self):
     u"""获取永久生效的hosts"""
     path = os.path.join(self.hosts_path, 'hosts.forever')
     hosts = Hosts(path=path,
                   title=lang.trans("forever_hosts"),
                   is_forever=True)
     if not os.path.isfile(path):
         title = lang.trans("forever_hosts")
         hosts = Hosts(path=path, title=title, is_forever=True)
         hosts.content = u"# %s" % title
         self.saveHosts(hosts)
     self.forever_hostses = [hosts]
     self.addHosts(hosts)
Exemple #3
0
    def saveNewHostFile(self, title,  url, is_online, fn = "" ):
        if not fn:
            fn = self.makeNewHostsFileName()

        if not fn:
            wx.MessageBox(u"hosts 文件数超出限制,无法再创建新 hosts 了!", caption=u"出错啦!")
            return

        path = os.path.join(self.hosts_path, fn)

        hosts = Hosts(path, title=title, url=url if is_online else None)
        hosts.content = u"# %s" % title

        if hosts.is_online:
            self.getHostsContent(hosts)

        self.addHosts(hosts, show_after_add=True)
        return hosts
Exemple #4
0
    def saveNewHostFile(self, title, url, is_online, fn=""):
        if not fn:
            fn = self.makeNewHostsFileName()

        if not fn:
            wx.MessageBox(u"hosts 文件数超出限制,无法再创建新 hosts 了!", caption=u"出错啦!")
            return

        path = os.path.join(self.hosts_path, fn)

        hosts = Hosts(path, title=title, url=url if is_online else None)
        hosts.content = u"# %s" % title

        if hosts.is_online:
            self.getHostsContent(hosts)

        self.addHosts(hosts, show_after_add=True)
        return hosts
Exemple #5
0
    def showDetailEditor(self, hosts=None, default_is_online=False):
        u"""显示详情编辑窗口"""

        dlg = ui.Dlg_addHosts(self)

        if hosts:
            # 初始化值
            dlg.m_radioBtn_local.SetValue(not hosts.is_online)
            dlg.m_radioBtn_online.SetValue(hosts.is_online)
            dlg.m_radioBtn_local.Enable(False)
            dlg.m_radioBtn_online.Enable(False)
            dlg.m_textCtrl_title.SetValue(hosts.title)
            if hosts.url:
                dlg.m_textCtrl_url.SetValue(hosts.url)
                dlg.m_textCtrl_url.Enable(True)

        else:
            dlg.m_radioBtn_local.SetValue(not default_is_online)
            dlg.m_radioBtn_online.SetValue(default_is_online)
            dlg.m_textCtrl_url.Enabled = default_is_online

        if dlg.ShowModal() != wx.ID_OK:
            dlg.Destroy()
            return

        dlg.Destroy()

        is_online = dlg.m_radioBtn_online.GetValue()
        title = dlg.m_textCtrl_title.GetValue().strip()
        url = dlg.m_textCtrl_url.GetValue().strip()

        if not title:
            wx.MessageBox(u"方案名不能为空!", caption=u"出错啦!")
            return

        for h in self.hostses:
            if h != hosts and h.title == title:
                wx.MessageBox(u"已经有名为 '%s' 的方案了!" % title, caption=u"出错啦!")
                return

        if not hosts:
            # 新建 hosts
            fn = self.makeNewHostsFileName()
            if not fn:
                wx.MessageBox(u"hosts 文件数超出限制,无法再创建新 hosts 了!",
                              caption=u"出错啦!")
                return

            path = os.path.join(self.hosts_path, fn)

            hosts = Hosts(path, title=title, url=url if is_online else None)
            hosts.content = u"# %s" % title

            if hosts.is_online:
                self.getHostsContent(hosts)

            self.addHosts(hosts, show_after_add=True)

        else:
            # 修改 hosts
            hosts.is_online = is_online
            hosts.title = title
            hosts.url = url if is_online else None
            self.updateHostsTitle(hosts)

        self.saveHosts(hosts)