Skip to content

Commit e7dd7e5

Browse files
committed
wo cuo le
1 parent 6ad469f commit e7dd7e5

163 files changed

Lines changed: 177803 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
记录下python学习过程中陆陆续续做的小项目,具体的实现均在各个文件夹内部有
2+
说明,如有疑问请查阅博客
3+
urlteam.org

python_Dragonfly/test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from dragonfly.all import Grammar, CompoundRule
2+
3+
# Voice command rule combining spoken form and recognition processing.
4+
class ExampleRule(CompoundRule):
5+
spec = "do something computer" # Spoken form of command.
6+
def _process_recognition(self, node, extras): # Callback when command is spoken.
7+
print "Voice command spoken."
8+
9+
# Create a grammar which contains and loads the command rule.
10+
grammar = Grammar("example grammar") # Create a grammar to contain the command rule.
11+
grammar.add_rule(ExampleRule()) # Add the command rule to the grammar.
12+
grammar.load() # Load the grammar.

python_GUI/gui1.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import wx
2+
3+
def load(event):
4+
file = open(filename.GetValue())
5+
contents.SetValue(file.read())
6+
file.close()
7+
8+
def save(event):
9+
file = open(filename.GetValue(),'w')
10+
file.write(contents.GetValue())
11+
file.close()
12+
13+
app = wx.App()
14+
win = wx.Frame(None,title = "edit", size=(410,335))
15+
bkg = wx.Panel(win)
16+
17+
loadButton = wx.Button(bkg, label = 'open')
18+
loadButton.Bind(wx.EVT_BUTTON,load)
19+
20+
saveButton = wx.Button(bkg, label = 'save')
21+
saveButton.Bind(wx.EVT_BUTTON,save)
22+
23+
filename = wx.TextCtrl(bkg)
24+
contents = wx.TextCtrl(bkg, style = wx.TE_MULTILINE | wx.HSCROLL)
25+
26+
hbox = wx.BoxSizer()
27+
hbox.Add(filename, proportion =1, flag = wx.EXPAND)
28+
hbox.Add(loadButton, proportion =0,flag = wx.LEFT, border = 5)
29+
hbox.Add(saveButton, proportion =0,flag = wx.LEFT, border = 5)
30+
31+
vbox = wx.BoxSizer(wx.VERTICAL)
32+
vbox.Add(hbox,proportion = 0,flag = wx.EXPAND | wx.ALL, border = 5)
33+
vbox.Add(contents, proportion = 1,flag=wx.EXPAND | wx.LEFT | wx.BOTTOM | wx.RIGHT, border = 5)
34+
35+
bkg.SetSizer(vbox)
36+
win.Show()
37+
app.MainLoop()

python_GUI/gui2.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import wx
2+
app = wx.PySimpleApp()
3+
frame = wx.Frame( None, -1,'')
4+
frame.SetToolTip( wx.ToolTip( 'this is a frame' )
5+
6+
#frame.SetCursor( wx.StockCursor( wx.CURSOR_MAGNIFIER))
7+
8+
#frame.SetPosition( wx.Point(0,0))
9+
#frame.SetSize(wx.Size(300,250))
10+
#frame.SetTitle('luyishisi.py')
11+
#frame.Show()
12+
13+
app.MainLoop()

python_GUI/gui3.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
# FileName: menu1.py
3+
import wx
4+
class MyMenu( wx.Frame ):
5+
def __init__(self,parent,ID,title):
6+
wx.Frame.__init__(self,parent,-1,title,wx.DefaultPosition,wx.Size(200, 150))
7+
menubar=wx.MenuBar()
8+
file=wx.Menu()
9+
edit=wx.Menu()
10+
help=wx.Menu()
11+
file.Append(101,'&Open','Open a new document')
12+
file.Append(102,'&Save','Save the document')
13+
file.AppendSeparator()
14+
quit=wx.MenuItem(file,105,'&Quit\tCtrl+Q','Quit the Application')
15+
quit.SetBitmap(wx.Image('stock_exit-16.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap())
16+
file.AppendItem(quit)
17+
menubar.Append(file,'&File')
18+
menubar.Append(edit,'&Edit')
19+
menubar.Append(help,'&Help')
20+
self.SetMenuBar( menubar )
21+
22+
class MyApp(wx.App):
23+
def OnInit(self):
24+
frame=MyMenu(None,-1,'menu1.py')
25+
frame.Show(True)
26+
return True
27+
28+
app=MyApp(0)
29+
app.MainLoop()

python_GUI/gui4.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import wx
2+
class MainWindow(wx.Frame):
3+
def __init__(self, parent, title):
4+
wx.Frame.__init__(self, parent, title=title, size=(300, 300))
5+
self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
6+
7+
self.setupMenuBar()
8+
self.Show(True)
9+
10+
def setupMenuBar(self):
11+
self.CreateStatusBar()
12+
13+
menubar = wx.MenuBar()
14+
menufile = wx.Menu()
15+
16+
mnuabout = menufile.Append(wx.ID_ABOUT, '&About', 'about this shit')
17+
mnuexit = menufile.Append(wx.ID_EXIT, 'E&xit', 'end program')
18+
19+
menubar.Append(menufile, '&File')
20+
21+
self.Bind(wx.EVT_MENU, self.onAbout, mnuabout)
22+
self.Bind(wx.EVT_MENU, self.onExit, mnuexit)
23+
24+
self.SetMenuBar(menubar)
25+
26+
def onAbout(self, evt):
27+
dlg = wx.MessageDialog(self, 'This app is a simple text editor', 'About my app', wx.OK)
28+
dlg.ShowModal()
29+
dlg.Destroy()
30+
31+
def onExit(self, evt):
32+
self.Close(True)
33+
app = wx.App(False)
34+
frame = MainWindow(None, 'Small Editor')
35+
36+
app.MainLoop()

python_GUI/gui_alarm_clock.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import sys
2+
import time
3+
from PyQt4.QtCore import *
4+
from PyQt4.QtGui import *
5+
app = QApplication(sys.argv)
6+
try:
7+
message = "Alert!"
8+
if len(sys.argv) < 2:
9+
raise ValueError
10+
hours, mins = sys.argv[1].split(":")
11+
due = QTime(int(hours), int(mins))
12+
if not due.isValid():
13+
raise ValueError
14+
if len(sys.argv) > 2:
15+
message = " ".join(sys.argv[2:])
16+
except ValueError:
17+
message = "Usage: alert.pyw HH:MM [optional message]" # 24hr clock
18+
while QTime.currentTime() < due:
19+
time.sleep(20) # 20 seconds
20+
label = QLabel("<font color=red size=72><b>" + message + "</b></font>")
21+
label.setWindowFlags(Qt.SplashScreen)
22+
label.show()
23+
QTimer.singleShot(60000, app.quit) # 1 minute
24+
app.exec_()

python_GUI/readme.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
制作说明,请看博客
2+
http://urlteam.org/2015/12/python-gui-%E7%AE%80%E5%8D%95%E7%9A%84%E6%96%87%E6%9C%AC%E6%96%87%E6%A1%A3/#more-348

python_aiml_test/1.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Text To Speech using SAPI (Windows) and Python module pyTTS by Peter Parente
2+
# download installer file pyTTS-3.0.win32-py2.4.exe
3+
# from: http://sourceforge.net/projects/uncassist
4+
# also needs: http://www.cs.unc.edu/Research/assist/packages/SAPI5SpeechInstaller.msi
5+
# and pywin32-204.win32-py2.4.exe at this date the latest version of win32com
6+
# from: http://sourceforge.net/projects/pywin32/
7+
# tested with Python24 on a Windows XP computer vagaseat 15jun2005
8+
import pyTTS
9+
import time
10+
tts = pyTTS.Create()
11+
# set the speech rate, higher value = faster
12+
# just for fun try values of -10 to 10
13+
tts.Rate = 1
14+
print "Speech rate =", tts.Rate
15+
# set the speech volume percentage (0-100%)
16+
tts.Volume = 90
17+
print "Speech volume =", tts.Volume
18+
# get a list of all the available voices
19+
print "List of voices =", tts.GetVoiceNames()
20+
# explicitly set a voice
21+
tts.SetVoiceByName('MSMary')
22+
print "Voice is set ot MSMary"
23+
print
24+
# announce the date and time, does a good job
25+
timeStr = "The date and time is " + time.asctime()
26+
print timeStr
27+
tts.Speak(timeStr)
28+
print
29+
str1 = """
30+
A young executive was leaving the office at 6 pm when he found
31+
the CEO standing in front of a shredder with a piece of paper in hand.
32+
"Listen," said the CEO, "this is important, and my secretary has left.
33+
Can you make this thing work?"
34+
"Certainly," said the young executive. He turned the machine on,
35+
inserted the paper, and pressed the start button.
36+
"Excellent, excellent!" said the CEO as his paper disappeared inside
37+
the machine. "I just need one copy."
38+
"""
39+
print str1
40+
tts.Speak(str1)
41+
tts.Speak('Haah haa haah haa')
42+
print
43+
str2 = """
44+
Finagle's fourth law:
45+
Once a job is fouled up, anything done to improve it only makes it worse.
46+
"""
47+
print str2
48+
print
49+
print "The spoken text above has been written to a wave file (.wav)"
50+
tts.SpeakToWave('Finagle4.wav', str2)
51+
print "The wave file is loaded back and spoken ..."
52+
tts.SpeakFromWave('Finagle4.wav')
53+
print
54+
print "Substitute a hard to pronounce word like Ctrl key ..."
55+
#create an instance of the pronunciation corrector
56+
p = pyTTS.Pronounce()
57+
# replace words that are hard to pronounce with something that
58+
# is spelled out or misspelled, but at least sounds like it
59+
p.AddMisspelled('Ctrl', 'Control')
60+
str3 = p.Correct('Please press the Ctrl key!')
61+
tts.Speak(str3)
62+
print
63+
print "2 * 3 = 6"
64+
tts.Speak('2 * 3 = 6')
65+
print
66+
tts.Speak("sounds goofy, let's replace * with times")
67+
print "Substitute * with times"
68+
# ' * ' needs the spaces
69+
p.AddMisspelled(' * ', 'times')
70+
str4 = p.Correct('2 * 3 = 6')
71+
tts.Speak(str4)
72+
print
73+
print "Say that real fast a few times!"
74+
str5 = "The sinking steamer sunk!"
75+
tts.Rate = 3
76+
for k in range(7):
77+
print str5
78+
tts.Speak(str5)
79+
time.sleep(0.3)
80+
tts.Rate = 0
81+
tts.Speak("Wow, not one mispronounced word!")

python_aiml_test/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# python_aiml_rebot
2+
#Required python tools aiml
3+
run commend like
4+
`sudo apt-get install python-aiml`
5+
6+
##Introduction:
7+
1. Use python tools aiml to bulit a talk-rebot.
8+
2. Still not complete Chinese language yet.Please wait.
9+
3. But it can support python commend like 'quit'(exit()) and so on, just write what you want!And tell the reboot to execute it.
10+
11+
##Quick start:
12+
```
13+
git clone https://github.com/ch710798472/python_aiml_rebot.git
14+
cd python_aiml_rebot/start
15+
python brain.py
16+
```
17+
18+
#### And then you can talk to him or her like this:
19+
```
20+
you say: hello
21+
bot say: What can I call you?
22+
you say: cc
23+
bot say: Nice to meet you Cc.
24+
you say:你好
25+
bot say:你好啊!
26+
you say:quit
27+
```
28+
#### Then you will exit the program

0 commit comments

Comments
 (0)