wallet_selector.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # GPL3 or any later version
  2. import os
  3. import gi
  4. import threading
  5. gi.require_version('Gtk', '3.0')
  6. from gi.repository import Gtk
  7. from gi.repository import Gdk
  8. from gi.repository import GLib
  9. from modules import wallet
  10. from modules import ui
  11. def refresh_wallets(box, wallets, win):
  12. for i in box.get_children():
  13. i.destroy()
  14. wallets_box = Gtk.VBox()
  15. for i in wallets:
  16. wallet_button = Gtk.Button()
  17. button_box = Gtk.HBox()
  18. wallet_button.add(button_box)
  19. button_box.pack_start(ui.icon(win, "x-office-presentation"), 0,0,0)
  20. button_box.pack_start(Gtk.Label(i), 1,1,5)
  21. wallet_button.set_relief(Gtk.ReliefStyle.NONE)
  22. def choose(w, win, name):
  23. win.wallet = name
  24. win.destroy()
  25. wallet_button.connect("clicked", choose, win, i)
  26. box.pack_start(wallet_button, 0,0,0)
  27. box.show_all()
  28. def select_wallet():
  29. win = Gtk.Window()
  30. win.connect("destroy", Gtk.main_quit)
  31. win.set_title("J.Y.Transactions")
  32. win.set_default_icon_from_file("icon_small.png")
  33. win.set_size_request(300, 300)
  34. box = Gtk.VBox()
  35. win.add(box)
  36. pannel = Gtk.HeaderBar()
  37. pannel.set_show_close_button(True)
  38. win.set_titlebar(pannel)
  39. # Let's get list of wallets
  40. wallets = wallet.get_list()
  41. # Adding menu
  42. add_menu = Gtk.Popover()
  43. add_box = Gtk.VBox()
  44. add_menu.add(add_box)
  45. add_name = Gtk.Entry()
  46. add_box.pack_start(add_name, 0,0,0)
  47. add_do = Gtk.Button("Add Wallet")
  48. add_do.set_relief(Gtk.ReliefStyle.NONE)
  49. add_box.pack_start(add_do, 0,0,0)
  50. def add_wallet_function(w):
  51. add_menu.hide()
  52. folder = wallet.save_folder()+"wallets/"+add_name.get_text()
  53. try:
  54. os.makedirs(folder)
  55. except:
  56. pass
  57. wallets = wallet.get_list()
  58. refresh_wallets(box, wallets, win)
  59. add_do.connect("clicked", add_wallet_function)
  60. add_name.connect("activate", add_wallet_function)
  61. add_box.show_all()
  62. # Adding button
  63. add_button = Gtk.MenuButton(popover=add_menu)
  64. add_button.set_relief(Gtk.ReliefStyle.NONE)
  65. add_button.add(ui.icon(win, "list-add"))
  66. add_button.set_tooltip_text("Add Wallet")
  67. pannel.pack_start(add_button)
  68. pannel.pack_start(Gtk.Label("Select Wallet"))
  69. if not wallets:
  70. box.pack_start(Gtk.Label("You have no wallets yet."), 1,1,1)
  71. else:
  72. refresh_wallets(box, wallets, win)
  73. win.wallet = False
  74. win.show_all()
  75. Gtk.main()
  76. return win.wallet