Как добавить лог в pytqt5?

Я новичок в pyqt5, и я пытаюсь создать программу с журналами, и я следую это.

Я создал графический интерфейс для своей программы с помощью QTDesigner:

gui.py

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'GUI.ui'
#
# Created by: PyQt5 UI code generator 5.10.1
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import Qt

from info import info_os, now, jam, wificonnectedto, ipaddress, mac,gatew,status
from Btn import Switch



class Ui_widps(object):
    def setupUi(self, widps):
        widps.setObjectName("widps")
        widps.resize(714, 548)
        widps.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
        widps.setAcceptDrops(False)
        widps.setDocumentMode(False)
        widps.setDockNestingEnabled(False)
        widps.setUnifiedTitleAndToolBarOnMac(False)
        self.centralwidget = QtWidgets.QWidget(widps)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(10, 30, 101, 101))
        self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
        self.LayoutInformation = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
        self.LayoutInformation.setContentsMargins(0, 0, 0, 0)
        self.LayoutInformation.setObjectName("LayoutInformation")
        self.txOs = QtWidgets.QLabel(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.txOs.setFont(font)
        self.txOs.setObjectName("txOs")
        self.LayoutInformation.addWidget(self.txOs)
        self.txCdate = QtWidgets.QLabel(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.txCdate.setFont(font)
        self.txCdate.setObjectName("txCdate")
        self.LayoutInformation.addWidget(self.txCdate)
        self.txCtime = QtWidgets.QLabel(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.txCtime.setFont(font)
        self.txCtime.setObjectName("txCtime")
        self.LayoutInformation.addWidget(self.txCtime)
        self.verticalLayoutWidget_2 = QtWidgets.QWidget(self.centralwidget)
        self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(10, 161, 81, 111))
        self.verticalLayoutWidget_2.setObjectName("verticalLayoutWidget_2")
        self.LayoutConnectionInfo = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_2)
        self.LayoutConnectionInfo.setContentsMargins(0, 0, 0, 0)
        self.LayoutConnectionInfo.setObjectName("LayoutConnectionInfo")
        self.txConnto = QtWidgets.QLabel(self.verticalLayoutWidget_2)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.txConnto.setFont(font)
        self.txConnto.setObjectName("txConnto")
        self.LayoutConnectionInfo.addWidget(self.txConnto)
        self.txtIpad = QtWidgets.QLabel(self.verticalLayoutWidget_2)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.txtIpad.setFont(font)
        self.txtIpad.setObjectName("txtIpad")
        self.LayoutConnectionInfo.addWidget(self.txtIpad)
        self.txMacAd = QtWidgets.QLabel(self.verticalLayoutWidget_2)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.txMacAd.setFont(font)
        self.txMacAd.setObjectName("txMacAd")
        self.LayoutConnectionInfo.addWidget(self.txMacAd)
        self.txGateway = QtWidgets.QLabel(self.verticalLayoutWidget_2)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.txGateway.setFont(font)
        self.txGateway.setObjectName("txGateway")
        self.LayoutConnectionInfo.addWidget(self.txGateway)
        self.verticalLayoutWidget_3 = QtWidgets.QWidget(self.centralwidget)
        self.verticalLayoutWidget_3.setGeometry(QtCore.QRect(80, 280, 119, 31))
        self.verticalLayoutWidget_3.setObjectName("verticalLayoutWidget_3")
        self.LayoutWirelessSec = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_3)
        self.LayoutWirelessSec.setContentsMargins(0, 0, 0, 0)
        self.LayoutWirelessSec.setObjectName("LayoutWirelessSec")
        self.txtWirelessSec = QtWidgets.QLabel(self.verticalLayoutWidget_3)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.txtWirelessSec.setFont(font)
        self.txtWirelessSec.setObjectName("txtWirelessSec")
        self.LayoutWirelessSec.addWidget(self.txtWirelessSec)
        self.verticalLayoutWidget_4 = QtWidgets.QWidget(self.centralwidget)
        self.verticalLayoutWidget_4.setGeometry(QtCore.QRect(10, 320, 161, 161))
        self.verticalLayoutWidget_4.setObjectName("verticalLayoutWidget_4")
        self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_4)
        self.verticalLayout_4.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_4.setObjectName("verticalLayout_4")
        self.txtArp = QtWidgets.QLabel(self.verticalLayoutWidget_4)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.txtArp.setFont(font)
        self.txtArp.setObjectName("txtArp")
        self.verticalLayout_4.addWidget(self.txtArp)
        self.txtRapp = QtWidgets.QLabel(self.verticalLayoutWidget_4)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.txtRapp.setFont(font)
        self.txtRapp.setObjectName("txtRapp")
        self.verticalLayout_4.addWidget(self.txtRapp)
        self.txtSniff = QtWidgets.QLabel(self.verticalLayoutWidget_4)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.txtSniff.setFont(font)
        self.txtSniff.setObjectName("txtSniff")
        self.verticalLayout_4.addWidget(self.txtSniff)
        self.verticalLayoutWidget_5 = QtWidgets.QWidget(self.centralwidget)
        self.verticalLayoutWidget_5.setGeometry(QtCore.QRect(340, 90, 371, 301))
        self.verticalLayoutWidget_5.setObjectName("verticalLayoutWidget_5")
        self.verticalLayout_5 = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_5)
        self.verticalLayout_5.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_5.setObjectName("verticalLayout_5")
        self.verticalLayoutWidget_6 = QtWidgets.QWidget(self.centralwidget)
        self.verticalLayoutWidget_6.setGeometry(QtCore.QRect(450, 10, 151, 71))
        self.verticalLayoutWidget_6.setObjectName("verticalLayoutWidget_6")
        self.verticalLayout_6 = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_6)
        self.verticalLayout_6.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_6.setObjectName("verticalLayout_6")
        self.txtGraph = QtWidgets.QLabel(self.verticalLayoutWidget_6)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.txtGraph.setFont(font)
        self.txtGraph.setAlignment(QtCore.Qt.AlignCenter)
        self.txtGraph.setObjectName("txtGraph")
        self.verticalLayout_6.addWidget(self.txtGraph)
        self.verticalLayoutWidget_8 = QtWidgets.QWidget(self.centralwidget)
        self.verticalLayoutWidget_8.setGeometry(QtCore.QRect(170, 320, 161, 171))
        self.verticalLayoutWidget_8.setObjectName("verticalLayoutWidget_8")
        self.LayoutBtnWirelessSec = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_8)
        self.LayoutBtnWirelessSec.setContentsMargins(0, 0, 0, 0)
        self.LayoutBtnWirelessSec.setObjectName("LayoutBtnWirelessSec")
        self.Arppbtn = Switch()
        self.Arppbtn.setObjectName("Arppbtn")
        self.LayoutBtnWirelessSec.addWidget(self.Arppbtn)
        self.Rappbtn = Switch()
        self.Rappbtn.setObjectName("Rappbtn")
        self.LayoutBtnWirelessSec.addWidget(self.Rappbtn)
        self.Sniffpbtn = Switch()
        self.Sniffpbtn.setObjectName("Sniffpbtn")
        self.LayoutBtnWirelessSec.addWidget(self.Sniffpbtn)
        self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.horizontalLayoutWidget.setGeometry(QtCore.QRect(410, 390, 247, 80))
        self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
        self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.txtthreat = QtWidgets.QLabel(self.horizontalLayoutWidget)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.txtthreat.setFont(font)
        self.txtthreat.setObjectName("txtthreat")
        self.horizontalLayout.addWidget(self.txtthreat)
        self.txttotalthreat = QtWidgets.QLabel(self.horizontalLayoutWidget)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.txttotalthreat.setFont(font)
        self.txttotalthreat.setObjectName("txttotalthreat")
        self.horizontalLayout.addWidget(self.txttotalthreat)
        self.verticalLayoutWidget_7 = QtWidgets.QWidget(self.centralwidget)
        self.verticalLayoutWidget_7.setGeometry(QtCore.QRect(109, 29, 141, 101))
        self.verticalLayoutWidget_7.setObjectName("verticalLayoutWidget_7")
        self.LayoutFungsiInfo = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_7)
        self.LayoutFungsiInfo.setContentsMargins(0, 0, 0, 0)
        self.LayoutFungsiInfo.setObjectName("LayoutFungsiInfo")
        self.osinfotxt = QtWidgets.QLabel(self.verticalLayoutWidget_7)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.osinfotxt.setFont(font)
        self.osinfotxt.setObjectName("osinfotxt")
        self.LayoutFungsiInfo.addWidget(self.osinfotxt)
        self.cdatetxt = QtWidgets.QLabel(self.verticalLayoutWidget_7)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.cdatetxt.setFont(font)
        self.cdatetxt.setObjectName("cdatetxt")
        self.LayoutFungsiInfo.addWidget(self.cdatetxt)
        self.ctimetxt = QtWidgets.QLabel(self.verticalLayoutWidget_7)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.ctimetxt.setFont(font)
        self.ctimetxt.setObjectName("ctimetxt")
        self.LayoutFungsiInfo.addWidget(self.ctimetxt)
        self.txtinfo = QtWidgets.QLabel(self.centralwidget)
        self.txtinfo.setGeometry(QtCore.QRect(90, 10, 91, 19))
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.txtinfo.setFont(font)
        self.txtinfo.setObjectName("txtinfo")
        self.verticalLayoutWidget_9 = QtWidgets.QWidget(self.centralwidget)
        self.verticalLayoutWidget_9.setGeometry(QtCore.QRect(90, 160, 181, 111))
        self.verticalLayoutWidget_9.setObjectName("verticalLayoutWidget_9")
        self.LayoutFungsiWCI = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_9)
        self.LayoutFungsiWCI.setContentsMargins(0, 0, 0, 0)
        self.LayoutFungsiWCI.setObjectName("LayoutFungsiWCI")
        self.contotxt = QtWidgets.QLabel(self.verticalLayoutWidget_9)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.contotxt.setFont(font)
        self.contotxt.setObjectName("contotxt")
        self.LayoutFungsiWCI.addWidget(self.contotxt)
        self.ipaddtxt = QtWidgets.QLabel(self.verticalLayoutWidget_9)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.ipaddtxt.setFont(font)
        self.ipaddtxt.setObjectName("ipaddtxt")
        self.LayoutFungsiWCI.addWidget(self.ipaddtxt)
        self.mactxt = QtWidgets.QLabel(self.verticalLayoutWidget_9)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.mactxt.setFont(font)
        self.mactxt.setObjectName("mactxt")
        self.LayoutFungsiWCI.addWidget(self.mactxt)
        self.getwaytxt = QtWidgets.QLabel(self.verticalLayoutWidget_9)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.getwaytxt.setFont(font)
        self.getwaytxt.setObjectName("getwaytxt")
        self.LayoutFungsiWCI.addWidget(self.getwaytxt)
        self.label_5 = QtWidgets.QLabel(self.centralwidget)
        self.label_5.setGeometry(QtCore.QRect(41, 140, 171, 20))
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.label_5.setFont(font)
        self.label_5.setObjectName("label_5")
        widps.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(widps)
        self.statusbar.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)
        self.statusbar.setSizeGripEnabled(True)
        self.statusbar.setObjectName("statusbar")
        widps.setStatusBar(self.statusbar)
        self.menubar = QtWidgets.QMenuBar(widps)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 714, 27))
        self.menubar.setObjectName("menubar")
        self.menuFile = QtWidgets.QMenu(self.menubar)
        self.menuFile.setObjectName("menuFile")
        self.menuAbout = QtWidgets.QMenu(self.menubar)
        self.menuAbout.setObjectName("menuAbout")
        widps.setMenuBar(self.menubar)
        self.actionSave_Logs = QtWidgets.QAction(widps)
        self.actionSave_Logs.setObjectName("actionSave_Logs")
        self.actionExit = QtWidgets.QAction(widps)
        self.actionExit.setObjectName("actionExit")
        self.actionInstruction = QtWidgets.QAction(widps)
        self.actionInstruction.setObjectName("actionInstruction")
        self.actionAbout = QtWidgets.QAction(widps)
        self.actionAbout.setObjectName("actionAbout")
        self.menuFile.addAction(self.actionSave_Logs)
        self.menuFile.addAction(self.actionExit)
        self.menuAbout.addAction(self.actionInstruction)
        self.menuAbout.addAction(self.actionAbout)
        self.menubar.addAction(self.menuFile.menuAction())
        self.menubar.addAction(self.menuAbout.menuAction())

        self.retranslateUi(widps)
        QtCore.QMetaObject.connectSlotsByName(widps)

    def retranslateUi(self, widps):
        _translate = QtCore.QCoreApplication.translate
        widps.setWindowTitle(_translate("widps", "Wireless Intrusion Prevention System"))
        self.txOs.setText(_translate("widps", "Operating System :"))
        self.txCdate.setText(_translate("widps", "Current Date :"))
        self.txCtime.setText(_translate("widps", "Current Time :"))
        self.txConnto.setText(_translate("widps", "Connected To : "))
        self.txtIpad.setText(_translate("widps", "IP Address :"))
        self.txMacAd.setText(_translate("widps", "Mac Address :"))
        self.txGateway.setText(_translate("widps", "Gateway :"))
        self.txtWirelessSec.setText(_translate("widps", "Wireless Security"))
        self.txtArp.setText(_translate("widps", "ARP Protection"))
        self.txtRapp.setText(_translate("widps", "Rogue Access Point Protection"))
        self.txtSniff.setText(_translate("widps", "Sniffing Protection"))
        self.txtGraph.setText(_translate("widps", "Logs"))
        self.Arppbtn.setText(_translate("widps", "On"))
        self.Rappbtn.setText(_translate("widps", "On"))
        self.Sniffpbtn.setText(_translate("widps", "On"))
        self.txtthreat.setText(_translate("widps", "Total Threats Detection :"))
        self.txttotalthreat.setText(_translate("widps", "0"))
        self.osinfotxt.setText(_translate("widps",info_os))
        self.cdatetxt.setText(_translate("widps",now.toString(Qt.DefaultLocaleLongDate)))
        self.ctimetxt.setText(_translate("widps", jam.toString(Qt.DefaultLocaleLongDate)))
        self.txtinfo.setText(_translate("widps", "Information"))
        self.contotxt.setText(_translate("widps",wificonnectedto))
        self.ipaddtxt.setText(_translate("widps", ipaddress))
        self.mactxt.setText(_translate("widps", mac))
        self.getwaytxt.setText(_translate("widps", gatew))
        self.statusbar.showMessage("Status: "+status)
        self.label_5.setText(_translate("widps", "Wireless Connection Info"))
        self.menuFile.setTitle(_translate("widps", "File"))
        self.menuAbout.setTitle(_translate("widps", "Help"))
        self.actionSave_Logs.setText(_translate("widps", "Save Logs"))
        self.actionExit.setText(_translate("widps", "Exit"))
        self.actionInstruction.setText(_translate("widps", "Instruction"))
        self.actionAbout.setText(_translate("widps", "About"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    widps = QtWidgets.QMainWindow()
    ui = Ui_widps()
    ui.setupUi(widps)
    widps.show()
    sys.exit(app.exec_())

Моя программная логика для добавления журналов:

widps.py

import sys
from PyQt5 import QtWidgets
import logging
from gui import Ui_widps

class QTextEditLogger(logging.Handler):
    def __init__(self, parent):
        super().__init__()
        self.widget = QtWidgets.QPlainTextEdit(parent)
        self.widget.setReadOnly(True)

    def emit(self, record):
        msg = self.format(record)
        self.widget.appendPlainText(msg)


class DialogLog(QtWidgets.QDialog, QtWidgets.QPlainTextEdit,Ui_widps):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setupUi(self)
        logTextBox = QTextEditLogger(self)
        logTextBox.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
        logging.getLogger().addHandler(logTextBox)
        logging.getLogger().setLevel(logging.DEBUG)
        self.verticalLayout_5.addWidget(logTextBox.widget)

app = QtWidgets.QApplication(sys.argv)
dlglog = DialogLog()
dlglog.show()
dlglog.raise_()
sys.exit(app.exec_())

info.py = функция для сбора информации по беспроводной сети

import platform
from PyQt5.QtCore import QDate, Qt, QTime
import subprocess
import uuid
import socket
import netifaces
import urllib.request
import sys
info_os = platform.system() + platform.release()
now = QDate.currentDate()
jam = QTime.currentTime()

try:
    url = "https://www.google.com"
    urllib.request.urlopen(url)
    status = "Wifi Terkoneksi"
except ConnectionError:
    status = "Wifi tidak terkoneksi silahkan koneksikan dahulu"
    sys.exit(0)

if platform.system() == "Linux":
    var = subprocess.check_output(["iwgetid","-r"])
elif platform.system() == "Windows":
    cmd = "netsh wlan show interface=Wi-Fi mode=ssid | findstr SSID"
    procs = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
    var = procs.communicate()[0]
wificonnectedto = var

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
ipaddress = s.getsockname()[0]
s.close()

gw = netifaces.gateways()
gatew = gw['default'][netifaces.AF_INET][0]

mac1 = str(hex(uuid.getnode()))
mac = mac1[2:4]+ ':' +mac1[4:6]+ ':' +mac1[6:8]+ ':' +mac1[8:10]+ ':' +mac1[10:12]+ ':' +mac1[12:14]

Btn.py = функция для кнопки

    from PyQt5.QtCore import QPropertyAnimation, QRectF, QSize, Qt, pyqtProperty
from PyQt5.QtGui import QPainter
from PyQt5.QtWidgets import (
    QAbstractButton,
    QApplication,
    QSizePolicy,
    QWidget,
)


class Switch(QAbstractButton):
    def __init__(self, parent=None, track_radius=10, thumb_radius=8):
        super().__init__(parent=parent)
        self.setCheckable(True)
        self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)

        self._track_radius = track_radius
        self._thumb_radius = thumb_radius

        self._margin = max(0, self._thumb_radius - self._track_radius)
        self._base_offset = max(self._thumb_radius, self._track_radius)
        self._end_offset = {
            True: lambda: self.width() - self._base_offset,
            False: lambda: self._base_offset,
        }
        self._offset = self._base_offset

        palette = self.palette()
        if self._thumb_radius > self._track_radius:
            self._track_color = {
                True: palette.highlight(),
                False: palette.dark(),
            }
            self._thumb_color = {
                True: palette.highlight(),
                False: palette.light(),
            }
            self._text_color = {
                True: palette.highlightedText().color(),
                False: palette.dark().color(),
            }
            self._thumb_text = {
                True: '',
                False: '',
            }
            self._track_opacity = 0.5
        else:
            self._thumb_color = {
                True: palette.highlightedText(),
                False: palette.light(),
            }
            self._track_color = {
                True: palette.highlight(),
                False: palette.dark(),
            }
            self._text_color = {
                True: palette.highlight().color(),
                False: palette.dark().color(),
            }
            self._thumb_text = {
                True: '✔',
                False: '✕',
            }
            self._track_opacity = 1

    @pyqtProperty(int)
    def offset(self):
        return self._offset

    @offset.setter
    def offset(self, value):
        self._offset = value
        self.update()

    def sizeHint(self):  # pylint: disable=invalid-name
        return QSize(
            4 * self._track_radius + 2 * self._margin,
            2 * self._track_radius + 2 * self._margin,
        )

    def setChecked(self, checked):
        super().setChecked(checked)
        self.offset = self._end_offset[checked]()

    def resizeEvent(self, event):
        super().resizeEvent(event)
        self.offset = self._end_offset[self.isChecked()]()

    def paintEvent(self, event):  # pylint: disable=invalid-name, unused-argument
        p = QPainter(self)
        p.setRenderHint(QPainter.Antialiasing, True)
        p.setPen(Qt.NoPen)
        track_opacity = self._track_opacity
        thumb_opacity = 1.0
        text_opacity = 1.0
        if self.isEnabled():
            track_brush = self._track_color[self.isChecked()]
            thumb_brush = self._thumb_color[self.isChecked()]
            text_color = self._text_color[self.isChecked()]
        else:
            track_opacity *= 0.8
            track_brush = self.palette().shadow()
            thumb_brush = self.palette().mid()
            text_color = self.palette().shadow().color()

        p.setBrush(track_brush)
        p.setOpacity(track_opacity)
        p.drawRoundedRect(
            self._margin,
            self._margin,
            self.width() - 2 * self._margin,
            self.height() - 2 * self._margin,
            self._track_radius,
            self._track_radius,
        )
        p.setBrush(thumb_brush)
        p.setOpacity(thumb_opacity)
        p.drawEllipse(
            self.offset - self._thumb_radius,
            self._base_offset - self._thumb_radius,
            2 * self._thumb_radius,
            2 * self._thumb_radius,
        )
        p.setPen(text_color)
        p.setOpacity(text_opacity)
        font = p.font()
        font.setPixelSize(1.5 * self._thumb_radius)
        p.setFont(font)
        p.drawText(
            QRectF(
                self.offset - self._thumb_radius,
                self._base_offset - self._thumb_radius,
                2 * self._thumb_radius,
                2 * self._thumb_radius,
            ),
            Qt.AlignCenter,
            self._thumb_text[self.isChecked()],
        )

    def mouseReleaseEvent(self, event):  # pylint: disable=invalid-name
        super().mouseReleaseEvent(event)
        if event.button() == Qt.LeftButton:
            anim = QPropertyAnimation(self, b'offset', self)
            anim.setDuration(120)
            anim.setStartValue(self.offset)
            anim.setEndValue(self._end_offset[self.isChecked()]())
            anim.start()

    def enterEvent(self, event):  # pylint: disable=invalid-name
        self.setCursor(Qt.PointingHandCursor)
        super().enterEvent(event)


def main():
    app = QApplication([])

    # Thumb size < track size (Gitlab style)
    w = QWidget()
    w.setLayout(l)
    w.show()

    app.exec()


if __name__ == '__main__':
    main()

Я пытаюсь запустить программу, но получаю такую ​​ошибку:

File "/home/s1gnific4nt/IDSIPS/widps.py", line 36, in <module>
    dlglog = DialogLog()
  File "/home/s1gnific4nt/IDSIPS/widps.py", line 23, in __init__
    self.setupUi(self)
  File "/home/s1gnific4nt/IDSIPS/gui.py", line 22, in setupUi
    widps.setDocumentMode(False)
AttributeError: 'DialogLog' object has no attribute 'setDocumentMode'

Почему это произошло и как это исправить?

1) Показываемая вами трассировка не имеет ничего общего с примером в вопросе; 2) Определите проблему; 3) напишите минимальный, рабочий пример, показывающее проблему.

Francesco Montesano 10.09.2018 10:07

пожалуйста, поделитесь info.py и Btn.py

eyllanesc 10.09.2018 10:13

добавлены info.py и btn.py

s1gnific4nt 10.09.2018 10:24
0
3
1 561
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

Ваша ошибка проста и не имеет ничего общего с журналом, но когда вы использовали Qt Designer, вы выбрали шаблон главного окна, и когда вы используете этот шаблон, вы должны использовать QMainWindow, поскольку когда вы конвертируете его в .py и используете методы этого класса Например, метод setDocumentMode() является частью QMainWindow, а не QDialog, поэтому он выдает ошибку, поэтому решение состоит в изменении наследования. С другой стороны, нет необходимости наследовать QTextEditLogger, поэтому удалите его, я не понимаю, почему ответы на указанный вами вопрос используют его.

import sys
import logging
from PyQt5 import QtCore, QtWidgets

from gui import Ui_widps


class QTextEditLogger(logging.Handler):
    def __init__(self, parent):
        super().__init__()
        self.widget = QtWidgets.QPlainTextEdit(parent)
        self.widget.setReadOnly(True)

    def emit(self, record):
        msg = self.format(record)
        self.widget.appendPlainText(msg)


class MainWindow(QtWidgets.QMainWindow, Ui_widps):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setupUi(self)
        logTextBox = QTextEditLogger(self)
        logTextBox.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
        logging.getLogger().addHandler(logTextBox)
        logging.getLogger().setLevel(logging.DEBUG)
        self.verticalLayout_5.addWidget(logTextBox.widget)

        # test: add log after 1 second
        QtCore.QTimer.singleShot(1000, self.test)

    def test(self):
        logging.debug('damn, a bug')
        logging.info('something to remember')
        logging.warning('that\'s not right')
        logging.error('foobar')

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    w = MainWindow()
    w.show()
    sys.exit(app.exec_())

enter image description here

спасибо, сэр ... я запутался, когда смотрел журналы для подписок и моих программ, теперь он работает! Благодарность

s1gnific4nt 10.09.2018 11:08

Другие вопросы по теме