main_window.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 totals
  11. from modules import transactions
  12. from modules import items
  13. from modules import merchants
  14. from modules import ui
  15. from modules import settings
  16. def show_main_window(the_wallet):
  17. # Shows the main window
  18. win = Gtk.Window()
  19. win.wallet = the_wallet
  20. win.connect("destroy", Gtk.main_quit)
  21. win.set_title("J.Y.Transactions")
  22. win.set_default_icon_from_file("icon_small.png")
  23. win.set_size_request(400, 400)
  24. win.maximize()
  25. box = Gtk.VBox()
  26. win.add(box)
  27. pannel = Gtk.HeaderBar()
  28. pannel.set_show_close_button(True)
  29. win.set_titlebar(pannel)
  30. # Adding button
  31. add_button = Gtk.Button()
  32. add_button.set_relief(Gtk.ReliefStyle.NONE)
  33. add_button.add(ui.icon(win, "list-add"))
  34. add_button.set_tooltip_text("Add Transaction")
  35. pannel.pack_start(add_button)
  36. def on_add(w):
  37. transactions.add(win)
  38. add_button.connect("clicked", on_add)
  39. # Folder button
  40. folder_button = Gtk.Button()
  41. folder_button.set_relief(Gtk.ReliefStyle.NONE)
  42. folder_button.add(ui.icon(win, "folder"))
  43. folder_button.set_tooltip_text("Files")
  44. pannel.pack_end(folder_button)
  45. def on_folder(w):
  46. folder = wallet.save_folder()
  47. os.system("xdg-open "+folder)
  48. folder_button.connect("clicked", on_folder)
  49. # Settings button
  50. folder_button = Gtk.Button()
  51. folder_button.set_relief(Gtk.ReliefStyle.NONE)
  52. folder_button.add(ui.icon(win, "preferences-system"))
  53. folder_button.set_tooltip_text("Settings")
  54. pannel.pack_end(folder_button)
  55. def on_settings(w):
  56. settings.dialog(win)
  57. folder_button.connect("clicked", on_settings)
  58. # Notebook
  59. notebook = Gtk.Notebook()
  60. notebook.set_scrollable(True)
  61. box.pack_start(notebook, 1,1,1)
  62. # Totals
  63. win.totals_box = Gtk.VBox()
  64. totals.update_totals(win)
  65. detailsbox = Gtk.HBox()
  66. detailsbox.pack_start(Gtk.Label(" Totals "), True, True, True)
  67. detailsbox.show_all()
  68. notebook.append_page(win.totals_box, detailsbox)
  69. # Transactions
  70. scrl = Gtk.ScrolledWindow()
  71. win.transactions_box = Gtk.VBox()
  72. scrl.add(win.transactions_box)
  73. transactions.update_transactions(win)
  74. detailsbox = Gtk.HBox()
  75. detailsbox.pack_start(Gtk.Label(" Transactions "), True, True, True)
  76. detailsbox.show_all()
  77. notebook.append_page(scrl, detailsbox)
  78. # Items
  79. def on_item(w, win, item):
  80. items.editor(win, item)
  81. items.refresh_items(*refreshpack)
  82. win.items_box = Gtk.VBox()
  83. refreshpack = items.select_widget(win, win.items_box, on_item)
  84. detailsbox = Gtk.HBox()
  85. detailsbox.pack_start(Gtk.Label(" Items "), True, True, True)
  86. detailsbox.show_all()
  87. notebook.append_page(win.items_box, detailsbox)
  88. # Merchants
  89. def on_merchant(w, win, item):
  90. merchants.editor(win, item)
  91. merchants.refresh_items(*merchants_refreshpack)
  92. win.merchants_box = Gtk.VBox()
  93. merchants_refreshpack = merchants.select_widget(win, win.merchants_box, on_merchant)
  94. detailsbox = Gtk.HBox()
  95. detailsbox.pack_start(Gtk.Label(" Merchants "), True, True, True)
  96. detailsbox.show_all()
  97. notebook.append_page(win.merchants_box, detailsbox)
  98. pannel.pack_start(Gtk.Label(the_wallet))
  99. win.show_all()
  100. Gtk.main()