forked from JackZProduction/python_chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChatFns.py
112 lines (98 loc) · 3.42 KB
/
ChatFns.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from Tkinter import *
from socket import *
import urllib
import re
import pygame
import win32gui
def getmixerargs():
pygame.mixer.init()
freq, size, chan = pygame.mixer.get_init()
return freq, size, chan
def initMixer():
BUFFER = 3072 # audio buffer size, number of samples since pygame 1.8.
FREQ, SIZE, CHAN = getmixerargs()
pygame.mixer.init(FREQ, SIZE, CHAN, BUFFER)
def playsound(soundfile):
"""Play sound through default mixer channel in blocking manner.
This will load the whole sound into memory before playback
"""
pygame.init()
pygame.mixer.init()
sound = pygame.mixer.Sound(soundfile)
clock = pygame.time.Clock()
sound.play()
while pygame.mixer.get_busy():
clock.tick(1000)
def playmusic(soundfile):
"""Stream music with mixer.music module in blocking manner.
This will stream the sound from disk while playing.
"""
pygame.init()
pygame.mixer.init()
clock = pygame.time.Clock()
pygame.mixer.music.load(soundfile)
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
clock.tick(1000)
def stopmusic():
"""stop currently playing music"""
pygame.mixer.music.stop()
#HOW TO PLAY SONG:
initMixer()
#playmusic(filename)
def FlashMyWindow(title):
ID = win32gui.FindWindow(None, title)
win32gui.FlashWindow(ID,True)
def FlashMyWindow2(title2):
ID2 = win32gui.FindWindow(None, title2)
win32gui.FlashWindow(ID2,True)
def GetExternalIP():
url = "http://checkip.dyndns.org"
request = urllib.urlopen(url).read()
return str(re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}", request))
def GetInternalIP():
return str(gethostbyname(getfqdn()))
def FilteredMessage(EntryText):
"""
Filter out all useless white lines at the end of a string,
returns a new, beautifully filtered string.
"""
EndFiltered = ''
for i in range(len(EntryText)-1,-1,-1):
if EntryText[i]!='\n':
EndFiltered = EntryText[0:i+1]
break
for i in range(0,len(EndFiltered), 1):
if EndFiltered[i] != "\n":
return EndFiltered[i:]+'\n'
return ''
def LoadConnectionInfo(ChatLog, EntryText):
if EntryText != '':
ChatLog.config(state=NORMAL)
if ChatLog.index('end') != None:
ChatLog.insert(END, EntryText+'\n')
ChatLog.config(state=DISABLED)
ChatLog.yview(END)
def LoadMyEntry(ChatLog, EntryText):
if EntryText != '':
ChatLog.config(state=NORMAL)
if ChatLog.index('end') != None:
LineNumber = float(ChatLog.index('end'))-1.0
ChatLog.insert(END, "You: " + EntryText)
ChatLog.tag_add("You", LineNumber, LineNumber+0.4)
ChatLog.tag_config("You", foreground="#FF8000", font=("Arial", 12, "bold"))
ChatLog.config(state=DISABLED)
ChatLog.yview(END)
def LoadOtherEntry(ChatLog, EntryText):
if EntryText != '':
ChatLog.config(state=NORMAL)
if ChatLog.index('end') != None:
try:
LineNumber = float(ChatLog.index('end'))-1.0
except:
pass
ChatLog.insert(END, "Other: " + EntryText)
ChatLog.tag_add("Other", LineNumber, LineNumber+0.6)
ChatLog.tag_config("Other", foreground="#04B404", font=("Arial", 12, "bold"))
ChatLog.config(state=DISABLED)
ChatLog.yview(END)