redak.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #! /usr/bin/env python
  2. # #ident "$Id: $"
  3. # @author: rzr@gna.org - rev: $Author: rzr$
  4. # Copyright: See README file that comes with this distribution
  5. ################################################################################
  6. # -*- encoding: iso-8859-15 -*-
  7. import sys
  8. import PySide
  9. from PySide import QtCore
  10. from PySide.QtCore import QObject, QUrl, QProcess
  11. from PySide.QtGui import QApplication
  12. from PySide.QtDeclarative import QDeclarativeView,QDeclarativeEngine
  13. from PySide.QtCore import Signal as pyqtSignal
  14. from PySide.QtCore import Slot as pyqtSlot
  15. __package__ = 'redak'
  16. __author__ = 'Philippe Coval (RzR)'
  17. __email__ = 'rzr@gna.org'
  18. __version__ = '0.0.0'
  19. class Redak(QDeclarativeView):
  20. contentChanged = pyqtSignal(str)
  21. def __init__(self, parent=None):
  22. platform = 'common'
  23. platform = 'desktop'
  24. src = 'qml/redak/' + platform + '/main.qml'
  25. super(Redak, self).__init__(parent)
  26. self.setWindowTitle(__package__)
  27. self.setSource(QUrl.fromLocalFile(src))
  28. self.setResizeMode(QDeclarativeView.SizeRootObjectToView)
  29. self.setGeometry(200, 200, 400, 400)
  30. # self.showFullScreen()
  31. root = self.rootObject()
  32. root.quit.connect( self.quit )
  33. root.test.connect( self.test )
  34. self.rootContext().setContextProperty("parentCore", self);
  35. print "http://bugs.pyside.org/show_bug.cgi?id=1000"
  36. # self.contentChanged.connect( self.slotContent );
  37. # self.contentChanged.connect( root.onContentChanged );
  38. # self.contentChanged.connect( root.handleContent );
  39. def quit(self):
  40. # print "quitting"
  41. self.rootContext().setContextProperty("parentCore", None );
  42. PySide.QtCore.QCoreApplication.quit()
  43. def test(self):
  44. # print "Testing emit"
  45. content = "content"
  46. print "Content: " + content
  47. self.contentChanged.emit( content )
  48. return content;
  49. @QtCore.Slot(unicode,result=unicode)
  50. def process(self,command):
  51. # print "process"
  52. content = "content"
  53. process = QProcess()
  54. process.start(command)
  55. process.closeWriteChannel()
  56. process.waitForFinished()
  57. # process.closeWriteChannel()
  58. content = process.readAllStandardOutput()
  59. print "Content: " + content
  60. return unicode(content);
  61. @QtCore.Slot(unicode,result=unicode)
  62. def load(self,command):
  63. return "todo"
  64. @QtCore.Slot(unicode,unicode,result=bool)
  65. def save(self,content,filename):
  66. return false
  67. @QtCore.Slot(str)
  68. def slotContent(self,content):
  69. print "#{ slotContent"
  70. root = self.rootObject()
  71. root.handleContent(content)
  72. print content
  73. @staticmethod
  74. def main(argv):
  75. if len(argv) > 1:
  76. print PySide.QtCore.qVersion()
  77. app = QApplication(argv)
  78. view = Redak()
  79. view.show()
  80. sys.exit(app.exec_())
  81. if __name__ == "__main__":
  82. Redak.main(sys.argv)
  83. #eof