error_notify.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ####################################
  2. # #
  3. # COPYRIGHT NOTICE #
  4. # #
  5. # This file is a part of Victori- #
  6. # ous Children Studio Organizer. #
  7. # Or simply VCStudio. Copyright #
  8. # of J.Y.Amihud. But don't be sad #
  9. # because I released the entire #
  10. # project under a GNU GPL license. #
  11. # You may use Version 3 or later. #
  12. # See www.gnu.org/licenses if your #
  13. # copy has no License file. Please #
  14. # note. Ones I used the GPL v2 for #
  15. # it. It's no longer the case. #
  16. # #
  17. ####################################
  18. import os
  19. import sys
  20. import traceback
  21. from settings import oscalls
  22. # We gonna have this show run when ever any mistake is caught when running
  23. # the UI. The concept is to give users an easy to understand UI message what
  24. # an arror had happened.
  25. # The main problem is that if the UI is not loading it will give an error
  26. # too. Meaning that we need to deal with this kind of error too.
  27. def show():
  28. # Printing the message of the python error
  29. message = str(traceback.format_exc())
  30. print(message)
  31. # Parsing the message to get the filename of the last file that had
  32. # an issue. Hope you know a better way of doing it. I spent a whole
  33. # day trying to come up with a way.
  34. Filename = "run.py"
  35. for i in message.split("\n"):
  36. if 'File "' in i:
  37. Filename = i[i.find('"')+1:i.replace('"'," ",1).find('"')]
  38. # trying to do this with a window
  39. try:
  40. from gi.repository import Gtk
  41. # If we are able to access the
  42. dialogWindow = Gtk.MessageDialog(
  43. #transient_for=self,
  44. flags=0,
  45. message_type=Gtk.MessageType.WARNING,
  46. buttons=("Edit Source",1, "Report Bug", 2, "Ignore", 3),
  47. text="BUG :(\n\n"+message,
  48. )
  49. response = dialogWindow.run()
  50. # Now we want to do something with what the user decides.
  51. if response == 1:
  52. oscalls.Open(Filename) # Edit source open the error file in
  53. # the text editor
  54. elif response == 2:
  55. oscalls.Open("https://notabug.org/jyamihud/VCStudio/issues")
  56. dialogWindow.destroy()
  57. except:
  58. raise