Skip to content

Commit

Permalink
合并 charlestang 的修改,修复重启时候不能加载正确图标颜色的问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
oldj committed Nov 16, 2012
1 parent fb0ba94 commit 71a77ca
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Email: [email protected]
* Blog: http://oldj.net/
* Source: https://github.com/oldj/SwitchHosts
* Latest Stable: 0.2.2.1784
* Latest Stable: 0.2.2.1785


这是一个用于快速切换 hosts 文件的小程序,基于 Python 和 wxPython 开发。
Expand All @@ -26,7 +26,7 @@

你可以直接下载源码到本地运行或编辑,或者在下面下载可执行版本:

* [SwitchHosts! Windows 绿色版下载](https://github.com/downloads/oldj/SwitchHosts/SwitchHosts_v0.2.1.1780.zip)
* [SwitchHosts! Windows 绿色版下载](https://github.com/downloads/oldj/SwitchHosts/SwitchHosts_v0.2.2.1785.zip)
* [所有下载](https://github.com/oldj/SwitchHosts/downloads)
* [SwitchHosts! 支持Common Host版本 绿色版下载](https://github.com/downloads/charlestang/SwitchHosts/SwitchHosts-6794add.zip)

Expand Down
2 changes: 1 addition & 1 deletion src/SwitchHosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class SwitchHostsApp(object):

VERSION = "0.2.2.1784"
VERSION = "0.2.2.1785"

def __init__(self):

Expand Down
24 changes: 11 additions & 13 deletions src/libs/Hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ def getContent(self, force=False, progress_dlg=None):
self.is_loading = True
c = ""
if self.is_online:

if force:
c = self.getContentFromUrl(progress_dlg)

Expand Down Expand Up @@ -187,16 +186,17 @@ def filename(self):
@property
def full_content(self):

cnt_for_save = [
"%s %s" % (self.flag, json.dumps({
"title": self.title,
"url": self.url,
"icon_idx": self.icon_idx,
})),
] + self.content.split("\n")

cnt_for_save = [self.configLine()] + self.content.split("\n")
return os.linesep.join(cnt_for_save).encode("utf-8")

def configLine(self):
u"""生成配置信息的注释行"""

return "%s %s" % (self.flag, json.dumps({
"title": self.title,
"url": self.url,
"icon_idx": self.icon_idx,
}))

def contentWithCommon(self, common=None):
u"""返回添加了公共内容的hosts"""
Expand All @@ -205,6 +205,7 @@ def contentWithCommon(self, common=None):
return self.full_content

return os.linesep.join([
self.configLine(),
common.content,
"# %s" % ("-" * 50),
self.content
Expand All @@ -216,15 +217,13 @@ def save(self, path=None, common=None):

if self.last_save_time:
time_delta = time.time() - self.last_save_time
# co.log(time_delta)
if time_delta < 0.001:
pass
# return False

path = path or self.path
path = path.encode(co.getLocalEncoding())

open(path, "w").write(self.contentWithCommon(common))

self.last_save_time = time.time()

return True
Expand All @@ -234,4 +233,3 @@ def remove(self):

if os.path.isfile(self.path):
os.remove(self.path)

5 changes: 4 additions & 1 deletion src/libs/MainFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ def tryToFlushDNS(self):


def highLightHosts(self, hosts):
u"""将切换的host文件高亮显示"""

self.m_tree.SelectItem(hosts.tree_item_id)

Expand Down Expand Up @@ -957,6 +958,9 @@ def OnTreeSelectionChange(self, event):
u"""当点击左边树状结构的节点的时候触发"""

hosts = self.getHostsFromTreeByEvent(event)

if not hosts:
return
self.current_tree_hosts = hosts
self.updateBtnStatus(hosts)

Expand Down Expand Up @@ -1204,4 +1208,3 @@ def getHostsIdx(hosts):
self.saveConfigs()
self.m_tree.Delete(source_item)
self.m_tree.SelectItem(source_hosts.tree_item_id)

0 comments on commit 71a77ca

Please sign in to comment.