Skip to content

Commit

Permalink
组织代码结构, 发布1.0.0版本
Browse files Browse the repository at this point in the history
  • Loading branch information
iamhefang committed Jul 7, 2019
1 parent 68501ce commit 260eda4
Show file tree
Hide file tree
Showing 14 changed files with 432 additions and 86 deletions.
2 changes: 1 addition & 1 deletion mHosts.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.0.1",
"version": "1.0.0",
"registry": {
"type": "list",
"url": "https://github.com/iamhefang/mHosts/releases"
Expand Down
4 changes: 2 additions & 2 deletions mHosts.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# _*_ coding: utf-8 _*_
import sys

from settings import Settings
from views.MainWindow import MainWindow
from src.settings import Settings
from src.views.MainWindow import MainWindow

if __name__ == '__main__':
Settings.Init()
Expand Down
44 changes: 22 additions & 22 deletions mHosts.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
block_cipher = None

datas = [
(r'./icons',r'icons'),
(r'./mHosts.json','.'),
(r'./icons/aliyun.png',r'icons'),
(r'./icons/chrome.png',r'icons'),
(r'./icons/darwin.png',r'icons'),
(r'./icons/database.png',r'icons'),
(r'./icons/edge.png',r'icons'),
(r'./icons/firefox.png',r'icons'),
(r'./icons/java.png',r'icons'),
(r'./icons/linux.png',r'icons'),
(r'./icons/logo.ico',r'icons'),
(r'./icons/logo.png',r'icons'),
(r'./icons/mysql.png',r'icons'),
(r'./icons/postgresql.png',r'icons'),
(r'./icons/python.png',r'icons'),
(r'./icons/qq.png',r'icons'),
(r'./icons/server.png',r'icons'),
(r'./icons/table.png',r'icons'),
(r'./icons/user.png',r'icons'),
(r'./icons/wechat.png',r'icons'),
(r'./icons/win32.png',r'icons')
(r'./icons', r'icons'),
(r'./mHosts.json', '.'),
(r'./icons/aliyun.png', r'icons'),
(r'./icons/chrome.png', r'icons'),
(r'./icons/darwin.png', r'icons'),
(r'./icons/database.png', r'icons'),
(r'./icons/edge.png', r'icons'),
(r'./icons/firefox.png', r'icons'),
(r'./icons/java.png', r'icons'),
(r'./icons/linux.png', r'icons'),
(r'./icons/logo.ico', r'icons'),
(r'./icons/logo.png', r'icons'),
(r'./icons/mysql.png', r'icons'),
(r'./icons/postgresql.png', r'icons'),
(r'./icons/python.png', r'icons'),
(r'./icons/qq.png', r'icons'),
(r'./icons/server.png', r'icons'),
(r'./icons/table.png', r'icons'),
(r'./icons/user.png', r'icons'),
(r'./icons/wechat.png', r'icons'),
(r'./icons/win32.png', r'icons')
]

a = Analysis(
Expand Down Expand Up @@ -54,6 +54,6 @@ exe = EXE(
strip=False,
upx=False,
runtime_tmpdir=None,
console=False ,
console=False,
icon='icons\\logo.ico'
)
8 changes: 5 additions & 3 deletions CheckNewVersionThread.py → src/CheckNewVersionThread.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from distutils.version import LooseVersion
from threading import Thread, Lock, Event

from wx import MessageBox, ICON_ERROR
from wx import MessageBox, ICON_ERROR, LaunchDefaultBrowser

from helpers import FetchNewVersion, Now
from settings import Settings
from src.helpers import FetchNewVersion, Now
from src.settings import Settings


class CheckNewVersionThread(Thread):
Expand All @@ -30,6 +30,8 @@ def run(self) -> None:
Settings.settings["lastCheckUpdateTime"] = Now()
if currentVersion < newVersion:
MessageBox("当前版本为%s, 检查到新版本%s" % (Settings.version(), newInfo["version"]))
if newInfo["registry"]["type"] == "list":
LaunchDefaultBrowser(newInfo["registry"]["url"])
self.__window.statusBar.SetStatusText("检查到新版本" + newInfo['version'], 2)
else:
self.__window.statusBar.SetStatusText("当前版本为最新版本", 2)
Expand Down
2 changes: 1 addition & 1 deletion Hosts.py → src/Hosts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys

from helpers import ReadText, WriteText
from src.helpers import ReadText, WriteText


def Save2System(content):
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions settings.py → src/settings.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
import os

import Hosts
from helpers import WriteText, GetChromePath, ResPath, Now
from src import Hosts
from src.helpers import WriteText, GetChromePath, ResPath, Now

settingPath = "settings.json"

Expand Down
35 changes: 35 additions & 0 deletions src/views/AboutView.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from wx import ID_ANY, DefaultPosition, html, LaunchDefaultBrowser
from wx.html import HtmlWindow

from src.settings import Settings


class AboutView(HtmlWindow):
def __init__(self, parent, size):
HtmlWindow.__init__(self, parent, ID_ANY, DefaultPosition, size=size, style=html.HW_SCROLLBAR_AUTO)
self.SetPage("""
<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>关于</title>
</head>
<body>
<h1>mHosts %(version)s</h1>
<h4>免费好用的跨平台Hosts管理工具</h4>
<table style="width:100%%">
<tr>
<td>项目地址:</td>
<td>
<a href="https://github.com/iamhefang/mHosts">https://github.com/iamhefang/mHosts</a>
</td>
</tr>
</table>
</body>
</html>""" % {"version": Settings.version()})

def OnLinkClicked(self, link):
LaunchDefaultBrowser(link.GetHref())
File renamed without changes.
22 changes: 11 additions & 11 deletions views/MainWindow.py → src/views/MainWindow.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import sys
from subprocess import Popen

from wx import App, MessageBox, ICON_ERROR, OK, ICON_NONE, EVT_CLOSE, LaunchDefaultBrowser, DisplaySize, \
from wx import App, MessageBox, ICON_ERROR, EVT_CLOSE, LaunchDefaultBrowser, DisplaySize, \
EVT_TREE_SEL_CHANGED, EVT_TREE_ITEM_RIGHT_CLICK, Menu, EVT_MENU, CommandEvent, Colour, EVT_TREE_ITEM_ACTIVATED, \
Locale, LANGUAGE_CHINESE_SIMPLIFIED
from wx.stc import EVT_STC_CHANGE

import Hosts
from CheckNewVersionThread import CheckNewVersionThread
from helpers import NowToTimestamp, Now
from settings import Settings, systemHosts, ID_SYSTEM_HOSTS
from views.TrayIcon import TrayIcon
from widgets import MainFrame, AboutDialog, EditDialog
from src import Hosts
from src.CheckNewVersionThread import CheckNewVersionThread
from src.helpers import NowToTimestamp, Now
from src.settings import Settings, systemHosts, ID_SYSTEM_HOSTS
from src.views.TrayIcon import TrayIcon
from src.widgets import MainFrame, AboutDialog, EditDialog, MessagePanel


class MainWindow(MainFrame):
Expand Down Expand Up @@ -152,7 +152,7 @@ def ApplyHosts(self, hostsId: int):
Hosts.TryFlushDNSCache()
for hosts in Settings.settings["hosts"]:
hosts["active"] = hosts["id"] == hostsId
MessageBox("Hosts已设置为" + currentHosts["name"], "保存成功", ICON_NONE)
MessagePanel.Send("Hosts已设置为" + currentHosts["name"], "保存成功")
else:
MessageBox("保存失败", "提示", ICON_ERROR)
self.InitHostsTree(ID_SYSTEM_HOSTS)
Expand Down Expand Up @@ -193,9 +193,9 @@ def OnMenuClicked(self, event: CommandEvent):
if callable(callback):
callback()
else:
print("该菜单绑定的事件不可用")
MessagePanel.Send("该菜单绑定的事件不可用", "菜单点击", dpi=(self.dpiX, self.dpiY))
else:
print("该菜单没有绑定事件")
MessagePanel.Send("该菜单没有绑定事件", "菜单点击", dpi=(self.dpiX, self.dpiY))

def CheckUpdate(self):
CheckNewVersionThread(self).start()
Expand All @@ -212,7 +212,7 @@ def LunchChrome(args=""):
@staticmethod
def DoRefreshDNS():
Hosts.TryFlushDNSCache()
MessageBox(u"刷新DNS成功", u"提示", OK | ICON_NONE)
MessagePanel.Send(u"刷新DNS成功", u"提示")

def Exit(self):
self.trayIcon.Destroy()
Expand Down
15 changes: 10 additions & 5 deletions views/TrayIcon.py → src/views/TrayIcon.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import sys

from wx import MenuItem, Icon, BITMAP_TYPE_ICO, Menu, EVT_MENU, NewId, adv, ITEM_CHECK, ID_ANY, Bitmap, BITMAP_TYPE_PNG
from wx.adv import TaskBarIcon

from helpers import iconPath, ResPath
from settings import Settings
from src.helpers import iconPath, ResPath
from src.settings import Settings


class TrayIcon(TaskBarIcon):
Expand Down Expand Up @@ -50,7 +52,8 @@ def __init__(self, window):
def CreatePopupMenu(self):
menu = Menu()
appMenuItem = menu.Append(ID_ANY, "mHosts v" + Settings.version())
appMenuItem.Enable(False)
if sys.platform != "linux":
appMenuItem.Enable(False)
appMenuItem.SetBitmap(Bitmap(ResPath("icons/logo.png"), BITMAP_TYPE_PNG))
menu.Append(self.ID_TOGGLE, r"%s主窗口" % ("隐藏" if self.__window.IsShown() else "显示"))
menu.AppendSeparator()
Expand All @@ -63,7 +66,8 @@ def CreatePopupMenu(self):

newHostMenu = Menu()
newHostMenu.Append(self.ID_NEW, "新建")
newHostMenu.Append(self.ID_IMPORT, "导入").Enable(False)
if sys.platform != "linux":
newHostMenu.Append(self.ID_IMPORT, "导入").Enable(False)
menu.Append(-1, "新建Hosts方案", newHostMenu)

menu.AppendSeparator()
Expand All @@ -76,7 +80,8 @@ def CreatePopupMenu(self):
menu.Append(-1, "启动 Google Chrome 浏览器", chromeMenu)

menu.AppendSeparator()
menu.Append(self.ID_UPDATE, "更新").Enable(False)
if sys.platform != "linux":
menu.Append(self.ID_UPDATE, "更新").Enable(False)
menu.Append(self.ID_EXIT, "退出")
self.menu = menu
return menu
Expand Down
Loading

0 comments on commit 260eda4

Please sign in to comment.