Advertisement
Guest User

Qt4 Signal cross classes Help!

a guest
Apr 24th, 2013
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.35 KB | None | 0 0
  1. from PyQt4 import QtCore, QtGui
  2. from mainScreen import Ui_mainScreen
  3. from editScreen import Ui_Dialog
  4.  
  5. try:
  6.     _fromUtf8 = QtCore.QString.fromUtf8
  7. except AttributeError:
  8.     def _fromUtf8(s):
  9.         return s
  10.  
  11.  
  12. class mainScreen(QtGui.QDialog,  Ui_mainScreen):
  13.     def __init__(self, parent=None):
  14.         QtGui.QWidget.__init__(self, parent)
  15.         self.setupUi(self)
  16.  
  17.         #filling the nic names into the selector
  18.         QtGui.QComboBox.addItems(self.adapterSelector,  nicNamesL)
  19.         #Setting up exit button
  20.         #self.pushButton_9.clicked.connect(self.close)
  21.         self.pushButton_9.clicked.connect(self.labelUpdate) #This manual refresh on the mainscreen works...
  22.         #Reading to config and assigning the values to our txt labels
  23.         self.labelUpdate()
  24.        
  25.         self.editLineOne.clicked.connect(lambda: self.editButton(1))
  26.         self.editLineTwo.clicked.connect(lambda: self.editButton(2))
  27.         self.EditLineThree.clicked.connect(lambda: self.editButton(3))
  28.         self.editLine4.clicked.connect(lambda: self.editButton(4))
  29.         self.editLine5.clicked.connect(lambda: self.editButton(5))
  30.         self.editWindow = None
  31.        
  32.     #@QtCore.pyqtSlot(object)    
  33.     def labelUpdate(self):
  34.         config = configparser.ConfigParser()
  35.         config.read('netSettings.ini')
  36.         #udating the labels from the config file
  37.         for i in config.sections():
  38.             num = "%s" % i
  39.             if num in config.sections():
  40.                 print("Running Label UPDATE!",  i)
  41.                 print("SElf",  self)
  42.                 apiLabel = "self.apiLabel%s.setText(config[num]['api'])" % i
  43.                 exec(apiLabel)
  44.                 ipLabel = "self.ipLabel%s.setText(config[num]['ip address'])" % i
  45.                 exec(ipLabel)
  46.                 gatewayLabel = "self.gatewayLabel%s.setText(config[num]['gateway'])" % i
  47.                 exec(gatewayLabel)
  48.        
  49.     def setIPSettings1(self):
  50.            
  51.         self.apiLabel1.setText(_fromUtf8("GRRA"))
  52.         print("here",  QtGui.QLabel.text(self.apiLabel1))
  53.         #here we find out which button was pushed and set the LAN or WLAN connection
  54.         return()
  55.  
  56.  
  57.     def editButton(self,  editButtonNum):
  58.         self.editWindow = None
  59.         global editButtonNumber
  60.         editButtonNumber = editButtonNum
  61.         if self.editWindow is None: #if Edit sceen not showing already
  62.             self.editWindow = editScreen(self)  #Create out editwindow from our class editscreen
  63.         self.editWindow.show()
  64.  
  65.  
  66. #connecting out editscreen python file as a class
  67. class editScreen(QtGui.QDialog, Ui_Dialog):
  68.     def __init__(self, parent=None):
  69.         QtGui.QDialog.__init__(self, parent)
  70.         self.setupUi(self)
  71.         self.editWindow = None
  72.         #Setting the default values
  73.         config = configparser.ConfigParser()
  74.         config.read('netSettings.ini')
  75.         num = editButtonNumber
  76.        
  77.         num = "%s" % num
  78.         if num in config.sections():
  79.             print("In config")
  80.             self.lineEditAPI.setText(config[num]['api'])
  81.             self.lineEditIP.setText(config[num]['ip address'])
  82.             self.lineEditMask.setText(config[num]['subnet mask'])
  83.             self.lineEditGateway.setText(config[num]['gateway'])
  84.             self.lineEditDNS1.setText(config[num]['dns1'])
  85.             self.lineEditDNS2.setText(config[num]['dns2'])
  86.  
  87.         #programming the cancel button
  88.         cancelButton = self.buttonBox.button(QtGui.QDialogButtonBox.Cancel)
  89.         cancelButton.clicked.connect(self.close)
  90.         #programming the OK Button on the edit dialog
  91.         okayButton = self.buttonBox.button(QtGui.QDialogButtonBox.Ok)
  92.         okayButton.clicked.connect(self.okaySignal)
  93.     def okaySignal(self):
  94.         print("Saving Data to slot ",  editButtonNumber)
  95.         num = editButtonNumber
  96.         config = configparser.ConfigParser()
  97.         #Reading the file so we don't overwrite entire file with one entry
  98.         config.read('netSettings.ini')
  99.         config[num] = {'API': self.lineEditAPI.text(),
  100.                               'IP ADDRESS': self.lineEditIP.text(),  
  101.                               'SUBNET MASK': self.lineEditMask.text(),
  102.                               'GATEWAY': self.lineEditGateway.text(),
  103.                               'DNS1': self.lineEditDNS1.text(),
  104.                               'DNS2': self.lineEditDNS2.text() }
  105.         configfile = open('netSettings.ini',  'w')
  106.         config.write(configfile)
  107.         configfile.close()  #Done with file, closing it  
  108.         print("Closing Edit Window")
  109.         self.close()
  110.  
  111.        
  112.  
  113. if __name__ == '__main__':
  114.    
  115.     import wmi
  116.     import sys
  117.     import configparser
  118.  
  119.     def readConfig():
  120.         try:
  121.             with open('netSettings.ini'):
  122.                 print("Reading Config File!")
  123.                 return True
  124.         except:
  125.             print("No config file! Will create new!")
  126.             config['DEFAULT'] = {'ServerAliveInterval': '45'} #TODO, this is test only
  127.             with open('netSettings.ini',  'w') as configfile:
  128.                 config.write(configfile)
  129.             return False
  130.  
  131.     #reading config file if created
  132.     config = configparser.ConfigParser()
  133.     readConfig()
  134.  
  135.     pc = wmi.WMI()
  136.     #obtain network adaptors
  137.     nic_configs = pc.Win32_NetworkAdapterConfiguration (IPEnabled=1)
  138.     #Finding nics by default names
  139.     nicLan = pc.Win32_NetworkAdapter (NetConnectionID="Local Area Connection")
  140.  
  141.     nicWireless = pc.Win32_NetworkAdapter (NetConnectionID="Wireless Area Connection")
  142.     #Creating a list of NIC's for our dropdown
  143.     nicNamesL = list()
  144.     try:
  145.         nicNamesL.append(nicLan[0].NetConnectionID)
  146.     except:
  147.         print("Unable to find Local Area Connection Adapter!")
  148.     try:
  149.         nicNamesL.append(nicWireless[0].NetConnectionID)
  150.     except:
  151.         print("Unable to find Wireless Connection Adapter!")
  152.    
  153.    
  154.    
  155.     #showing our main window
  156.     app = QtGui.QApplication(sys.argv)
  157.     window = mainScreen()
  158.     window.show()
  159.     sys.exit(app.exec_())
  160.  
  161.  
  162.        
  163. #        
  164. #        def trigger_test(self):
  165. #            self.trigger.connect(self.handleTrigger)
  166. #            self.trigger.emit()
  167. #    
  168. #        #trigger = QtCore.pyqtSignal()
  169. #        #trigger_test(self)
  170. #
  171. #        
  172. #        #def handleTrigger(self):
  173. #            #print("trigger recieved")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement