Skip to content

Instantly share code, notes, and snippets.

@projectyotta
Created March 14, 2018 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save projectyotta/b04d3dbd87b958b814df2b84d9807f39 to your computer and use it in GitHub Desktop.
Save projectyotta/b04d3dbd87b958b814df2b84d9807f39 to your computer and use it in GitHub Desktop.
Wxpython script to open up a GUI window , take inputs , and use them to run pysim read and write modules
# how to install the wx package :
# open a terminal and type : sudo apt-get install python-wxgtk3.0
# if it asks for additional inbstructions in there , just say yes and let it run .
import os
import sys
from subprocess import Popen, PIPE
import pandas as pd
if sys.version_info[0] < 3:
from StringIO import StringIO
else:
from io import StringIO
import wx
vals = []
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "VNC SIM TOOL",size=(500,400))
self.panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
self.log = wx.TextCtrl(self.panel, wx.ID_ANY, size=(400,300),style = wx.TE_MULTILINE|wx.TE_READONLY|wx.VSCROLL)
self.button = wx.Button(self.panel, label="Input values")
sizer.Add(self.log, 0, wx.EXPAND | wx.ALL, 10)
sizer.Add(self.button, 0, wx.EXPAND | wx.ALL, 10)
self.panel.SetSizer(sizer)
self.Bind(wx.EVT_BUTTON, self.OnButton)
def OnButton(self,event):
dlg = GetData(parent = self.panel)
dlg.ShowModal()
if dlg.result_iccid:
self.log.AppendText("ICCID "+dlg.result_iccid+"\n")
self.log.AppendText("IMSI "+dlg.result_imsi+"\n")
self.log.AppendText("ACC "+dlg.result_acc+"\n")
self.log.AppendText("ADM "+dlg.result_adm+"\n")
self.log.AppendText("OP "+dlg.result_op+"\n")
self.log.AppendText("KI "+dlg.result_ki+"\n")
self.log.AppendText("OPC "+dlg.result_opc+"\n")
self.log.AppendText("MCC "+dlg.result_mcc+"\n")
self.log.AppendText("MNC "+dlg.result_mnc+"\n")
self.log.AppendText("Reading done")
self.log.AppendText("Writing done")
vals.append(dlg.result_iccid)
vals.append(dlg.result_imsi)
vals.append(dlg.result_acc)
vals.append(dlg.result_adm)
vals.append(dlg.result_op)
vals.append(dlg.result_ki)
vals.append(dlg.result_opc)
vals.append(dlg.result_mcc)
vals.append(dlg.result_mnc)
else:
self.log.AppendText("No Input found\n")
dlg.Destroy()
class GetData(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__(self, parent, wx.ID_ANY, "Name Input", size= (650,500))
self.panel = wx.Panel(self,wx.ID_ANY)
self.lbliccid = wx.StaticText(self.panel, label="ICCID :", pos=(20,20))
self.iccid = wx.TextCtrl(self.panel, value="", pos=(110,20), size=(500,-1))
self.lblimsi = wx.StaticText(self.panel, label="IMSI :", pos=(20,40))
self.imsi = wx.TextCtrl(self.panel, value="", pos=(110,40), size=(500,-1))
self.lblacc = wx.StaticText(self.panel, label="ACC", pos=(20,60))
self.acc = wx.TextCtrl(self.panel, value='', pos=(110,60), size=(500,-1))
self.lbladm = wx.StaticText(self.panel, label="ADM", pos=(20,80))
self.adm = wx.TextCtrl(self.panel, value="", pos=(110,80), size=(500,-1))
self.lblop = wx.StaticText(self.panel, label="OP ", pos=(20,100))
self.op = wx.TextCtrl(self.panel, value="", pos=(110,100), size=(500,-1))
self.ki = wx.StaticText(self.panel, label="KI ", pos=(20,120))
self.ki = wx.TextCtrl(self.panel, value="", pos=(110,120), size=(500,-1))
self.lblopc = wx.StaticText(self.panel, label="OPC ", pos=(20,140))
self.opc = wx.TextCtrl(self.panel, value="", pos=(110,140), size=(500,-1))
self.lblmcc = wx.StaticText(self.panel, label="MCC ", pos=(20,160))
self.mcc = wx.TextCtrl(self.panel, value="", pos=(110,160), size=(500,-1))
self.lblmnc = wx.StaticText(self.panel, label="MNC ", pos=(20,180))
self.mnc = wx.TextCtrl(self.panel, value="", pos=(110,180), size=(500,-1))
self.saveButton =wx.Button(self.panel, label="Save", pos=(110,250))
self.closeButton =wx.Button(self.panel, label="Cancel", pos=(210,250))
self.saveButton.Bind(wx.EVT_BUTTON, self.SaveConnString)
self.closeButton.Bind(wx.EVT_BUTTON, self.OnQuit)
self.Bind(wx.EVT_CLOSE, self.OnQuit)
self.Show()
def OnQuit(self, event):
self.result_iccid = None
self.Destroy()
def SaveConnString(self, event):
self.result_iccid = self.iccid.GetValue()
self.result_imsi = self.imsi.GetValue()
self.result_acc = self.acc.GetValue()
self.result_adm = self.adm.GetValue()
self.result_op = self.op.GetValue()
self.result_ki = self.ki.GetValue()
self.result_opc = self.opc.GetValue()
self.result_mcc = self.mcc.GetValue()
self.result_mnc = self.mnc.GetValue()
# get to the required directory and execute the pysim read file
os.chdir("pysim")
#os.system("./pySim-read.py -p0")
stdout = Popen('./pySim-read.py -p0', shell=True, stdout=PIPE).stdout
output = stdout.read()
df = pd.read_csv(StringIO(output), sep=":")
global iccid
global imsi
global acc
iccid = ((str(df['Reading ...'][0]).strip()))
imsi = ((str(df['Reading ...'][1]).strip()))
acc = ((str(df['Reading ...'][3]).strip()))
amaze = str('./pySim-prog.py -p 0 -s ' + str(iccid) + str(' -i ') + str(imsi) + str(' --acc ') + str(acc) + str(' -a ') + str(self.result_adm) + str(' --op ') + str(self.result_op) + str(' -k ') + str(self.result_ki) +str(' -o ') + str(self.result_opc) +str(' -x ') + str(self.result_mcc) + str(' -y ') + str(self.result_mnc))
stdout1 = Popen(amaze, shell=True, stdout=PIPE).stdout
output1 = stdout1.read()
df1 = pd.read_csv(StringIO(output1),sep=":",skiprows=2)
for i in range(0,len(df1)):
print(str(df1['Unnamed: 1'][i]).strip())
self.Destroy()
app = wx.App()
frame = MyFrame(None)
frame.Show()
app.MainLoop()
"""
# get to the required directory and execute the pysim read file
os.chdir("pysim")
#os.system("./pySim-read.py -p0")
stdout = Popen('./pySim-read.py -p0', shell=True, stdout=PIPE).stdout
output = stdout.read()
df = pd.read_csv(StringIO(output), sep=":")
iccid = ((str(df['Reading ...'][0]).strip()))
imsi = ((str(df['Reading ...'][1]).strip()))
acc = ((str(df['Reading ...'][3]).strip()))
"""
"""
amaze = str('./pySim-prog.py -p 0 -s ' + str(vals[0]) + str(' -i ') + str(vals[1]) + str(' --acc ') + str(vals[2]) + str(' -a ') + str(vals[3]) + str(' --op ') + str(vals[4]) + str(' -k ') + str(vals[5]) +str(' -o ') + str(vals[6]) +str(' -x ') + str(vals[7]) + str(' -y ') + str(vals[8]))
stdout1 = Popen(amaze, shell=True, stdout=PIPE).stdout
output1 = stdout1.read()
df1 = pd.read_csv(StringIO(output1),sep=":",skiprows=2)
for i in range(0,len(df1)):
print(str(df1['Unnamed: 1'][i]).strip())
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment