settings.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # GPL3 or any later version
  2. import os
  3. import json
  4. import time
  5. import gi
  6. import threading
  7. gi.require_version('Gtk', '3.0')
  8. from gi.repository import Gtk
  9. from gi.repository import Gdk
  10. from gi.repository import GLib
  11. from modules import wallet
  12. from modules import totals
  13. def dialog(win):
  14. # This is the settings window
  15. dialogWindow = Gtk.Dialog("Settings",
  16. buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
  17. Gtk.STOCK_OK, Gtk.ResponseType.OK),
  18. )
  19. dialogWindow.set_size_request(400, 400)
  20. box = dialogWindow.get_content_area()
  21. data = wallet.get_totals(win.wallet)
  22. # Curranty
  23. def on_currancy(w):
  24. data["currancy"] = w.get_text()
  25. ebox = Gtk.HBox()
  26. ebox.pack_start(Gtk.Label("Currancy:"), 0,0,5)
  27. box.pack_start(ebox, 0,0,5)
  28. currancy_entry = Gtk.Entry()
  29. currancy_entry.connect("changed", on_currancy)
  30. currancy_entry.set_text(data.get("currancy", "$"))
  31. ebox.pack_end(currancy_entry, 0,0,5)
  32. # Payday
  33. def on_payday(w):
  34. data["payday"] = int(w.get_value())
  35. ebox = Gtk.HBox()
  36. ebox.pack_start(Gtk.Label("Payday: Every month at"), 0,0,5)
  37. box.pack_start(ebox, 0,0,5)
  38. payday_adjust = Gtk.Adjustment(data.get("payday", 10),
  39. lower=1,
  40. upper=28,
  41. step_increment=1)
  42. payday_entry = Gtk.SpinButton(adjustment=payday_adjust,
  43. digits=0)
  44. payday_entry.connect("changed", on_payday)
  45. ebox.pack_end(payday_entry, 0, 0, 5)
  46. box.show_all()
  47. response = dialogWindow.run()
  48. if response == Gtk.ResponseType.OK:
  49. wallet.save_totals(win.wallet, data)
  50. totals.update_totals(win)
  51. dialogWindow.destroy()