Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, requests, json, threading, subprocess
- from PyQt5.QtWidgets import *
- from PyQt5.QtGui import QIcon, QPixmap
- from PyQt5.QtCore import pyqtSlot, Qt
- import psutil
- def ProcessExists(processName):
- for proc in psutil.process_iter():
- try:
- if processName.lower() in proc.name().lower():
- return True
- except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
- pass
- return False
- def GUICtrlUpdateStyle(control):
- style = control.type + '''#''' + control.objectName() + ''' {
- font-size: ''' + control.myfontsize + ''';
- font-weight: ''' + control.myfontweight + ''';
- background-color: ''' + control.mybackgroundcolor + ''';
- color: ''' + control.mycolor + ''';
- border: ''' + control.myborder + ''';
- }
- '''
- if control.type == 'QLineEdit':
- style += control.type + '''#''' + control.objectName() + ''' {
- padding: 0px 5px 0px 5px;
- }
- '''
- if control.type == 'QPushButton':
- style += control.type + '''#''' + control.objectName() + ''':hover {
- background-color: ''' + control.myhoverbackgroundcolor + ''';
- color: ''' + control.myhovercolor + ''';
- }
- '''
- control.setStyleSheet(style)
- def GUICtrlSetBkColor(control, color):
- control.mybackgroundcolor = color
- GUICtrlUpdateStyle(control)
- def GUICtrlSetFontWeight(control, weight):
- control.myfontweight = weight
- GUICtrlUpdateStyle(control)
- def GUICtrlSetColor(control, color):
- control.mycolor = color
- GUICtrlUpdateStyle(control)
- def GUICtrlSetFontSize(control, size):
- control.myfontsize = size
- GUICtrlUpdateStyle(control)
- def ValidAmount(szAmount):
- szChrset = "0123456789."
- for iChr in range(0, len(szAmount), 1):
- if not szAmount[iChr:1] in szChrset:
- return 0
- return 1
- def find_str(s, char):
- index = 0
- if char in s:
- c = char[0]
- for ch in s:
- if ch == c:
- if s[index:index+len(char)] == char:
- return index
- index += 1
- return -1
- def GetNodeInfo():
- response = requests.post('http://127.0.0.1:22869/rpc', data='{"method" : "explorer.info.node", "params" : null, "id" : "", "jsonrpc" : "2.0"}', headers={'Content-Type':'application/json'})
- return json.loads(response.text)
- def GetWalletBalance():
- response = requests.post('http://127.0.0.1:38070/json_rpc', data='{"method" : "getBalance", "params" : {}, "id" : "", "jsonrpc" : "2.0"}', headers={'Content-Type':'application/json'})
- return json.loads(response.text)
- class App(QWidget):
- def __init__(self):
- super().__init__()
- self.title = 'Galaxia Wallet'
- self.width = 800
- self.height = 470
- self.ctrlCount = 0
- self.timer = 0
- self.xi_daemon = 0
- self.XiNetworkState, self.walletBalance, self.walletBalanceLocked = 0, 0, 0
- self.initUI()
- def closeEvent(self, event):
- self.timer.cancel()
- requests.post('http://127.0.0.1:38070/json_rpc', data='{"method" : "shutdown", "params" : {}, "id" : "", "jsonrpc" : "2.0"}', headers={'Content-Type':'application/json'})
- if self.xi_daemon: self.xi_daemon.terminate()
- def initUI(self):
- self.setWindowTitle(self.title)
- self.setFixedSize(self.width, self.height)
- self.tabsControls = {}
- #Image background
- background = QLabel(self)
- background.setPixmap(QPixmap("bg.png"))
- #Background rects
- self.GUICtrlCreateBox('rgba(255, 255, 255, 10%)', 0, 0, 200, 145)
- self.GUICtrlCreateBox('rgba(255, 255, 255, 10%)', 0, 290, 200, 115)
- self.GUICtrlCreateBox('rgba(255, 255, 255, 10%)', 0, 410, 200, 60)
- #Balance labels
- self.hLabelGalaxia = self.GUICtrlCreateLabel("GALAXIA", 0, 0, 200, 60, 0, 0, '32px')
- self.hLabelGalaxia.setAlignment(Qt.AlignHCenter)
- self.hLabelBalance = self.GUICtrlCreateLabel("Balance", 25, 60, 0, 0, 0, 0, '11px', 'normal')
- self.hLabelBalanceValue = self.GUICtrlCreateLabel('0.000000', 25, 70, 175, 35, 0, 'white', '22px', 'normal')
- self.hLabelBalanceLocked = self.GUICtrlCreateLabel("Locked balance", 25, 105, 0, 0, 0, 0, '11px' , 'normal')
- self.hLabelBalanceLockedValue = self.GUICtrlCreateLabel('0.000000', 25, 115, 175, 25, 0, 'white', '18px', 'normal')
- #Network status
- self.hLogoGreen = QPixmap('logo_green.png').scaledToWidth(50, Qt.SmoothTransformation)
- self.hLogoRed = QPixmap('logo_red.png').scaledToWidth(50, Qt.SmoothTransformation)
- self.hLogoYellow = QPixmap('logo_yellow.png').scaledToWidth(50, Qt.SmoothTransformation)
- self.hLabelNetworkIcon = self.GUICtrlCreateLabel('', 5, 415, 50, 50)
- self.hLabelNetworkIcon.setPixmap(self.hLogoRed)
- self.hLabelNetwork = self.GUICtrlCreateLabel("Network status", 60, 425, 0, 0, 'transparent', 0, '14px', 'bold')
- self.hLabelNetworkStatus = self.GUICtrlCreateLabel("Disconnected", 60, 435, 145, 30, 'transparent', '#fc7c7c', '11px', 'bold')
- #Nav
- self.activeTab = self.hButtonSend = self.GUICtrlCreateButton('Send', 0, 150, 200, 35, 'rgba(26, 188, 156, 50%)', 'white')
- self.hButtonReceive = self.GUICtrlCreateButton("Receive", 0, 185, 200, 35)
- self.hButtonHistory = self.GUICtrlCreateButton("Transactions", 0, 220, 200, 35)
- self.hButtonSettings = self.GUICtrlCreateButton("Settings", 0, 255, 200, 35)
- #Send TAB
- self.hInputAmount = self.GUICtrlCreateInput('', 215, 30, 250, 30, 'rgba(255, 0, 0, 15%)')
- self.hInputAddress = self.GUICtrlCreateInput('', 215, 80, 250, 30, 'rgba(255, 0, 0, 15%)')
- self.hInputPaymentID = self.GUICtrlCreateInput('', 215, 130, 125, 30)
- self.hLabelAmount = self.GUICtrlCreateLabel("Amount", 215, 15)
- self.hLabelAmountErr = self.GUICtrlCreateLabel("Enter amount", 365, 60, 100, 20, 0, '#b53b3b')
- self.hLabelAddress = self.GUICtrlCreateLabel("Address", 215, 65)
- self.hLabelAddressErr = self.GUICtrlCreateLabel("Enter address", 365, 110, 100, 20, 0, '#b53b3b')
- self.hLabelPaymentID = self.GUICtrlCreateLabel("Payment ID (Optional)", 215, 115)
- self.hButtonAmountAll = self.GUICtrlCreateButton("or All", 475, 30, 50, 30)
- self.hButtonAddressPaste = self.GUICtrlCreateButton("Paste", 475, 80, 50, 30)
- self.hButtonSendSend = self.GUICtrlCreateButton("Send", 215, 170, 50, 30)
- self.tabsControls[self.hButtonSend.objectName()] = [self.hInputAmount, self.hInputAddress, self.hInputPaymentID, self.hLabelAmount, self.hLabelAmountErr,
- self.hLabelAddress, self.hLabelAddressErr, self.hLabelPaymentID, self.hButtonAmountAll, self.hButtonAddressPaste,
- self.hButtonSendSend]
- #Settings TAB
- self.hLabelStartupBk = self.GUICtrlCreateBox('rgba(255, 255, 255, 10%)', 215, 15, 25, 25)
- self.hCheckboxStartup = self.GUICtrlCreateCheckBox('', 215, 15)
- self.tabsControls[self.hButtonSettings.objectName()] = [self. hLabelStartupBk, self.hCheckboxStartup]
- #Transactions TAB
- self.hTableTransactions = QTableWidget(100, 4, self)
- self.hTableTransactions.move(215, 15)
- self.hTableTransactions.setFixedSize(570, 200)
- self.hTableTransactions.setItem(1, 1, QTableWidgetItem('sounds aaa but aaaa'))
- self.hTableTransactions.verticalHeader().hide()
- self.hTableTransactions.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
- self.hTableTransactions.setHorizontalHeaderLabels(['Date', 'Tx hash', 'Amount', 'From address'])
- self.hTableTransactions.horizontalHeader().setSectionResizeMode(QHeaderView.Fixed)
- self.hTableTransactions.horizontalHeader().resizeSection(0, 50)
- self.tabsControls[self.hButtonReceive.objectName()] = []
- self.tabsControls[self.hButtonHistory.objectName()] = [self.hTableTransactions]
- for ctrl in self.tabsControls[self.hButtonSettings.objectName()]:
- ctrl.hide()
- for ctrl in self.tabsControls[self.hButtonHistory.objectName()]:
- ctrl.hide()
- self.timer = threading.Timer(2.5, self.XiNetworkUpdate)
- self.timer.start()
- self.show()
- def GUICtrlCreateButton(self, text, left, top, width = 0, height = 0, background = 0, color = 0, fontsize = 0, fontweight = 0):
- button = QPushButton(text, self)
- self.ctrlCount += 1
- button.setObjectName(str(self.ctrlCount))
- if width: button.setFixedWidth(width)
- if height: button.setFixedHeight(height)
- button.move(left, top)
- button.type = 'QPushButton'
- button.myfontsize = fontsize if fontsize else '14px'
- button.myfontweight = fontweight if fontweight else 'bold'
- button.mybackgroundcolor = background if background else 'rgba(255, 255, 255, 10%)'
- button.mycolor = color if color else 'rgb(26, 188, 156)'
- button.myborder = 'none'
- button.myhoverbackgroundcolor = 'rgba(26, 188, 156, 50%)'
- button.myhovercolor = 'white'
- GUICtrlUpdateStyle(button)
- button.clicked.connect(self.button_proc)
- return button
- def GUICtrlCreateCheckBox(self, text, left, top):
- checkbox = QCheckBox(text, self)
- self.ctrlCount += 1
- checkbox.setObjectName(str(self.ctrlCount))
- checkbox.move(left, top)
- checkbox.type = 'QCheckBox'
- #checkbox.clicked.connect(self.checkbox_proc)
- return checkbox
- def GUICtrlCreateBox(self, color, left, top, width, height):
- box = QLabel(self)
- box.move(left, top)
- box.setFixedSize(width, height)
- box.setStyleSheet('background-color: ' + color)
- box.setAlignment(Qt.AlignHCenter)
- box.setAlignment(Qt.AlignVCenter)
- return box
- def GUICtrlCreateLabel(self, text, left, top, width = 0, height = 0, background = 0, color = 0, fontsize = 0, fontweight = 0):
- label = QLabel(text, self)
- self.ctrlCount += 1
- label.setObjectName(str(self.ctrlCount))
- if width: label.setFixedWidth(width)
- if height: label.setFixedHeight(height)
- label.move(left, top)
- label.type = 'QLabel'
- label.mywidth = str(width) if width else ''
- label.myheight = str(height) if height else ''
- label.myfontsize = fontsize if fontsize else '10px'
- label.myfontweight = fontweight if fontweight else 'bold'
- label.mybackgroundcolor = background if background else 'transparent'
- label.mycolor = color if color else 'rgb(26, 188, 156)'
- label.myborder = 'none'
- GUICtrlUpdateStyle(label)
- return label
- def GUICtrlCreateInput(self, text, left, top, width, height, background = 0, color = 0, fontsize = 0, fontweight = 0):
- input = QLineEdit(self)
- self.ctrlCount += 1
- input.setObjectName(str(self.ctrlCount))
- input.move(left, top)
- input.type = 'QLineEdit'
- input.setFixedSize(width, height)
- input.myfontsize = fontisze if fontsize else '14px'
- input.myfontweight = fontweight if fontweight else 'bold'
- input.mybackgroundcolor = background if background else 'rgba(255, 255, 255, 10%)'
- input.mycolor = color if color else 'rgb(26, 188, 156)'
- input.myborder = 'none'
- GUICtrlUpdateStyle(input)
- input.setText(text)
- input.textEdited.connect(self.input_proc)
- input.editingFinished.connect(self.input_proc_end)
- return input
- def XiNetworkSetState(self, iState, iPercent = 0):
- if iState != self.XiNetworkState:
- self.XiNetworkState = iState
- if iState == 0:
- GUICtrlSetColor(self.hLabelNetworkIcon, '#fc7c7c')
- GUICtrlSetColor(self.hLabelNetworkStatus, '#fc7c7c')
- self.hLabelNetworkStatus.setText("Disconnected")
- self.hLabelNetworkIcon.setPixmap(self.hLogoRed)
- elif iState == 1:
- GUICtrlSetColor(self.hLabelNetworkIcon, '#f7ff91')
- GUICtrlSetColor(self.hLabelNetworkStatus, '#f7ff91')
- self.hLabelNetworkStatus.setText("Syncing (" + '%.2f' % iPercent + "%)")
- self.hLabelNetworkIcon.setPixmap(self.hLogoYellow)
- elif iState == 2:
- GUICtrlSetColor(self.hLabelNetworkIcon, 'rgb(26, 188, 156)')
- GUICtrlSetColor(self.hLabelNetworkStatus, 'rgb(26, 188, 156)')
- self.hLabelNetworkStatus.setText("Synced")
- self.hLabelNetworkIcon.setPixmap(self.hLogoGreen)
- def button_proc(self):
- obj = self.sender()
- if obj != self.activeTab:
- if obj == self.hButtonSend or obj == self.hButtonReceive or obj == self.hButtonHistory or obj == self.hButtonSettings:
- GUICtrlSetBkColor(self.activeTab, 'rgba(255, 255, 255, 10%)')
- GUICtrlSetColor(self.activeTab, 'rgb(26, 188, 156)')
- for ctrl in self.tabsControls[self.activeTab.objectName()]:
- ctrl.hide()
- GUICtrlSetBkColor(obj, 'rgba(26, 188, 156, 50%)')
- GUICtrlSetColor(obj, 'white')
- for ctrl in self.tabsControls[obj.objectName()]:
- ctrl.show()
- self.activeTab = obj
- return
- def input_proc_end(self):
- obj = self.sender()
- if obj == self.hInputAmount:
- if obj.text() != '': obj.setText('%.6f' % float(obj.text()))
- def input_proc(self):
- obj = self.sender()
- if obj == self.hInputAmount:
- dot = find_str(obj.text(), '.')
- if dot >= 0 and len(obj.text()) > 7 + dot:
- self.hLabelAmountErr.setText('Bad amount')
- GUICtrlSetBkColor(self.hInputAmount, 'rgba(255, 0, 0, 15%)')
- elif not ValidAmount(obj.text()):
- self.hLabelAmountErr.setText('Bad amount')
- GUICtrlSetBkColor(self.hInputAmount, 'rgba(255, 0, 0, 15%)')
- elif obj.text() == '' or float(obj.text()) == 0 :
- self.hLabelAmountErr.setText('Enter amount')
- GUICtrlSetBkColor(self.hInputAmount, 'rgba(255, 0, 0, 15%)')
- elif float(obj.text()) > self.walletBalance:
- self.hLabelAmountErr.setText('Not enought founds')
- GUICtrlSetBkColor(self.hInputAmount, 'rgba(255, 0, 0, 15%)')
- else:
- self.hLabelAmountErr.setText('')
- GUICtrlSetBkColor(self.hInputAmount, 'rgba(255, 255, 255, 10%)')
- elif obj == self.hInputAddress:
- if obj.text() == '':
- self.hLabelAddressErr.setText('Enter address')
- GUICtrlSetBkColor(self.hInputAddress, 'rgba(255, 0, 0, 15%)')
- elif len(obj.text()) != 98:
- self.hLabelAddressErr.setText('Bad address')
- GUICtrlSetBkColor(self.hInputAddress, 'rgba(255, 0, 0, 15%)')
- elif obj.text()[0:3] != 'gxi':
- self.hLabelAddressErr.setText('Bad address')
- GUICtrlSetBkColor(self.hInputAddress, 'rgba(255, 0, 0, 15%)')
- else:
- self.hLabelAddressErr.setText('')
- GUICtrlSetBkColor(self.hInputAddress, 'rgba(255, 255, 255, 10%)')
- return
- def XiNetworkUpdate(self):
- nodeSync, networkSync = 0, 0
- if not ProcessExists("xi-daemon"):
- self.XiNetworkSetState(0)
- self.xi_daemon = subprocess.Popen("xi-daemon --p2p-local-ip --rpc-server --block-explorer-enable --network Galaxia.MainNet")
- elif not ProcessExists("xi-pgservice"):
- self.XiNetworkSetState(0)
- subprocess.Popen("xi-pgservice.exe -w BunkierWallet.wallet --rpc-legacy-security --network Galaxia.MainNet")
- else:
- nodeInfo = GetNodeInfo()
- nodeSync = nodeInfo['result']['chain']['top_height']
- networkSync = nodeInfo['result']['p2p']['height']
- if networkSync and networkSync > 1:
- if nodeSync < networkSync:
- self.XiNetworkSetState(1, nodeSync / networkSync * 100)
- else:
- self.XiNetworkSetState(2)
- else:
- self.XiNetworkSetState(0)
- walletInfo = GetWalletBalance()
- self.walletBalance = walletInfo['result']['available_balance'] / 1000000
- self.walletBalanceLocked = walletInfo['result']['locked_amount'] / 1000000
- self.UpdateBalance()
- self.timer = threading.Timer(2.5, self.XiNetworkUpdate)
- self.timer.start()
- def UpdateBalance(self):
- self.hLabelBalanceValue.setText('%.6f' % self.walletBalance)
- self.hLabelBalanceLockedValue.setText('%.6f' % self.walletBalanceLocked)
- style = '''
- QHeaderView::section {
- background-color: transparent;
- color: white;
- padding-left: 4px;
- border: 1px solid rgba(26, 188, 156);
- }
- QHeaderView {
- background-color: rgba(255, 255, 255, 10%);
- }
- QHeaderView::section:checked
- {
- background-color: transparent;
- }
- QTableWidget {
- gridline-color: rgba(26, 188, 156);
- background-color: rgba(255, 255, 255, 10%);
- border: 1px solid rgba(26, 188, 156);
- color: rgb(26, 188, 156)
- }
- QCheckBox {
- background-color: transparent;
- color: rgb(26, 188, 156);
- width: 25px;
- height: 25px;
- font-size: 12px;
- }
- QCheckBox::indicator {
- width: 25px;
- height: 25px;
- background-color: transparent;
- }
- QCheckBox::indicator:checked {
- margin: 7.5px 7.5px 7.5px 7.5px;
- width: 10px;
- height: 10px;
- background-color: rgb(26, 188, 156);
- }
- QCheckBox::indicator:unchecked {
- width: 25px;
- height: 25px;
- }
- '''
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- app.setStyleSheet(style)
- ex = App()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement