-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSYNOP Decoder.py
174 lines (137 loc) · 5.51 KB
/
SYNOP Decoder.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
# -*- coding: utf-8 -*-
#------------------------------------------------------------------------------
# Platform : GUI Decoder file
# Project Name : SYNOP DATA DECODER
# Author : Nikhil Dhandre
# Start Date : 03-07-2016
# Last Modified : 09-01-2017
#------------------------------------------------------------------------------
#--------------------------import library files--------------------------------
from Tkinter import *
import tkFont
from tkFileDialog import askopenfilename, asksaveasfilename
from PIL import ImageTk, Image
import datetime
from main import *
from export_data_csv_file import *
#------------------------------------------------------------------------------
decoding_status = None
msg_file_status = None
ndc_form_III_status = None
#----------------------------GUI Initialization--------------------------------
root = Tk()
root.title("SYNOP Decoder")
#root.geometry("600x450")
#root.geometry("600x450")
# we are using pack method
helv36 = tkFont.Font(family='Helvetica', size=12, weight='bold')
#------------------------------------------------------------------------------
#------------------------------Fuction Defining--------------------------------
#-----------Clock fuction------------------------------------------------------
def tick():
global time1
#time2 = time.strftime('%H:%M:%S')
utc_time = datetime.datetime.utcnow()
time2 = utc_time.strftime("%H:%M:%S")
# if time string has changed, update it
if time2 != time1:
time1 = time2
clock.config(text=time2 + " UTC")
clock.after(200, tick)
#------------------------file name reading fuction-----------------------------
def o_file():
try:
print("Opening file")
msg = askopenfilename() # fuction for opening file
msg = str(msg)
print(msg)
status_list = decoder(msg)
global decoding_status
decoding_status = status_list[1]
global msg_file_status
msg_file_status = status_list[0]
global ndc_form_III_status
ndc_form_III_status = status_list[2]
except:
print("Error: Opening file and decoding fail")
#------------------------file Saving fuction-----------------------------------
def s_CVC_file():
save_filename = asksaveasfilename(filetypes = [('CSV', '.csv'),('all files', '.*') ],defaultextension=".csv")
if save_filename:
print("Save file name is - ", save_filename )
csv_save(save_filename)
def s_NDC_III_comma():
save_filename = asksaveasfilename(filetypes = [('Text', '.txt'),('all files', '.*') ],defaultextension=".txt")
if save_filename:
print("Save file name is - ", save_filename )
ndc_III_save_comma(save_filename)
def s_NDC_III():
save_filename = asksaveasfilename(filetypes = [('Text', '.txt'),('all files', '.*') ],defaultextension=".txt")
if save_filename:
print("Save file name is - ", save_filename )
ndc_III_save(save_filename)
#------------------------------------------------------------------------------
#--------------------------Main loop Start-------------------------------------
#----------------- logo of IMD-------------------------------------------------
img_l = ImageTk.PhotoImage(Image.open("figures/IMDLogo2.png"))
#img_l = img_l.resize((250,250), Image.ANTIALIAS )
panel_l = Label(root, image = img_l)
panel_l.pack()
#-------------------blank label------------------------------------------------
bl_1=Label(root, text='').pack(fill=X)
#-----------------clock--------------------------------------------------------
time1 = '' # variable for saving current time
clock = Label(root, font=('times', 25, 'bold'),fg="blue")
clock.pack()
tick() # calling fuction
#-------------------blank label------------------------------------------------
bl_2=Label(root, text='').pack(fill=X)
#---------------- open msg file button------------------------------------------
open_button = Button(root,
text="Open Message",
font=helv36,
padx=55,
pady=10,
fg="green",
command=o_file)
open_button.pack()
#------------------- label in --------------------------------------------
bl_3 = Label(root, text='').pack(fill=X)
#---------------- Save file button---------------------------------------------
save_button = Button(root,
text="Decoded CSV",
font=helv36,
padx=57,
pady=10,
fg="red",
command = s_CVC_file)
save_button.pack()
#---------------- Export NDC-Form-III file button ----------------------------
ndc_III_button = Button(root,
text="NDC FORM-III",
font=helv36,
padx=59,
pady=10,
fg="blue",
command = s_NDC_III)
ndc_III_button.pack()
#---------------- Export NDC-Form-III file button ----------------------------
ndc_III_button = Button(root,
text="NDC FORM-III (csv)",
font=helv36,
padx=38,
pady=10,
fg="blue",
command = s_NDC_III_comma)
ndc_III_button.pack()
#-------------------blank label------------------------------------------------
bl_4 = Label(root, text='').pack(fill=X)
#-------------------blank label------------------------------------------------
bl_5 = Label(root, text='').pack(fill=X)
#-------------------blank label------------------------------------------------
bl_6 = Label(root, text='').pack(fill=X)
#-------------------blank label------------------------------------------------
bl_7=Label(root, text='').pack(fill=X)
#------------------------------------------------------------------------------
root.mainloop()
#----------------------------sript end-----------------------------------------