Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.56 KB | None | 0 0
  1. import sys, requests, json, threading, subprocess, configparser
  2. from PyQt5.QtWidgets import *
  3. from PyQt5.QtGui import *
  4. from PyQt5.QtCore import *
  5. from pathlib import Path
  6. from tkinter import Tk, filedialog
  7. import psutil, time, random
  8. #qrcode, io
  9.  
  10. def randomWords(howMuchWords):
  11. words = ['wallet', 'chain', 'galaxia', 'mining', 'block', 'crypto', 'miner', 'node', 'network', 'fancy', 'cats', 'dogs', 'mining', 'coins', 'dollars', 'bad', 'halving', 'atomic', 'balance']
  12. out = random.choice(words)
  13. for i in range(0, howMuchWords -1):
  14. out = out + ' ' + random.choice(words)
  15. return out
  16.  
  17. def randomString(stringLength=10):
  18. letters = string.ascii_lowercase
  19. return ''.join(random.choice(letters) for i in range(stringLength))
  20.  
  21. def ProcessExists(processName):
  22. for proc in psutil.process_iter():
  23. try:
  24. if processName.lower() in proc.name().lower():
  25. return True
  26. except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
  27. pass
  28. return False
  29.  
  30. def GUICtrlUpdateStyle(control):
  31. style = control.type + '''#''' + control.objectName() + ''' {
  32. font-size: ''' + control.myfontsize + ''';
  33. font-weight: ''' + control.myfontweight + ''';
  34. background: ''' + control.mybackgroundcolor + ''';
  35. color: ''' + control.mycolor + ''';
  36. border: ''' + control.myborder + ''';
  37. }
  38. '''
  39. if control.type == 'QLineEdit':
  40. style += control.type + '''#''' + control.objectName() + ''' {
  41. padding: 0px 5px 0px 5px;
  42. }
  43. '''
  44. if control.type == 'QPushButton':
  45. style += control.type + '''#''' + control.objectName() + ''':hover {
  46. background: ''' + control.myhoverbackgroundcolor + ''';
  47. color: ''' + control.myhovercolor + ''';
  48. }
  49. '''
  50. control.setStyleSheet(style)
  51.  
  52. initStyle = '''
  53. QPushButton {
  54. background: rgba(255, 255, 255, 10%);
  55. color: rgb(26, 188, 156);
  56. border-radius: 50%;
  57. font-size: 22px;
  58. }
  59. QPushButton:hover {
  60. background: rgba(26, 188, 156, 50%);
  61. color: white;
  62. }
  63. '''
  64.  
  65. def GUICtrlSetBkColor(control, color):
  66. control.mybackgroundcolor = color
  67. GUICtrlUpdateStyle(control)
  68.  
  69. def GUICtrlSetHoverBkColor(control, color):
  70. control.myhoverbackgroundcolor = color
  71. GUICtrlUpdateStyle(control)
  72.  
  73. def GUICtrlSetFontWeight(control, weight):
  74. control.myfontweight = weight
  75. GUICtrlUpdateStyle(control)
  76.  
  77. def GUICtrlSetColor(control, color):
  78. control.mycolor = color
  79. GUICtrlUpdateStyle(control)
  80.  
  81. def GUICtrlSetFontSize(control, size):
  82. control.myfontsize = size
  83. GUICtrlUpdateStyle(control)
  84.  
  85. def ValidAmount(szAmount):
  86. szChrset = "0123456789."
  87. for iChr in range(0, len(szAmount), 1):
  88. if not szAmount[iChr] in szChrset:
  89. return 0
  90. return 1
  91.  
  92. def find_str(s, char):
  93. index = 0
  94.  
  95. if char in s:
  96. c = char[0]
  97. for ch in s:
  98. if ch == c:
  99. if s[index:index+len(char)] == char:
  100. return index
  101.  
  102. index += 1
  103.  
  104. return -1
  105.  
  106. def GetNodeInfo():
  107. 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'})
  108. return json.loads(response.text)
  109.  
  110. def GetWalletBalance():
  111. response = requests.post('http://127.0.0.1:38070/json_rpc', data='{"method" : "getBalance", "params" : {}, "id" : "", "jsonrpc" : "2.0"}', headers={'Content-Type':'application/json'})
  112. return json.loads(response.text)
  113.  
  114. def blinkProc(ctrl, times, delay):
  115. for i in range(times):
  116. ctrl.hide()
  117. time.sleep(delay)
  118. ctrl.show()
  119. time.sleep(delay)
  120.  
  121. class App(QWidget):
  122. def __init__(self):
  123. super().__init__()
  124. self.title = 'Galaxia GUI Wallet'
  125. self.width = 800
  126. self.height = 470
  127. self.ctrlCount = 0
  128. self.timer = 0
  129. self.xi_daemon = 0
  130. self.XiNetworkState, self.walletBalance, self.walletBalanceLocked = 0, 1337, 0.9
  131. self.wallet_address = ''
  132. self.exit_from_tray = False
  133. self.valid_amount = False
  134. self.valid_address = False
  135. self.tkroot = Tk()
  136. self.tkroot.withdraw()
  137.  
  138. self.initUI()
  139.  
  140. def closeEvent(self, event):
  141. #Tray close
  142. if self.hCheckboxTrayClose.isChecked() and not self.exit_from_tray:
  143. self.hide()
  144. event.ignore()
  145. else:
  146. self.tkroot.destroy()
  147. event.accept()
  148. if not '--offline' in app.arguments():
  149. if self.timer: self.timer.cancel()
  150. try:
  151. requests.post('http://127.0.0.1:38070/json_rpc', data='{"method" : "shutdown", "params" : {}, "id" : "", "jsonrpc" : "2.0"}', headers={'Content-Type':'application/json'})
  152. except:
  153. print('eror')
  154. if self.xi_daemon: self.xi_daemon.terminate()
  155.  
  156. def initUI(self):
  157. self.setWindowTitle(self.title)
  158. self.setFixedSize(self.width, self.height)
  159. self.tabsControls = {}
  160.  
  161. #Image background
  162. background = QLabel(self)
  163. background.setPixmap(QPixmap("./assets/bg.png"))
  164.  
  165. self.hLabelLogo = self.GUICtrlCreateLabel('GALAXIA', 0, 0, 800, 150, 0, 0, '60px')
  166. self.hLabelLogo.setAlignment(Qt.AlignCenter)
  167. self.hLabelInit = self.GUICtrlCreateLabel('initializing...', 470, 100, 0, 0, 0, 0, '14px')
  168. self.hLabelCopyrights = self.GUICtrlCreateLabel('All rights reserved © 2019 MrKris7100', 550, 450, 0, 0, 0, 0, '12px')
  169. self.hLabelTip = self.GUICtrlCreateLabel('What you want to do?', 250, 320, 300, 0, 0, 0, '14px')
  170. self.hLabelTip.setAlignment(Qt.AlignCenter)
  171.  
  172. self.hButtonCreate = self.GUICtrlCreateButton('', 250, 200, 100, 100)
  173. GUICtrlSetBkColor(self.hButtonCreate, "url('./assets/wallet_new.png') 0 0/100px 100px no-repeat")
  174. GUICtrlSetHoverBkColor(self.hButtonCreate, "url('./assets/wallet_new_hover.png') 0 0/100px 100px no-repeat")
  175. self.hButtonCreate.installEventFilter(self)
  176.  
  177. self.hButtonOpen = self.GUICtrlCreateButton('', 450, 200, 100, 100)
  178. #GUICtrlSetBkColor(self.hButtonOpen, "url('./assets/wallet_new.png')")
  179. #GUICtrlSetHoverBkColor(self.hButtonOpen, "url('./assets/wallet_new_hover.png')")
  180. self.hButtonOpen.installEventFilter(self)
  181.  
  182. '''
  183. Left Panel controls
  184. '''
  185. #Background rects
  186. self.box1 = self.GUICtrlCreateBox('rgba(255, 255, 255, 10%)', 0, 0, 200, 145)
  187. self.box2 = self.GUICtrlCreateBox('rgba(255, 255, 255, 10%)', 0, 325, 200, 80)
  188. self.box3 = self.GUICtrlCreateBox('rgba(255, 255, 255, 10%)', 0, 410, 200, 60)
  189.  
  190. #Balance labels
  191. self.hLabelGalaxia = self.GUICtrlCreateLabel("GALAXIA", 0, 0, 200, 60, 0, 0, '32px')
  192. self.hLabelGalaxia.setAlignment(Qt.AlignHCenter)
  193. self.hLabelBalance = self.GUICtrlCreateLabel("Balance", 25, 60, 0, 0, 0, 0, '11px', 'normal')
  194. self.hLabelBalanceValue = self.GUICtrlCreateLabel('0.000000', 25, 70, 175, 35, 0, 'white', '22px', 'normal')
  195. self.hLabelBalanceLocked = self.GUICtrlCreateLabel("Locked balance", 25, 105, 0, 0, 0, 0, '11px' , 'normal')
  196. self.hLabelBalanceLockedValue = self.GUICtrlCreateLabel('0.000000', 25, 115, 175, 25, 0, 'white', '18px', 'normal')
  197. #Network status
  198. self.hLogoGreen = QPixmap('./assets/logo_green.png').scaledToWidth(50, Qt.SmoothTransformation)
  199. self.hLogoRed = QPixmap('./assets/logo_red.png').scaledToWidth(50, Qt.SmoothTransformation)
  200. self.hLogoYellow = QPixmap('./assets/logo_yellow.png').scaledToWidth(50, Qt.SmoothTransformation)
  201. self.hLabelNetworkIcon = self.GUICtrlCreateLabel('', 5, 415, 50, 50)
  202. self.hLabelNetworkIcon.setPixmap(self.hLogoRed)
  203. self.hLabelNetwork = self.GUICtrlCreateLabel("Network status", 60, 425, 0, 0, 'transparent', 0, '14px', 'bold')
  204. self.hLabelNetworkStatus = self.GUICtrlCreateLabel("Disconnected", 60, 435, 145, 30, 'transparent', '#fc7c7c', '11px', 'bold')
  205. #Nav
  206. self.activeTab = self.hButtonSend = self.GUICtrlCreateButton('Send', 0, 150, 200, 35, 'rgba(26, 188, 156, 50%)', 'white')
  207. self.hButtonReceive = self.GUICtrlCreateButton("Receive", 0, 185, 200, 35)
  208. self.hButtonHistory = self.GUICtrlCreateButton("Transactions", 0, 220, 200, 35)
  209. self.hButtonSettings = self.GUICtrlCreateButton("Settings", 0, 255, 200, 35)
  210. self.hButtonAbout = self.GUICtrlCreateButton("About", 0, 290, 200, 35)
  211.  
  212. self.navButtons = (self.hButtonSend, self.hButtonReceive, self.hButtonHistory, self.hButtonSettings, self.hButtonAbout)
  213.  
  214. self.tabsControls['leftpanel'] = [self.box1, self.box2, self.box3, self.hLabelGalaxia, self.hLabelBalance,
  215. self.hLabelBalanceValue, self.hLabelBalanceLocked, self.hLabelBalanceLockedValue,
  216. self.hLabelNetworkIcon, self.hLabelNetwork, self.hButtonSend, self.hButtonReceive,
  217. self.hButtonHistory, self.hButtonSettings, self.hLabelNetworkStatus, self.hButtonAbout]
  218.  
  219. #Send TAB
  220. self.hInputAmount = self.GUICtrlCreateInput('', 215, 30, 250, 30, 'rgba(255, 0, 0, 15%)')
  221. self.hInputAddress = self.GUICtrlCreateInput('', 215, 80, 250, 30, 'rgba(255, 0, 0, 15%)')
  222. self.hInputPaymentID = self.GUICtrlCreateInput('', 215, 130, 125, 30)
  223.  
  224. self.hLabelAmount = self.GUICtrlCreateLabel("Amount", 215, 15)
  225. self.hLabelAmountErr = self.GUICtrlCreateLabel("Please enter amount", 335, 60, 130, 20, 0, '#b53b3b')
  226. self.hLabelAmountErr.setAlignment(Qt.AlignRight)
  227. self.hLabelAddress = self.GUICtrlCreateLabel("Receiver address", 215, 65)
  228. self.hLabelAddressErr = self.GUICtrlCreateLabel("Please enter address", 335, 110, 130, 20, 0, '#b53b3b')
  229. self.hLabelAddressErr.setAlignment(Qt.AlignRight)
  230. self.hLabelPaymentID = self.GUICtrlCreateLabel("Payment ID (Optional)", 215, 115)
  231.  
  232. self.hButtonAmountAll = self.GUICtrlCreateButton("or All", 475, 30, 50, 30)
  233. self.hButtonAddressPaste = self.GUICtrlCreateButton("Paste", 475, 80, 50, 30)
  234. self.hButtonSendSend = self.GUICtrlCreateButton("Send", 215, 170, 50, 30)
  235.  
  236. self.tabsControls[self.hButtonSend.objectName()] = [self.hInputAmount, self.hInputAddress, self.hInputPaymentID, self.hLabelAmount, self.hLabelAmountErr,
  237. self.hLabelAddress, self.hLabelAddressErr, self.hLabelPaymentID, self.hButtonAmountAll, self.hButtonAddressPaste,
  238. self.hButtonSendSend]
  239.  
  240. #Receive TAB
  241. self.hInputWalletAddress = self.GUICtrlCreateInput('', 215, 30, 250, 30, 'rgba(255, 255, 255, 10%)')
  242. self.hInputWalletAddress.setReadOnly(True)
  243.  
  244. self.hLabelWalletAddress = self.GUICtrlCreateLabel("Wallet address", 215, 15)
  245.  
  246. self.hButtonWalletCopy = self.GUICtrlCreateButton("Copy", 475, 30, 50, 30)
  247.  
  248. self.tabsControls[self.hButtonReceive.objectName()] = [self.hInputWalletAddress, self.hLabelWalletAddress, self.hButtonWalletCopy]
  249. ''' kiedyś tu QR będzie
  250. self.QrAddress = GUICtrlCreateLabel('', 215, 15, 100, 100)
  251. qr = qrcode.QRCode()
  252. qr.add_data('test')
  253. qr.make(fit=True)
  254. qr_img = qr.make_image()
  255. fp = io.BytesIO()
  256. qr_img.save(fp, "BMP")
  257. img = QImage()
  258. img.loadFromData(fp.getvalue, "BMP")
  259. pixmap = QPixmap.fromImage(img)
  260. self.QrAddress.setPixmap(pixmap)
  261. '''
  262. #Settings TAB
  263. self.hCheckboxStartupBk = self.GUICtrlCreateBox('rgba(255, 255, 255, 10%)', 215, 15, 25, 25)
  264. self.hCheckboxStartup = self.GUICtrlCreateCheckBox('', 215, 15)
  265. if int(config['wallet']['autostart']):
  266. self.hCheckboxStartup.setCheckState(2)
  267. self.hCheckboxText = self.GUICtrlCreateLabel('Run at windows startup', 245, 20, 0, 0, 0, 0, '13px')
  268.  
  269. self.hCheckboxTrayCloseBk = self.GUICtrlCreateBox('rgba(255, 255, 255, 10%)', 215, 45, 25, 25)
  270. self.hCheckboxTrayClose = self.GUICtrlCreateCheckBox('', 215, 45)
  271. if int(config['wallet']['trayclose']):
  272. self.hCheckboxTrayClose.setCheckState(2)
  273. self.hCheckboxTrayCloseText = self.GUICtrlCreateLabel('Hide to tray instead of closing', 245, 50, 0, 0, 0, 0, '13px')
  274.  
  275. self.hCheckboxAutoHideBk = self.GUICtrlCreateBox('rgba(255, 255, 255, 10%)', 215, 75, 25, 25)
  276. self.hCheckboxAutoHide = self.GUICtrlCreateCheckBox('', 215, 75)
  277. if int(config['wallet']['autohide']):
  278. self.hCheckboxAutoHide.setCheckState(2)
  279. self.hCheckboxAutoHideText = self.GUICtrlCreateLabel('Hide to tray on startup', 245, 80, 0, 0, 0, 0, '13px')
  280.  
  281. self.tabsControls[self.hButtonSettings.objectName()] = [self.hCheckboxStartup, self.hCheckboxStartupBk, self.hCheckboxText, self.hCheckboxTrayClose,
  282. self.hCheckboxTrayCloseBk, self.hCheckboxTrayCloseText, self.hCheckboxAutoHide, self.hCheckboxAutoHideBk, self.hCheckboxAutoHideText]
  283.  
  284. #Transactions TAB
  285. self.hTableTransactions = QTableWidget(100, 4, self)
  286. self.hTableTransactions.move(215, 15)
  287. self.hTableTransactions.setFixedSize(570, 200)
  288. self.hTableTransactions.setItem(1, 1, QTableWidgetItem('sounds aaa but aaaa'))
  289. self.hTableTransactions.verticalHeader().hide()
  290. self.hTableTransactions.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
  291. self.hTableTransactions.setHorizontalHeaderLabels(['Date', 'Tx hash', 'Amount', 'From address'])
  292. self.hTableTransactions.horizontalHeader().setSectionResizeMode(QHeaderView.Fixed)
  293. self.hTableTransactions.horizontalHeader().resizeSection(0, 50)
  294. #About TAB
  295. self.hLabelAbout = self.GUICtrlCreateLabel('''Galaxia GUI Wallet v1.0
  296.  
  297. Author: MrKris7100
  298.  
  299. Special thanks to njamnjam, MadHater, EMPEROR and other people from Galaxia team.
  300.  
  301. This program is not official part of Galaxia project.
  302. This program uses 3rd party applications: xi-daemon and xi-pgservice from Galaxia project.
  303.  
  304. If you enjoy the program you can support me by donating some GLX using button below.''', 215, 15, 0, 0, 0, 0, '11px')
  305. self.hButtonDonate = self.GUICtrlCreateButton('Donate', 215, 150, 75, 30)
  306.  
  307. self.tabsControls[self.hButtonAbout.objectName()] = [self.hLabelAbout, self.hButtonDonate]
  308.  
  309. self.tabsControls[self.hButtonHistory.objectName()] = [self.hTableTransactions]
  310.  
  311. for ctrl in self.tabsControls[self.hButtonAbout.objectName()]:
  312. ctrl.hide()
  313. for ctrl in self.tabsControls[self.hButtonReceive.objectName()]:
  314. ctrl.hide()
  315. for ctrl in self.tabsControls[self.hButtonSettings.objectName()]:
  316. ctrl.hide()
  317. for ctrl in self.tabsControls[self.hButtonHistory.objectName()]:
  318. ctrl.hide()
  319.  
  320. # Create the menu
  321. self.tray_menu = QMenu()
  322. self.tray_show = QAction("Show")
  323. self.tray_show.triggered.connect(self.tray_event)
  324. self.tray_exit = QAction("Exit")
  325. self.tray_exit.triggered.connect(self.tray_exit_proc)
  326. self.tray_menu.addAction(self.tray_show)
  327. self.tray_menu.addAction(self.tray_exit)
  328.  
  329. #Create tray icon
  330. self.tray_icon = QSystemTrayIcon()
  331. #add menu to tray
  332. self.tray_icon.setContextMenu(self.tray_menu)
  333. self.tray_icon.activated.connect(self.tray_event)
  334. #Set window and tray icon
  335. self.tray_icon.setIcon(QIcon(self.hLogoGreen))
  336. self.setWindowIcon(QIcon(self.hLogoGreen))
  337.  
  338. #Show window and tray icon
  339. if not (int(config['wallet']['autohide']) and '--autostart' in app.arguments()):
  340. self.show()
  341. self.tray_icon.show()
  342.  
  343. #Wallet initialization
  344. if not '--offline' in app.arguments():
  345. for ctrl in self.tabsControls['leftpanel']:
  346. ctrl.hide()
  347. for ctrl in self.tabsControls[self.hButtonSend.objectName()]:
  348. ctrl.hide()
  349.  
  350. #Wallet config if needed
  351. if Path(config['wallet']['path']).is_file():
  352. threading.Timer(0, self.WalletInit).start()
  353. self.hButtonCreate.hide()
  354. self.hButtonOpen.hide()
  355. self.hLabelTip.hide()
  356. else:
  357. self.hLabelInit.hide()
  358. else:
  359. self.hLabelLogo.hide()
  360. self.hLabelInit.hide()
  361. self.hButtonCreate.hide()
  362. self.hButtonOpen.hide()
  363. self.hLabelTip.hide()
  364. threading.Timer(0, self.WalletInit).start()
  365.  
  366. def eventFilter(self, obj, event):
  367. type = event.type()
  368. if type == 129:
  369. if obj == self.hButtonCreate:
  370. self.hLabelTip.setText('Create new wallet')
  371. elif obj == self.hButtonOpen:
  372. self.hLabelTip.setText('Open existing wallet')
  373. if type == 128 and (obj == self.hButtonCreate or obj == self.hButtonOpen):
  374. self.hLabelTip.setText('What you want to do?')
  375. return 0
  376.  
  377. def tray_exit_proc(self):
  378. self.exit_from_tray = True
  379. self.close()
  380.  
  381. def tray_event(self, reason):
  382. if reason == QSystemTrayIcon.DoubleClick or reason == QWidgetAction.Trigger:
  383. self.show()
  384. self.setWindowState(Qt.WindowNoState)
  385.  
  386. def UpdateWalletAddress(self):
  387. self.wallet_address = 'gxid1j832db198n28d21d' #Read here
  388. self.hInputWalletAddress.setText(self.wallet_address)
  389.  
  390. def GUICtrlCreateButton(self, text, left, top, width = 0, height = 0, background = 0, color = 0, fontsize = 0, fontweight = 0):
  391. button = QPushButton(text, self)
  392. self.ctrlCount += 1
  393. button.setObjectName(str(self.ctrlCount))
  394. if width: button.setFixedWidth(width)
  395. if height: button.setFixedHeight(height)
  396. button.move(left, top)
  397. button.type = 'QPushButton'
  398. button.myfontsize = fontsize if fontsize else '14px'
  399. button.myfontweight = fontweight if fontweight else 'bold'
  400. button.mybackgroundcolor = background if background else 'rgba(255, 255, 255, 10%)'
  401. button.mycolor = color if color else 'rgb(26, 188, 156)'
  402. button.myborder = 'none'
  403. button.myhoverbackgroundcolor = 'rgba(26, 188, 156, 50%)'
  404. button.myhovercolor = 'white'
  405. GUICtrlUpdateStyle(button)
  406. button.clicked.connect(self.button_proc)
  407. return button
  408.  
  409. def GUICtrlCreateCheckBox(self, text, left, top):
  410. checkbox = QCheckBox(text, self)
  411. self.ctrlCount += 1
  412. checkbox.setObjectName(str(self.ctrlCount))
  413. checkbox.move(left, top)
  414. checkbox.type = 'QCheckBox'
  415. checkbox.toggled.connect(self.checkbox_proc)
  416. return checkbox
  417.  
  418. def GUICtrlCreateBox(self, color, left, top, width, height):
  419. box = QLabel(self)
  420. box.move(left, top)
  421. box.setFixedSize(width, height)
  422. box.setStyleSheet('background-color: ' + color)
  423. box.setAlignment(Qt.AlignHCenter)
  424. box.setAlignment(Qt.AlignVCenter)
  425. return box
  426.  
  427. def GUICtrlCreateLabel(self, text, left, top, width = 0, height = 0, background = 0, color = 0, fontsize = 0, fontweight = 0):
  428. label = QLabel(text, self)
  429. self.ctrlCount += 1
  430. label.setObjectName(str(self.ctrlCount))
  431. if width: label.setFixedWidth(width)
  432. if height: label.setFixedHeight(height)
  433. label.move(left, top)
  434. label.type = 'QLabel'
  435. label.mywidth = str(width) if width else 'initial'
  436. label.myheight = str(height) if height else 'initial'
  437. label.myfontsize = fontsize if fontsize else '10px'
  438. label.myfontweight = fontweight if fontweight else 'bold'
  439. label.mybackgroundcolor = background if background else 'transparent'
  440. label.mycolor = color if color else 'rgb(26, 188, 156)'
  441. label.myborder = 'none'
  442. GUICtrlUpdateStyle(label)
  443. return label
  444.  
  445. def GUICtrlCreateInput(self, text, left, top, width, height, background = 0, color = 0, fontsize = 0, fontweight = 0):
  446. input = QLineEdit(self)
  447. self.ctrlCount += 1
  448. input.setObjectName(str(self.ctrlCount))
  449. input.move(left, top)
  450. input.type = 'QLineEdit'
  451. input.setFixedSize(width, height)
  452. input.myfontsize = fontisze if fontsize else '14px'
  453. input.myfontweight = fontweight if fontweight else 'bold'
  454. input.mybackgroundcolor = background if background else 'rgba(255, 255, 255, 10%)'
  455. input.mycolor = color if color else 'rgb(26, 188, 156)'
  456. input.myborder = 'none'
  457. GUICtrlUpdateStyle(input)
  458. input.setText(text)
  459. input.textChanged.connect(self.input_proc)
  460. input.editingFinished.connect(self.input_proc_end)
  461. return input
  462.  
  463. def XiNetworkSetState(self, iState, iPercent = 0):
  464. if iState != self.XiNetworkState:
  465. self.XiNetworkState = iState
  466. if iState == 0:
  467. GUICtrlSetColor(self.hLabelNetworkIcon, '#fc7c7c')
  468. GUICtrlSetColor(self.hLabelNetworkStatus, '#fc7c7c')
  469. self.hLabelNetworkStatus.setText("Disconnected")
  470. self.hLabelNetworkIcon.setPixmap(self.hLogoRed)
  471. elif iState == 1:
  472. GUICtrlSetColor(self.hLabelNetworkIcon, '#f7ff91')
  473. GUICtrlSetColor(self.hLabelNetworkStatus, '#f7ff91')
  474. self.hLabelNetworkStatus.setText("Syncing (" + '%.2f' % iPercent + "%)")
  475. self.hLabelNetworkIcon.setPixmap(self.hLogoYellow)
  476. elif iState == 2:
  477. GUICtrlSetColor(self.hLabelNetworkIcon, 'rgb(26, 188, 156)')
  478. GUICtrlSetColor(self.hLabelNetworkStatus, 'rgb(26, 188, 156)')
  479. self.hLabelNetworkStatus.setText("Synced")
  480. self.hLabelNetworkIcon.setPixmap(self.hLogoGreen)
  481. elif iState == 1:
  482. self.hLabelNetworkStatus.setText("Syncing (" + '%.2f' % iPercent + "%)")
  483.  
  484. def button_proc(self):
  485. obj = self.sender()
  486. if obj != self.activeTab:
  487. if obj in self.navButtons:
  488. GUICtrlSetBkColor(self.activeTab, 'rgba(255, 255, 255, 10%)')
  489. GUICtrlSetColor(self.activeTab, 'rgb(26, 188, 156)')
  490. for ctrl in self.tabsControls[self.activeTab.objectName()]:
  491. ctrl.hide()
  492. GUICtrlSetBkColor(obj, 'rgba(26, 188, 156, 50%)')
  493. GUICtrlSetColor(obj, 'white')
  494. for ctrl in self.tabsControls[obj.objectName()]:
  495. ctrl.show()
  496. self.activeTab = obj
  497. else:
  498. if obj == self.hButtonDonate:
  499. self.hInputAddress.setText(donate_address)
  500. self.hInputPaymentID.setText('DONATE')
  501. self.hButtonSend.click()
  502. elif obj == self.hButtonOpen:
  503. file_path = filedialog.askopenfilename(title='Select wallet file', filetypes=[('Wallet containers', '*.wallet')])
  504. if Path(file_path).is_file():
  505. config['wallet']['path'] = file_path
  506. with open("Wallet.ini", "w") as configfile:
  507. config.write(configfile)
  508. elif obj == self.hButtonCreate:
  509. random_container = randomString(10)
  510. config['wallet']['path'] = random_container + '.wallet'
  511. mnemonic_seed = randomWords(24)
  512. #Generate new wallet
  513. subprocess.Popen("xi-pgservice.exe -g -w " + config['wallet']['path'] + ' --mnemonic-seed "' + randomWords(24) + '"', creationflags = subprocess.CREATE_NO_WINDOW)
  514. with open("Wallet.ini", "w") as configfile:
  515. config.write(configfile)
  516. threading.Timer(0, self.WalletInit).start()
  517. self.hButtonCreate.hide()
  518. self.hButtonOpen.hide()
  519. self.hLabelTip.hide()
  520. elif obj == self.hButtonAmountAll and self.walletBalance > 0:
  521. self.hInputAmount.setText('%.6f' % float(self.walletBalance - 0.01))
  522. elif obj == self.hButtonWalletCopy:
  523. self.tkroot.clipboard_clear()
  524. self.tkroot.clipboard_append(self.wallet_address)
  525. elif obj == self.hButtonAddressPaste:
  526. self.hInputAddress.setText(self.tkroot.clipboard_get())
  527. elif obj== self.hButtonSendSend:
  528. sending = True
  529. if not self.valid_amount:
  530. self.controlBlink(self.hLabelAmountErr, 3, 0.15)
  531. sending = False
  532. if not self.valid_address:
  533. self.controlBlink(self.hLabelAddressErr, 3, 0.15)
  534. sending = False
  535. if sending:
  536. print('Yay! We can send!')
  537. return
  538.  
  539. def input_proc_end(self):
  540. obj = self.sender()
  541. if obj == self.hInputAmount:
  542. dot = find_str(obj.text(), '.')
  543. 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()))
  544.  
  545. def input_proc(self):
  546. obj = self.sender()
  547. if obj == self.hInputAmount:
  548. self.valid_amount = False
  549. dot = find_str(obj.text(), '.')
  550. if dot >= 0 and len(obj.text()) > 7 + dot:
  551. self.hLabelAmountErr.setText('Invalid amount')
  552. elif not ValidAmount(obj.text()):
  553. self.hLabelAmountErr.setText('Invalid amount')
  554. elif obj.text() == '' or float(obj.text()) == 0 :
  555. self.hLabelAmountErr.setText('Please enter amount')
  556. elif float(obj.text()) + 0.01 > self.walletBalance:
  557. self.hLabelAmountErr.setText('Not enought founds')
  558. else:
  559. self.hLabelAmountErr.setText('')
  560. self.valid_amount = True
  561. if self.valid_amount:
  562. GUICtrlSetBkColor(self.hInputAmount, 'rgba(255, 255, 255, 10%)')
  563. else:
  564. GUICtrlSetBkColor(self.hInputAmount, 'rgba(255, 0, 0, 15%)')
  565. elif obj == self.hInputAddress:
  566. #Checking typed address
  567. self.valid_address = False
  568. if obj.text() == '': #Not entered
  569. self.hLabelAddressErr.setText('Please enter address')
  570. elif len(obj.text()) != 98: #Too short
  571. self.hLabelAddressErr.setText('Invalid address')
  572. elif obj.text()[0:3] != 'gxi': #Not valid - no prefix
  573. self.hLabelAddressErr.setText('Invalid address')
  574. else:
  575. self.hLabelAddressErr.setText('')
  576. self.valid_address = True
  577. if self.valid_address:
  578. GUICtrlSetBkColor(self.hInputAddress, 'rgba(255, 255, 255, 10%)')
  579. else:
  580. GUICtrlSetBkColor(self.hInputAddress, 'rgba(255, 0, 0, 15%)')
  581. return
  582.  
  583. def checkbox_proc(self):
  584. obj = self.sender()
  585. if obj == self.hCheckboxStartup:
  586. config['wallet']['autostart'] = str(int(obj.isChecked()))
  587. elif obj == self.hCheckboxTrayClose:
  588. config['wallet']['trayclose'] = str(int(obj.isChecked()))
  589. elif obj == self.hCheckboxAutoHide:
  590. config['wallet']['autohide'] = str(int(obj.isChecked()))
  591. #Update config file
  592. with open("Wallet.ini", "w") as configfile:
  593. config.write(configfile)
  594.  
  595. def controlBlink(self, ctrl, times = 5, delay = 0.1):
  596. threading.Timer(0, blinkProc, args=[ctrl, times, delay]).start()
  597.  
  598. def XiNetworkUpdate(self):
  599. nodeSync, networkSync = 0, 0
  600. nodeInfo = GetNodeInfo()
  601. nodeSync = nodeInfo['result']['chain']['top_height']
  602. networkSync = nodeInfo['result']['p2p']['height']
  603. print(str(nodeSync) + '/' + str(networkSync))
  604. if networkSync and networkSync > 1:
  605. if nodeSync < networkSync:
  606. self.XiNetworkSetState(1, nodeSync / networkSync * 100)
  607. else:
  608. self.XiNetworkSetState(2)
  609. else:
  610. self.XiNetworkSetState(0)
  611. walletInfo = GetWalletBalance()
  612. self.walletBalance = walletInfo['result']['available_balance'] / 1000000
  613. self.walletBalanceLocked = walletInfo['result']['locked_amount'] / 1000000
  614. self.UpdateBalance()
  615. self.timer = threading.Timer(2.5, self.XiNetworkUpdate)
  616. self.timer.start()
  617.  
  618. def WalletInit(self):
  619. if not '--offline' in app.arguments():
  620. self.hLabelInit.show()
  621. if not ProcessExists("xi-daemon"):
  622. self.xi_daemon = subprocess.Popen("xi-daemon --p2p-local-ip --rpc-server --block-explorer-enable --network Galaxia.MainNet", creationflags = subprocess.CREATE_NO_WINDOW)
  623. time.sleep(2)
  624. if not ProcessExists("xi-pgservice"):
  625. subprocess.Popen("xi-pgservice.exe --log-level 0 -w " + config['wallet']['path'] + " --rpc-legacy-security --network Galaxia.MainNet", creationflags = subprocess.CREATE_NO_WINDOW)
  626. time.sleep(2)
  627. self.UpdateWalletAddress()
  628. self.UpdateBalance()
  629. self.hLabelLogo.hide()
  630. self.hLabelInit.hide()
  631. self.hButtonCreate.hide()
  632. for ctrl in self.tabsControls['leftpanel']:
  633. ctrl.show()
  634. for ctrl in self.tabsControls[self.hButtonSend.objectName()]:
  635. ctrl.show()
  636.  
  637. def UpdateBalance(self):
  638. self.hLabelBalanceValue.setText('%.6f' % self.walletBalance)
  639. self.hLabelBalanceLockedValue.setText('%.6f' % self.walletBalanceLocked)
  640.  
  641. style = '''
  642. QHeaderView::section {
  643. background-color: transparent;
  644. color: white;
  645. padding-left: 4px;
  646. border: 1px solid rgb(26, 188, 156);
  647. }
  648. QHeaderView {
  649. background-color: rgba(255, 255, 255, 10%);
  650. }
  651. QHeaderView::section:checked
  652. {
  653. background-color: transparent;
  654. }
  655. QTableWidget {
  656. gridline-color: rgb(26, 188, 156);
  657. background-color: rgba(255, 255, 255, 10%);
  658. border: 1px solid rgb(26, 188, 156);
  659. color: rgb(26, 188, 156)
  660. }
  661. QCheckBox {
  662. background-color: transparent;
  663. color: rgb(26, 188, 156);
  664. width: 25px;
  665. height: 25px;
  666. font-size: 12px;
  667. }
  668. QCheckBox::indicator {
  669. width: 25px;
  670. height: 25px;
  671. background-color: transparent;
  672. }
  673. QCheckBox::indicator:checked {
  674. margin: 7.5px 7.5px 7.5px 7.5px;
  675. width: 10px;
  676. height: 10px;
  677. background-color: rgb(26, 188, 156);
  678. }
  679. QCheckBox::indicator:unchecked {
  680. width: 25px;
  681. height: 25px;
  682. }
  683. '''
  684.  
  685. if __name__ == '__main__':
  686. donate_address = 'gxi16HXcDn89QD2idxs1ALibWfSLkTZtLe2PWsVU43sJYSvEC3WNcfed2yRFPdMtw57u1W9BemT4ZhujHhs98gZxAZ7tqDm1Yd'
  687. config = configparser.ConfigParser()
  688. #Initial config
  689. if not Path("Wallet.ini").is_file():
  690. newwallet = True
  691. trayclose = 0
  692. autostart = 0
  693. autohide = 0
  694. with open("Wallet.ini", "w") as configfile:
  695. config['wallet'] = {'path' : '', 'trayclose' : trayclose, 'autostart' : autostart, 'autohide' : autohide}
  696. config.write(configfile)
  697. #~~~~~~~~~~~~~~ dodac sprawdzanie istnienia pliku portfela
  698. config.read("Wallet.ini")
  699. app = QApplication(sys.argv)
  700. app.setStyleSheet(style)
  701. ex = App()
  702. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement