Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, requests, json, threading, subprocess, configparser
- from PyQt5.QtWidgets import *
- from PyQt5.QtGui import *
- from PyQt5.QtCore import *
- from pathlib import Path
- from tkinter import Tk, filedialog
- import psutil, time, random
- #qrcode, io
- def randomWords(howMuchWords):
- words = ['wallet', 'chain', 'galaxia', 'mining', 'block', 'crypto', 'miner', 'node', 'network', 'fancy', 'cats', 'dogs', 'mining', 'coins', 'dollars', 'bad', 'halving', 'atomic', 'balance']
- out = random.choice(words)
- for i in range(0, howMuchWords -1):
- out = out + ' ' + random.choice(words)
- return out
- def randomString(stringLength=10):
- letters = string.ascii_lowercase
- return ''.join(random.choice(letters) for i in range(stringLength))
- 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: ''' + 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: ''' + control.myhoverbackgroundcolor + ''';
- color: ''' + control.myhovercolor + ''';
- }
- '''
- control.setStyleSheet(style)
- initStyle = '''
- QPushButton {
- background: rgba(255, 255, 255, 10%);
- color: rgb(26, 188, 156);
- border-radius: 50%;
- font-size: 22px;
- }
- QPushButton:hover {
- background: rgba(26, 188, 156, 50%);
- color: white;
- }
- '''
- def GUICtrlSetBkColor(control, color):
- control.mybackgroundcolor = color
- GUICtrlUpdateStyle(control)
- def GUICtrlSetHoverBkColor(control, color):
- control.myhoverbackgroundcolor = 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] 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)
- def blinkProc(ctrl, times, delay):
- for i in range(times):
- ctrl.hide()
- time.sleep(delay)
- ctrl.show()
- time.sleep(delay)
- class App(QWidget):
- def __init__(self):
- super().__init__()
- self.title = 'Galaxia GUI Wallet'
- self.width = 800
- self.height = 470
- self.ctrlCount = 0
- self.timer = 0
- self.xi_daemon = 0
- self.XiNetworkState, self.walletBalance, self.walletBalanceLocked = 0, 1337, 0.9
- self.wallet_address = ''
- self.exit_from_tray = False
- self.valid_amount = False
- self.valid_address = False
- self.tkroot = Tk()
- self.tkroot.withdraw()
- self.initUI()
- def closeEvent(self, event):
- #Tray close
- if self.hCheckboxTrayClose.isChecked() and not self.exit_from_tray:
- self.hide()
- event.ignore()
- else:
- self.tkroot.destroy()
- event.accept()
- if not '--offline' in app.arguments():
- if self.timer: self.timer.cancel()
- try:
- requests.post('http://127.0.0.1:38070/json_rpc', data='{"method" : "shutdown", "params" : {}, "id" : "", "jsonrpc" : "2.0"}', headers={'Content-Type':'application/json'})
- except:
- print('eror')
- 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("./assets/bg.png"))
- self.hLabelLogo = self.GUICtrlCreateLabel('GALAXIA', 0, 0, 800, 150, 0, 0, '60px')
- self.hLabelLogo.setAlignment(Qt.AlignCenter)
- self.hLabelInit = self.GUICtrlCreateLabel('initializing...', 470, 100, 0, 0, 0, 0, '14px')
- self.hLabelCopyrights = self.GUICtrlCreateLabel('All rights reserved © 2019 MrKris7100', 550, 450, 0, 0, 0, 0, '12px')
- self.hLabelTip = self.GUICtrlCreateLabel('What you want to do?', 250, 320, 300, 0, 0, 0, '14px')
- self.hLabelTip.setAlignment(Qt.AlignCenter)
- self.hButtonCreate = self.GUICtrlCreateButton('', 250, 200, 100, 100)
- GUICtrlSetBkColor(self.hButtonCreate, "url('./assets/wallet_new.png') 0 0/100px 100px no-repeat")
- GUICtrlSetHoverBkColor(self.hButtonCreate, "url('./assets/wallet_new_hover.png') 0 0/100px 100px no-repeat")
- self.hButtonCreate.installEventFilter(self)
- self.hButtonOpen = self.GUICtrlCreateButton('', 450, 200, 100, 100)
- #GUICtrlSetBkColor(self.hButtonOpen, "url('./assets/wallet_new.png')")
- #GUICtrlSetHoverBkColor(self.hButtonOpen, "url('./assets/wallet_new_hover.png')")
- self.hButtonOpen.installEventFilter(self)
- '''
- Left Panel controls
- '''
- #Background rects
- self.box1 = self.GUICtrlCreateBox('rgba(255, 255, 255, 10%)', 0, 0, 200, 145)
- self.box2 = self.GUICtrlCreateBox('rgba(255, 255, 255, 10%)', 0, 325, 200, 80)
- self.box3 = 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('./assets/logo_green.png').scaledToWidth(50, Qt.SmoothTransformation)
- self.hLogoRed = QPixmap('./assets/logo_red.png').scaledToWidth(50, Qt.SmoothTransformation)
- self.hLogoYellow = QPixmap('./assets/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)
- self.hButtonAbout = self.GUICtrlCreateButton("About", 0, 290, 200, 35)
- self.navButtons = (self.hButtonSend, self.hButtonReceive, self.hButtonHistory, self.hButtonSettings, self.hButtonAbout)
- self.tabsControls['leftpanel'] = [self.box1, self.box2, self.box3, self.hLabelGalaxia, self.hLabelBalance,
- self.hLabelBalanceValue, self.hLabelBalanceLocked, self.hLabelBalanceLockedValue,
- self.hLabelNetworkIcon, self.hLabelNetwork, self.hButtonSend, self.hButtonReceive,
- self.hButtonHistory, self.hButtonSettings, self.hLabelNetworkStatus, self.hButtonAbout]
- #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("Please enter amount", 335, 60, 130, 20, 0, '#b53b3b')
- self.hLabelAmountErr.setAlignment(Qt.AlignRight)
- self.hLabelAddress = self.GUICtrlCreateLabel("Receiver address", 215, 65)
- self.hLabelAddressErr = self.GUICtrlCreateLabel("Please enter address", 335, 110, 130, 20, 0, '#b53b3b')
- self.hLabelAddressErr.setAlignment(Qt.AlignRight)
- 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]
- #Receive TAB
- self.hInputWalletAddress = self.GUICtrlCreateInput('', 215, 30, 250, 30, 'rgba(255, 255, 255, 10%)')
- self.hInputWalletAddress.setReadOnly(True)
- self.hLabelWalletAddress = self.GUICtrlCreateLabel("Wallet address", 215, 15)
- self.hButtonWalletCopy = self.GUICtrlCreateButton("Copy", 475, 30, 50, 30)
- self.tabsControls[self.hButtonReceive.objectName()] = [self.hInputWalletAddress, self.hLabelWalletAddress, self.hButtonWalletCopy]
- ''' kiedyś tu QR będzie
- self.QrAddress = GUICtrlCreateLabel('', 215, 15, 100, 100)
- qr = qrcode.QRCode()
- qr.add_data('test')
- qr.make(fit=True)
- qr_img = qr.make_image()
- fp = io.BytesIO()
- qr_img.save(fp, "BMP")
- img = QImage()
- img.loadFromData(fp.getvalue, "BMP")
- pixmap = QPixmap.fromImage(img)
- self.QrAddress.setPixmap(pixmap)
- '''
- #Settings TAB
- self.hCheckboxStartupBk = self.GUICtrlCreateBox('rgba(255, 255, 255, 10%)', 215, 15, 25, 25)
- self.hCheckboxStartup = self.GUICtrlCreateCheckBox('', 215, 15)
- if int(config['wallet']['autostart']):
- self.hCheckboxStartup.setCheckState(2)
- self.hCheckboxText = self.GUICtrlCreateLabel('Run at windows startup', 245, 20, 0, 0, 0, 0, '13px')
- self.hCheckboxTrayCloseBk = self.GUICtrlCreateBox('rgba(255, 255, 255, 10%)', 215, 45, 25, 25)
- self.hCheckboxTrayClose = self.GUICtrlCreateCheckBox('', 215, 45)
- if int(config['wallet']['trayclose']):
- self.hCheckboxTrayClose.setCheckState(2)
- self.hCheckboxTrayCloseText = self.GUICtrlCreateLabel('Hide to tray instead of closing', 245, 50, 0, 0, 0, 0, '13px')
- self.hCheckboxAutoHideBk = self.GUICtrlCreateBox('rgba(255, 255, 255, 10%)', 215, 75, 25, 25)
- self.hCheckboxAutoHide = self.GUICtrlCreateCheckBox('', 215, 75)
- if int(config['wallet']['autohide']):
- self.hCheckboxAutoHide.setCheckState(2)
- self.hCheckboxAutoHideText = self.GUICtrlCreateLabel('Hide to tray on startup', 245, 80, 0, 0, 0, 0, '13px')
- self.tabsControls[self.hButtonSettings.objectName()] = [self.hCheckboxStartup, self.hCheckboxStartupBk, self.hCheckboxText, self.hCheckboxTrayClose,
- self.hCheckboxTrayCloseBk, self.hCheckboxTrayCloseText, self.hCheckboxAutoHide, self.hCheckboxAutoHideBk, self.hCheckboxAutoHideText]
- #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)
- #About TAB
- self.hLabelAbout = self.GUICtrlCreateLabel('''Galaxia GUI Wallet v1.0
- Author: MrKris7100
- Special thanks to njamnjam, MadHater, EMPEROR and other people from Galaxia team.
- This program is not official part of Galaxia project.
- This program uses 3rd party applications: xi-daemon and xi-pgservice from Galaxia project.
- If you enjoy the program you can support me by donating some GLX using button below.''', 215, 15, 0, 0, 0, 0, '11px')
- self.hButtonDonate = self.GUICtrlCreateButton('Donate', 215, 150, 75, 30)
- self.tabsControls[self.hButtonAbout.objectName()] = [self.hLabelAbout, self.hButtonDonate]
- self.tabsControls[self.hButtonHistory.objectName()] = [self.hTableTransactions]
- for ctrl in self.tabsControls[self.hButtonAbout.objectName()]:
- ctrl.hide()
- for ctrl in self.tabsControls[self.hButtonReceive.objectName()]:
- ctrl.hide()
- for ctrl in self.tabsControls[self.hButtonSettings.objectName()]:
- ctrl.hide()
- for ctrl in self.tabsControls[self.hButtonHistory.objectName()]:
- ctrl.hide()
- # Create the menu
- self.tray_menu = QMenu()
- self.tray_show = QAction("Show")
- self.tray_show.triggered.connect(self.tray_event)
- self.tray_exit = QAction("Exit")
- self.tray_exit.triggered.connect(self.tray_exit_proc)
- self.tray_menu.addAction(self.tray_show)
- self.tray_menu.addAction(self.tray_exit)
- #Create tray icon
- self.tray_icon = QSystemTrayIcon()
- #add menu to tray
- self.tray_icon.setContextMenu(self.tray_menu)
- self.tray_icon.activated.connect(self.tray_event)
- #Set window and tray icon
- self.tray_icon.setIcon(QIcon(self.hLogoGreen))
- self.setWindowIcon(QIcon(self.hLogoGreen))
- #Show window and tray icon
- if not (int(config['wallet']['autohide']) and '--autostart' in app.arguments()):
- self.show()
- self.tray_icon.show()
- #Wallet initialization
- if not '--offline' in app.arguments():
- for ctrl in self.tabsControls['leftpanel']:
- ctrl.hide()
- for ctrl in self.tabsControls[self.hButtonSend.objectName()]:
- ctrl.hide()
- #Wallet config if needed
- if Path(config['wallet']['path']).is_file():
- threading.Timer(0, self.WalletInit).start()
- self.hButtonCreate.hide()
- self.hButtonOpen.hide()
- self.hLabelTip.hide()
- else:
- self.hLabelInit.hide()
- else:
- self.hLabelLogo.hide()
- self.hLabelInit.hide()
- self.hButtonCreate.hide()
- self.hButtonOpen.hide()
- self.hLabelTip.hide()
- threading.Timer(0, self.WalletInit).start()
- def eventFilter(self, obj, event):
- type = event.type()
- if type == 129:
- if obj == self.hButtonCreate:
- self.hLabelTip.setText('Create new wallet')
- elif obj == self.hButtonOpen:
- self.hLabelTip.setText('Open existing wallet')
- if type == 128 and (obj == self.hButtonCreate or obj == self.hButtonOpen):
- self.hLabelTip.setText('What you want to do?')
- return 0
- def tray_exit_proc(self):
- self.exit_from_tray = True
- self.close()
- def tray_event(self, reason):
- if reason == QSystemTrayIcon.DoubleClick or reason == QWidgetAction.Trigger:
- self.show()
- self.setWindowState(Qt.WindowNoState)
- def UpdateWalletAddress(self):
- self.wallet_address = 'gxid1j832db198n28d21d' #Read here
- self.hInputWalletAddress.setText(self.wallet_address)
- 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.toggled.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 'initial'
- label.myheight = str(height) if height else 'initial'
- 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.textChanged.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)
- elif iState == 1:
- self.hLabelNetworkStatus.setText("Syncing (" + '%.2f' % iPercent + "%)")
- def button_proc(self):
- obj = self.sender()
- if obj != self.activeTab:
- if obj in self.navButtons:
- 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
- else:
- if obj == self.hButtonDonate:
- self.hInputAddress.setText(donate_address)
- self.hInputPaymentID.setText('DONATE')
- self.hButtonSend.click()
- elif obj == self.hButtonOpen:
- file_path = filedialog.askopenfilename(title='Select wallet file', filetypes=[('Wallet containers', '*.wallet')])
- if Path(file_path).is_file():
- config['wallet']['path'] = file_path
- with open("Wallet.ini", "w") as configfile:
- config.write(configfile)
- elif obj == self.hButtonCreate:
- random_container = randomString(10)
- config['wallet']['path'] = random_container + '.wallet'
- mnemonic_seed = randomWords(24)
- #Generate new wallet
- subprocess.Popen("xi-pgservice.exe -g -w " + config['wallet']['path'] + ' --mnemonic-seed "' + randomWords(24) + '"', creationflags = subprocess.CREATE_NO_WINDOW)
- with open("Wallet.ini", "w") as configfile:
- config.write(configfile)
- threading.Timer(0, self.WalletInit).start()
- self.hButtonCreate.hide()
- self.hButtonOpen.hide()
- self.hLabelTip.hide()
- elif obj == self.hButtonAmountAll and self.walletBalance > 0:
- self.hInputAmount.setText('%.6f' % float(self.walletBalance - 0.01))
- elif obj == self.hButtonWalletCopy:
- self.tkroot.clipboard_clear()
- self.tkroot.clipboard_append(self.wallet_address)
- elif obj == self.hButtonAddressPaste:
- self.hInputAddress.setText(self.tkroot.clipboard_get())
- elif obj== self.hButtonSendSend:
- sending = True
- if not self.valid_amount:
- self.controlBlink(self.hLabelAmountErr, 3, 0.15)
- sending = False
- if not self.valid_address:
- self.controlBlink(self.hLabelAddressErr, 3, 0.15)
- sending = False
- if sending:
- print('Yay! We can send!')
- return
- def input_proc_end(self):
- obj = self.sender()
- if obj == self.hInputAmount:
- dot = find_str(obj.text(), '.')
- if obj.text() != '' and ValidAmount(obj.text()) and float(obj.text()) > 0 and not (dot >= 0 and len(obj.text()) > 7 + dot): obj.setText('%.6f' % float(obj.text()))
- def input_proc(self):
- obj = self.sender()
- if obj == self.hInputAmount:
- self.valid_amount = False
- dot = find_str(obj.text(), '.')
- if dot >= 0 and len(obj.text()) > 7 + dot:
- self.hLabelAmountErr.setText('Invalid amount')
- elif not ValidAmount(obj.text()):
- self.hLabelAmountErr.setText('Invalid amount')
- elif obj.text() == '' or float(obj.text()) == 0 :
- self.hLabelAmountErr.setText('Please enter amount')
- elif float(obj.text()) + 0.01 > self.walletBalance:
- self.hLabelAmountErr.setText('Not enought founds')
- else:
- self.hLabelAmountErr.setText('')
- self.valid_amount = True
- if self.valid_amount:
- GUICtrlSetBkColor(self.hInputAmount, 'rgba(255, 255, 255, 10%)')
- else:
- GUICtrlSetBkColor(self.hInputAmount, 'rgba(255, 0, 0, 15%)')
- elif obj == self.hInputAddress:
- #Checking typed address
- self.valid_address = False
- if obj.text() == '': #Not entered
- self.hLabelAddressErr.setText('Please enter address')
- elif len(obj.text()) != 98: #Too short
- self.hLabelAddressErr.setText('Invalid address')
- elif obj.text()[0:3] != 'gxi': #Not valid - no prefix
- self.hLabelAddressErr.setText('Invalid address')
- else:
- self.hLabelAddressErr.setText('')
- self.valid_address = True
- if self.valid_address:
- GUICtrlSetBkColor(self.hInputAddress, 'rgba(255, 255, 255, 10%)')
- else:
- GUICtrlSetBkColor(self.hInputAddress, 'rgba(255, 0, 0, 15%)')
- return
- def checkbox_proc(self):
- obj = self.sender()
- if obj == self.hCheckboxStartup:
- config['wallet']['autostart'] = str(int(obj.isChecked()))
- elif obj == self.hCheckboxTrayClose:
- config['wallet']['trayclose'] = str(int(obj.isChecked()))
- elif obj == self.hCheckboxAutoHide:
- config['wallet']['autohide'] = str(int(obj.isChecked()))
- #Update config file
- with open("Wallet.ini", "w") as configfile:
- config.write(configfile)
- def controlBlink(self, ctrl, times = 5, delay = 0.1):
- threading.Timer(0, blinkProc, args=[ctrl, times, delay]).start()
- def XiNetworkUpdate(self):
- nodeSync, networkSync = 0, 0
- nodeInfo = GetNodeInfo()
- nodeSync = nodeInfo['result']['chain']['top_height']
- networkSync = nodeInfo['result']['p2p']['height']
- print(str(nodeSync) + '/' + str(networkSync))
- 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 WalletInit(self):
- if not '--offline' in app.arguments():
- self.hLabelInit.show()
- if not ProcessExists("xi-daemon"):
- self.xi_daemon = subprocess.Popen("xi-daemon --p2p-local-ip --rpc-server --block-explorer-enable --network Galaxia.MainNet", creationflags = subprocess.CREATE_NO_WINDOW)
- time.sleep(2)
- if not ProcessExists("xi-pgservice"):
- subprocess.Popen("xi-pgservice.exe --log-level 0 -w " + config['wallet']['path'] + " --rpc-legacy-security --network Galaxia.MainNet", creationflags = subprocess.CREATE_NO_WINDOW)
- time.sleep(2)
- self.UpdateWalletAddress()
- self.UpdateBalance()
- self.hLabelLogo.hide()
- self.hLabelInit.hide()
- self.hButtonCreate.hide()
- for ctrl in self.tabsControls['leftpanel']:
- ctrl.show()
- for ctrl in self.tabsControls[self.hButtonSend.objectName()]:
- ctrl.show()
- 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 rgb(26, 188, 156);
- }
- QHeaderView {
- background-color: rgba(255, 255, 255, 10%);
- }
- QHeaderView::section:checked
- {
- background-color: transparent;
- }
- QTableWidget {
- gridline-color: rgb(26, 188, 156);
- background-color: rgba(255, 255, 255, 10%);
- border: 1px solid rgb(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__':
- donate_address = 'gxi16HXcDn89QD2idxs1ALibWfSLkTZtLe2PWsVU43sJYSvEC3WNcfed2yRFPdMtw57u1W9BemT4ZhujHhs98gZxAZ7tqDm1Yd'
- config = configparser.ConfigParser()
- #Initial config
- if not Path("Wallet.ini").is_file():
- newwallet = True
- trayclose = 0
- autostart = 0
- autohide = 0
- with open("Wallet.ini", "w") as configfile:
- config['wallet'] = {'path' : '', 'trayclose' : trayclose, 'autostart' : autostart, 'autohide' : autohide}
- config.write(configfile)
- #~~~~~~~~~~~~~~ dodac sprawdzanie istnienia pliku portfela
- config.read("Wallet.ini")
- app = QApplication(sys.argv)
- app.setStyleSheet(style)
- ex = App()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement