def run(self):
        localHostName = QHostInfo.localHostName()
        hostinfo = QHostInfo.fromName(localHostName)
        listaddress = hostinfo.addresses()

        for address in listaddress:
            if QHostAddress(
                    address).protocol() == QAbstractSocket.IPv4Protocol:
                address = QHostAddress(address).toString()
        print(address)

        host_info = ""
        confList = QNetworkConfigurationManager().allConfigurations()
        print("confList = ", confList.__len__())
        for conf in confList:
            if str(conf.bearerTypeName()) == "Ethernet":
                host_info += "\n"
                host_info += "name : " + QNetworkConfiguration(
                    conf).name() + "\n"
                host_info += str(QNetworkConfiguration(conf).isValid()) + "\n"
                host_info += "bearerType: " + QNetworkConfiguration(
                    conf).bearerTypeName() + "\n"

        list = QNetworkInterface.allInterfaces()
        for interface in list:
            host_info += "\n"
            host_info += "=============================\n"
            host_info += "name: " + interface.name() + "\n"
            host_info += QNetworkInterface(interface).hardwareAddress() + "\n"
            host_info += str(QNetworkInterface(interface).isValid()) + "\n"
            host_info += "---------\n"
            if QNetworkInterface(interface).flags() & QNetworkInterface.IsUp:
                host_info += "Interface: is up\n"
            if QNetworkInterface(
                    interface).flags() & QNetworkInterface.IsLoopBack:
                host_info += "Interface: is loop back\n"  # 迴環地址
            if QNetworkInterface(
                    interface).flags() & QNetworkInterface.IsRunning:
                host_info += "Interface: is running \n"  # 網絡已經啓動運行
            if interface.flags() & QNetworkInterface.CanMulticast:
                host_info += "Interface: CanMulticast\n"  # 多播
            if interface.flags() & QNetworkInterface.CanBroadcast:
                host_info += "Interface: CanBroadcast\n"
            host_info += "---------\n"

            entryList = QNetworkInterface(interface).addressEntries()
            for entry in entryList:
                address = entry.ip()
                if QHostAddress(address).protocol(
                ) == QAbstractSocket.IPv4Protocol:  # and  \
                    # str(address.toString()) != "127.0.0.1":
                    host_info += "IP Address: " + QNetworkAddressEntry(
                        entry).ip().toString() + "\n"
                    host_info += "Netmask: " + QNetworkAddressEntry(
                        entry).netmask().toString() + "\n"
                    host_info += "Broadcast: " + QNetworkAddressEntry(
                        entry).broadcast().toString() + "\n"
            host_info += "=============================\n"
        self.sig.emit(host_info)
Пример #2
0
    def __init__(self, username, parent=None):
        super().__init__(parent)
        self.username = username

        self._status = 'UNKNOWN'

        self.last_session = None
        self.sessions = []

        self.balance = None
        self.byte = None

        self.network_manager = QNetworkConfigurationManager(self)
Пример #3
0
    def __init__(self, parent=None):
        """
        Constructor
        
        @param parent reference to the parent widget
        @type QWidget
        """
        super(E5NetworkIcon, self).__init__(parent)

        self.__networkManager = QNetworkConfigurationManager(self)
        self.__online = self.__networkManager.isOnline()
        self.__onlineStateChanged(self.__online)

        self.__networkManager.onlineStateChanged.connect(
            self.__onlineStateChanged)
    def __init__(self, writeableDirectories, parent=None):
        """
        Constructor
        
        @param writeableDirectories list of writable directories
        @type list of str
        @param parent reference to the parent widget
        @type QWidget
        """
        super(ManageDictionariesDialog, self).__init__(parent)
        self.setupUi(self)

        self.__refreshButton = self.buttonBox.addButton(
            self.tr("Refresh"), QDialogButtonBox.ActionRole)
        self.__installButton = self.buttonBox.addButton(
            self.tr("Install Selected"), QDialogButtonBox.ActionRole)
        self.__installButton.setEnabled(False)
        self.__uninstallButton = self.buttonBox.addButton(
            self.tr("Uninstall Selected"), QDialogButtonBox.ActionRole)
        self.__uninstallButton.setEnabled(False)
        self.__cancelButton = self.buttonBox.addButton(
            self.tr("Cancel"), QDialogButtonBox.ActionRole)
        self.__cancelButton.setEnabled(False)

        self.locationComboBox.addItems(writeableDirectories)

        self.dictionariesUrlEdit.setText(
            Preferences.getWebBrowser("SpellCheckDictionariesUrl"))

        if Preferences.getUI("DynamicOnlineCheck"):
            self.__networkConfigurationManager = QNetworkConfigurationManager(
                self)
            self.__onlineStateChanged(
                self.__networkConfigurationManager.isOnline())
            self.__networkConfigurationManager.onlineStateChanged.connect(
                self.__onlineStateChanged)
        else:
            self.__networkConfigurationManager = None
            self.__onlineStateChanged(True)
        self.__replies = []

        self.__downloadCancelled = False
        self.__dictionariesToDownload = []

        self.__populateList()
    def __init__(self, parent=None):
        super(Server, self).__init__(parent)

        self.tcpServer = None
        self.networkSession = None

        self.statusLabel = QLabel()
        quitButton = QPushButton("Quit")
        quitButton.setAutoDefault(False)

        manager = QNetworkConfigurationManager()
        if manager.capabilities(
        ) & QNetworkConfigurationManager.NetworkSessionRequired:
            settings = QSettings(QSettings.UserScope, 'QtProject')
            settings.beginGroup('QtNetwork')
            id = settings.value('DefaultNetworkConfiguration', '')
            settings.endGroup()

            config = manager.configurationFromIdentifier(id)
            if config.state() & QNetworkConfiguration.Discovered == 0:
                config = manager.defaultConfiguration()

            self.networkSession = QNetworkSession(config, self)
            self.networkSession.opened.connect(self.sessionOpened)

            self.statusLabel.setText("Opening network session.")
            self.networkSession.open()
        else:
            self.sessionOpened()

        quitButton.clicked.connect(self.close)
        self.tcpServer.newConnection.connect(self.sendFortune)

        buttonLayout = QHBoxLayout()
        buttonLayout.addStretch(1)
        buttonLayout.addWidget(quitButton)
        buttonLayout.addStretch(1)

        mainLayout = QVBoxLayout()
        mainLayout.addWidget(self.statusLabel)
        mainLayout.addLayout(buttonLayout)
        self.setLayout(mainLayout)

        self.setWindowTitle("Fortune Server")
