A little program to convert angles to and from Decimal degrees, Degrees decimal minutes and Degrees minutes decimal seconds.
AngleDegreeConverter
#!/usr/bin/env python
import wx
import math
[wxID_FRAME1, wxID_FRAME1CHOICE1, wxID_FRAME1CHOICE2, wxID_FRAME1PANEL1,
wxID_FRAME1STATICTEXT1, wxID_FRAME1STATICTEXT2, wxID_FRAME1STATICTEXT3,
wxID_FRAME1STATICTEXT4, wxID_FRAME1STATICTEXT5, wxID_FRAME1STATICTEXT6,
wxID_FRAME1STATICTEXT7, wxID_FRAME1TEXTCTRL1, wxID_FRAME1TEXTCTRL2,
wxID_FRAME1TEXTCTRL3, wxID_FRAME1TEXTCTRL4,
] = [wx.NewId() for _init_ctrls in range(15)]
class Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(320, 268), size=wx.Size(764, 405),
style=wx.DEFAULT_FRAME_STYLE, title=u'Degrees converter')
self.SetClientSize(wx.Size(764, 405))
self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
pos=wx.Point(0, 0), size=wx.Size(764, 405),
style=wx.TAB_TRAVERSAL)
self.choice1 = wx.Choice(choices=['Decimal degrees: dd.dddd',
'Degrees, decimal minutes: dd mm.mmmm',
'Degrees, minutes, decimal seconds: dd mm ss.ssss'],
id=wxID_FRAME1CHOICE1, name='choice1', parent=self.panel1,
pos=wx.Point(216, 63), size=wx.Size(500, 32), style=0)
self.choice1.SetStringSelection(u'Decimal degrees, Degrees decimal minutes, Degrees minutes decimal seconds')
self.choice1.SetSelection(3)
self.choice1.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False,
u'Sans'))
self.choice1.SetMinSize(wx.Size(500, 32))
self.choice1.Bind(wx.EVT_CHOICE, self.OnChoice1Choice,
id=wxID_FRAME1CHOICE1)
self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1,
label=u'Convert from:', name='staticText1', parent=self.panel1,
pos=wx.Point(47, 68), size=wx.Size(125, 19), style=0)
self.staticText1.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD,
False, u'Sans'))
self.staticText2 = wx.StaticText(id=wxID_FRAME1STATICTEXT2,
label=u'Convert to:', name='staticText2', parent=self.panel1,
pos=wx.Point(47, 221), size=wx.Size(102, 19), style=0)
self.staticText2.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD,
False, u'Sans'))
self.choice2 = wx.Choice(choices=['Decimal degrees: dd.dddd',
'Degrees, decimal minutes: dd mm.mmmm',
'Degrees, minutes, decimal seconds: dd mm ss.ssss'],
id=wxID_FRAME1CHOICE2, name='choice2', parent=self.panel1,
pos=wx.Point(216, 216), size=wx.Size(500, 32), style=0)
self.choice2.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False,
u'Sans'))
self.choice2.SetMinSize(wx.Size(500, 32))
self.choice2.Bind(wx.EVT_CHOICE, self.OnChoice2Choice,
id=wxID_FRAME1CHOICE2)
self.staticText3 = wx.StaticText(id=wxID_FRAME1STATICTEXT3,
label=u'Enter value:', name='staticText3', parent=self.panel1,
pos=wx.Point(47, 146), size=wx.Size(106, 19), style=0)
self.staticText3.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD,
False, u'Sans'))
self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL1, name='textCtrl1',
parent=self.panel1, pos=wx.Point(216, 143), size=wx.Size(104, 27),
style=0, value=u'')
self.textCtrl1.SetMinSize(wx.Size(33, 27))
self.textCtrl1.SetToolTipString(u'enter value =< 360')
self.staticText4 = wx.StaticText(id=wxID_FRAME1STATICTEXT4,
label=u'Converted value:', name='staticText4', parent=self.panel1,
pos=wx.Point(47, 302), size=wx.Size(151, 19), style=0)
self.staticText4.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD,
False, u'Sans'))
self.textCtrl2 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL2, name='textCtrl2',
parent=self.panel1, pos=wx.Point(344, 143), size=wx.Size(104, 27),
style=0, value=u'0')
self.textCtrl2.SetMinSize(wx.Size(104, 27))
self.textCtrl2.Show(False)
self.textCtrl2.SetToolTipString(u'enter value < 60')
self.textCtrl3 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL3, name='textCtrl3',
parent=self.panel1, pos=wx.Point(480, 143), size=wx.Size(104, 27),
style=0, value=u'0')
self.textCtrl3.Show(False)
self.textCtrl3.SetToolTipString(u'enter value < 60')
self.textCtrl4 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL4, name='textCtrl4',
parent=self.panel1, pos=wx.Point(216, 296), size=wx.Size(184, 27),
style=0, value=u'')
self.staticText5 = wx.StaticText(id=wxID_FRAME1STATICTEXT5,
label=u'Degrees', name='staticText5', parent=self.panel1,
pos=wx.Point(224, 172), size=wx.Size(54, 17), style=0)
self.staticText6 = wx.StaticText(id=wxID_FRAME1STATICTEXT6,
label=u'Minutes', name='staticText6', parent=self.panel1,
pos=wx.Point(352, 172), size=wx.Size(50, 17), style=0)
self.staticText6.Show(False)
self.staticText7 = wx.StaticText(id=wxID_FRAME1STATICTEXT7,
label=u'Seconds', name='staticText7', parent=self.panel1,
pos=wx.Point(488, 172), size=wx.Size(55, 17), style=0)
self.staticText7.Show(False)
def __init__(self, parent):
self._init_ctrls(parent)
def OnChoice1Choice(self, event):
self.textCtrl1.SetValue("0")
self.textCtrl2.SetValue("0")
self.textCtrl3.SetValue("0")
self.textCtrl4.SetValue(" ")
x = self.choice1.GetSelection()
if x == 0:
self.textCtrl2.Show(False)
self.staticText6.Show(False)
self.textCtrl3.Show(False)
self.staticText7.Show(False)
if x == 1:
self.textCtrl2.Show(True)
self.staticText6.Show(True)
self.textCtrl3.Show(False)
self.staticText7.Show(False)
if x ==2:
self.textCtrl2.Show(True)
self.staticText6.Show(True)
self.textCtrl3.Show(True)
self.staticText7.Show(True)
def OnChoice2Choice(self, event):
if float(self.textCtrl1.GetValue()) >= 360:
self.textCtrl1.SetValue(" ")
if float(self.textCtrl2.GetValue()) >= 60:
self.textCtrl2.SetValue(" ")
if float(self.textCtrl3.GetValue()) >= 60:
self.textCtrl3.SetValue(" ")
self.textCtrl4.SetValue(" ")
def x0y1():
str_txt = self.textCtrl1.GetValue()
degrees = float(str_txt)
dd = math.modf(degrees)
calc = str(int(dd[1]))
mm = str(dd[0]*60)
calc = calc +" -- " + mm
self.textCtrl4.SetValue(calc)
def x0y2():
str_txt = self.textCtrl1.GetValue()
degrees = float(str_txt)
dd = math.modf(degrees)
calc = str(int(dd[1]))
mm = dd[0]*60
ss = math.modf(mm)
mins = str(int(ss[1]))
secs = str(ss[0]*60)
calc = calc + " -- " + mins + " -- " + secs
self.textCtrl4.SetValue(calc)
def x1y0():
txtdeg = self.textCtrl1.GetValue()
deg = float(txtdeg)
txtmins = self.textCtrl2.GetValue()
mins = float(txtmins)/60
value = deg + mins
calc = str(value)
self.textCtrl4.SetValue(calc)
def x1y2():
txtdeg = self.textCtrl1.GetValue()
txtmins = self.textCtrl2.GetValue()
mm = float(txtmins)
ss = math.modf(mm)
mins = str(int(ss[1]))
calc = txtdeg + " -- " + mins + " -- " + str(ss[0]*60)
self.textCtrl4.SetValue(calc)
def x2y0():
txtdeg = self.textCtrl1.GetValue()
txtmins = self.textCtrl2.GetValue()
txtsecs = self.textCtrl3.GetValue()
deg = float(txtdeg)
mins = float(txtmins)/60
secs = float(txtsecs)/3600
calc = deg + mins + secs
self.textCtrl4.SetValue(str(calc))
def x2y1():
txtdeg = self.textCtrl1.GetValue()
txtmins = self.textCtrl2.GetValue()
txtsecs = self.textCtrl3.GetValue()
secs = float(txtsecs)/60
mins = float(txtmins) + secs
calc = txtdeg + " - " +str(mins)
self.textCtrl4.SetValue(str(calc))
x = self.choice1.GetSelection()
y = self.choice2.GetSelection()
if x == 0 and y == 0:
return
if x == 1 and y == 1:
return
if x == 2 and y == 2:
return
if x == 0 and y == 1:
x0y1()
if x == 0 and y == 2:
x0y2()
if x == 1 and y == 0:
x1y0()
if x == 1 and y == 2:
x1y2()
if x == 2 and y == 0:
x2y0()
if x == 2 and y == 1:
x2y1()
def create(parent):
return Frame1(parent)
class MyApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
self.main = create(None)
self.main.Show()
self.SetTopWindow(self.main)
return True
def main():
application = MyApp(0)
application.MainLoop()
if __name__ == '__main__':
main()
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.