data_view.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #####################################################################
  2. # #
  3. # THIS IS A SOURCE CODE FILE FROM A PROGRAM TO INTERACT WITH THE #
  4. # LBRY PROTOCOL ( lbry.com ). IT WILL USE THE LBRY SDK ( lbrynet ) #
  5. # FROM THEIR REPOSITORY ( https://github.com/lbryio/lbry-sdk ) #
  6. # WHICH I GONNA PRESENT TO YOU AS A BINARY. SINCE I DID NOT DEVELOP #
  7. # IT AND I'M LAZY TO INTEGRATE IN A MORE SMART WAY. THE SOURCE CODE #
  8. # OF THE SDK IS AVAILABLE IN THE REPOSITORY MENTIONED ABOVE. #
  9. # #
  10. # ALL THE CODE IN THIS REPOSITORY INCLUDING THIS FILE IS #
  11. # (C) J.Y.Amihud and Other Contributors 2021. EXCEPT THE LBRY SDK. #
  12. # YOU CAN USE THIS FILE AND ANY OTHER FILE IN THIS REPOSITORY UNDER #
  13. # THE TERMS OF GNU GENERAL PUBLIC LICENSE VERSION 3 OR ANY LATER #
  14. # VERSION. TO FIND THE FULL TEXT OF THE LICENSE GO TO THE GNU.ORG #
  15. # WEBSITE AT ( https://www.gnu.org/licenses/gpl-3.0.html ). #
  16. # #
  17. # THE LBRY SDK IS UNFORTUNATELY UNDER THE MIT LICENSE. IF YOU ARE #
  18. # NOT INTENDING TO USE MY CODE AND JUST THE SDK. YOU CAN FIND IT ON #
  19. # THEIR OFFICIAL REPOSITORY ABOVE. THEIR LICENSE CHOICE DOES NOT #
  20. # SPREAD ONTO THIS PROJECT. DON'T GET A FALSE ASSUMPTION THAT SINCE #
  21. # THEY USE A PUSH-OVER LICENSE, I GONNA DO THE SAME. I'M NOT. #
  22. # #
  23. # THE LICENSE CHOSEN FOR THIS PROJECT WILL PROTECT THE 4 ESSENTIAL #
  24. # FREEDOMS OF THE USER FURTHER, BY NOT ALLOWING ANY WHO TO CHANGE #
  25. # THE LICENSE AT WILL. SO NO PROPRIETARY SOFTWARE DEVELOPER COULD #
  26. # TAKE THIS CODE AND MAKE THEIR USER-SUBJUGATING SOFTWARE FROM IT. #
  27. # #
  28. #####################################################################
  29. from gi.repository import Gtk
  30. def populate_dict(treeStore, data, parent=None):
  31. # This will take a dictionary and populate a tree out of it.
  32. if type(data) in [list, tuple]:
  33. # Inspired by the Json visualizer of Firefox
  34. newvalue = {}
  35. for n, i in enumerate(data):
  36. newvalue[n] = i
  37. data = newvalue
  38. for key in data:
  39. value = data[key]
  40. if not type(value) in [dict, list, tuple]:
  41. putvalue = str(value)
  42. else:
  43. putvalue = None
  44. currentIter = treeStore.append(parent, [str(key),putvalue])
  45. if type(value) in [dict, list, tuple]:
  46. populate_dict(treeStore, value, currentIter)
  47. def data_widget(data):
  48. # This will create and return a treeview object
  49. data_tree_store = Gtk.TreeStore(str, str)
  50. populate_dict(data_tree_store, data)
  51. data_tree_view = Gtk.TreeView(data_tree_store)
  52. key_column = Gtk.TreeViewColumn("Category")
  53. text_col = Gtk.CellRendererText()
  54. text_col.set_property("editable", True)
  55. key_column.pack_start(text_col, True)
  56. key_column.add_attribute(text_col, "text", 0)
  57. data_tree_view.append_column(key_column)
  58. value_column = Gtk.TreeViewColumn("Information")
  59. text_col = Gtk.CellRendererText()
  60. text_col.set_property("editable", True)
  61. value_column.pack_start(text_col, True)
  62. value_column.add_attribute(text_col, "text", 1)
  63. data_tree_view.append_column(value_column)
  64. return data_tree_view