Пример #6
0
    def __init__(self, parent=None):
        super(Client, self).__init__(parent)

        self.networkSession = None
        self.blockSize = 0
        self.currentFortune = ''
        self.title = "扫码收货PC辅助程序"

        hostLabel = QLabel('IP:')
        hostLabel.setFont(qtawesome.font('fa', 14))

        portLabel = QLabel('端口:')
        portLabel.setFont(qtawesome.font('fa', 14))

        taskCodeLabel = QLabel('任务码:')
        taskCodeLabel.setFont(qtawesome.font('fa', 14))
        self.serverMsgLable = QLabel('来自服务端的消息:')
        self.serverMsgLable.setFont(qtawesome.font('fa', 14))

        self.sendMsgLabel = QLabel('将要发送的消息:')
        self.sendMsgLabel.setFont(qtawesome.font('fa', 14))

        self.hostCombo = QComboBox()
        self.hostCombo.setEditable(True)

        name = QHostInfo.localHostName()
        if name != '':
            self.hostCombo.addItem(name)

            domain = QHostInfo.localDomainName()
            if domain != '':
                self.hostCombo.addItem(name + '.' + domain)

        if name != 'localhost':
            self.hostCombo.addItem('10.286.88.124')

        ipAddressesList = QNetworkInterface.allAddresses()

        for ipAddress in ipAddressesList:
            if not ipAddress.isLoopback():
                self.hostCombo.addItem(ipAddress.toString())

        for ipAddress in ipAddressesList:
            if ipAddress.isLoopback():
                self.hostCombo.addItem(ipAddress.toString())

        self.portLineEdit = QLineEdit()
        self.portLineEdit.setValidator(QIntValidator(1, 65535, self))
        self.portLineEdit.setPlaceholderText("请输入端口")

        self.taskLineEdit = QLineEdit()
        self.taskLineEdit.setPlaceholderText("请向组长询问后输入任务码")
        self.taskLineEdit.setValidator(QIntValidator(1, 9999, self))

        self.serverLineEdit = QLineEdit()
        self.serverLineEdit.setPlaceholderText('服务器发送的消息会显示在这里')

        self.sendTextEdit = QTextEdit()
        self.sendTextEdit.setPlaceholderText('请输入先要发送给服务器的消息')

        hostLabel.setBuddy(self.hostCombo)
        portLabel.setBuddy(self.portLineEdit)
        taskCodeLabel.setBuddy(self.taskLineEdit)
        self.serverMsgLable.setBuddy(self.serverLineEdit)
        self.sendMsgLabel.setBuddy(self.sendTextEdit)

        self.statusLabel = QLabel("状态:尚未连接")
        self.statusLabel.setAutoFillBackground(True)
        self.statusLabel.setAlignment(Qt.AlignCenter)
        palette = QPalette()  # 新建一个调色板
        palette.setColor(QPalette.Window, Qt.red)  # 设置颜色
        self.statusLabel.setPalette(palette)
        self.statusLabel.setStyleSheet('''
                color:#ffffff;
                font-size:18px;
                font-weight:bold;
        ''')

        self.getFortuneButton = QPushButton("启动连接")
        self.getFortuneButton.setDefault(True)
        self.getFortuneButton.setEnabled(False)

        quitButton = QPushButton("退出")
        self.stopButton = QPushButton("中止连接")
        self.stopButton.setDefault(True)
        self.stopButton.setEnabled(False)

        buttonBox = QDialogButtonBox()
        buttonBox.addButton(self.getFortuneButton, QDialogButtonBox.ActionRole)
        buttonBox.addButton(self.stopButton, QDialogButtonBox.AcceptRole)
        buttonBox.addButton(quitButton, QDialogButtonBox.RejectRole)
        self.sendMsgbutton = QPushButton('发送消息')
        self.webSocket = QWebSocket()

        self.hostCombo.editTextChanged.connect(self.enableGetFortuneButton)
        self.portLineEdit.textChanged.connect(self.enableGetFortuneButton)
        self.taskLineEdit.textChanged.connect(self.enableGetFortuneButton)
        self.getFortuneButton.clicked.connect(self.CreateNewConn)
        self.stopButton.clicked.connect(self.stopCurrentConn)
        quitButton.clicked.connect(self.close)
        self.webSocket.connected.connect(self.websocketConnect)
        self.webSocket.disconnected.connect(self.webSocketDisconnect)
        self.webSocket.error.connect(self.displayError)
        self.webSocket.textMessageReceived.connect(
            self.webSocketMessageReceived)
        self.sendTextEdit.textChanged.connect(self.enableSendMessageButton)
        self.sendMsgbutton.clicked.connect(self.sendMsgToServer)

        mainLayout = QGridLayout()
        mainLayout.addWidget(hostLabel, 0, 0)
        mainLayout.addWidget(self.hostCombo, 0, 1)
        mainLayout.addWidget(portLabel, 1, 0)
        mainLayout.addWidget(self.portLineEdit, 1, 1)
        mainLayout.addWidget(taskCodeLabel, 2, 0)
        mainLayout.addWidget(self.taskLineEdit, 2, 1)
        mainLayout.addWidget(self.statusLabel, 3, 0, 1, 2)
        mainLayout.addWidget(buttonBox, 4, 0, 1, 2)
        mainLayout.addWidget(self.serverMsgLable, 5, 0)
        mainLayout.addWidget(self.serverLineEdit, 5, 1, 1, 1)
        mainLayout.addWidget(self.sendMsgLabel, 6, 0)
        mainLayout.addWidget(self.sendTextEdit, 6, 1)
        mainLayout.addWidget(self.sendMsgbutton, 7, 0, 1, 5)
        self.serverLineEdit.setEnabled(False)
        self.serverMsgLable.setVisible(False)
        self.serverLineEdit.setVisible(False)
        self.sendMsgLabel.setVisible(False)
        self.sendTextEdit.setVisible(False)
        self.sendMsgbutton.setEnabled(False)
        self.sendMsgbutton.setVisible(False)
        self.setLayout(mainLayout)
        mainLayout.setSpacing(10)
        self.setWindowTitle(self.title)
        self.portLineEdit.setFocus()
        manager = QNetworkConfigurationManager()
        if manager.capabilities(
        ) & QNetworkConfigurationManager.NetworkSessionRequired:
            settings = QSettings(QSettings.UserScope, 'QtProject')
            settings.beginGroup('QtNetwork')
            id = settings.value('DefaultNetworkConfiguration')
            settings.endGroup()

            config = manager.configurationFromIdentifier(id)
            if config.state() & QNetworkConfiguration.Discovered == 0:
                config = manager.defaultConfiguration()

            self.networkSession = QNetworkSession(config, self)
            self.networkSession.opened.connect(self.sessionOpened)

            self.getFortuneButton.setEnabled(False)
            self.statusLabel.setText("Opening network session.")
            self.networkSession.open()
 def __init__(self, parent=None, external=False):
     """
     Constructor
     
     @param parent parent of this dialog (QWidget)
     @param external flag indicating an instatiation as a main
         window (boolean)
     """
     super(PluginRepositoryWidget, self).__init__(parent)
     self.setupUi(self)
     
     self.__updateButton = self.buttonBox.addButton(
         self.tr("Update"), QDialogButtonBox.ActionRole)
     self.__downloadButton = self.buttonBox.addButton(
         self.tr("Download"), QDialogButtonBox.ActionRole)
     self.__downloadButton.setEnabled(False)
     self.__downloadInstallButton = self.buttonBox.addButton(
         self.tr("Download && Install"),
         QDialogButtonBox.ActionRole)
     self.__downloadInstallButton.setEnabled(False)
     self.__downloadCancelButton = self.buttonBox.addButton(
         self.tr("Cancel"), QDialogButtonBox.ActionRole)
     self.__installButton = \
         self.buttonBox.addButton(self.tr("Close && Install"),
                                  QDialogButtonBox.ActionRole)
     self.__downloadCancelButton.setEnabled(False)
     self.__installButton.setEnabled(False)
     
     self.repositoryUrlEdit.setText(
         Preferences.getUI("PluginRepositoryUrl6"))
     
     self.repositoryList.headerItem().setText(
         self.repositoryList.columnCount(), "")
     self.repositoryList.header().setSortIndicator(0, Qt.AscendingOrder)
     
     self.__pluginContextMenu = QMenu(self)
     self.__hideAct = self.__pluginContextMenu.addAction(
         self.tr("Hide"), self.__hidePlugin)
     self.__hideSelectedAct = self.__pluginContextMenu.addAction(
         self.tr("Hide Selected"), self.__hideSelectedPlugins)
     self.__pluginContextMenu.addSeparator()
     self.__showAllAct = self.__pluginContextMenu.addAction(
         self.tr("Show All"), self.__showAllPlugins)
     self.__pluginContextMenu.addSeparator()
     self.__pluginContextMenu.addAction(
         self.tr("Cleanup Downloads"), self.__cleanupDownloads)
     
     self.pluginRepositoryFile = \
         os.path.join(Utilities.getConfigDir(), "PluginRepository")
     
     self.__external = external
     
     # attributes for the network objects
     self.__networkManager = QNetworkAccessManager(self)
     self.__networkManager.proxyAuthenticationRequired.connect(
         proxyAuthenticationRequired)
     if SSL_AVAILABLE:
         self.__sslErrorHandler = E5SslErrorHandler(self)
         self.__networkManager.sslErrors.connect(self.__sslErrors)
     self.__replies = []
     
     self.__networkConfigurationManager = QNetworkConfigurationManager(self)
     self.__onlineStateChanged(
         self.__networkConfigurationManager.isOnline())
     
     self.__networkConfigurationManager.onlineStateChanged.connect(
         self.__onlineStateChanged)
     
     self.__doneMethod = None
     self.__inDownload = False
     self.__pluginsToDownload = []
     self.__pluginsDownloaded = []
     self.__isDownloadInstall = False
     self.__allDownloadedOk = False
     
     self.__hiddenPlugins = Preferences.getPluginManager("HiddenPlugins")
     
     self.__populateList()
 def __init__(self, pluginManager, parent=None):
     """
     Constructor
     
     @param pluginManager reference to the plugin manager object
     @type PluginManager
     @param parent parent of this dialog
     @type QWidget
     """
     super(PluginRepositoryWidget, self).__init__(parent)
     self.setupUi(self)
     
     if pluginManager is None:
         # started as external plug-in repository dialog
         from .PluginManager import PluginManager
         self.__pluginManager = PluginManager()
         self.__external = True
     else:
         self.__pluginManager = pluginManager
         self.__external = False
     
     self.__updateButton = self.buttonBox.addButton(
         self.tr("Update"), QDialogButtonBox.ActionRole)
     self.__downloadButton = self.buttonBox.addButton(
         self.tr("Download"), QDialogButtonBox.ActionRole)
     self.__downloadButton.setEnabled(False)
     self.__downloadInstallButton = self.buttonBox.addButton(
         self.tr("Download && Install"),
         QDialogButtonBox.ActionRole)
     self.__downloadInstallButton.setEnabled(False)
     self.__downloadCancelButton = self.buttonBox.addButton(
         self.tr("Cancel"), QDialogButtonBox.ActionRole)
     self.__downloadCancelButton.setEnabled(False)
     self.__installButton = self.buttonBox.addButton(
         self.tr("Close && Install"), QDialogButtonBox.ActionRole)
     self.__installButton.setEnabled(False)
     self.__closeButton = self.buttonBox.button(QDialogButtonBox.Close)
     self.__closeButton.setEnabled(True)
     
     self.repositoryUrlEdit.setText(
         Preferences.getUI("PluginRepositoryUrl6"))
     
     self.repositoryList.headerItem().setText(
         self.repositoryList.columnCount(), "")
     self.repositoryList.header().setSortIndicator(0, Qt.AscendingOrder)
     
     self.__pluginContextMenu = QMenu(self)
     self.__hideAct = self.__pluginContextMenu.addAction(
         self.tr("Hide"), self.__hidePlugin)
     self.__hideSelectedAct = self.__pluginContextMenu.addAction(
         self.tr("Hide Selected"), self.__hideSelectedPlugins)
     self.__pluginContextMenu.addSeparator()
     self.__showAllAct = self.__pluginContextMenu.addAction(
         self.tr("Show All"), self.__showAllPlugins)
     self.__pluginContextMenu.addSeparator()
     self.__pluginContextMenu.addAction(
         self.tr("Cleanup Downloads"), self.__cleanupDownloads)
     
     self.pluginRepositoryFile = os.path.join(Utilities.getConfigDir(),
                                              "PluginRepository")
     
     # attributes for the network objects
     self.__networkManager = QNetworkAccessManager(self)
     self.__networkManager.proxyAuthenticationRequired.connect(
         proxyAuthenticationRequired)
     if SSL_AVAILABLE:
         self.__sslErrorHandler = E5SslErrorHandler(self)
         self.__networkManager.sslErrors.connect(self.__sslErrors)
     self.__replies = []
     
     if Preferences.getUI("DynamicOnlineCheck"):
         self.__networkConfigurationManager = (
             QNetworkConfigurationManager(self)
         )
         self.__onlineStateChanged(
             self.__networkConfigurationManager.isOnline())
         self.__networkConfigurationManager.onlineStateChanged.connect(
             self.__onlineStateChanged)
     else:
         self.__networkConfigurationManager = None
         self.__onlineStateChanged(True)
     
     self.__pluginsToDownload = []
     self.__pluginsDownloaded = []
     self.__isDownloadInstall = False
     self.__allDownloadedOk = False
     
     self.__hiddenPlugins = Preferences.getPluginManager("HiddenPlugins")
     
     self.__populateList()
