Пример #1
0
    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
Пример #2
0
    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
Пример #3
0
    def updateHostsList(self, selected_title=None):
        u"""更新 hosts 列表"""

        hosts_list = listLocalHosts()
#        hosts_list.insert(0, co.getSysHostsPath())
        hosts_list = [list(os.path.split(fn)) + [fn] for fn in hosts_list]
        self.hosts_lists = hosts_list
        self.hosts_objects = []

        self.m_list.DeleteAllItems()
        ch = self.taskbar_icon.current_hosts
        c_idx = -1

        il = wx.ImageList(16, 16, True)
        icons_count = len(co.ICONS)
        for i in xrange(icons_count):
            il.Add(co.GetMondrianBitmap(i))
        self.m_list.AssignImageList(il, wx.IMAGE_LIST_SMALL)

        for idx, (folder, fn, fn2) in enumerate(hosts_list):

            icon_idx = idx if idx < icons_count else icons_count - 1
            ohosts = Hosts(idx, fn2, icon_idx)
            self.hosts_objects.append(ohosts)

            i, t, t2 = fn.partition(".")
            if i.isdigit():
                i = int(i)
                if i > self.current_max_hosts_index:
                    self.current_max_hosts_index = i

            c = ""
            index = self.m_list.InsertStringItem(sys.maxint, ohosts.getTitle())

            # 如果指定了当前选中的 hosts
            if ohosts.getTitle() == selected_title:
                ch = self.taskbar_icon.current_hosts = fn2
                self.SetIcon(co.GetMondrianIcon(ohosts.icon_idx))
                self.taskbar_icon.SetIcon(co.GetMondrianIcon(ohosts.icon_idx), u"当前 hosts 方案:%s" % ohosts.getTitle())
                self.m_list.SetItemFont(idx, self.font_bold)


            if (ch and ch == fn2) or \
                (not selected_title and not ch and co.decode(fn) == DEFAULT_HOSTS_FN):
                c = SELECTED_FLAG
            if c:
                c_idx = index
            self.m_list.SetStringItem(index, 1, c)
            self.m_list.SetItemImage(index, ohosts.icon_idx, ohosts.icon_idx)


        if self.current_selected_hosts_index >= 0:
            c_idx = self.current_selected_hosts_index

        while c_idx >= len(self.hosts_objects) and c_idx > 0:
            c_idx -= 1

        ohosts = self.hosts_objects[c_idx]

        self.m_list.Select(c_idx)
        self.current_selected_hosts_index = c_idx
        self.current_selected_hosts_fn = self.hosts_objects[c_idx].path

        self.m_textCtrl_content.Value = ohosts.getContent()
Пример #4
0
    def updateHostsList(self, selected_title=None):
        u"""更新 hosts 列表"""

        hosts_list = listLocalHosts()
        #        hosts_list.insert(0, co.getSysHostsPath())
        hosts_list = [list(os.path.split(fn)) + [fn] for fn in hosts_list]
        self.hosts_lists = hosts_list
        self.hosts_objects = []

        self.m_list.DeleteAllItems()
        ch = self.taskbar_icon.current_hosts
        c_idx = -1

        il = wx.ImageList(16, 16, True)
        icons_count = len(co.ICONS)
        for i in xrange(icons_count):
            il.Add(co.GetMondrianBitmap(i))
        self.m_list.AssignImageList(il, wx.IMAGE_LIST_SMALL)

        for idx, (folder, fn, fn2) in enumerate(hosts_list):

            icon_idx = idx if idx < icons_count else icons_count - 1
            ohosts = Hosts(idx, fn2, icon_idx)
            self.hosts_objects.append(ohosts)

            i, t, t2 = fn.partition(".")
            if i.isdigit():
                i = int(i)
                if i > self.current_max_hosts_index:
                    self.current_max_hosts_index = i

            c = ""
            index = self.m_list.InsertStringItem(sys.maxint, ohosts.getTitle())

            # 如果指定了当前选中的 hosts
            if ohosts.getTitle() == selected_title:
                ch = self.taskbar_icon.current_hosts = fn2
                self.SetIcon(co.GetMondrianIcon(ohosts.icon_idx))
                self.taskbar_icon.SetIcon(
                    co.GetMondrianIcon(ohosts.icon_idx),
                    u"当前 hosts 方案:%s" % ohosts.getTitle())
                self.m_list.SetItemFont(idx, self.font_bold)


            if (ch and ch == fn2) or \
                (not selected_title and not ch and co.decode(fn) == DEFAULT_HOSTS_FN):
                c = SELECTED_FLAG
            if c:
                c_idx = index
            self.m_list.SetStringItem(index, 1, c)
            self.m_list.SetItemImage(index, ohosts.icon_idx, ohosts.icon_idx)

        if self.current_selected_hosts_index >= 0:
            c_idx = self.current_selected_hosts_index

        while c_idx >= len(self.hosts_objects) and c_idx > 0:
            c_idx -= 1

        ohosts = self.hosts_objects[c_idx]

        self.m_list.Select(c_idx)
        self.current_selected_hosts_index = c_idx
        self.current_selected_hosts_fn = self.hosts_objects[c_idx].path

        self.m_textCtrl_content.Value = ohosts.getContent()