-
Notifications
You must be signed in to change notification settings - Fork 0
/
pymorsegui.py
181 lines (157 loc) · 7.86 KB
/
pymorsegui.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# generated by wxGlade 0.9.4 on Sat Feb 1 19:14:54 2020
#
import wx
from pymorsecode import MorseCode
# begin wxGlade: dependencies
# end wxGlade
# begin wxGlade: extracode
# end wxGlade
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.SetSize((602, 444))
self.text_ctrl_txt = wx.TextCtrl(self, wx.ID_ANY, "Enter String", style=wx.TE_MULTILINE | wx.TE_NO_VSCROLL)
self.spin_ctrl_wpm = wx.SpinCtrl(self, wx.ID_ANY, "15", min=5, max=25)
self.spin_ctrl_hz = wx.SpinCtrl(self, wx.ID_ANY, "800", min=500, max=1000)
self.text_ctrl_morsecode = wx.TextCtrl(self, wx.ID_ANY, "Generated Morse Code", style=wx.TE_MULTILINE | wx.TE_NO_VSCROLL | wx.TE_READONLY)
self.button_clear = wx.Button(self, wx.ID_ANY, "Clear")
self.button_open = wx.Button(self, wx.ID_ANY, "Open")
self.button_save = wx.Button(self, wx.ID_ANY, "Save")
self.button_play = wx.Button(self, wx.ID_ANY, "Play")
self.button_generate = wx.Button(self, wx.ID_ANY, "Generate")
self.button_exit = wx.Button(self, wx.ID_ANY, "Exit")
self.morse = MorseCode("Kayleb Walter")
print("Starting program")
# Menu Bar
self.frame_menubar = wx.MenuBar()
wxglade_tmp_menu = wx.Menu()
wxglade_tmp_menu.Append(1, "Open", "")
self.Bind(wx.EVT_MENU, self.onOpen, id=1)
wxglade_tmp_menu.Append(2, "Save", "")
self.Bind(wx.EVT_MENU, self.onSave, id=2)
wxglade_tmp_menu.AppendSeparator()
wxglade_tmp_menu.Append(3, "Generate", "")
self.Bind(wx.EVT_MENU, self.onGenerate, id=3)
wxglade_tmp_menu.Append(4, "Play", "")
self.Bind(wx.EVT_MENU, self.onPlay, id=4)
wxglade_tmp_menu.AppendSeparator()
wxglade_tmp_menu.Append(5, "Exit", "")
self.Bind(wx.EVT_MENU, self.onExit, id=5)
self.frame_menubar.Append(wxglade_tmp_menu, "File")
self.SetMenuBar(self.frame_menubar)
# Menu Bar end
self.__set_properties()
self.__do_layout()
self.Bind(wx.EVT_BUTTON, self.onClear, self.button_clear)
self.Bind(wx.EVT_BUTTON, self.onOpen, self.button_open)
self.Bind(wx.EVT_BUTTON, self.onSave, self.button_save)
self.Bind(wx.EVT_BUTTON, self.onPlay, self.button_play)
self.Bind(wx.EVT_BUTTON, self.onGenerate, self.button_generate)
self.Bind(wx.EVT_BUTTON, self.onExit, self.button_exit)
self.Bind(wx.EVT_SPINCTRL, self.onWpm, self.spin_ctrl_wpm)
self.Bind(wx.EVT_SPINCTRL, self.onHz, self.spin_ctrl_hz)
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("Morse Code Program")
self.text_ctrl_txt.SetToolTip("Enter the text you want to convert to morse code in this text box")
self.text_ctrl_txt.SetFocus()
self.spin_ctrl_wpm.SetToolTip("Morse Code speed in words per minute")
self.spin_ctrl_hz.SetToolTip("Audio Frequency for the tone")
self.text_ctrl_morsecode.SetToolTip("Morse Code will be generated in this text box")
self.button_clear.SetToolTip("Clears the textboxes")
self.button_open.SetToolTip("Opens a wave file")
self.button_save.SetToolTip("Save the morse code audio to a wave file")
self.button_play.SetToolTip("Play an audio version of the morse code")
self.button_generate.SetToolTip("Takes a text string and convert it to morse code")
self.button_exit.SetToolTip("Exit the program")
# end wxGlade
def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_2 = wx.BoxSizer(wx.VERTICAL)
sizer_5 = wx.BoxSizer(wx.HORIZONTAL)
sizer_6 = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, "Actions"), wx.VERTICAL)
sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
sizer_4 = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, "Options"), wx.VERTICAL)
label_1 = wx.StaticText(self, wx.ID_ANY, "Morse Code Generator", style=wx.ALIGN_CENTER)
label_1.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
sizer_2.Add(label_1, 0, wx.EXPAND, 0)
sizer_3.Add(self.text_ctrl_txt, 3, wx.ALL | wx.EXPAND, 5)
label_2 = wx.StaticText(self, wx.ID_ANY, "Speed (words/minute):")
sizer_4.Add(label_2, 0, 0, 0)
sizer_4.Add(self.spin_ctrl_wpm, 0, 0, 0)
label_3 = wx.StaticText(self, wx.ID_ANY, "Audio Frequency (Hz):")
sizer_4.Add(label_3, 0, 0, 0)
sizer_4.Add(self.spin_ctrl_hz, 0, 0, 0)
sizer_3.Add(sizer_4, 1, wx.ALL | wx.EXPAND, 3)
sizer_2.Add(sizer_3, 1, wx.EXPAND, 0)
sizer_5.Add(self.text_ctrl_morsecode, 3, wx.ALL | wx.EXPAND, 5)
sizer_6.Add(self.button_clear, 0, wx.ALL | wx.EXPAND, 1)
sizer_6.Add(self.button_open, 0, wx.ALL | wx.EXPAND, 1)
sizer_6.Add(self.button_save, 0, wx.ALL | wx.EXPAND, 1)
sizer_6.Add(self.button_play, 0, wx.ALL | wx.EXPAND, 1)
sizer_6.Add(self.button_generate, 0, wx.ALL | wx.EXPAND, 1)
sizer_6.Add(self.button_exit, 0, wx.ALL | wx.EXPAND, 1)
sizer_5.Add(sizer_6, 1, wx.ALL | wx.EXPAND, 3)
sizer_2.Add(sizer_5, 1, wx.EXPAND, 0)
sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
self.SetSizer(sizer_1)
self.Layout()
# end wxGlade
def onClear(self, event): # wxGlade: MyFrame.<event_handler>
self.text_ctrl_txt.SetValue("")
self.text_ctrl_morsecode.SetValue("")
def onOpen(self, event): # wxGlade: MyFrame.<event_handler>
openfile = wx.LoadFileSelector('Open a Wave file', '.wav', 'testmorse.wav', None)
if(openfile != ""):
self.SetTitle("Morse Code Wave File - " + openfile)
self.text_ctrl_txt.SetValue("Please Wait Generating....")
self.text_ctrl_morsecode.SetValue("Please Wait Generating....")
self.morse.sound_info(openfile)
print("Generating morse code from audio")
self.morse.sound_to_morse(openfile)
self.text_ctrl_txt.SetValue(self.morse.morse_text)
self.text_ctrl_morsecode.SetValue(self.morse.morse_code)
print("Finished with translating audio to morse code")
def onSave(self, event): # wxGlade: MyFrame.<event_handler>
savefile = wx.SaveFileSelector('Open a Wave file', '.wav', 'testmorse.wav', None)
if(savefile != ""):
self.SetTitle("Morse Code Wave File - " + savefile)
self.morse.save_wav(savefile)
def onGenerate(self, event): # wxGlade: MyFrame.<event_handler>
print("Generating morse code")
morse_text = self.text_ctrl_txt.GetValue()
morse_code = self.morse.to_morse(morse_text)
self.text_ctrl_morsecode.SetValue(self.morse.morse_code)
def onExit(self, event): # wxGlade: MyFrame.<event_handler>
print("Closing program")
self.Destroy()
def onPlay(self, event): # wxGlade: MyFrame.<event_handler>
print("Playing morse code")
morse_code = self.text_ctrl_morsecode.GetValue()
self.morse.play_morse(morse_code)
def onWpm(self, event):
wpm = self.spin_ctrl_wpm.GetValue()
print("Change the WPM value")
self.morse.time_period = self.morse.set_time_period(wpm)
def onHz(self, event):
hz = self.spin_ctrl_hz.GetValue()
print("Change the frequency value")
self.morse.tone = self.morse.set_tone(hz)
# end of class MyFrame
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, wx.ID_ANY, "")
self.SetTopWindow(self.frame)
self.frame.Show()
return True
# end of class MyApp
if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()