Пример #9
0
    def __init__(self, parent=None):
        super(Client, self).__init__(parent)

        self.networkSession = None
        self.blockSize = 0
        self.currentFortune = ''

        hostLabel = QLabel("&Server name:")
        portLabel = QLabel("S&erver port:")

        self.hostCombo = QComboBox()
        self.hostCombo.setEditable(True)

        name = QHostInfo.localHostName()
        if name != '':
            self.hostCombo.addItem(name)

            domain = QHostInfo.localDomainName()
            if domain != '':
                self.hostCombo.addItem(name + '.' + domain)

        if name != 'localhost':
            self.hostCombo.addItem('localhost')

        ipAddressesList = QNetworkInterface.allAddresses()

        for ipAddress in ipAddressesList:
            if not ipAddress.isLoopback():
                self.hostCombo.addItem(ipAddress.toString())

        for ipAddress in ipAddressesList:
            if ipAddress.isLoopback():
                self.hostCombo.addItem(ipAddress.toString())

        self.portLineEdit = QLineEdit()
        self.portLineEdit.setValidator(QIntValidator(1, 65535, self))

        hostLabel.setBuddy(self.hostCombo)
        portLabel.setBuddy(self.portLineEdit)

        self.statusLabel = QLabel("This examples requires that you run "
                                  "the Fortune Server example as well.")

        self.getFortuneButton = QPushButton("Get Fortune")
        self.getFortuneButton.setDefault(True)
        self.getFortuneButton.setEnabled(False)

        quitButton = QPushButton("Quit")

        buttonBox = QDialogButtonBox()
        buttonBox.addButton(self.getFortuneButton, QDialogButtonBox.ActionRole)
        buttonBox.addButton(quitButton, QDialogButtonBox.RejectRole)

        self.tcpSocket = QTcpSocket(self)

        self.hostCombo.editTextChanged.connect(self.enableGetFortuneButton)
        self.portLineEdit.textChanged.connect(self.enableGetFortuneButton)
        self.getFortuneButton.clicked.connect(self.requestNewFortune)
        quitButton.clicked.connect(self.close)
        self.tcpSocket.readyRead.connect(self.readFortune)
        self.tcpSocket.error.connect(self.displayError)

        mainLayout = QGridLayout()
        mainLayout.addWidget(hostLabel, 0, 0)
        mainLayout.addWidget(self.hostCombo, 0, 1)
        mainLayout.addWidget(portLabel, 1, 0)
        mainLayout.addWidget(self.portLineEdit, 1, 1)
        mainLayout.addWidget(self.statusLabel, 2, 0, 1, 2)
        mainLayout.addWidget(buttonBox, 3, 0, 1, 2)
        self.setLayout(mainLayout)

        self.setWindowTitle("Fortune Client")
        self.portLineEdit.setFocus()

        manager = QNetworkConfigurationManager()
        if manager.capabilities(
        ) & QNetworkConfigurationManager.NetworkSessionRequired:
            settings = QSettings(QSettings.UserScope, 'QtProject')
            settings.beginGroup('QtNetwork')
            id = settings.value('DefaultNetworkConfiguration')
            settings.endGroup()

            config = manager.configurationFromIdentifier(id)
            if config.state() & QNetworkConfiguration.Discovered == 0:
                config = manager.defaultConfiguration()

            self.networkSession = QNetworkSession(config, self)
            self.networkSession.opened.connect(self.sessionOpened)

            self.getFortuneButton.setEnabled(False)
            self.statusLabel.setText("Opening network session.")
            self.networkSession.open()