Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PyQt4 import QtCore, QtGui
- from mainScreen import Ui_mainScreen
- from editScreen import Ui_Dialog
- try:
- _fromUtf8 = QtCore.QString.fromUtf8
- except AttributeError:
- def _fromUtf8(s):
- return s
- class mainScreen(QtGui.QDialog, Ui_mainScreen):
- def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
- self.setupUi(self)
- #filling the nic names into the selector
- QtGui.QComboBox.addItems(self.adapterSelector, nicNamesL)
- #Setting up exit button
- #self.pushButton_9.clicked.connect(self.close)
- self.pushButton_9.clicked.connect(self.labelUpdate) #This manual refresh on the mainscreen works...
- #Reading to config and assigning the values to our txt labels
- self.labelUpdate()
- self.editLineOne.clicked.connect(lambda: self.editButton(1))
- self.editLineTwo.clicked.connect(lambda: self.editButton(2))
- self.EditLineThree.clicked.connect(lambda: self.editButton(3))
- self.editLine4.clicked.connect(lambda: self.editButton(4))
- self.editLine5.clicked.connect(lambda: self.editButton(5))
- self.editWindow = None
- #@QtCore.pyqtSlot(object)
- def labelUpdate(self):
- config = configparser.ConfigParser()
- config.read('netSettings.ini')
- #udating the labels from the config file
- for i in config.sections():
- num = "%s" % i
- if num in config.sections():
- print("Running Label UPDATE!", i)
- print("SElf", self)
- apiLabel = "self.apiLabel%s.setText(config[num]['api'])" % i
- exec(apiLabel)
- ipLabel = "self.ipLabel%s.setText(config[num]['ip address'])" % i
- exec(ipLabel)
- gatewayLabel = "self.gatewayLabel%s.setText(config[num]['gateway'])" % i
- exec(gatewayLabel)
- def setIPSettings1(self):
- self.apiLabel1.setText(_fromUtf8("GRRA"))
- print("here", QtGui.QLabel.text(self.apiLabel1))
- #here we find out which button was pushed and set the LAN or WLAN connection
- return()
- def editButton(self, editButtonNum):
- self.editWindow = None
- global editButtonNumber
- editButtonNumber = editButtonNum
- if self.editWindow is None: #if Edit sceen not showing already
- self.editWindow = editScreen(self) #Create out editwindow from our class editscreen
- self.editWindow.show()
- #connecting out editscreen python file as a class
- class editScreen(QtGui.QDialog, Ui_Dialog):
- def __init__(self, parent=None):
- QtGui.QDialog.__init__(self, parent)
- self.setupUi(self)
- self.editWindow = None
- #Setting the default values
- config = configparser.ConfigParser()
- config.read('netSettings.ini')
- num = editButtonNumber
- num = "%s" % num
- if num in config.sections():
- print("In config")
- self.lineEditAPI.setText(config[num]['api'])
- self.lineEditIP.setText(config[num]['ip address'])
- self.lineEditMask.setText(config[num]['subnet mask'])
- self.lineEditGateway.setText(config[num]['gateway'])
- self.lineEditDNS1.setText(config[num]['dns1'])
- self.lineEditDNS2.setText(config[num]['dns2'])
- #programming the cancel button
- cancelButton = self.buttonBox.button(QtGui.QDialogButtonBox.Cancel)
- cancelButton.clicked.connect(self.close)
- #programming the OK Button on the edit dialog
- okayButton = self.buttonBox.button(QtGui.QDialogButtonBox.Ok)
- okayButton.clicked.connect(self.okaySignal)
- def okaySignal(self):
- print("Saving Data to slot ", editButtonNumber)
- num = editButtonNumber
- config = configparser.ConfigParser()
- #Reading the file so we don't overwrite entire file with one entry
- config.read('netSettings.ini')
- config[num] = {'API': self.lineEditAPI.text(),
- 'IP ADDRESS': self.lineEditIP.text(),
- 'SUBNET MASK': self.lineEditMask.text(),
- 'GATEWAY': self.lineEditGateway.text(),
- 'DNS1': self.lineEditDNS1.text(),
- 'DNS2': self.lineEditDNS2.text() }
- configfile = open('netSettings.ini', 'w')
- config.write(configfile)
- configfile.close() #Done with file, closing it
- print("Closing Edit Window")
- self.close()
- if __name__ == '__main__':
- import wmi
- import sys
- import configparser
- def readConfig():
- try:
- with open('netSettings.ini'):
- print("Reading Config File!")
- return True
- except:
- print("No config file! Will create new!")
- config['DEFAULT'] = {'ServerAliveInterval': '45'} #TODO, this is test only
- with open('netSettings.ini', 'w') as configfile:
- config.write(configfile)
- return False
- #reading config file if created
- config = configparser.ConfigParser()
- readConfig()
- pc = wmi.WMI()
- #obtain network adaptors
- nic_configs = pc.Win32_NetworkAdapterConfiguration (IPEnabled=1)
- #Finding nics by default names
- nicLan = pc.Win32_NetworkAdapter (NetConnectionID="Local Area Connection")
- nicWireless = pc.Win32_NetworkAdapter (NetConnectionID="Wireless Area Connection")
- #Creating a list of NIC's for our dropdown
- nicNamesL = list()
- try:
- nicNamesL.append(nicLan[0].NetConnectionID)
- except:
- print("Unable to find Local Area Connection Adapter!")
- try:
- nicNamesL.append(nicWireless[0].NetConnectionID)
- except:
- print("Unable to find Wireless Connection Adapter!")
- #showing our main window
- app = QtGui.QApplication(sys.argv)
- window = mainScreen()
- window.show()
- sys.exit(app.exec_())
- #
- # def trigger_test(self):
- # self.trigger.connect(self.handleTrigger)
- # self.trigger.emit()
- #
- # #trigger = QtCore.pyqtSignal()
- # #trigger_test(self)
- #
- #
- # #def handleTrigger(self):
- # #print("trigger recieved")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement