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

# Form implementation generated from reading ui file '.\redesign.ui'
#
# Created by: PyQt5 UI code generator 5.9.2
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
from PyQt5.QtCore import QCoreApplication
from web3 import Web3, HTTPProvider, IPCProvider
import pymysql
import json
import os
import time
import shutil
import cytoolz._signatures
import cytoolz.utils
import qrcode
import datetime
# import Crypto.Cipher._raw_ecb
# import cytoolz
# import toolz
# import web3
import requests
from bs4 import BeautifulSoup
import eth_utils


def transPrivate(str1):
    str2 = str(str1)
    print((str2[2:-1]))
    splitstr = ((str2[2:-1]).split('\\'))
    print(splitstr)
    addr = '0x'
    for i in range(len(splitstr)):
        if splitstr[i] == '':
            pass
        elif splitstr[i][0] == 'x' and len(splitstr[i]) == 3:
            addr += splitstr[i][1:]
        elif splitstr[i][0] == 'x' and len(splitstr[i]) > 3:
            addr += splitstr[i][1:3]
            for k in range(3, len(splitstr[i])):
                temp1 = ord(splitstr[i][k])
                addr += hex(temp1)[2:]
        else:
            for j in range(len(splitstr[i])):
                temp = ord(splitstr[i][j])
                addr += hex(temp)[2:]
    return addr

blue_color = ["rgb(115, 210, 246);", "rgb(0, 173, 238);", "rgb(30, 130, 220);"]
red_color = ["rgb(255, 140, 105);", "rgb(255, 64, 64);", "rgb(205, 38, 38);"]
theme = []
theme.append(blue_color)
theme.append(red_color)

class Ui_MainWindow(QWidget):
    def setupUi(self, MainWindow):
        requests.adapters.DEFAULT_RETRIES = 5
        s = requests.session()
        s.keep_alive = False
        self.w3 = Web3(HTTPProvider('http://127.0.0.1:8545', request_kwargs={'timeout': 3}))
        self.setting_file = open('./settings.ini', 'r')
        self.setting_list = self.setting_file.readlines()
        self.setting_file.close()
        self.current_theme = self.setting_list[2].strip(' \n\r\t')
        self.current_mining_way = self.setting_list[3].strip(' \n\r\t')
        if self.current_mining_way == 'True':
            print('CPU Mining')
            output = os.system("mining_cpu.vbs")
        else:
            print('GPU Mining')
            output0 = os.system("mining_gpu.vbs")
            output1 = os.system("gpu_running.vbs")
        print(self.current_theme)
        self.mining_default_mining_account = self.setting_list[1].strip(' \n\r\t')
        self.thread = Worker()
        self.thread_hashrate = RefreshHash()
        self.change_theme_first_time = 0
        self.mining_first_time = 0
        # color settings
        if self.current_theme == 'Blue':
            self.button_back_color = "rgb(0, 173, 238);"
            self.button_font_color = "rgb(255, 255, 255);"
            self.button_font_disabled_color = "rgb(115, 210, 246);"

            self.inputtext_back_color = "rgb(0, 173, 238);"
            self.inputtext_font_color = "rgb(255, 255, 255);"

            self.tabheader_back_color = "rgb(0, 173, 238);"
            self.tabheader_font_color = "rgb(0, 173, 238);"
            self.tabheader_font_disable_color = "rgb(115, 210, 246);"
            self.tabheader_selected_color = "rgb(30, 130, 220);"

            self.label_font_color = "rgb(0, 173, 238);"

            self.list_header_back_color = "rgb(0, 173, 238);"
            self.list_header_font_color = "rgb(255, 255, 255);"
            self.list_content_color = "rgb(255, 255, 255);"
            self.list_content_select_color = "rgb(0, 173, 238);"
        else:
            self.button_back_color = theme[1][1]
            self.button_font_color = "rgb(255, 255, 255);"
            self.button_font_disabled_color = theme[1][0]

            self.inputtext_back_color = theme[1][1]
            self.inputtext_font_color = "rgb(255, 255, 255);"

            self.tabheader_back_color = theme[1][1]
            self.tabheader_font_color = theme[1][1]
            self.tabheader_font_disable_color = theme[1][0]
            self.tabheader_selected_color = theme[1][2]

            self.label_font_color = theme[1][1]

            self.list_header_back_color = theme[1][1]
            self.list_header_font_color = "rgb(255, 255, 255);"
            self.list_content_color = theme[1][1]
            self.list_content_select_color = theme[1][1]

        self.password = ''
        self.mining_account = ''
        self.unlock_way = 0
        self.is_first_time = 0
        self.keystore = ''
        self.mining_is_first_time = 0
        self.is_mining = False
        self.cpu_core_amount = int(self.setting_list[0].strip(' \n\r\t'))
        self.origin_key_store = '''
                                {"version":3,"id":"854205a1-7cf2-44e7-94d8-d05918125827","address":"825b6b51bc02f6d127a242be6528fd355fda5d9e","crypto":{"ciphertext":"7bb641e59480613c86ccf0fe0e046a991e39b7b146d097707bc5ba6647465202","cipherparams":{"iv":"fcedac10b7885987ae6172fd1793b53b"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"dklen":32,"salt":"3d03ae68389bf8dc651738913d88547178a82d512233d4b6eb1d36531edf4d10","n":1024,"r":8,"p":1},"mac":"18fd6d8c6969c5e9b4f360803655e2995c6c74d7bc0acfe6ae6b8b11f2d2f403"}}
                                '''
        MainWindow.setObjectName("MainWindow")
        # palette = QPalette()
        # palette.setBrush(QPalette.Background, QBrush(QPixmap("./walton.jpg")))
        # MainWindow.setPalette(palette)
        MainWindow.resize(1000, 600)
        # MainWindow.setFixedSize(self.size())
        MainWindow.setFixedSize(1000, 600)
        # MainWindow.setObjectName("MainWindow1")
        # MainWindow.setStyleSheet("#MainWindow{border-image:url(walton.jpg);}")
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
        
        # home page layout
        home_page_layout = QVBoxLayout()
        home_page_layout.addWidget(self.tabWidget)
        self.centralwidget.setLayout(home_page_layout)
        # fixed tabwidget
        # self.tabWidget.setGeometry(QtCore.QRect(0, 0, 800, 551))
        self.tabWidget.setObjectName("tabWidget")
        self.tab = QtWidgets.QWidget()
        self.tab.setObjectName("tab123")
        self.tabWidget.addTab(self.tab, "")
        self.tab_2 = QtWidgets.QWidget()
        self.tab_2.setObjectName("tab_2")
        self.tabWidget.addTab(self.tab_2, "")
        self.tab_3 = QtWidgets.QWidget()
        self.tab_3.setObjectName("tab_3")
        self.tabWidget.addTab(self.tab_3, "")
        self.tab_4 = QtWidgets.QWidget()
        self.tab_4.setObjectName("tab_4")
        self.tabWidget.addTab(self.tab_4, "")
        # self.tab_5 = QtWidgets.QWidget()
        # self.tab_5.setObjectName("tab_5")
        # self.tabWidget.addTab(self.tab_5, "")
        self.tabWidget.setTabEnabled(2, False)
        # self.tabWidget.setTabEnabled(3, False)
        # self.tabWidget.setTabEnabled(4, False)
        self.tabWidget.setCurrentIndex(0)
        # paintEvent background color
        # painter = QPainter(self)
        # pixmap = QPixmap('walton1.jpg')
        # painter.drawPixmap(self.rect(), pixmap)
        # QSS set background color
        self.tab.setStyleSheet("#tab123{border-image:url(walton3.jpg)}")
        self.tab_2.setStyleSheet("#tab_2{border-image:url(walton1.jpg);}")
        self.tab_3.setStyleSheet("#tab_3{border-image:url(walton3.jpg);}")
        self.tab_4.setStyleSheet("#tab_4{border-image:url(walton1.jpg);}")
        # self.tab_5.setStyleSheet("#tabz_5{border-image:url(walton1.jpg);}")
        # QPalette background color
        # oImage = QImage("walton1.jpg")
        # palette = QPalette()
        # palette.setBrush(QPalette.Background, QBrush(QPixmap("./walton1.jpg")))
        # self.tab_2.setPalette(palette)
        self.disabled_button_style = "QPushButton{border:5px; padding:4px 10px; background-color: "+ self.button_font_disabled_color +" font-size: 20px; font-family: Arial; color: white} QPushButton:hover{background-color: "+self.button_font_disabled_color+"}"
        self.button_style = "QPushButton{border:5px; padding:4px 10px; background-color: "+ self.button_back_color +" font-size: 20px; font-family: Arial; color: white} QPushButton:hover{background-color: "+ self.button_font_disabled_color+"}"
        self.label_style = "QLabel{font-size: 20px; color: "+self.label_font_color+"}"
        self.font_style = "*{font-size: 20px; font-family: Arial;}"
        font_style = '''*{font-size: 16px; font-family: Arial} 
                        QLineEdit{border:2px solid '''+self.inputtext_back_color+'''}
                        QPushButton{border:5px; padding:4px 10px; background-color: '''+self.button_back_color+''' font-size: 20px; font-family: Arial; color: white} 
                        QPushButton:hover{background-color: '''+self.button_back_color+'''}
                     '''
        totoal_style = "*{font-size: 17px; font-family: Arial;} "
        table_style = "QTableWidget{font-size: 14px; font-family: Arial}"
        self.create_button_style = '#create_passworrd_button{border:5px; padding:4px 10px; background-color: '+self.button_back_color+' font-size: 25px; font-family: Arial; color: white} #create_passworrd_button:hover{background-color: '+self.button_font_disabled_color+'}'
        self.submit_transaction_button_style = "*{border:5px; padding:4px 10px; background-color: "+self.button_back_color+" font-size: 20px; font-family: Arial; color: white} *:hover{background-color: "+self.button_font_disabled_color+"}"
        self.label_style1 = "QLabel{font-size: 30px; color: "+self.label_font_color+"}"
        self.lineedit_style1 = 'QLineEdit{font-size: 18px; font-family: Arial; border:2px solid '+self.inputtext_back_color+'}'
        self.label_style2 = 'QLabel{font-size: 20px; color: '+self.label_font_color+'}'
        self.label_style3 = "QLabel{font-size: 25px; color: "+self.label_font_color+"}"
        # MainWindow.setStyleSheet(button_style)
        MainWindow.setStyleSheet(totoal_style)
        MainWindow.setCentralWidget(self.centralwidget)
        tab_label_stylesheet = """ 
                    QTabBar::tab {background-color: """+self.tabheader_back_color+"""font-size: 24px; font-family: Arial; color: white; padding: 5px; height:34px; border-right: 6px solid white;}
                    QTabBar::tab:selected {background-color: """+self.tabheader_selected_color+"""font-size: 24px; font-family: Arial; color: white; height:34px;}
                    QTabBar::tab:disabled {background-color: """+self.tabheader_font_disable_color+"""font-size: 24px; font-family: Arial; color: white; height:34px;}
                    QTabWidget>QWidget>QWidget{background-color: """+self.tabheader_back_color+"""font-size: 24px; font-family: Arial; color: white; height:34px;}
                     """
        self.tabWidget.setStyleSheet(tab_label_stylesheet)
        # New Wallet
        new_wallet_layout = QVBoxLayout()
        new_wallet_h1 = QHBoxLayout()
        new_wallet_box1 = QWidget()
        vbox1 = QWidget()
        self.create_wallet_label = QLabel()
        self.create_wallet_label.setText('Create a new wallet protected by your password.')
        self.create_wallet_label.setAlignment(Qt.AlignCenter)
        self.create_wallet_label.setObjectName('create_wallet_label')
        self.create_wallet_label.setStyleSheet(self.label_style1)
        self.create_wallet_labe2 = QLabel()
        self.create_wallet_labe2.setText('Password:')
        self.create_wallet_labe2.setObjectName('create_wallet_labe2')
        self.create_wallet_labe2.setStyleSheet('#create_wallet_labe2{font-size: 25px; color: '+self.label_font_color+'}')
        # self.create_wallet_labe2.setAlignment(Qt.AlignCenter)
        self.create_wallet_enter_label = QLabel()
        self.create_wallet_enter_label.setText('')
        self.create_wallet_enter_label.setAlignment(Qt.AlignCenter)
        self.create_wallet_enter_label.setObjectName('create_wallet_enter_label')
        self.create_wallet_enter_label.setStyleSheet('#create_wallet_enter_label{font-size: 30px; color: '+self.label_font_color+'}')
        self.enter_password = QLineEdit()
        self.enter_password.setObjectName('enter_password')
        self.enter_password.setStyleSheet(self.lineedit_style1)
        self.enter_password.setFixedSize(300, 50)
        self.enter_password.setPlaceholderText('Password')
        self.enter_password.setEchoMode(QLineEdit.Password)
        self.create_passworrd_button = QPushButton('Create')
        self.create_passworrd_button.setFixedSize(300, 50)
        self.create_passworrd_button.setObjectName('create_passworrd_button')
        self.create_passworrd_button.setStyleSheet('#create_passworrd_button{border:5px; padding:4px 10px; background-color: '+self.button_back_color+' font-size: 25px; font-family: Arial; color: white} #create_passworrd_button:hover{background-color: '+self.button_font_disabled_color+'}')
        # self.create_passworrd_button.setStyleSheet(button_style)
        self.create_passworrd_button.clicked.connect(self.createWallet)
        # set label background
        self.pic = QLabel()
        self.pic.setObjectName("pic1")
        # self.pic.setStyleSheet("#pic1{border-image:url(walton2.jpg);}")
        # self.created_address = QLabel()
        self.pic.setFixedWidth(957.5)
        self.pic.setFixedHeight(320)
        # new_wallet_h1.addWidget(self.create_wallet_labe2)
        new_wallet_h1.addWidget(self.enter_password)
        # new_wallet_h1.addWidget(self.create_passworrd_button)
        new_wallet_box1.setLayout(new_wallet_h1)
        self.new_wallet_space = QLabel()
        new_wallet_layout.addWidget(self.new_wallet_space)
        new_wallet_layout.addWidget(self.new_wallet_space)
        new_wallet_layout.addWidget(self.create_wallet_label)
        new_wallet_layout.addWidget(self.new_wallet_space)
        new_wallet_layout.addWidget(self.create_wallet_enter_label)
        new_wallet_layout.addWidget(self.new_wallet_space)
        # new_wallet_layout.addWidget(self.enter_password)
        # new_wallet_layout.addStretch(1)
        new_wallet_layout.addWidget(new_wallet_box1)
        new_wallet_layout.addWidget(self.create_passworrd_button, 0, Qt.AlignCenter)
        new_wallet_layout.addWidget(self.pic, Qt.AlignCenter)
        # new_wallet_layout.addStretch(1)
        # new_wallet_layout.addStretch(1)
        # new_wallet_layout.addStretch(1)
        # new_wallet_layout.addStretch(1)
        self.tab.setLayout(new_wallet_layout)

        # view_wallet_info layout
        view_wallet_info_layout = QVBoxLayout()
        view_wallet_info_layout_hbox0 = QHBoxLayout()
        view_wallet_info_layout_hbox1 = QHBoxLayout()
        view_wallet_info_layout_hbox2 = QHBoxLayout()
        view_wallet_info_layout_hbox3 = QHBoxLayout()
        # balance label
        view_wallet_info_layout_form1 = QHBoxLayout()
        hbox0 = QWidget()
        hbox1 = QWidget()
        hbox2 = QWidget()
        hbox3 = QWidget()
        form1 = QWidget()
        self.view_wallet_info_space = QLabel()
        self.file_name_label = QLabel()
        self.file_name_label.setText('Public Key:')
        self.file_name_label.setObjectName('file_name_label')
        self.file_name_label.setStyleSheet(self.label_style2)
        self.chosen_file_name = QLineEdit()
        self.chosen_file_name.setObjectName('chosen_file_name')
        self.chosen_file_name.setStyleSheet(self.lineedit_style1)
        self.chosen_file_name.setFixedSize(450, 36)
        self.chosen_file_name.setPlaceholderText('Your Waltonchain Wallet Address ...')
        self.choose_file_button = QPushButton("Unlock Wallet With Keystore")
        self.choose_file_button.setObjectName('choose_file_button')
        self.choose_file_button.setStyleSheet(self.button_style)
        # self.choose_file_button.setStyleSheet('#choose_file_button{border:5px; padding:4px 10px; background-color: '+self.button_back_color+' font-size: 20px; font-family: Arial; color: white} #choose_file_button:hover{background-color: '+self.button_font_disabled_color+'}')
        self.choose_file_button.clicked.connect(self.wayToUnlock)
        self.choose_file_button.setFixedSize(450, 40);
        self.choose_file_button2 = QPushButton("Unlock Wallet With Private Key")
        self.choose_file_button2.setObjectName("choose_file_button2")
        self.choose_file_button2.setStyleSheet(self.button_style)
        # self.choose_file_button2.setStyleSheet('#choose_file_button2{border:5px; padding:4px 10px; background-color: '+self.button_back_color+' font-size: 20px; font-family: Arial; color: white} #choose_file_button2:hover{background-color: '+self.button_font_disabled_color+'}')
        self.choose_file_button2.setFixedSize(380, 40)
        self.choose_file_button2.clicked.connect(self.privateToUnlock)
        self.password_label = QLabel()
        # address line
        # self.password_label.setText('Private Key:')
        # self.private_lineedit = QLineEdit()
        # self.password_lineedit.setEchoMode(QLineEdit.Password)
        # self.private_lineedit.setPlaceholderText('Your Private Key')
        self.copy_button = QPushButton('Copy')
        self.copy_button.setEnabled(False)
        self.copy_button.setStyleSheet(self.disabled_button_style)
        self.copy_button.setFixedSize(123, 36)
        self.copy_button.setObjectName('copy_button')
        # self.copy_button.setStyleSheet(self.button_style)
        self.submit_button = QPushButton('View QR')
        self.submit_button.setFixedSize(123, 36)
        self.submit_button.setObjectName('submit_button')
        self.submit_button.setStyleSheet(self.disabled_button_style)
        self.submit_button.setEnabled(False)
        self.private_QRCode = QPushButton('Private Key')
        self.private_QRCode.setObjectName('private_QRCode')
        self.private_QRCode.setStyleSheet(self.disabled_button_style)
        self.private_QRCode.setFixedHeight(36)
        self.private_QRCode.setEnabled(False)
        self.submit_button.clicked.connect(self.showPublicDialog)
        self.private_QRCode.clicked.connect(self.showPrivateDialog)
        self.copy_button.clicked.connect(self.copyPublicKey)
        # self.submit_button.clicked.connect(self.unLockWallet)
        self.balance_label = QLabel()
        self.balance_label.setText('Balance:')
        self.show_balance = QLabel()
        self.refresh_button = QPushButton("Refresh")
        # self.refresh_button.setStyleSheet(button_style)
        # self.refresh_button.setEnabled(False)
        self.thread.counter_value.connect(self.thread_refresh)
        view_wallet_info_layout_hbox0.addWidget(QLabel("           "))
        view_wallet_info_layout_hbox0.addWidget(self.choose_file_button, 0, Qt.AlignRight)
        view_wallet_info_layout_hbox0.addWidget(self.choose_file_button2, 0, Qt.AlignRight)
        hbox0.setLayout(view_wallet_info_layout_hbox0)
        view_wallet_info_layout_hbox1.addWidget(self.file_name_label)
        view_wallet_info_layout_hbox1.addWidget(self.chosen_file_name)
        view_wallet_info_layout_hbox1.addWidget(self.copy_button)
        view_wallet_info_layout_hbox1.addWidget(self.submit_button)
        view_wallet_info_layout_hbox1.addWidget(self.private_QRCode)
        # view_wallet_info_layout_hbox2.addWidget(self.password_label)
        # view_wallet_info_layout_hbox2.addWidget(self.private_lineedit)
        # view_wallet_info_layout_hbox2.addWidget(self.private_QRCode)
        hbox1.setLayout(view_wallet_info_layout_hbox1)
        # hbox2.setLayout(view_wallet_info_layout_hbox2)
        # view_wallet_info_layout.addStretch(1)
        view_wallet_info_layout.addWidget(self.view_wallet_info_space)
        view_wallet_info_layout.addWidget(hbox0)
        view_wallet_info_layout.addWidget(hbox1)
        # view_wallet_info_layout.addWidget(hbox2)
        # view_wallet_info_layout_form1.addWidget(self.balance_label)
        # view_wallet_info_layout_form1.addWidget(self.show_balance)
        view_wallet_info_layout_form1.addWidget(self.balance_label)
        view_wallet_info_layout_form1.addWidget(self.show_balance, Qt.AlignLeft)
        # view_wallet_info_layout_form1.addWidget(self.refresh_button)
        form1.setLayout(view_wallet_info_layout_form1)
        view_wallet_info_layout.addWidget(form1)
        self.transaction_table = QTableWidget()
        self.transaction_table.setEditTriggers(QAbstractItemView.DoubleClicked)
        self.transaction_table.setStyleSheet(table_style)
        self.transaction_table.setWindowOpacity(0.01)
        # self.transaction_table.setRowCount(10)
        # self.transaction_table.setColumnCount(5)
        view_wallet_info_layout_hbox3.addWidget(self.transaction_table)
        hbox3.setLayout(view_wallet_info_layout_hbox3)

        view_wallet_info_layout.addWidget(hbox3)
        self.tab_2.setLayout(view_wallet_info_layout)

        # send transaction
        send_transaction_layout = QVBoxLayout()
        send_transaction_form = QFormLayout()
        self.for_contact_book = QHBoxLayout()
        form1 = QWidget()
        self.send_transaction_h1 = QHBoxLayout()
        self.send_transaction_label_space1 = QLabel()
        self.send_transaction_label_space2 = QLabel()
        self.send_transaction_box1 = QWidget()
        self.send_transaction_label1 = QLabel()
        self.send_transaction_label1.setFixedWidth(125)
        self.send_transaction_label1.setText('Balance:  ')
        self.send_transaction_label1.setObjectName('send_transaction_label1')
        self.send_transaction_label1.setStyleSheet(self.label_style3)
        self.send_transaction_label2 = QLabel()
        self.send_transaction_label2.setFixedWidth(125)
        self.send_transaction_label2.setText('Sender:   ')
        self.send_transaction_label2.setObjectName('send_transaction_label2')
        self.send_transaction_label2.setStyleSheet(self.label_style3)
        self.send_transaction_label3 = QLabel()
        self.send_transaction_label3.setFixedWidth(125)
        self.send_transaction_label3.setText('Receiver: ')
        self.send_transaction_label3.setObjectName('send_transaction_label3')
        self.send_transaction_label3.setStyleSheet(self.label_style3)
        self.send_transaction_label4 = QLabel()
        self.send_transaction_label4.setFixedWidth(125)
        self.send_transaction_label4.setText('Amount:   ')
        self.send_transaction_label4.setObjectName('send_transaction_label4')
        self.send_transaction_label4.setStyleSheet(self.label_style3)
        self.send_transaction_text1 = QLabel()
        self.send_transaction_text1.setObjectName('send_transaction_text1')
        self.send_transaction_text2 = QLabel()
        self.send_transaction_text2.setObjectName('send_transaction_text2')
        self.send_transaction_text3 = QLineEdit()
        self.send_transaction_text3.setObjectName('send_transaction_text3')
        self.send_transaction_text3.setStyleSheet(self.lineedit_style1)
        self.send_transaction_text3.setFixedSize(645, 36)
        self.send_transaction_text3.setPlaceholderText('Example: 0x...')
        self.send_transaction_text4 = QLineEdit()
        self.send_transaction_text4.setObjectName('send_transaction_text4')
        self.send_transaction_text4.setStyleSheet(self.lineedit_style1)
        self.send_transaction_text4.setFixedSize(800, 36)
        self.send_transaction_text4.setPlaceholderText('Example: 1000')
        self.submit_transaction = QPushButton("Submit Transaction")
        self.submit_transaction.setObjectName('submit_transaction')
        self.submit_transaction.setFixedSize(388, 50)
        self.submit_transaction.setStyleSheet(self.submit_transaction_button_style)
        self.submit_transaction.setWindowOpacity(0)
        self.submit_transaction.clicked.connect(self.sendTransaction)
        self.submit_transaction_choose_contact = QPushButton('Contact Book')
        self.submit_transaction_choose_contact.clicked.connect(self.choose_contact)
        self.submit_transaction_choose_contact.setFixedSize(150, 36)
        self.for_contact_book.addWidget(self.send_transaction_label3)
        self.for_contact_book.addWidget(self.send_transaction_text3)
        self.for_contact_book.addWidget(self.submit_transaction_choose_contact)
        self.for_contact_book_widget = QWidget()
        self.for_contact_book_widget.setLayout(self.for_contact_book)
        self.submit_transaction_choose_contact.setStyleSheet(self.submit_transaction_button_style)
        self.send_transaction_line1 = QHBoxLayout()
        self.send_transaction_line2 = QHBoxLayout()
        self.send_transaction_line4 = QHBoxLayout()
        self.send_transaction_widget1 = QWidget()
        self.send_transaction_widget2 = QWidget()
        self.send_transaction_widget4 = QWidget()
        self.send_transaction_line1.addWidget(self.send_transaction_label1, 0, Qt.AlignLeft)
        self.send_transaction_line1.addWidget(self.send_transaction_text1, 0, Qt.AlignLeft)
        self.send_transaction_line2.addWidget(self.send_transaction_label2, 0, Qt.AlignLeft)
        self.send_transaction_line2.addWidget(self.send_transaction_text2, 0, Qt.AlignLeft)
        self.send_transaction_line4.addWidget(self.send_transaction_label4, 0, Qt.AlignLeft)
        self.send_transaction_line4.addWidget(self.send_transaction_text4, 0, Qt.AlignLeft)
        self.send_transaction_widget1.setLayout(self.send_transaction_line1)
        self.send_transaction_widget2.setLayout(self.send_transaction_line2)
        self.send_transaction_widget4.setLayout(self.send_transaction_line4)
        # send_transaction_form.addRow(self.send_transaction_label1, self.send_transaction_text1)
        # send_transaction_form.addRow(self.send_transaction_label2, self.send_transaction_text2)
        # send_transaction_form.addRow(self.for_contact_book_widget)
        # send_transaction_form.addRow(self.send_transaction_label4, self.send_transaction_text4)
        send_transaction_layout.addStretch(1)
        send_transaction_layout.addWidget(self.send_transaction_widget1, 0, Qt.AlignLeft)
        send_transaction_layout.addWidget(self.send_transaction_widget2, 0, Qt.AlignLeft)
        send_transaction_layout.addWidget(self.for_contact_book_widget, 0, Qt.AlignLeft)
        send_transaction_layout.addWidget(self.send_transaction_widget4, 0, Qt.AlignLeft)
        # form1.setLayout(send_transaction_form)
        # send_transaction_layout.addStretch(1)
        # send_transaction_layout.addWidget(form1)
        # send_transaction_layout.addStretch(1)
        self.submit_transaction_last_line = QHBoxLayout()
        self.submit_transaction_widget = QWidget()
        self.submit_transaction_label_space = QLabel('       ')
        self.submit_transaction_label_space.setStyleSheet(self.label_style3)
        # self.submit_transaction_last_line.addWidget(self.submit_transaction_label_space, 0, Qt.AlignLeft)
        # self.submit_transaction_last_line.addWidget(self.submit_transaction_choose_contact, 0, Qt.AlignLeft)
        # self.send_transaction_h1.addWidget(self.send_transaction_label_space1, 0, Qt.AlignCenter)
        self.send_transaction_h1.addWidget(self.submit_transaction, 0, Qt.AlignCenter)
        # self.send_transaction_h1.addWidget(self.send_transaction_label_space2, 0, Qt.AlignCenter)
        self.send_transaction_box1.setLayout(self.send_transaction_h1)
        self.submit_transaction_last_line.addWidget(self.send_transaction_box1, 0, Qt.AlignCenter)
        self.submit_transaction_widget.setLayout(self.submit_transaction_last_line)
        # send_transaction_layout.addWidget(self.send_transaction_box1)
        send_transaction_layout.addWidget(self.submit_transaction_widget)
        send_transaction_layout.addStretch(1)
        send_transaction_layout.addStretch(1)
        send_transaction_layout.addStretch(1)
        self.tab_3.setLayout(send_transaction_layout)

        # mining layout
        mining_start_layout = QVBoxLayout()
        mining_start_h1 = QHBoxLayout()
        mining_start_box1 = QWidget()
        mining_start_h2 = QHBoxLayout()
        mining_start_box2 = QWidget()
        mining_start_h3 = QHBoxLayout()
        mining_start_box3 = QWidget()
        self.cores_label = QLabel()
        self.cores_label.setText('')
        self.cores_label.setStyleSheet(self.label_style)
        self.cores_label.setAlignment(Qt.AlignCenter)
        self.nodes_label = QLineEdit()
        # self.nodes_label.setText('Nodes Connected :')
        self.nodes_label.setText("Miner: "+self.mining_default_mining_account)
        self.nodes_label.setFixedSize(400, 36)
        self.nodes_label.setReadOnly(1)
        self.nodes_label.setAlignment(Qt.AlignCenter)
        self.nodes_label.setFixedSize(655, 36)
        self.nodes_label.setStyleSheet("QLineEdit{font-size: 16px; font: 20px}")
        self.mining_show_peers = QPushButton("Show Nodes")
        self.mining_show_peers.setFixedHeight(36)
        self.mining_show_peers.setStyleSheet(self.button_style)
        self.mining_show_peers.clicked.connect(self.showNodes)
        self.mining_hashrate = QLineEdit('Current HashRate: 0')
        self.mining_hashrate.setReadOnly(1)
        self.mining_hashrate.setObjectName('mining_hashrate')
        self.mining_hashrate.setFixedSize(300, 36)
        self.mining_hashrate.setAlignment(Qt.AlignCenter)
        self.mining_hashrate.setStyleSheet('#mining_hashrate{font-size: 16px; font: 20px}')
        if self.current_mining_way == "True":
            self.choose_cores = QLineEdit('Status : CPU Not Mining')
        else:
            self.choose_cores = QLineEdit('Status : GPU Not Mining')
        self.choose_cores.setFixedSize(350, 36)
        self.choose_cores.setObjectName('mining_status')
        self.choose_cores.setStyleSheet(
            "#mining_status{background-color: rgb(220, 93, 93); font-size: 16px; font: 20px}")
        self.choose_cores.setReadOnly(1)
        self.choose_cores.setAlignment(Qt.AlignCenter)
        self.mining_start_button = QPushButton('Start Mining')
        self.mining_start_button.setStyleSheet(self.button_style)
        self.mining_start_button.clicked.connect(self.startMining)
        self.mining_end_button = QPushButton('Start/Stop Mining')
        # self.mining_end_button.setEnabled(False)
        self.mining_end_button.setFixedHeight(36)
        self.mining_end_button.setStyleSheet(self.button_style)
        self.mining_end_button.clicked.connect(self.stopMining)
        self.mining_mined_blocks = QLabel("Blocks Mined: ")
        self.show_mining_mined_blocks = QLabel()
        mining_start_h3.addWidget(self.mining_mined_blocks)
        mining_start_h3.addWidget(self.show_mining_mined_blocks, Qt.AlignLeft)
        mining_start_box3.setLayout(mining_start_h3)
        mining_start_h1.addWidget(self.choose_cores)
        mining_start_h1.addWidget(self.mining_hashrate)
        mining_start_h1.addWidget(self.mining_end_button)
        mining_start_box1.setLayout(mining_start_h1)
        mining_start_layout.addWidget(self.cores_label)
        # mining_start_layout.addStretch(1)
        # mining_start_layout.addStretch(1)
        mining_start_h2.addWidget(self.nodes_label)
        mining_start_h2.addWidget(self.mining_show_peers)
        mining_start_box2.setLayout(mining_start_h2)
        mining_start_layout.addWidget(mining_start_box2)
        mining_start_layout.addWidget(mining_start_box1)
        # mining_start_layout.addStretch(1)
        mining_start_layout.addWidget(mining_start_box3)
        self.minging_info_table = QTableWidget()
        self.minging_info_table.setStyleSheet(table_style)
        self.minging_info_table.setEditTriggers(QAbstractItemView.DoubleClicked)
        mining_start_layout.addWidget(self.minging_info_table)
        self.minging_info_table.setWindowOpacity(0.01)
        self.tab_4.setLayout(mining_start_layout)

        # minging info layout
        # mining_hbox1 = QWidget()
        # minging_info_layout = QVBoxLayout()
        # minging_info_layout_hbox1 = QHBoxLayout()
        # self.minging_info_table = QTableWidget()
        # # self.minging_info_table.setRowCount(10)
        # # self.minging_info_table.setColumnCount(5)
        # minging_info_layout_hbox1.addWidget(self.minging_info_table)
        # mining_hbox1.setLayout(minging_info_layout_hbox1)
        # minging_info_layout.addWidget(mining_hbox1)
        # self.tab_5.setLayout(minging_info_layout)

        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 23))
        self.menubar.setObjectName("menubar")
        self.menuFile_F = QtWidgets.QMenu(self.menubar)
        self.menuFile_F.setObjectName("menuFile_F")
        self.menuHelp_H = QtWidgets.QMenu(self.menubar)
        self.menuHelp_H.setObjectName("menuHelp_H")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.menubar.addAction(self.menuFile_F.menuAction())
        self.menubar.addAction(self.menuHelp_H.menuAction())
        # self.menuFile_F.addAction('Address Book')
        # self.menuHelp_H.addAction('About')
        contact = QAction('Contact Book', self.menuFile_F)
        address = QAction("Settings", self.menuFile_F)
        exit = QAction("Exit", self.menuFile_F)
        about = QAction('About', self.menuFile_F)
        self.menuFile_F.addAction(contact)
        self.menuFile_F.addAction(address)
        self.menuHelp_H.addAction(about)
        self.menuFile_F.addAction(exit)
        
        address.triggered.connect(self.addressBook)
        about.triggered.connect(self.about)
        exit.triggered.connect(self.quit)
        contact.triggered.connect(self.contact)
        self.retranslateUi(MainWindow)
        # self.tabWidget.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def copyPublicKey(self):
        self.clipboard_public_key = QApplication.clipboard()
        self.clipboard_public_key.setText(self.true_account)
     
    def showPublicDialog(self):
        public_key_QR_layout = QVBoxLayout()
        self.public_key_QR = QDialog()
        self.public_key_QR.setWindowIcon(QIcon('./walton.jpg'))
        self.public_key_QR.setWindowTitle('Public Key QR')
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(15)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        # self.public_key_QR.setFont(font)
        # self.public_key_QR1 = QLabel()
        # self.public_key_QR1.setText('Public Key QR')
        # self.public_key_QR2 = QLabel()
        # self.public_key_QR2.setText(self.this_account)
        self.public_key_QR_lineedit = QLineEdit(self.this_account)
        self.public_key_QR_lineedit.setReadOnly(1)
        self.public_key_QR_lineedit.setFixedSize(450, 36)
        self.public_key_QR_lineedit.setStyleSheet(self.lineedit_style1)
        self.public_key_QR_pic = QLabel()
        self.public_key_QR_pic.setObjectName("public_key_QR_pic")
        self.public_key_QR_pic.setStyleSheet("#public_key_QR_pic{border-image:url(qrcode.png);}")
        # self.created_address = QLabel()
        self.public_key_QR_pic.setFixedWidth(372)
        self.public_key_QR_pic.setFixedHeight(372)
        self.public_key_QR_btn1 = QPushButton('Close', self.public_key_QR)
        self.public_key_QR_btn1.setStyleSheet(self.button_style)
        self.public_key_QR_btn1.clicked.connect(self.reject_showPublicDialog)
        # public_key_QR_layout.addWidget(self.public_key_QR1, Qt.AlignCenter)
        public_key_QR_layout.addWidget(self.public_key_QR_lineedit, 0, Qt.AlignCenter)
        public_key_QR_layout.addWidget(self.public_key_QR_pic, 0, Qt.AlignCenter)
        public_key_QR_layout.addWidget(self.public_key_QR_btn1, 0, Qt.AlignCenter)
        self.public_key_QR.setFont(font)
        self.public_key_QR.setLayout(public_key_QR_layout)
        self.public_key_QR.exec_()

    def reject_showPublicDialog(self):
        self.public_key_QR.reject()

    def showPrivateDialog(self):
        private_key_QR_layout = QVBoxLayout()
        self.private_key_QR = QDialog()
        self.private_key_QR.setWindowIcon(QIcon('./walton.jpg'))
        self.private_key_QR.setWindowTitle('Private Key QR')
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(15)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.private_key_QR.setFont(font)
        # self.private_key_QR1 = QLabel()
        # self.private_key_QR1.setText('Public Key QR')
        # self.private_key_QR2 = QLabel()
        # self.private_key_QR2.setText(transPrivate(str(self.private_key)))
        self.private_key_QR1_lineedit = QLineEdit(self.private_key)
        self.private_key_QR1_lineedit.setReadOnly(1)
        self.private_key_QR1_lineedit.setStyleSheet(self.lineedit_style1)
        self.private_key_QR1_lineedit.setFixedSize(700, 36)
        self.private_key_QR_pic = QLabel()
        self.private_key_QR_pic.setObjectName("private_key_QR_pic")
        self.private_key_QR_pic.setStyleSheet("#private_key_QR_pic{border-image:url(privatecode.png);}")
        # self.created_address = QLabel()
        self.private_key_QR_pic.setFixedWidth(372)
        self.private_key_QR_pic.setFixedHeight(372)
        self.private_key_QR_btn1 = QPushButton('Close', self.private_key_QR)
        self.private_key_QR_btn1.setStyleSheet(self.button_style)
        self.private_key_QR_btn1.clicked.connect(self.reject_showPrivateDiaglog)
        # private_key_QR_layout.addWidget(self.private_key_QR1, Qt.AlignCenter)
        private_key_QR_layout.addWidget(self.private_key_QR1_lineedit, 0, Qt.AlignCenter)
        private_key_QR_layout.addWidget(self.private_key_QR_pic, 0, Qt.AlignCenter)
        private_key_QR_layout.addWidget(self.private_key_QR_btn1, 0, Qt.AlignCenter)
        self.private_key_QR.setFont(font)
        self.private_key_QR.setLayout(private_key_QR_layout)
        self.private_key_QR.exec_()

    def reject_showPrivateDiaglog(self):
        self.private_key_QR.reject()

    def showNodes(self):
        show_nodes_layout = QVBoxLayout()
        self.show_nodes = QDialog()
        self.show_nodes.setWindowIcon(QIcon('./walton.jpg'))
        self.show_nodes.setWindowTitle('Show Nodes')
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(15)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        # self.show_nodes.setFont(font)
        try:
            node_list = self.w3.admin.peers
        except Exception as e:
            # raise e
            # showNodes()
            node_list = []
            # pass
        else:
            pass      
        # w3 = Web3(HTTPProvider('http://127.0.0.1:8545', request_kwargs={'timeout': 60}))
        self.statusbar.showMessage('Connected to ' + str(len(node_list)) + ' nodes')
        self.show_nodes1 = QLabel()
        self.show_nodes1.setText('Nodes List ' + str(len(node_list)))
        self.show_nodes2 = QLabel()
        self.show_nodes2.setText('Nodes connected:')
        self.show_nodes_btn1 = QPushButton('Close', self.show_nodes)
        self.show_nodes_btn1.setStyleSheet(self.button_style)
        self.show_nodes_btn1.clicked.connect(self.rejectShowNodes)
        # show_nodes_layout.addWidget(self.show_nodes1, 0, Qt.AlignCenter)
        show_nodes_layout.addWidget(self.show_nodes2, 0, Qt.AlignCenter)
        for i in range(len(node_list)):
            self.nodes_label1 = QLabel('(' + str(i + 1) + ')' + node_list[i]['network']['remoteAddress'])
            show_nodes_layout.addWidget(self.nodes_label1)
        # self.nodes_label.setText('Nodes Connected: ' + str(len(w3.admin.peers)))
        # if len(w3.admin.peers) > 0:
        #     self.statusbar.showMessage('Connected to ' + str(len(w3.admin.peers)) + ' nodes')
        # else:
        #     self.statusbar.showMessage('Connected to ' + str(len(w3.admin.peers)) + ' nodes, you can not send transaction or start mining!Please Refresh and wait.')
        show_nodes_layout.addWidget(self.show_nodes_btn1, Qt.AlignCenter)
        self.show_nodes.setFont(font)
        self.show_nodes.setLayout(show_nodes_layout)
        self.show_nodes.exec_()

    def rejectShowNodes(self):
        self.show_nodes.reject()

    def addressBook(self):
        # output = os.system("run.vbs")
        self.setting_file = open('./settings.ini', 'r')
        self.setting_list = self.setting_file.readlines()
        self.setting_file.close()
        address_book_layout = QVBoxLayout()
        address_book_mining_way_layout = QHBoxLayout()
        self.address_book = QDialog()
        self.address_book.setStyleSheet("*{background-color:white; font-size: 18px; font-family: Arial; color: black}");
        self.address_book.setWindowIcon(QIcon('./walton.jpg'))
        self.address_book.setWindowTitle('Settings')
        # self.address_book.setStyleSheet(self.label_style)
        self.cpu_core = QSpinBox()
        self.cpu_core.setValue(int(self.setting_list[0].strip(' \n\r\t')))
        self.cpu_core.setMinimum(1)
        self.cpu_core.setMaximum(10)
        self.default_mining_account = QLineEdit()
        self.default_mining_account.setText(self.setting_list[1].strip(' \n\r\t'))
        self.default_mining_account.setAlignment(Qt.AlignCenter)
        self.default_mining_account.setFixedSize(500, 36)
        # self.cpu_core_amount = self.cpu_core.value()
        self.address_book1 = QLabel()
        self.address_book1.setText('')
        self.address_book2 = QLabel()
        self.address_book2.setText('Number of mining threads: ')
        self.address_book_btn1 = QPushButton(' Save ', self.address_book)
        self.address_book3 = QLabel()
        self.address_book3.setText('Miner\'s public key: ')
        self.address_book4 = QLabel('Mining Way: ')
        self.address_book_radio0 = QRadioButton('CPU')
        self.address_book_radio1 = QRadioButton('GPU')
        print(self.setting_list[3])
        if self.setting_list[3] == 'True':
            self.address_book_radio0.setChecked(True)
        else:
            self.address_book_radio1.setChecked(True)
        self.address_book_radio1.toggled.connect(self.change_gpu)
        self.address_book_radio0.toggled.connect(self.change_cpu)
        self.address_mining_way_widget0 = QWidget()
        address_book_mining_way_layout.addWidget(self.address_book4, 0, Qt.AlignCenter)
        address_book_mining_way_layout.addWidget(self.address_book_radio0)
        address_book_mining_way_layout.addWidget(self.address_book_radio1)
        self.address_mining_way_widget0.setLayout(address_book_mining_way_layout)

        self.address_book_btn1.setStyleSheet(self.button_style)
        self.address_book_btn1.clicked.connect(self.addressBookSubmit)
        self.address_book_btn2 = QPushButton('Cancel', self.address_book)
        self.address_book_btn2.setStyleSheet(self.button_style)
        self.address_book_btn2.clicked.connect(self.reject_address_book)
        self.address_book_combobox1 = QComboBox()
        self.address_book_combobox1.setFixedSize(150, 30)
        self.address_book_combobox1.addItems(['Blue', 'Red'])
        if self.current_theme == 'Blue':
            self.address_book_combobox1.setCurrentIndex(0)
        else:
            self.address_book_combobox1.setCurrentIndex(1)
        self.address_book4 = QLabel('Color theme:')
        if self.current_mining_way == "False":
            self.cpu_core.setEnabled(False)
        address_book_layout.addWidget(self.address_book1, 0, Qt.AlignCenter)
        address_book_layout.addWidget(self.address_book2, 0, Qt.AlignCenter)
        address_book_layout.addWidget(self.cpu_core, 0, Qt.AlignCenter)
        address_book_layout.addWidget(self.address_mining_way_widget0)
        address_book_layout.addWidget(self.address_book3, 0, Qt.AlignCenter)
        address_book_layout.addWidget(self.default_mining_account, 0, Qt.AlignCenter)
        address_book_layout.addWidget(self.address_book4, 0, Qt.AlignCenter)
        address_box_hbox = QWidget()
        btn_layout = QHBoxLayout()
        btn_layout.addWidget(self.address_book_btn1, 0, Qt.AlignCenter)
        btn_layout.addWidget(self.address_book_btn2, 0, Qt.AlignCenter)
        address_book_layout.addWidget(self.address_book_combobox1, 0, Qt.AlignCenter)
        address_box_hbox.setLayout(btn_layout)
        address_book_layout.addWidget(address_box_hbox, 0, Qt.AlignCenter)
        self.address_book.setLayout(address_book_layout)
        self.address_book.exec_()
    
    def change_gpu(self):
        self.cpu_core.setEnabled(False)
        self.current_mining_way = "False"

    def change_cpu(self):
        self.cpu_core.setEnabled(True)
        self.current_mining_way = "True"

    def wrong_mining_address_reject(self):
        self.wrong_mining_address.reject()

    def addressBookSubmit(self):
        print(self.address_book_combobox1.currentText())
        if self.address_book_combobox1.currentText() == self.current_theme:
            pass
        else:
            theme_index = self.address_book_combobox1.currentIndex()
            self.button_back_color = theme[theme_index][1]
            self.button_font_color = "rgb(255, 255, 255);"
            self.button_font_disabled_color = theme[theme_index][0]

            self.inputtext_back_color = theme[theme_index][1]
            self.inputtext_font_color = "rgb(255, 255, 255);"

            self.tabheader_back_color = theme[theme_index][1]
            self.tabheader_font_color = theme[theme_index][1]
            self.tabheader_font_disable_color = theme[theme_index][0]
            self.tabheader_selected_color = theme[theme_index][2]

            self.label_font_color = theme[theme_index][1]

            self.list_header_back_color = theme[theme_index][1]
            self.list_header_font_color = "rgb(255, 255, 255);"
            self.list_content_color = theme[theme_index][1]
            self.list_content_select_color = theme[theme_index][1]
            tab_label_stylesheet = """ 
                        QTabBar::tab {background-color: """+self.tabheader_back_color+"""font-size: 24px; font-family: Arial; color: white; padding: 5px; height:34px; border-right: 6px solid white;}
                        QTabBar::tab:selected {background-color: """+self.tabheader_selected_color+"""font-size: 24px; font-family: Arial; color: white; height:34px;}
                        QTabBar::tab:disabled {background-color: """+self.tabheader_font_disable_color+"""font-size: 24px; font-family: Arial; color: white; height:34px;}
                        QTabWidget>QWidget>QWidget{background-color: """+self.tabheader_back_color+"""font-size: 24px; font-family: Arial; color: white; height:34px;}
                         """
            self.tabWidget.setStyleSheet(tab_label_stylesheet)
            self.disabled_button_style = "QPushButton{border:5px; padding:4px 10px; background-color: "+ self.button_font_disabled_color +" font-size: 20px; font-family: Arial; color: white} QPushButton:hover{background-color: "+self.button_font_disabled_color+"}"

            # self.tabWidget.repaint()
            # self.tabWidget.update()
            self.button_style = "QPushButton{border:5px; padding:4px 10px; background-color: "+ self.button_back_color +" font-size: 20px; font-family: Arial; color: white} QPushButton:hover{background-color: "+ self.button_font_disabled_color+"}"
            self.create_button_style = '#create_passworrd_button{border:5px; padding:4px 10px; background-color: '+self.button_back_color+' font-size: 25px; font-family: Arial; color: white} #create_passworrd_button:hover{background-color: '+self.button_font_disabled_color+'}'
            self.create_passworrd_button.setStyleSheet(self.create_button_style)
            self.mining_show_peers.setStyleSheet(self.button_style)
            self.choose_file_button.setStyleSheet(self.button_style)
            self.choose_file_button2.setStyleSheet(self.button_style)
            if self.is_first_time == 0:
                self.copy_button.setStyleSheet(self.disabled_button_style)
                self.submit_button.setStyleSheet(self.disabled_button_style)
                self.private_QRCode.setStyleSheet(self.disabled_button_style)
            else:
                self.copy_button.setStyleSheet(self.button_style)
                self.submit_button.setStyleSheet(self.button_style)
                self.private_QRCode.setStyleSheet(self.button_style)
            self.label_style2 = 'QLabel{font-size: 20px; color: '+self.label_font_color+'}'
            self.file_name_label.setStyleSheet(self.label_style2)
            self.label_style1 = "#create_wallet_label{font-size: 30px; color: "+self.label_font_color+"}"
            self.create_wallet_label.setStyleSheet(self.label_style1)
            self.lineedit_style1 = 'QLineEdit{font-size: 18px; font-family: Arial; border:2px solid '+self.inputtext_back_color+'}'
            self.enter_password.setStyleSheet(self.lineedit_style1)
            self.chosen_file_name.setStyleSheet(self.lineedit_style1)
            self.submit_transaction_button_style = "*{border:5px; padding:4px 10px; background-color: "+self.button_back_color+" font-size: 20px; font-family: Arial; color: white} #submit_transaction:hover{background-color: "+self.button_font_disabled_color+"}"
            self.submit_transaction.setStyleSheet(self.submit_transaction_button_style)
            self.send_transaction_text3.setStyleSheet(self.lineedit_style1)
            self.send_transaction_text4.setStyleSheet(self.lineedit_style1)
            self.label_style3 = "QLabel{font-size: 25px; color: "+self.label_font_color+"}"
            self.send_transaction_label1.setStyleSheet(self.label_style3)
            self.send_transaction_label2.setStyleSheet(self.label_style3)
            self.send_transaction_label3.setStyleSheet(self.label_style3)
            self.send_transaction_label4.setStyleSheet(self.label_style3)
            self.mining_end_button.setStyleSheet(self.button_style)
            # self.public_key_QR_lineedit.setStyleSheet(self.lineedit_style1)
            # self.private_key_QR1_lineedit.setStyleSheet(self.lineedit_style1)

            self.current_theme = self.address_book_combobox1.currentText()
        self.mining_is_first_time = 0
        self.temp_default_mining_account = self.default_mining_account.text()
        try:
            self.mining_default_mining_account = Web3.toChecksumAddress(self.temp_default_mining_account)
        except Exception as e:
            print(e)
            self.wrong_mining_address = QDialog()
            self.wrong_mining_address.setWindowIcon(QIcon('./walton.jpg'))
            self.wrong_mining_address.setWindowTitle('Wrong Mining Address')
            wrong_mining_address_layout = QVBoxLayout()
            self.wrong_mining_address_label1 = QLabel('Warning: ')
            self.wrong_mining_address_label1.setStyleSheet(self.font_style)
            self.wrong_mining_address_label2 = QLabel('You entered a wrong mining address, please check and reenter.')
            self.wrong_mining_address_label2.setStyleSheet(self.font_style)
            self.wrong_mining_address_btn1 = QPushButton('Close')
            self.wrong_mining_address_btn1.setStyleSheet(self.button_style)
            self.wrong_mining_address_btn1.clicked.connect(self.wrong_mining_address_reject)
            wrong_mining_address_layout.addWidget(self.wrong_mining_address_label1, 0, Qt.AlignCenter)
            wrong_mining_address_layout.addWidget(self.wrong_mining_address_label2, 0, Qt.AlignCenter)
            wrong_mining_address_layout.addWidget(self.wrong_mining_address_btn1, 0, Qt.AlignCenter)
            self.wrong_mining_address.setLayout(wrong_mining_address_layout)
            self.wrong_mining_address.exec_()
        else:
            # print(self.mining_default_mining_account)
            # self.thread_hashrate.start()
            # self.thread_hashrate.refreshhash_counter_value.connect(self.refreshHashrate)
            # print(self.cpu_core.value())
            
            # write mining keystore file
            # keyFile = open('./node1/keysotres/minerKeystore', 'w')
            # print(type(self.origin_key_store))
            # trans_keystore = json.loads(self.origin_key_store)
            # trans_keystore['address'] = self.mining_default_mining_account
            # keyFile.write(str(json.dumps(trans_keystore)).strip(' '))
            # keyFile.close()
            self.w3.miner.setEtherBase(self.mining_default_mining_account)
            # print(self.w3.eth.coinbase)
            self.nodes_label.setText("Miner: "+self.mining_default_mining_account)

            
            
            self.save_setting_file = open('./settings.ini', 'r')
            self.save_setting_file_list = self.save_setting_file.readlines()
            self.save_setting_file.close()
            print(str(self.address_book_radio0.isChecked()))
            print(self.save_setting_file_list[3].strip(' /n/t/r'))
            if str(self.address_book_radio0.isChecked()) == (self.save_setting_file_list[3].strip(' /n/t/r')):
                print('current mining way: ' + str(self.address_book_radio0.isChecked()))
                self.cpu_core_amount = self.cpu_core.value()
                print(self.cpu_core_amount)
                self.save_setting_file = open('./settings.ini', 'w')
                self.save_setting_file.writelines([str(self.cpu_core_amount)+'\n', self.mining_default_mining_account+'\n', self.current_theme+'\n', str(self.address_book_radio0.isChecked())])
                self.save_setting_file.close()
            else:
                print('current mining way: ' + str(self.address_book_radio0.isChecked()))
                self.cpu_core_amount = self.cpu_core.value()
                print(self.cpu_core_amount)
                self.save_setting_file = open('./settings.ini', 'w')
                self.save_setting_file.writelines([str(self.cpu_core_amount)+'\n', self.mining_default_mining_account+'\n', self.current_theme+'\n', str(self.address_book_radio0.isChecked())])
                self.save_setting_file.close()
                
                self.current_mining_way = str(self.address_book_radio0.isChecked())
                self.mining_method_changed_dialog = QDialog()
                self.mining_method_changed_dialog.setWindowIcon(QIcon('./walton.jpg'))
                self.mining_method_changed_dialog.setWindowTitle('Restart Notification')
                self.mining_method_changed_dialog.setStyleSheet("*{background-color:white; font-size: 18px; font-family: Arial; color: black}")
                self.mining_method_changed_layout  = QVBoxLayout()
                self.mining_method_changed_label0 = QLabel("You have changed your mining way. \nPlease wait until WaltonWallet.exe restarts automatically! ")
                self.mining_method_changed_button0 = QPushButton('Submit')
                self.mining_method_changed_button0.setStyleSheet(self.button_style)
                self.mining_method_changed_button0.clicked.connect(self.reopen_exe)
                self.mining_method_changed_layout.addWidget(self.mining_method_changed_label0)
                self.mining_method_changed_layout.addWidget(self.mining_method_changed_button0)
                self.mining_method_changed_dialog.setLayout(self.mining_method_changed_layout)
                self.mining_method_changed_dialog.exec_()

            self.address_book.reject()
            
    def reopen_exe(self):
        self.mining_method_changed_dialog.reject()
        kill_walton = os.system("taskkill /im walton.exe /f")
        kill_mining = os.system("taskkill /im ming_run.exe /f")
        restart_applciation = os.system("restart.vbs")
        sys.exit(app.exec_())

    def choose_contact(self):
        self.choose_contact_layout = QVBoxLayout()
        self.choose_contact_operate_layout = QHBoxLayout()
        self.choose_contact_widget0 = QWidget()
        self.choose_contact_dialog = QDialog()
        self.choose_contact_dialog.setStyleSheet("*{background-color:white; font-size: 18px; font-family: Arial; color: black}");
        self.choose_contact_label_spcae = QLabel()
        self.choose_contact_dialog.setWindowIcon(QIcon('./walton.jpg'))
        self.choose_contact_dialog.setWindowTitle('Choose receiver from your contact book')
        contact_file = open('contact.ini', 'r')
        contact_list = contact_file.readlines()
        contact_file.close()
        self.choose_contact_combobox = QComboBox()
        self.choose_contact_combobox.setFixedWidth(650)
        self.choose_contact_combobox.setFixedHeight(25)
        self.choose_contact_button0 = QPushButton('Select')
        self.choose_contact_button0.clicked.connect(self.select_contact)
        self.choose_contact_button0.setStyleSheet(self.button_style)
        self.choose_contact_operate_layout.addWidget(self.choose_contact_button0)
        self.choose_contact_widget0.setLayout(self.choose_contact_operate_layout)
        for i in range(len(contact_list)):
            self.choose_contact_combobox.addItem(contact_list[i].strip('\n\t'))
        # self.contact_combobox.addItems(contact_list)
        self.choose_contact_layout.addWidget(self.choose_contact_label_spcae, 0, Qt.AlignCenter)
        self.choose_contact_layout.addWidget(self.choose_contact_combobox, 0 ,Qt.AlignCenter)
        self.choose_contact_layout.addWidget(self.choose_contact_label_spcae, 0, Qt.AlignCenter)
        self.choose_contact_layout.addWidget(self.choose_contact_widget0)
        if len(contact_list) == 0:
            self.choose_contact_button0.setEnabled(False)
            self.choose_contact_button0.setStyleSheet(self.disabled_button_style)
        self.choose_contact_dialog.setLayout(self.choose_contact_layout)
        self.choose_contact_dialog.exec_()

    def select_contact(self):
        current_select = self.choose_contact_combobox.currentText()
        select_address = current_select.split('-')[0]
        self.send_transaction_text3.setText(select_address)
        self.choose_contact_dialog.reject()

    def contact(self):
        self.contact_layout = QVBoxLayout()
        self.contact_operate_layout = QHBoxLayout()
        self.contact_widget0 = QWidget()
        self.contact = QDialog()
        self.contact.setStyleSheet("*{background-color:white; font-size: 18px; font-family: Arial; color: black}");
        self.contact_label_spcae = QLabel()
        self.contact.setWindowIcon(QIcon('./walton.jpg'))
        self.contact.setWindowTitle('Contact Book Management')
        contact_file = open('contact.ini', 'r')
        contact_list = contact_file.readlines()
        contact_file.close()
        self.contact_add_button = QPushButton('Add', self.contact)
        self.contact_add_button.clicked.connect(self.contact_add)
        self.contact_delete_button = QPushButton('Delete')
        self.contact_delete_button.clicked.connect(self.contact_delete)
        self.contact_edit_button = QPushButton('Edit')
        self.contact_edit_button.clicked.connect(self.contact_edit)
        self.contact_add_button.setStyleSheet(self.button_style)
        self.contact_delete_button.setStyleSheet(self.button_style)
        self.contact_edit_button.setStyleSheet(self.button_style)
        self.contact_cancel_button = QPushButton('Cancel', self.contact)
        self.contact_cancel_button.clicked.connect(self.reject_contact)
        self.contact_cancel_button.setStyleSheet(self.button_style)
        self.contact_combobox = QComboBox()
        self.contact_combobox.setFixedWidth(650)
        self.contact_combobox.setFixedHeight(25)
        self.contact_operate_layout.addWidget(self.contact_add_button, 0, Qt.AlignCenter)
        self.contact_operate_layout.addWidget(self.contact_edit_button, 0, Qt.AlignCenter)
        self.contact_operate_layout.addWidget(self.contact_delete_button, 0, Qt.AlignCenter)
        self.contact_operate_layout.addWidget(self.contact_cancel_button, 0, Qt.AlignCenter)
        self.contact_widget0.setLayout(self.contact_operate_layout)
        for i in range(len(contact_list)):
            self.contact_combobox.addItem(contact_list[i].strip('\n\t'))
        # self.contact_combobox.addItems(contact_list)
        if len(contact_list) == 0:
            self.contact_edit_button.setEnabled(False)
            self.contact_edit_button.setStyleSheet(self.disabled_button_style)
        self.contact_layout.addWidget(self.contact_label_spcae, 0, Qt.AlignCenter)
        self.contact_layout.addWidget(self.contact_combobox, 0 ,Qt.AlignCenter)
        self.contact_layout.addWidget(self.contact_label_spcae, 0, Qt.AlignCenter)
        self.contact_layout.addWidget(self.contact_widget0)

        self.contact.setLayout(self.contact_layout)
        self.contact.exec_()

    def reject_contact(self):
        self.contact.reject()

    def contact_edit(self):
        self.contact_edit_dialog = QDialog()
        self.contact_edit_layout = QVBoxLayout()
        self.contact_edit_operate_layout = QHBoxLayout()
        self.contact_edit_dialog.setStyleSheet("*{background-color:white; font-size: 18px; font-family: Arial; color: black}");
        self.contact_edit_dialog.setWindowIcon(QIcon('./walton.jpg'))
        self.contact_edit_dialog.setWindowTitle('Edit Contact Record')
        self.contact_edit_lineedit0 = QLineEdit(self.contact_combobox.currentText().split('-')[0])
        self.contact_edit_lineedit0.setFixedSize(500, 25)
        self.contact_edit_lineedit1 = QLineEdit(self.contact_combobox.currentText().split('-')[1])
        self.contact_edit_lineedit1.setFixedSize(500, 25)
        self.contact_edit_button0 = QPushButton('Update')
        self.contact_edit_button1 = QPushButton('Cancel')
        self.contact_edit_button1.clicked.connect(self.reject_contact_edit)
        self.contact_edit_button1.setStyleSheet(self.button_style)
        self.contact_edit_button0.clicked.connect(self.contact_edit_confirm)
        self.contact_edit_button0.setStyleSheet(self.button_style)
        self.contact_edit_operate_layout.addWidget(self.contact_edit_button0, 0, Qt.AlignCenter)
        self.contact_edit_operate_layout.addWidget(self.contact_edit_button1, 0, Qt.AlignCenter)
        self.contact_edit_operate_widget = QWidget()
        self.contact_edit_operate_widget.setLayout(self.contact_edit_operate_layout)
        self.contact_edit_layout.addWidget(self.contact_edit_lineedit0, 0, Qt.AlignCenter)
        self.contact_edit_layout.addWidget(self.contact_edit_lineedit1, 0, Qt.AlignCenter)
        self.contact_edit_layout.addWidget(self.contact_edit_operate_widget, 0, Qt.AlignCenter)
        self.contact_edit_dialog.setLayout(self.contact_edit_layout)
        self.contact_edit_dialog.exec_()

    def reject_contact_edit(self):
        self.contact_edit_dialog.reject()

    def contact_edit_confirm(self):
        validation_address = self.contact_edit_lineedit0.text()
        former_item = self.contact_combobox.currentText()
        if self.w3.isAddress(validation_address):
            edit_item = self.w3.toChecksumAddress(validation_address)

            contact_file = open('contact.ini', 'r')
            contact_list = contact_file.readlines()
            contact_file.close()
            contact_file = open('contact.ini', 'w')
            for line in contact_list:
                print(line)
                if line.strip('\n\t') == former_item:
                    # print(line)
                    # print(delete_item)
                    contact_file.write(self.contact_edit_lineedit0.text()+'-'+self.contact_edit_lineedit1.text()+'\n')
                else:
                    contact_file.write(line)
            contact_file.close()

            contact_file = open('contact.ini', 'r')
            contact_list = contact_file.readlines()
            contact_file.close()
            self.contact_combobox.clear()
            for i in range(len(contact_list)):
                self.contact_combobox.addItem(contact_list[i].strip('\n\t'))
            self.contact_edit_confirm_success()
        else:
            self.contact_add_confirm_error()

    def contact_edit_confirm_success(self):
        self.contact_edit_confirm_success_dialog = QDialog()
        self.contact_edit_confirm_success_layout = QVBoxLayout()
        self.contact_edit_confirm_success_dialog.setStyleSheet("*{background-color:white; font-size: 18px; font-family: Arial; color: black}");
        self.contact_edit_confirm_success_dialog.setWindowIcon(QIcon('./walton.jpg'))
        self.contact_edit_confirm_success_dialog.setWindowTitle('Adding Walton Address Success')
        self.contact_edit_confirm_success_label0 = QLabel('You have successfully updated a contact record')
        self.contact_edit_confirm_success_layout.addWidget(self.contact_edit_confirm_success_label0, 0 , Qt.AlignCenter)
        self.contact_edit_confirm_success_button0 = QPushButton('Submit')
        self.contact_edit_confirm_success_button0.clicked.connect(self.reject_contact_edit_confirm_success_dialog)
        self.contact_edit_confirm_success_button0.setStyleSheet(self.button_style)
        self.contact_edit_confirm_success_layout.addWidget(self.contact_edit_confirm_success_button0, 0, Qt.AlignCenter)
        self.contact_edit_confirm_success_dialog.setLayout(self.contact_edit_confirm_success_layout)
        self.contact_edit_confirm_success_dialog.exec_()

    def reject_contact_edit_confirm_success_dialog(self):
        self.contact_edit_confirm_success_dialog.reject()
        self.contact_edit_dialog.reject()

    def contact_delete(self):
        print('delete')
        delete_item = self.contact_combobox.currentText()
        # print(delete_item)
        contact_file = open('contact.ini', 'r')
        contact_list = contact_file.readlines()
        contact_file.close()
        contact_file = open('contact.ini', 'w')
        for line in contact_list:
            # print(line)
            if line.strip('\n\t') == delete_item:
                # print(line)
                # print(delete_item)
                continue
            contact_file.write(line)
        contact_file.close()
        contact_file = open('contact.ini', 'r')
        contact_list = contact_file.readlines()
        contact_file.close()
        self.contact_combobox.clear()
        for i in range(len(contact_list)):
            self.contact_combobox.addItem(contact_list[i].strip('\n\t'))
        if len(contact_list) == 0:
            self.contact_edit_button.setEnabled(False)
            self.contact_edit_button.setStyleSheet(self.disabled_button_style)

    def contact_add(self):
        self.contact_add_layout = QVBoxLayout()
        # self.contact_
        self.contact_add_operate_layout = QHBoxLayout()
        self.contact_add_dialog = QDialog()
        self.contact_add_dialog.setStyleSheet("*{background-color:white; font-size: 18px; font-family: Arial; color: black}");
        self.contact_add_label_spcae = QLabel()
        self.contact_add_dialog.setWindowIcon(QIcon('./walton.jpg'))
        self.contact_add_dialog.setWindowTitle('Add new contact book')
        self.contact_add_button0 = QPushButton('Add', self.contact_add_dialog)
        self.contact_add_button0.clicked.connect(self.contact_add_confirm)
        self.contact_add_button0.setStyleSheet(self.button_style)
        self.contact_add_button1 = QPushButton('Cancel', self.contact_add_dialog)
        self.contact_add_button1.clicked.connect(self.reject_contact_add)
        self.contact_add_button1.setStyleSheet(self.button_style)
        self.contact_add_lineedit0 = QLineEdit()
        self.contact_add_lineedit0.setPlaceholderText('Walton Address')
        self.contact_add_lineedit0.setFixedSize(500, 25)
        self.contact_add_lineedit1 = QLineEdit()
        self.contact_add_lineedit1.setPlaceholderText('Contact Name')
        self.contact_add_lineedit1.setFixedSize(500, 25)
        self.contact_add_operate_layout.addWidget(self.contact_add_button0, 0, Qt.AlignCenter)
        self.contact_add_operate_layout.addWidget(self.contact_add_button1, 0, Qt.AlignCenter)
        self.contact_add_operate_widget = QWidget()
        self.contact_add_operate_widget.setLayout(self.contact_add_operate_layout)
        self.contact_add_layout.addWidget(self.contact_add_lineedit0, 0, Qt.AlignCenter)
        self.contact_add_layout.addWidget(self.contact_add_label_spcae, 0, Qt.AlignCenter)
        self.contact_add_layout.addWidget(self.contact_add_lineedit1, 0, Qt.AlignCenter)
        self.contact_add_layout.addWidget(self.contact_add_operate_widget, 0, Qt.AlignCenter)
        self.contact_add_dialog.setLayout(self.contact_add_layout)
        self.contact_add_dialog.exec_()

    def reject_contact_add(self):
        self.contact_add_dialog.reject()

    def contact_add_confirm(self):
        validation_address = self.contact_add_lineedit0.text()
        if self.w3.isAddress(validation_address):
            validation_address_checksum = self.w3.toChecksumAddress(validation_address)
            contact_file = open('contact.ini', 'a')
            contact_list = contact_file.write(validation_address_checksum+'-'+self.contact_add_lineedit1.text()+'\n')
            contact_file.close()
            contact_file = open('contact.ini', 'r')
            contact_list = contact_file.readlines()
            contact_file.close()
            self.contact_combobox.clear()
            for i in range(len(contact_list)):
                self.contact_combobox.addItem(contact_list[i].strip('\n\t'))
            if len(contact_list) == 0:
                self.contact_edit_button.setEnabled(False)
                self.contact_edit_button.setStyleSheet(self.disabled_button_style)
            else:
                self.contact_edit_button.setEnabled(True)
                self.contact_edit_button.setStyleSheet(self.button_style)
            self.contact_add_confirm_success()
        else:
            self.contact_add_confirm_error()

    def contact_add_confirm_success(self):
        self.contact_add_confirm_success_dialog = QDialog()
        self.contact_add_confirm_success_layout = QVBoxLayout()
        self.contact_add_confirm_success_dialog.setStyleSheet("*{background-color:white; font-size: 18px; font-family: Arial; color: black}");
        self.contact_add_confirm_success_dialog.setWindowIcon(QIcon('./walton.jpg'))
        self.contact_add_confirm_success_dialog.setWindowTitle('Adding Walton Address Success')
        self.contact_add_confirm_success_label0 = QLabel('You have successfully added a contact record')
        self.contact_add_confirm_success_layout.addWidget(self.contact_add_confirm_success_label0, 0 , Qt.AlignCenter)
        self.contact_add_confirm_success_button0 = QPushButton('Submit')
        self.contact_add_confirm_success_button0.clicked.connect(self.reject_contact_add_confirm_success_dialog)
        self.contact_add_confirm_success_button0.setStyleSheet(self.button_style)
        self.contact_add_confirm_success_layout.addWidget(self.contact_add_confirm_success_button0, 0, Qt.AlignCenter)
        self.contact_add_confirm_success_dialog.setLayout(self.contact_add_confirm_success_layout)
        self.contact_add_confirm_success_dialog.exec_()

    def reject_contact_add_confirm_success_dialog(self):
        self.contact_add_confirm_success_dialog.reject()
        self.contact_add_dialog.reject()

    def contact_add_confirm_error(self):
        self.contact_add_confirm_error_layout = QVBoxLayout()
        self.contact_add_confirm_error_dialog = QDialog()
        self.contact_add_confirm_error_dialog.setStyleSheet("*{background-color:white; font-size: 18px; font-family: Arial; color: black}");
        self.contact_add_confirm_error_label_spcae = QLabel()
        self.contact_add_confirm_error_dialog.setWindowIcon(QIcon('./walton.jpg'))
        self.contact_add_confirm_error_dialog.setWindowTitle('Walton Address Validation Error')
        self.contact_add_confirm_error_button0 = QPushButton('Cancel')
        self.contact_add_confirm_error_button0.clicked.connect(self.reject_contact_add_confirm_error)
        self.contact_add_confirm_error_button0.setStyleSheet(self.button_style)
        self.contact_add_confirm_error_label0 = QLabel("Walton address validation error.")
        self.contact_add_confirm_error_label1 = QLabel("Please check your contact address and enter again.")
        self.contact_add_confirm_error_layout.addWidget(self.contact_add_confirm_error_label0, 0, Qt.AlignCenter)
        self.contact_add_confirm_error_layout.addWidget(self.contact_add_confirm_error_label1, 0, Qt.AlignCenter)
        self.contact_add_confirm_error_layout.addWidget(self.contact_add_confirm_error_button0, 0, Qt.AlignCenter)
        self.contact_add_confirm_error_dialog.setLayout(self.contact_add_confirm_error_layout)
        self.contact_add_confirm_error_dialog.exec_()

    def reject_contact_add_confirm_error(self):
        self.contact_add_confirm_error_dialog.reject()

    def contact_lineedit(self):
        self.contact_layout = QVBoxLayout()
        self.contact = QDialog()
        self.contact.setWindowIcon(QIcon('./walton.jpg'))
        self.contact.setWindowTitle('Contact Book')
        contact_file = open('contact.ini', 'r')
        contact_list = contact_file.readlines()
        each_line0 = []
        each_line1 = []
        for i in range(len(contact_list)):
            self.contact_widget = QWidget()
            self.contact_each_line = QHBoxLayout()
            self.contactLineEdit0 = QLineEdit(contact_list[i].split('-')[0])
            self.contactLineEdit1 = QLineEdit(contact_list[i].split('-')[1])
            each_line0.append(self.contactLineEdit0)
            each_line1.append(self.contactLineEdit1)
            self.contact_each_line.addWidget(self.contactLineEdit0)
            self.contact_each_line.addWidget(self.contactLineEdit1)
            self.contact_widget.setLayout(self.contact_each_line)
            self.contact_layout.addWidget(self.contact_widget)
        self.contact.setLayout(self.contact_layout)
        print(each_line0[0].text())
        print(each_line1[0].text())
        self.contact.exec_()

    def about(self):
        about_layout = QVBoxLayout()
        self.about = QDialog()
        # self.about.setStyleSheet()
        self.about.setWindowIcon(QIcon('./walton.jpg'))
        self.about.setWindowTitle('About')
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(15)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        # self.about.setFont(font)
        self.about1 = QLabel()
        self.about1.setFixedSize(355, 152)
        # self.about1.setText('About')
        self.about1.setObjectName('about1')
        self.about1.setStyleSheet("#about1{border-image:url(walton2.jpg);}")
        self.about2 = QLabel()
        self.about2.setText('Waltonchain Wallet v1.4.0')
        self.about3 = QLabel()
        self.about3.setOpenExternalLinks(True)
        self.about3.setText('<a href="http://www.waltonchain.org" style="color:#0000ff;"><b>http://www.waltonchain.org</b></a>')
        self.about4 = QLabel()
        self.about4.setText("Copyright © 2017-2018 <br> Waltonchain Foundation")
        self.about_space = QLabel()
        self.about_btn1 = QPushButton('Close', self.about)
        self.about_btn1.clicked.connect(self.reject_about)
        about_layout.addWidget(self.about1, 0, Qt.AlignCenter)
        about_layout.addWidget(self.about4, 0, Qt.AlignCenter)
        about_layout.addWidget(self.about3, 0, Qt.AlignCenter)
        about_layout.addWidget(self.about2, 0, Qt.AlignCenter)
        about_layout.addWidget(self.about_btn1, 0, Qt.AlignCenter)
        self.about.setFont(font)
        self.about.setLayout(about_layout)
        self.about.exec_()

    def reject_about(self):
        self.about.reject()

    def reject_address_book(self):
        self.address_book.reject()

    def selectFile(self, MainWindow):
        # self.lineEdit.setText('utc')
        # fname = QFileDialog.getOpenFileName(self, 'Open123123 file', '/home')
        fname = QFileDialog.getOpenFileName(self, 'Open Your Keystore File', '.')
        try:
            if fname[0]:
                f = open(fname[0], 'r')
                with f:
                    data = f.read()
                    self.wayToUnlock_line1.setText(fname[0])
                    self.keystore = data.replace('Crypto', 'crypto')
        except Exception as e:
            print("1316")
            print(e)
            self.keystore_file_error_dialog = QDialog()
            self.keystore_file_error_dialog.setWindowIcon(QIcon('./walton.jpg'))
            self.keystore_file_error_dialog.setWindowTitle('Wrong Keystore File Error')
            self.keystore_file_error_dialog.setStyleSheet("*{background-color:white; font-size: 18px; font-family: Arial; color: black}");
            self.keystore_file_error_layout = QVBoxLayout()
            self.keystore_file_error_label0 = QLabel("You have choosen wrong keystore file.")
            self.keystore_file_error_label1 = QLabel("Please choose the right one.")
            self.keystore_file_error_button0 = QPushButton("Submit")
            self.keystore_file_error_button0.clicked.connect(self.reject_keystore_file_error_dialog)
            self.keystore_file_error_button0.setStyleSheet(self.button_style)
            self.keystore_file_error_label_space = QLabel("")
            self.keystore_file_error_layout.addWidget(self.keystore_file_error_label0, 0, Qt.AlignCenter)
            self.keystore_file_error_layout.addWidget(self.keystore_file_error_label1, 0, Qt.AlignCenter)
            self.keystore_file_error_layout.addWidget(self.keystore_file_error_label_space, 0, Qt.AlignCenter)
            self.keystore_file_error_layout.addWidget(self.keystore_file_error_button0, 0, Qt.AlignCenter)
            self.keystore_file_error_dialog.setLayout(self.keystore_file_error_layout)
            self.keystore_file_error_dialog.exec_()
        finally:
            pass 
        self.btn2.setFocus()

    def reject_keystore_file_error_dialog(self):
        self.keystore_file_error_dialog.reject()
                
    def sendTransaction(self, MainWindow):
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(15)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        sendTransaction_layout = QVBoxLayout()
        print(self.w3.eth.blockNumber)
        print(self.send_transaction_text2.text())
        print(self.send_transaction_text3.text())
        try:
            true_account1 = Web3.toChecksumAddress(self.send_transaction_text2.text())
            true_account2 = Web3.toChecksumAddress(self.send_transaction_text3.text())
            print("send Transaction")
            print(self.password)
            print(true_account1)
            print(self.w3.eth.getBalance(true_account1) / (10 ** 18))
            print(self.w3.personal.unlockAccount(true_account1, self.password))
            # print(float(str(self.send_transaction_text4.text())) * 10)
            print(type(self.send_transaction_text4.text()))
            print({'to': true_account2, 'from': true_account1, 'value': hex(
                int(float(str(self.send_transaction_text4.text())) * (10 ** 18)))})
            send_transaction_hash = (self.w3.eth.sendTransaction({'to': true_account2, 'from': true_account1, 'value': hex(
                int(float(str(self.send_transaction_text4.text())) * (10 ** 18)))}))
        except Exception as e:
            print(e)
            show_send_transaction_error_layout = QVBoxLayout()
            self.show_send_transaction_error = QDialog()
            self.show_send_transaction_error.setWindowIcon(QIcon('./walton.jpg'))
            self.show_send_transaction_error.setWindowTitle('Send Transaction Error')
            font = QtGui.QFont()
            font.setFamily("Times New Roman")
            font.setPointSize(15)
            font.setBold(False)
            font.setItalic(False)
            font.setWeight(50)
            # self.show_send_transaction_error.setFont(font)
            self.show_send_transaction_error1 = QLabel()
            self.show_send_transaction_error1.setText('Failed to Send Transaction.')
            self.show_send_transaction_error2 = QLabel()
            self.show_send_transaction_error2.setText('Please Check Your Receiver and Send Value.')
            self.show_send_transaction_error_btn1 = QPushButton('Close', self.show_send_transaction_error)
            self.show_send_transaction_error_btn1.setStyleSheet(self.button_style)
            self.show_send_transaction_error_btn1.clicked.connect(self.reject_send_transaction_error)
            show_send_transaction_error_layout.addWidget(self.show_send_transaction_error1, Qt.AlignCenter)
            show_send_transaction_error_layout.addWidget(self.show_send_transaction_error2, Qt.AlignCenter)
            show_send_transaction_error_layout.addWidget(self.show_send_transaction_error_btn1, Qt.AlignCenter)
            self.show_send_transaction_error.setFont(font)
            self.show_send_transaction_error.setLayout(show_send_transaction_error_layout)
            self.show_send_transaction_error.exec_()
        else:
            # pass
            # send_transaction_hash = (w3.eth.sendTransaction({'to': true_account2, 'from': true_account1, 'value': hex(int(float(str(self.send_transaction_text4.text()))*(10**18)))}))
            print(send_transaction_hash)
            print(type(send_transaction_hash))
            self.dialog_sendTransaction = QDialog()
            self.dialog_sendTransaction.setWindowIcon(QIcon('./walton.jpg'))
            self.dialog_sendTransaction.setFont(font)
            # self.dialog_sendTransaction.resize(450, 200)
            lab1_sendTransaction = QLabel('Transaction is submitted to be included in next block.',
                                          self.dialog_sendTransaction)
            lab3_sendTransaction = QLabel('You can use the hash value shown below to check transaction status.',
                                          self.dialog_sendTransaction)
            lab2_sendTransaction = QLineEdit(self.w3.toHex(str(send_transaction_hash)), self.dialog_sendTransaction)
            lab2_sendTransaction.setStyleSheet(self.lineedit_style1)
            lab2_sendTransaction.setReadOnly(1)
            self.send_btn1 = QPushButton('Close', self.dialog_sendTransaction)
            self.send_btn1.setStyleSheet(self.button_style)
            self.send_btn1.clicked.connect(self.rejectSend)
            # lab1_sendTransaction.setAlignment(Qt.AlignCenter)
            # lab2_sendTransaction.setAlignment(Qt.AlignCenter)
            # lab1_sendTransaction.move(50, 50)
            # lab2_sendTransaction.move(50, 80)
            sendTransaction_layout.addWidget(lab1_sendTransaction, Qt.AlignCenter)
            sendTransaction_layout.addWidget(lab3_sendTransaction, Qt.AlignCenter)
            sendTransaction_layout.addWidget(lab2_sendTransaction, Qt.AlignCenter)
            sendTransaction_layout.addStretch(1)
            sendTransaction_layout.addStretch(1)
            sendTransaction_layout.addWidget(self.send_btn1, Qt.AlignCenter)
            sendTransaction_layout.addStretch(1)
            sendTransaction_layout.addStretch(1)
            self.dialog_sendTransaction.setLayout(sendTransaction_layout)
            self.dialog_sendTransaction.setWindowTitle('Transaction Sent Success')
            self.dialog_sendTransaction.setWindowModality(Qt.ApplicationModal)
            self.send_transaction_text4.clear()
            self.dialog_sendTransaction.exec_()

    def rejectSend(self):
        self.dialog_sendTransaction.reject()

    def wayToUnlock(self, MainWindow):
        self.unlock_way = 1
        self.is_first_time = 0
        self.thread.is_running = False
        # output = os.system("run.vbs")
        wayToUnlock_layout_all = QVBoxLayout()
        wayToUnlock_layout1 = QHBoxLayout
        wayToUnlock_layout2 = QHBoxLayout
        wayToUnlock_layout2 = QHBoxLayout
        wayToUnlock_layout3 = QHBoxLayout
        wayToUnlock_layout4 = QHBoxLayout
        self.wayToUnlock_label1 = QLabel()
        self.wayToUnlock_label1.setText('')
        self.wayToUnlock_label2 = QLabel()
        self.wayToUnlock_label2.setText('')
        self.wayToUnlock_label2.setAlignment(Qt.AlignCenter)
        self.wayToUnlock_label3 = QLabel()
        self.wayToUnlock_label3.setText('')
        self.wayToUnlock_label3.setAlignment(Qt.AlignCenter)
        # self.wayToUnlock_line = QLineEdit()
        # self.wayToUnlock_line.setPlaceholderText('')
        self.dialog = QDialog()
        self.dialog.setWindowIcon(QIcon('./walton.jpg'))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(15)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.dialog.setFont(font)
        self.btn1 = QPushButton('Choose Keystore File', self.dialog)
        self.btn1.setStyleSheet(self.button_style)
        # self.btn2 = QPushButton('Enter Your Private Key', self.dialog)
        self.btn1.clicked.connect(self.selectFile)
        # self.btn1.move(50, 50)
        # self.btn2.move(50, 80)
        self.wayToUnlock_line1 = QLineEdit()
        self.wayToUnlock_line1.setPlaceholderText('Keystore Path')
        self.wayToUnlock_line1.setStyleSheet(self.lineedit_style1)
        self.wayToUnlock_line1.setFixedSize(400, 36)
        self.wayToUnlock_line1.setReadOnly(1)
        # self.wayToUnlock_line2 = QLineEdit()
        # self.wayToUnlock_line2.setPlaceholderText('Enter Your Password')
        # self.password_label.setText('Password:')
        self.password_lineedit = QLineEdit()
        self.password_lineedit.setPlaceholderText('Password')
        self.password_lineedit.setFixedSize(400, 36)
        self.password_lineedit.setStyleSheet(self.lineedit_style1)
        self.password_lineedit.setEchoMode(QLineEdit.Password)
        self.dialog.setWindowTitle('Unlock Wallet')
        self.dialog.setWindowModality(Qt.ApplicationModal)
        self.btn2 = QPushButton('Unlock', self.dialog)
        self.btn2.setStyleSheet(self.button_style)
        self.btn2.setEnabled(True)
        self.btn2.setFocus()
        self.wayToUnlock_space = QLabel()
        self.password_lineedit.returnPressed.connect(self.btn2_move_focus)
        self.btn2.clicked.connect(self.unLockWallet)
        wayToUnlock_layout_all.addWidget(self.wayToUnlock_label1, 0, Qt.AlignCenter)
        wayToUnlock_layout_all.addWidget(self.btn1, 0, Qt.AlignCenter)
        wayToUnlock_layout_all.addWidget(self.wayToUnlock_label3, 0, Qt.AlignCenter)
        wayToUnlock_layout_all.addWidget(self.wayToUnlock_line1, 0, Qt.AlignCenter)
        wayToUnlock_layout_all.addWidget(self.wayToUnlock_label2, 0, Qt.AlignCenter)
        wayToUnlock_layout_all.addWidget(self.password_lineedit, 0, Qt.AlignCenter)
        wayToUnlock_layout_all.addWidget(self.wayToUnlock_space,0 ,Qt.AlignCenter)
        wayToUnlock_layout_all.addWidget(self.btn2, 0, Qt.AlignCenter)
        self.dialog.setLayout(wayToUnlock_layout_all)
        self.dialog.exec_()

    def btn2_move_focus(self):
        self.btn2.setFocus()

    def privateToUnlock(self, MainWindow):
        self.unlock_way = 2
        self.is_first_time = 0
        self.thread.is_running = False
        # output = os.system("run.vbs")
        privateToUnlock_layout_all = QVBoxLayout()
        privateToUnlock_layout1 = QHBoxLayout
        privateToUnlock_layout2 = QHBoxLayout
        privateToUnlock_layout2 = QHBoxLayout
        privateToUnlock_layout3 = QHBoxLayout
        privateToUnlock_layout4 = QHBoxLayout
        self.privateToUnlock_label1 = QLabel()
        self.privateToUnlock_label1.setText('')
        self.privateToUnlock_label2 = QLabel()
        self.privateToUnlock_label2.setText('')
        self.privateToUnlock_label2.setAlignment(Qt.AlignCenter)
        self.privateToUnlock_label3 = QLabel()
        self.privateToUnlock_label3.setText('')
        self.privateToUnlock_label3.setAlignment(Qt.AlignCenter)
        # self.privateToUnlock_line = QLineEdit()
        # self.privateToUnlock_line.setPlaceholderText('')
        self.dialog = QDialog()
        self.dialog.setWindowIcon(QIcon('./walton.jpg'))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(15)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.dialog.setFont(font)
        
        self.privateToUnlock_line1 = QLineEdit()
        self.privateToUnlock_line1.setPlaceholderText('Private Key')
        self.privateToUnlock_line1.setStyleSheet(self.lineedit_style1)
        self.privateToUnlock_line1.setFixedSize(400, 36)
        
        self.dialog.setWindowTitle('Unlock Wallet')
        self.dialog.setWindowModality(Qt.ApplicationModal)
        self.privateToUnlock_btn2 = QPushButton('Unlock', self.dialog)
        self.privateToUnlock_btn2.setFocus()
        self.privateToUnlock_btn2.setStyleSheet(self.button_style)
        self.privateToUnlock_btn2.setEnabled(True)
        self.privateToUnlock_space = QLabel()
        self.privateToUnlock_btn2.clicked.connect(self.unLockWallet)
        privateToUnlock_layout_all.addWidget(self.privateToUnlock_label1, 0, Qt.AlignCenter)
        # privateToUnlock_layout_all.addWidget(self.btn1, 0, Qt.AlignCenter)
        privateToUnlock_layout_all.addWidget(self.privateToUnlock_label3, 0, Qt.AlignCenter)
        privateToUnlock_layout_all.addWidget(self.privateToUnlock_line1, 0, Qt.AlignCenter)
        privateToUnlock_layout_all.addWidget(self.privateToUnlock_label2, 0, Qt.AlignCenter)
        # privateToUnlock_layout_all.addWidget(self.password_lineedit, 0, Qt.AlignCenter)
        privateToUnlock_layout_all.addWidget(self.privateToUnlock_space,0 ,Qt.AlignCenter)
        privateToUnlock_layout_all.addWidget(self.privateToUnlock_btn2, 0, Qt.AlignCenter)
        self.dialog.setLayout(privateToUnlock_layout_all)
        self.copy_button.setStyleSheet(self.button_style)
        self.submit_button.setStyleSheet(self.button_style)
        self.private_QRCode.setStyleSheet(self.button_style)
        self.dialog.exec_()

    def startMining(self):
        self.cores_to_mine = self.choose_cores.text()
        self.choose_cores.setStyleSheet(
            "#mining_status{background-color: rgb(123, 188, 135); font-size: 16px; font: 20px}")
        print(self.cores_to_mine)
        print("Start Mining")
        self.choose_cores.setText('Mining Status : Mining')
        self.w3.miner.start(2)

    def stopMining(self):
        if self.mining_first_time == 0:
            print(self.mining_default_mining_account)
            self.thread_hashrate.start()
            self.thread_hashrate.refreshhash_counter_value.connect(self.refreshHashrate)
            # self.cpu_core_amount = self.cpu_core.value()
            print(self.cpu_core_amount)
            self.save_setting_file = open('./settings.ini', 'w')
            self.save_setting_file.writelines([str(self.cpu_core_amount)+'\n', self.mining_default_mining_account+'\n', self.current_theme+'\n', self.current_mining_way])
            self.save_setting_file.close()
            # keyFile = open('./node1/keysotres/minerKeystore', 'w')
            # print(type(self.origin_key_store))
            # trans_keystore = json.loads(self.origin_key_store)
            # trans_keystore['address'] = self.mining_default_mining_account
            # keyFile.write(str(json.dumps(trans_keystore)).strip(' '))
            # keyFile.close()
            self.w3.miner.setEtherBase(self.mining_default_mining_account)
            print(self.w3.eth.coinbase)
            self.nodes_label.setText("Miner: "+self.mining_default_mining_account)
            self.mining_wait_synchronization = QDialog()
            self.mining_wait_synchronization.setWindowIcon(QIcon('./walton.jpg'))
            self.mining_wait_synchronization.setWindowTitle('Synchronizating')
            self.mining_wait_synchronization_lable_space = QLabel(" ")
            self.mining_wait_synchronization_layout = QVBoxLayout()
            self.mining_wait_synchronization_label1 = QLabel('')
            self.mining_wait_synchronization_label1.setObjectName("mining_wait_synchronization_label1")
            self.mining_wait_synchronization_label1.setFixedSize(64, 64)
            self.mining_wait_synchronization_label1.setStyleSheet("#mining_wait_synchronization_label1{border-image:url(wait.png); font-size: 19px; font-family: Arial; }")
            self.mining_wait_synchronization_label2 = QLabel('Synchronizating mining data, please wait!')
            # self.mining_wait_synchronization_label1.setStyleSheet("QLabel{font-size: 19px; font-family: Arial; }")
            self.mining_wait_synchronization_label2.setStyleSheet("QLabel{font-size: 19px; font-family: Arial; }")
            self.mining_wait_synchronization_layout.addWidget(self.mining_wait_synchronization_lable_space, 0, Qt.AlignCenter)
            self.mining_wait_synchronization_layout.addWidget(self.mining_wait_synchronization_label1, 0, Qt.AlignCenter)
            self.mining_wait_synchronization_layout.addWidget(self.mining_wait_synchronization_label2, 0, Qt.AlignCenter)
            self.mining_wait_synchronization_layout.addWidget(self.mining_wait_synchronization_lable_space, 0, Qt.AlignCenter)
            self.mining_wait_synchronization.setLayout(self.mining_wait_synchronization_layout)
            self.mining_end_button.setStyleSheet(self.button_style)
            self.mining_end_button.setEnabled(True)
            # self.mining_wait_synchronization.reject()
            self.mining_wait_synchronization.exec_()
            # self.address_book.reject()
            self.mining_first_time = 1
        else:
            pass
        if self.is_mining == False:
            # self.addressBook()
            self.thread_hashrate.start()
            self.is_mining = True
            self.cores_to_mine = self.choose_cores.text()
            self.choose_cores.setStyleSheet(
                "#mining_status{background-color: rgb(123, 188, 135); font-size: 16px; font: 20px}")
            print(self.cores_to_mine)
            print("Start Mining")
            if self.current_mining_way ==  "True":
                self.choose_cores.setText('Mining Status : CPU Mining')
            else:
                self.choose_cores.setText('Mining Status : GPU Mining')
            print(self.cpu_core_amount)
            self.w3.miner.start(self.cpu_core_amount)
        else:
            self.is_mining = False
            if self.current_mining_way == "True":
                self.choose_cores.setText('Mining Status : CPU Not Mining')
            else:
                self.choose_cores.setText('Mining Status : GPU Not Mining')
            self.choose_cores.setStyleSheet(
                "#mining_status{background-color: rgb(220, 93, 93); font-size: 16px; font: 20px}")
            self.w3.miner.stop()
            # self.mining_hashrate.setText("Current HashRate: " + '0')

    def createWallet(self):
        self.new_wallet_password = self.enter_password.text()
        print(self.new_wallet_password)
        # web3 = Web3(HTTPProvider('http://27.102.106.133:7856'))
        acct = self.w3.eth.account.create(self.new_wallet_password)
        self.new_wallet_privatekey = acct.privateKey
        self.new_wallet_address = acct.address
        encrypted = self.w3.eth.account.encrypt(self.new_wallet_privatekey, self.new_wallet_password)
        
        fsave_keystore = QFileDialog.getSaveFileName(self, 'Save Your Keystore File', '.')
        if fsave_keystore[0]:
            file_save_keystore = open(fsave_keystore[0], 'w')
            with file_save_keystore:
                data = file_save_keystore.write(json.dumps(encrypted))
            self.enter_password.clear()
            created_address_layout = QVBoxLayout()
            self.created_address = QDialog()
            self.created_address.setWindowIcon(QIcon('./walton.jpg'))
            self.created_address.setWindowTitle('Details of Created Account')
            font = QtGui.QFont()
            font.setFamily("Times New Roman")
            font.setPointSize(15)
            font.setBold(False)
            font.setItalic(False)
            font.setWeight(50)
            # self.created_address.setFont(font)
            self.created_address1 = QLabel()
            self.created_address1.setText('Details.')
            self.created_address2 = QLabel()
            self.created_address2.setText('Address(Public Key) of your Created Account just now:')
            self.created_address_lineedit1 = QLineEdit(self.new_wallet_address)
            self.created_address_btn1 = QPushButton('Close', self.created_address)
            self.created_address_btn1.setStyleSheet(self.button_style)
            self.created_address_btn1.clicked.connect(self.reject_created_address)
            created_address_layout.addWidget(self.created_address1, Qt.AlignCenter)
            created_address_layout.addWidget(self.created_address2, Qt.AlignCenter)
            created_address_layout.addWidget(self.created_address_lineedit1)
            created_address_layout.addWidget(self.created_address_btn1, Qt.AlignCenter)
            self.created_address.setFont(font)
            self.created_address.setLayout(created_address_layout)
            self.created_address.exec_()
        else:
            pass
        # self.created_address.exec_()

    def reject_created_address(self):
        self.created_address.reject()

    def showQRCode(self):
        try:
            self.img.show()
        except Exception as e:
            print(e)
            show_QRCode_error_layout = QVBoxLayout()
            self.show_QRCode_error = QDialog()
            self.show_QRCode_error.setWindowIcon(QIcon('./walton.jpg'))
            self.show_QRCode_error.setWindowTitle('Show QR Code Error')
            font = QtGui.QFont()
            font.setFamily("Times New Roman")
            font.setPointSize(15)
            font.setBold(False)
            font.setItalic(False)
            font.setWeight(50)
            # self.show_QRCode_error.setFont(font)
            self.show_QRCode_error1 = QLabel()
            self.show_QRCode_error1.setText('Failed to Load Public Key QR Code.')
            self.show_QRCode_error2 = QLabel()
            self.show_QRCode_error2.setText('Please Unlock Your Wallet First.')
            self.show_QRCode_error_btn1 = QPushButton('Close', self.show_QRCode_error)
            self.show_QRCode_error_btn1.setStyleSheet(self.button_style)
            self.show_QRCode_error_btn1.clicked.connect(self.rejecet_show_QRCode_error)
            show_QRCode_error_layout.addWidget(self.show_QRCode_error1, Qt.AlignCenter)
            show_QRCode_error_layout.addWidget(self.show_QRCode_error2, Qt.AlignCenter)
            show_QRCode_error_layout.addWidget(self.show_QRCode_error_btn1, Qt.AlignCenter)
            self.show_QRCode_error.setFont(font)
            self.show_QRCode_error.setLayout(show_QRCode_error_layout)
            self.show_QRCode_error.exec_()

        else:
            pass

    def showPrivateQRCode(self):
        try:
            self.private_img.show()
        except Exception as e:
            print(e)
            show_private_QRCode_error_layout = QVBoxLayout()
            self.show_private_QRCode_error = QDialog()
            self.show_private_QRCode_error.setWindowIcon(QIcon('./walton.jpg'))
            self.show_private_QRCode_error.setWindowTitle('Show QR Code Error')
            font = QtGui.QFont()
            font.setFamily("Times New Roman")
            font.setPointSize(15)
            font.setBold(False)
            font.setItalic(False)
            font.setWeight(50)
            # self.show_QRCode_error.setFont(font)
            self.show_private_QRCode_error1 = QLabel()
            self.show_private_QRCode_error1.setText('Failed to Load Private Key QR Code.')
            self.show_private_QRCode_error2 = QLabel()
            self.show_private_QRCode_error2.setText('Please Unlock Your Wallet First.')
            self.show_private_QRCode_error_btn1 = QPushButton('Close', self.show_private_QRCode_error)
            self.show_private_QRCode_error_btn1.setStyleSheet(self.button_style)
            self.show_private_QRCode_error_btn1.clicked.connect(self.rejecet_show_private_QRCode_error)
            show_private_QRCode_error_layout.addWidget(self.show_private_QRCode_error1, 0, Qt.AlignCenter)
            show_private_QRCode_error_layout.addWidget(self.show_private_QRCode_error2, 0, Qt.AlignCenter)
            show_private_QRCode_error_layout.addWidget(self.show_private_QRCode_error_btn1, Qt.AlignCenter)
            self.show_private_QRCode_error.setFont(font)
            self.show_private_QRCode_error.setLayout(show_private_QRCode_error_layout)
            self.show_private_QRCode_error.exec_()

    def rejecet_show_QRCode_error(self):
        self.show_QRCode_error.reject()

    def rejecet_show_private_QRCode_error(self):
        self.show_private_QRCode_error.reject()

    def reject_unlock_error(self):
        self.unlock_error_dialog.reject()

    def reject_send_transaction_error(self):
        self.show_send_transaction_error.reject()

    def unLockWallet(self):
        if (os.path.exists('Data')):
            time.sleep(0.1)
        else:
            time.sleep(2)
        # time.sleep(1)
        # print(self.password)
        # web3 = Web3(HTTPProvider('http://127.0.0.1:8545'))
        # private_key = web3.eth.account.decrypt(json.loads(self.keystore), self.password)
        try:
            if self.unlock_way == 1:
                self.password = self.password_lineedit.text()
                print(self.keystore)
                self.raw_private_key = self.w3.eth.account.decrypt(json.loads(self.keystore), self.password)
                self.private_key = self.w3.toHex(self.raw_private_key)
                print(self.private_key)
                self.btn2.setEnabled(False)
            else:
                self.private_key = self.privateToUnlock_line1.text()
            # print(private_key)
            acct = self.w3.eth.account.privateKeyToAccount(self.private_key)
        except BaseException as e:
            print('decrypt error')
            print(e)
            # self.dialog.reject()
            unlock_error_layout = QVBoxLayout()
            self.unlock_error_dialog = QDialog()
            self.unlock_error_dialog.setWindowIcon(QIcon('./walton.jpg'))
            self.unlock_error_dialog.setWindowTitle('Unlock Error')
            font = QtGui.QFont()
            font.setFamily("Times New Roman")
            font.setPointSize(15)
            font.setBold(False)
            font.setItalic(False)
            font.setWeight(50)
            self.unlock_error_dialog.setFont(font)
            self.unlock_error1 = QLabel()
            self.unlock_error1.setText('Failed to Unlock Your Wallet.')
            self.unlock_error2 = QLabel()
            self.unlock_error2.setText('Please Rematch and unlock again.')
            self.unlock_error_btn1 = QPushButton('Try again', self.unlock_error2)
            self.unlock_error_btn1.clicked.connect(self.reject_unlock_error)
            unlock_error_layout.addWidget(self.unlock_error1, Qt.AlignCenter)
            unlock_error_layout.addWidget(self.unlock_error2, Qt.AlignCenter)
            unlock_error_layout.addWidget(self.unlock_error_btn1, Qt.AlignCenter)
            self.unlock_error_dialog.setFont(font)
            self.unlock_error_dialog.setLayout(unlock_error_layout)
            self.unlock_error_dialog.exec_()
            # self.btn2.setEnabled(True)

        else:
            print('decrypt success')
            self.copy_button.setStyleSheet(self.button_style)
            self.submit_button.setStyleSheet(self.button_style)
            self.private_QRCode.setStyleSheet(self.button_style)
            
            self.thread.quit()
            self.thread.start()
            self.thread.is_running = True
            # original write unlocked keystore
            keyFile = open('./Data/keystores/thisKeystore', 'w')
            print(type(self.keystore))
            keyFile.write(self.keystore)
            keyFile.close()
            self.this_account = (str(acct.address)).lower()
            print(self.this_account)
            self.true_account = Web3.toChecksumAddress(self.this_account)
            self.w3.eth.defaultAccount = self.true_account
            self.chosen_file_name.setText(self.true_account)
            self.chosen_file_name.setReadOnly(1)
            self.send_transaction_text2.setText(self.true_account)
            # self.private_lineedit.setText(transPrivate(str(private_key)))
            # self.private_lineedit.setReadOnly(1)
            # qrcode
            print('qr_start123')
            self.img = qrcode.make(self.true_account)
            self.img.save('qrcode.png')
            # 打开数据库连接
            self.private_img = qrcode.make(self.w3.toHex(str(self.private_key)))
            self.private_img.save('privatecode.png')
            print('qr_end123')
            # start request
            self.dialog.reject()
            # w3 = Web3(HTTPProvider('http://127.0.0.1:8545'))
            peers_list = self.w3.admin.peers
            print(peers_list)
            print(len(peers_list))
            if len(peers_list) > 0:
                self.statusbar.showMessage('Connected to ' + str(len(peers_list)) + ' nodes')
            else:
                self.statusbar.showMessage('Checking node status ......')
            self.tabWidget.setTabEnabled(2, True)
            self.tabWidget.setTabEnabled(3, True)
            self.tabWidget.setTabEnabled(4, True)
            self.submit_button.setEnabled(True)
            self.copy_button.setEnabled(True)
            self.private_QRCode.setEnabled(True)
            
            self.wait_synchronization = QDialog()
            self.wait_synchronization.setWindowIcon(QIcon('./walton.jpg'))
            self.wait_synchronization.setWindowTitle('Openning wallet...')
            self.wait_synchronization_lable_space = QLabel(" ")
            self.wait_synchronization_layout = QVBoxLayout()
            self.wait_synchronization_label1 = QLabel('')
            self.wait_synchronization_label1.setObjectName("wait_synchronization_label1")
            self.wait_synchronization_label1.setFixedSize(64, 64)
            self.wait_synchronization_label1.setStyleSheet("#wait_synchronization_label1{border-image:url(wait.png); font-size: 19px; font-family: Arial; }")
            self.wait_synchronization_label2 = QLabel('Synchronizating wallet data, please wait!')
            # self.wait_synchronization_label1.setStyleSheet("QLabel{font-size: 19px; font-family: Arial; }")
            self.wait_synchronization_label2.setStyleSheet("QLabel{font-size: 19px; font-family: Arial; }")
            self.wait_synchronization_layout.addWidget(self.wait_synchronization_lable_space, 0, Qt.AlignCenter)
            self.wait_synchronization_layout.addWidget(self.wait_synchronization_label1, 0, Qt.AlignCenter)
            self.wait_synchronization_layout.addWidget(self.wait_synchronization_label2, 0, Qt.AlignCenter)
            self.wait_synchronization_layout.addWidget(self.wait_synchronization_lable_space, 0, Qt.AlignCenter)
            self.wait_synchronization.setLayout(self.wait_synchronization_layout)
            # self.wait_synchronization.reject()
            self.copy_button.setStyleSheet(self.button_style)
            self.submit_button.setStyleSheet(self.button_style)
            self.private_QRCode.setStyleSheet(self.button_style)
            self.wait_synchronization.exec_()

    def thread_refresh(self):
        print('disable')
        try:
            if self.unlock_way == 1:
                print(self.keystore)
                self.raw_private_key = self.w3.eth.account.decrypt(json.loads(self.keystore), self.password)
                self.private_key = self.w3.toHex(self.raw_private_key)
            else:
                self.private_key = self.privateToUnlock_line1.text()
            # print(private_key)
        except BaseException as e:
            print('decrypt error')
            print(e)
            # self.dialog.reject()
            unlock_error_layout = QVBoxLayout()
            self.unlock_error_dialog = QDialog()
            self.unlock_error_dialog.setWindowIcon(QIcon('./walton.jpg'))
            self.unlock_error_dialog.setWindowTitle('Unlock Error')
            font = QtGui.QFont()
            font.setFamily("Times New Roman")
            font.setPointSize(15)
            font.setBold(False)
            font.setItalic(False)
            font.setWeight(50)
            self.unlock_error_dialog.setFont(font)
            self.unlock_error1 = QLabel()
            self.unlock_error1.setText('Failed to Unlock Your Wallet.')
            self.unlock_error2 = QLabel()
            self.unlock_error2.setText('Please Rematch and unlock again.')
            self.unlock_error_btn1 = QPushButton('Try again', self.unlock_error2)
            self.unlock_error_btn1.clicked.connect(self.reject_unlock_error)
            unlock_error_layout.addWidget(self.unlock_error1, Qt.AlignCenter)
            unlock_error_layout.addWidget(self.unlock_error2, Qt.AlignCenter)
            unlock_error_layout.addWidget(self.unlock_error_btn1, Qt.AlignCenter)
            self.unlock_error_dialog.setFont(font)
            self.unlock_error_dialog.setLayout(unlock_error_layout)
            self.unlock_error_dialog.exec_()
            # self.refresh_button.setEnabled(True)
        else:
            acct = self.w3.eth.account.privateKeyToAccount(self.private_key)
            print('decrypt success')
            self.this_account = (str(acct.address)).lower()
            print(self.this_account)
            self.true_account = Web3.toChecksumAddress(self.this_account)
            self.chosen_file_name.setText(self.true_account)
            self.chosen_file_name.setReadOnly(1)
            self.send_transaction_text2.setText(self.true_account)
            # self.private_lineedit.setText(transPrivate(str(private_key)))
            # self.private_lineedit.setReadOnly(1)
            # qrcode
            self.img = qrcode.make(self.true_account)
            self.img.save('qrcode.png')
            # 打开数据库连接
            self.private_img = qrcode.make(self.private_key)
            self.private_img.save('privatecode.png')
            # 
            print('123')
            this_account_balance = float(self.thread.result4[2].table.tbody.tr.find_all('td')[1].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
            # this_block = web3.eth.blockNumber
            self.show_balance.setText(str(
                str("{:,}".format(this_account_balance)) + ' (WTC)                   Updated on ' + time.strftime('%Y-%m-%d %H:%M:%S',
                                                                                                 time.localtime(
                                                                                                     time.time()))))
            self.send_transaction_text1.setText(str(this_account_balance))
            try:
                self.transaction_table.setRowCount(len(self.thread.response))
            except Exception as e:
                print("1953")
                print(e)
                self.transaction_table.setRowCount(0)
            else:
                pass
            self.transaction_table.setColumnCount(5)
            # self.transaction_table.setHorizontalHeaderLabels(
            #     ['Block #', 'Transaction Hash', 'Sender/Receiver', 'In/Out', 'Amount'])
            newItemHeader1 = QtWidgets.QTableWidgetItem('Block #')
            self.transaction_table.setHorizontalHeaderItem(0, newItemHeader1)
            newItemHeader2 = QtWidgets.QTableWidgetItem('Transaction Hash')
            self.transaction_table.setHorizontalHeaderItem(1, newItemHeader2)
            newItemHeader3 = QtWidgets.QTableWidgetItem('Sender/Receiver')
            self.transaction_table.setHorizontalHeaderItem(2, newItemHeader3)
            newItemHeader4 = QtWidgets.QTableWidgetItem('In/Out')
            self.transaction_table.setHorizontalHeaderItem(3, newItemHeader4)
            newItemHeader5 = QtWidgets.QTableWidgetItem('Amount')
            self.transaction_table.setHorizontalHeaderItem(4, newItemHeader5)       
            stylesheet = "QHeaderView::section:horizontal, QTableCornerButton::section{font-size: 18px;color: "+self.list_header_font_color+"Background-color: "+self.list_header_back_color+"margin: 5px;text-align: right;}"
            self.transaction_table.setStyleSheet(stylesheet)
            # 分行显示
            for i in range(len(self.thread.response)):
                # newItem0 = QTableWidgetItem(str(
                    # datetime.datetime.fromtimestamp(web3.eth.getBlock(response[i][0])['timestamp']).strftime(
                    #     "%Y-%m-%d %H:%M:%S")))
                newItem1 = QTableWidgetItem(str(self.thread.response[i][0]))
                newItem2 = QTableWidgetItem(str(self.thread.response[i][1]))
                newItem3 = QTableWidgetItem(str(self.thread.response[i][2]))
                newItem4 = QTableWidgetItem(str(self.thread.response[i][3]))
                newItem5 = QTableWidgetItem(str(self.thread.response[i][4]))
                self.transaction_table.setItem(i, 0, newItem1)
                self.transaction_table.setItem(i, 1, newItem2)
                self.transaction_table.setItem(i, 2, newItem3)
                self.transaction_table.setItem(i, 3, newItem4)
                self.transaction_table.setItem(i, 4, newItem5)
                # self.transaction_table.setItem(i, 5, newItem5)
            self.transaction_table.setColumnWidth(0, 80)
            self.transaction_table.setColumnWidth(1, 340)
            self.transaction_table.setColumnWidth(2, 300)
            self.transaction_table.setColumnWidth(3, 70)
            self.transaction_table.setColumnWidth(4, 100)
            print('456')
            
            peers_list = self.w3.admin.peers
            # print(peers_list)
            print(len(peers_list))
            # self.nodes_label.setText('Nodes Connected: ' + str(len(peers_list)))
            self.nodes_label.setStyleSheet("QLineEdit{font-size: 16px; font: 20px}")
            if len(peers_list) > 0:
                self.statusbar.showMessage('Connected to ' + str(len(peers_list)) + ' nodes')
            else:
                self.statusbar.showMessage('Checking node status ......')
            self.tabWidget.setTabEnabled(2, True)
            self.tabWidget.setTabEnabled(3, True)
            self.tabWidget.setTabEnabled(4, True)
            if self.is_first_time == 0:
                self.wait_synchronization.reject()
                self.is_first_time = 1
            else:
                pass
            # self.refresh_dialog.reject()
            # time.sleep(2)
            # print('here')
            # self.refresh_button.setEnabled(True)
            # if self.is_mining == True:
            #     self.mining_hashrate.setText("Current HashRate: " + str(self.w3.eth.hashrate))

    def refreshHashrate(self):
        # if self.is_mining == True:
        if self.current_mining_way == 'True':
            self.refresh_hash_rate = self.w3.eth.hashrate
        else:
            hash_rate_file = open("0202001")
            hash_rate_file_list = hash_rate_file.readlines()
            hash_rate_file.close()
            self.refresh_hash_rate = hash_rate_file_list[0].strip(' /n/r/t').split('.')[0]
        self.mining_hashrate.setText("Current HashRate: " + str(self.refresh_hash_rate))
        refresh_peers_list = self.w3.admin.peers
        if len(refresh_peers_list) > 0:
            self.statusbar.showMessage('Connected to ' + str(len(refresh_peers_list)) + ' nodes')
        else:
            self.statusbar.showMessage('Checking node status ......')
        # self.nodes_label.setText('Nodes Connected: ' + str(len(refresh_peers_list)))
        self.nodes_label.setStyleSheet("QLineEdit{font-size: 16px; font: 20px}")
        this_account_mined_blocks = int(self.thread_hashrate.result3[2].table.tbody.find_all('tr')[2].find_all('td')[1].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
        # print(this_account_mined_blocks)
        self.show_mining_mined_blocks.setText(str(str(this_account_mined_blocks) + ' (Blocks)                   Updated on ' + time.strftime('%Y-%m-%d %H:%M:%S',
                                                                                             time.localtime(
                                                                                                 time.time()))))
        mining_response = []
        for i in range(1, len(self.thread_hashrate.result2)):
            mining_response.append([])
        for i in range(len(mining_response)):
            mining_response[i].append(self.thread_hashrate.result2[i+1].find_all('td')[0].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
            mining_response[i].append(self.thread_hashrate.result2[i+1].find_all('td')[1].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
            mining_response[i].append(self.thread_hashrate.result2[i+1].find_all('td')[2].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
            mining_response[i].append(self.thread_hashrate.result2[i+1].find_all('td')[3].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
            mining_response[i].append(self.thread_hashrate.result2[i+1].find_all('td')[4].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
            mining_response[i].append(self.thread_hashrate.result2[i+1].find_all('td')[5].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
        print(len(mining_response))
        for i in range(len(mining_response)):
            print(mining_response[i])
        self.minging_info_table.setRowCount(len(mining_response))
        self.minging_info_table.setColumnCount(6)
        # self.minging_info_table.setHorizontalHeaderLabels(
        #     ['Block #', 'Hash', 'Reward(WTC)', 'Difficulty', 'Nonce', 'Size'])
        newItemMiningHeader1 = QtWidgets.QTableWidgetItem('Block #')
        self.minging_info_table.setHorizontalHeaderItem(0, newItemMiningHeader1)
        newItemMiningHeader2 = QtWidgets.QTableWidgetItem('Hash')
        self.minging_info_table.setHorizontalHeaderItem(1, newItemMiningHeader2)
        newItemMiningHeader3 = QtWidgets.QTableWidgetItem('Reward(WTC)')
        self.minging_info_table.setHorizontalHeaderItem(2, newItemMiningHeader3)
        newItemMiningHeader4 = QtWidgets.QTableWidgetItem('Difficulty')
        self.minging_info_table.setHorizontalHeaderItem(3, newItemMiningHeader4)
        newItemMiningHeader5 = QtWidgets.QTableWidgetItem('Nonce')
        self.minging_info_table.setHorizontalHeaderItem(4, newItemMiningHeader5) 
        newItemMiningHeader6 = QtWidgets.QTableWidgetItem('Size')
        self.minging_info_table.setHorizontalHeaderItem(5, newItemMiningHeader6)             
        stylesheet = "QHeaderView::section:horizontal, QTableCornerButton::section{font-size: 18px; color: "+self.list_header_font_color+" background-color: "+self.list_header_back_color+"; margin: 5px; text-align: right;}"
        self.minging_info_table.setStyleSheet(stylesheet)
        # mining info分行显示 
        for i in range(len(mining_response)):
            newItem0 = QTableWidgetItem(str(mining_response[i][0]))
            newItem1 = QTableWidgetItem(str(mining_response[i][1]))
            newItem2 = QTableWidgetItem(str(mining_response[i][2]))
            newItem3 = QTableWidgetItem(str(mining_response[i][3]))
            newItem4 = QTableWidgetItem(str(mining_response[i][4]))
            newItem5 = QTableWidgetItem(str(mining_response[i][5]))
            self.minging_info_table.setItem(i, 0, newItem0)
            self.minging_info_table.setItem(i, 1, newItem1)
            self.minging_info_table.setItem(i, 2, newItem2)
            self.minging_info_table.setItem(i, 3, newItem3)
            self.minging_info_table.setItem(i, 4, newItem4)
            self.minging_info_table.setItem(i, 5, newItem5)
        self.minging_info_table.setColumnWidth(0, 80)
        self.minging_info_table.setColumnWidth(1, 340)
        self.minging_info_table.setColumnWidth(2, 150)
        self.minging_info_table.setColumnWidth(3, 120)
        self.minging_info_table.setColumnWidth(4, 135)
        self.minging_info_table.setColumnWidth(5, 60)
        if self.mining_is_first_time == 0:
            self.mining_wait_synchronization.reject()
            self.mining_is_first_time = 1
        else:
            pass

    def quit(self, event):
        # reply = QMessageBox.question(self, 'Message', 'You are sure to quit?',
        #                              QMessageBox.Yes | QMessageBox.No, QMessageBox.No)

        # if reply == QMessageBox.Yes:
        #     event.accept()
        # else:
        #     event.ignore()
        kill_walton = os.system("taskkill /im walton.exe /f")
        kill_mining = os.system("taskkill /im ming_run.exe /f")
        sys.exit(app.exec_())

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Waltonchain Wallet"))
        MainWindow.setWindowIcon(QIcon('./walton.jpg'))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "              Create Wallet              "))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("MainWindow", "              View Wallet              "))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_3), _translate("MainWindow", "              Send WTC              "))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_4), _translate("MainWindow", "              Mining WTC              "))
        # self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_5), _translate("MainWindow", "Mining Info"))
        self.menuFile_F.setTitle(_translate("MainWindow", "&File"))
        self.menuHelp_H.setTitle(_translate("MainWindow", "&Help"))

class MyWindow(QMainWindow):
    def closeEvent(self, event):
        reply = QMessageBox.question(self, 'Message', 'Are you sure to quit?',
                                     QMessageBox.Yes | QMessageBox.No, QMessageBox.No)

        if reply == QMessageBox.Yes:
            kill_walton = os.system("taskkill /im walton.exe /f")
            kill_mining = os.system("taskkill /im ming_run.exe /f")
            event.accept()
        else:
            event.ignore()

class waitToUnlock(QtCore.QThread):
    counter_value = QtCore.pyqtSignal(int)
    def __init__(self, parent=None, counter_start = 0):
        super(waitToUnlock, self).__init__(parent)
        self.counter = counter_start
        self.is_running = True

    def run(self):
        while self.is_running == True:
            pass

class RefreshHash(QtCore.QThread):
    refreshhash_counter_value = QtCore.pyqtSignal(int)
    def __init__(self, parent=None, refreshhash_counter_start = 0):
        super(RefreshHash, self).__init__(parent)
        self.refreshhash_counter = refreshhash_counter_start
        self.is_refreshhash = True

    def run(self):
        while self.is_refreshhash == True:
            time.sleep(2)
            self.refreshhash_counter += 1
            print('refresh')
            # self.current_hashrate = ui.w3.eth.hashrate
            try:
                r2 = requests.get("http://walchain.info/minerpagination/"+ui.mining_default_mining_account+"/1", timeout=5)
                soup2 = BeautifulSoup(r2.text, "html.parser")
                self.result2 = soup2.table.find_all('tr')
            except Exception as e:
                print(e)
                pass
            else:
                # print(len(result1[1].find_all('tr')))
                # for i in range(1, len(result2)):
                #     print(result2[i].find_all('td')[0].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''), result2[i].find_all('td')[1].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''), result2[i].find_all('td')[2].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''), result2[i].find_all('td')[3].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''), result2[i].find_all('td')[4].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''), result2[i].find_all('td')[5].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
                self.mining_response = []
                for i in range(1, len(self.result2)):
                    self.mining_response.append([])
                for i in range(len(self.mining_response)):
                    self.mining_response[i].append(self.result2[i+1].find_all('td')[0].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
                    self.mining_response[i].append(self.result2[i+1].find_all('td')[1].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
                    self.mining_response[i].append(self.result2[i+1].find_all('td')[2].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
                    self.mining_response[i].append(self.result2[i+1].find_all('td')[3].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
                    self.mining_response[i].append(self.result2[i+1].find_all('td')[4].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
                    self.mining_response[i].append(self.result2[i+1].find_all('td')[5].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
                print(len(self.mining_response))
            try:
                r3 = requests.get("http://walchain.info/address/"+ui.mining_default_mining_account, timeout=5)
                soup3 = BeautifulSoup(r3.text, "html.parser")
            except Exception as e:
                print(e)
                pass
            else:
                self.result3 = soup3.find_all(class_='col-md-8')
            self.refreshhash_counter_value.emit(self.refreshhash_counter)
            time.sleep(10)


class Worker(QtCore.QThread):
    counter_value = QtCore.pyqtSignal(int)
    def __init__(self, parent=None, counter_start = 0):
        super(Worker, self).__init__(parent)
        self.counter = counter_start
        self.is_running = True

    def run(self):
        while self.is_running == True: 
            time.sleep(1)
            self.counter += 1
            # ui.refresh()
            try:
                r1 = requests.get("http://walchain.info/transactionpagination/"+ui.true_account+"/1", timeout=5)
                soup1 = BeautifulSoup(r1.text, "html.parser")
                self.result1 = soup1.table.find_all('tr')
            except Exception as e:
                print(e)
                pass
            else:
                # print(len(result1[1].find_all('tr')))
                # for i in range(1, len(result1)):
                #     print(result1[i].find_all('td')[0].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''), result1[i].find_all('td')[1].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''), result1[i].find_all('td')[2].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''), result1[i].find_all('td')[3].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''), result1[i].find_all('td')[4].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''), result1[i].find_all('td')[5].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
                self.response = []
                for i in range(1, len(self.result1)):
                    self.response.append([])
                for i in range(len(self.response)):
                    self.response[i].append(self.result1[i+1].find_all('td')[0].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
                    self.response[i].append(self.result1[i+1].find_all('td')[1].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
                    self.response[i].append(self.result1[i+1].find_all('td')[2].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
                    self.response[i].append(self.result1[i+1].find_all('td')[3].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
                    self.response[i].append(self.result1[i+1].find_all('td')[4].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
                    # response[i].append(result1[i].find_all('td')[5].text.replace(' ', '').replace('\n', '').replace('\r', '').replace('\t', ''))
                print(len(self.response))
                for i in range(len(self.response)):
                    print(self.response[i])
                # print("Database version : %s " % data)
                '''
                drop web3 usage to improve
                this_account_balance = web3.eth.getBalance(self.true_account) / (10 ** 18)
                '''
            try:
                r4 = requests.get("http://walchain.info/address/"+ui.true_account, timeout=5)
                soup4 = BeautifulSoup(r4.text, "html.parser")
            except Exception as e:
                print(e)
                pass
            else:
                self.result4 = soup4.find_all(class_='col-md-8')
            print('456')
            self.counter_value.emit(self.counter)
            print(str(self.counter) + '----------')
            time.sleep(10)


if __name__ == "__main__":
    import sys

    app = QtWidgets.QApplication(sys.argv)
    # 原来的
    # MainWindow = QtWidgets.QMainWindow()
    # 关闭窗口
    MainWindow = MyWindow()

    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    # MainWindow.close()
    sys.exit(app.exec_())
    print('application end')
