Skip to content

Commit

Permalink
[done] update osx menubar
Browse files Browse the repository at this point in the history
  • Loading branch information
eisneim committed Mar 23, 2017
1 parent 2b792bf commit e17700f
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 28 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cytron_tts_gui
=========
simple text to speech client GUI using Baidu's tts API

# WIP
simple text to speech client GUI using Baidu's tts API, currently only supports chinese language
![snapshot](snapshot.png)

this simple app is writen in Python3 tkinter

Expand Down
28 changes: 28 additions & 0 deletions cytronui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import time
import os
from sys import platform


from uiHandlers import handlers
Expand Down Expand Up @@ -36,13 +37,40 @@ def __init__(self, master, ctx):
else:
log.info("token expired, show init page")
self.show_frame(ConfigPage)
# --------- setup menu -------
_menubar = tk.Menu(master)
if platform == 'darwin': # for mac only
_appMenu = tk.Menu(_menubar, name="apple")
_menubar.add_cascade(menu=_appMenu)
_appMenu.add_command(label="About CytronTTS", command=self.showAbout)
# _appMenu.add_separator()
# master.createcommand('tk::mac::ShowPreferences', do_preferences)


_filemenu = tk.Menu(_menubar)
_menubar.add_cascade(label="File", menu=_filemenu)

_filemenu.add_command(label="Load Text File..",
command=self.frames["MainPage"].addTextFromFile)
_filemenu.add_command(label="Destination Folder",
command=self.frames["MainPage"].setDestFolder)
_filemenu.add_separator()
_filemenu.add_command(label="Exit", command=master.quit)

master.config(menu=_menubar)

def show_frame(self, cont):
name = cont if type(cont) == str else cont.__name__
frame = self.frames[name]
frame.tkraise()

def showAbout(self):
messagebox.showinfo("about CytronTTS", """
version: 0.1.0
auhtor: Eisneim Terry<eisneim1@gmail.com>
github: https://github.com/eisneim/cytron_tts_gui
""")

def receive(self, msg):
log.debug("get message from worker: {}".format(msg))
mtype = msg["type"]
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, master, ctx, dispatch):
self.queue = ctx.queue
self.master = master

master.title("Simple TTS")
master.title("CytronTTS")
master.configure(bg="red")

master.grid_rowconfigure(0, weight=1)
Expand Down
Binary file added snapshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 38 additions & 24 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,48 @@
import re
from tkinter import *
from tkinter.messagebox import *

def splitText(text, maxBytes):
text = re.sub(r"\n+", "\n", text)
# every chinese char == 3 bytes
maxChineseChar = maxBytes // 3 + 1
idx = 0
parts = []
while idx < len(text):
parts.append(text[idx : (idx + maxChineseChar)])
idx += maxChineseChar
return parts
def do_about_dialog():
tk_version = window.tk.call('info', 'patchlevel')
showinfo(message= app_name + "\nThe answer to all your problems.\n\nTK version: " + tk_version)

tex = """
既然发出祝福的人可以从网上复制一条段子,甚至可能是随手复制七大姑八大姨群发给TA自己的段子,然后在微信群发助手全选联系人,往里面一粘贴点击发送就成功地搞定了所有过去的一年里爱过帮助过鼓励过同舟共济过的亲朋好友们。
def do_preferences():
showinfo(message="Preferences window")

def do_button():
print("You pushed my button")

def main():
global app_name
app_name = "Chocolate Rain"
global window
window = Tk()
window.title("Main")

那我为什么不可以用类似的方式去搞定企图用群发来搞定我的人呢?
# find out which version of Tk we are using
tk_version = window.tk.call('info', 'patchlevel')
tk_version = tk_version.replace('.', '')
tk_version = tk_version[0:2]
tk_version = int(tk_version)

不过我也不是批评群发祝福这种行为,敷衍确实是敷衍了一点,多少也算一份心意。
menubar = Menu(window)
app_menu = Menu(menubar, name='apple')
menubar.add_cascade(menu=app_menu)

可是收到祝福的我就很尴尬了,假如我不回显得我不近人情,我要是手动回复了,很明显是我吃亏了,可能一整天的精力都要耗在回复祝福上。并且我也不愿意做那种群发祝福敷衍我的亲朋好友的那种人。
app_menu.add_command(label='About ' + app_name, command=do_about_dialog)
app_menu.add_separator()

有没有既不浪费时间又能保持礼貌和客套的办法呢?
好歹也算是学过两年编程的人,其实只需要12行Python代码,就可以让你的微信拥有自动回复功能了,并且还能够自动判断消息种类和内容,只回复新年祝福相关的消息。
if tk_version < 85:
app_menu.add_command(label="Preferences...", command=do_preferences)
else:
# Tk 8.5 and up provides the Preferences menu item
window.createcommand('tk::mac::ShowPreferences', do_preferences)

首先确保你安装好了Python和Python的包管理工具pip
感谢知友们的支持,更新一个进阶版,可以自动获取好友的备注名,并且从祝福语API里随机抽取祝福词进行定制的回复,并且会记录回复过的好友,不会因为重复自动回复露馅。
"""
window.config(menu=menubar) # sets the window to use this menubar

ll = splitText(tex, 1024)
print(len(ll))
print(ll[0])
my_button = Button(window, text="Push", command=do_button)
my_button.grid(row=0, column=0, padx=50, pady=30)

mainloop()

if __name__ == "__main__":
main()

0 comments on commit e17700f

Please sign in to comment.