log_dialog.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/python3
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2012 Agnieszka Kostrzewa <agnieszka.kostrzewa@gmail.com>
  6. # Copyright (C) 2012 Marek Marczykowski <marmarek@mimuw.edu.pl>
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public License along
  19. # with this program; if not, see <http://www.gnu.org/licenses/>.
  20. #
  21. #
  22. from PyQt4 import QtCore
  23. from PyQt4 import QtGui
  24. from . import ui_logdlg
  25. from . import clipboard
  26. # Display only this size of log
  27. LOG_DISPLAY_SIZE = 1024*1024
  28. class LogDialog(ui_logdlg.Ui_LogDialog, QtGui.QDialog):
  29. def __init__(self, app, log_path, parent=None):
  30. super(LogDialog, self).__init__(parent)
  31. self.app = app
  32. self.log_path = log_path
  33. self.setupUi(self)
  34. self.setWindowTitle(log_path)
  35. self.connect(self.copy_to_qubes_clipboard,
  36. QtCore.SIGNAL("clicked()"),
  37. self.copy_to_qubes_clipboard_triggered)
  38. self.__init_log_text__()
  39. def __init_log_text__(self):
  40. self.displayed_text = ""
  41. log = open(self.log_path)
  42. log.seek(0, clipboard.os.SEEK_END)
  43. if log.tell() > LOG_DISPLAY_SIZE:
  44. self.displayed_text = self.tr(
  45. "(Showing only last %d bytes of file)\n") % LOG_DISPLAY_SIZE
  46. log.seek(-LOG_DISPLAY_SIZE, clipboard.os.SEEK_END)
  47. else:
  48. log.seek(0, clipboard.os.SEEK_SET)
  49. self.displayed_text += log.read()
  50. log.close()
  51. self.log_text.setPlainText(self.displayed_text)
  52. def copy_to_qubes_clipboard_triggered(self):
  53. clipboard.copy_text_to_qubes_clipboard(self.displayed_text)