Advertisement
bezeee

PyQtResizeWebkit

Jul 22nd, 2011
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.80 KB | None | 0 0
  1. import sys
  2.  
  3. from PyQt4.QtCore import *
  4. from PyQt4.QtGui import *
  5. from PyQt4.QtWebKit import *
  6.  
  7.  
  8. HTML = """
  9. <html>
  10.  <head>
  11.      <script type="text/javascript"
  12.              src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  13.      <script type="text/javascript"
  14.              src="http://brianz.s3.amazonaws.com/jquery.flot.min.js"></script>
  15.      <style type="text/css">
  16.        #foo {
  17.            border: 1px solid black;
  18.            width: 20px;
  19.            height: 20px;
  20.            margin: 10px auto;
  21.        }
  22.      </style>
  23.  </head>
  24.  <body>
  25.  
  26.    <div id="foo" style="width:600px;height:300px;"></div>
  27.  
  28.    <script type="text/javascript">
  29.  
  30.        var doPlot = function() {
  31.            var d1 = [];
  32.            for (var i = 0; i < 14; i += 0.5)
  33.                d1.push([i, Math.sin(i)]);
  34.  
  35.            var d2 = [[0, 3], [4, 8], [8, 5], [9, 13]];
  36.  
  37.            // a null signifies separate line segments
  38.            var d3 = [[0, 12], [7, 12], null, [7, 2.5], [12, 2.5]];
  39.  
  40.            $.plot($("#foo"), [ d1, d2, d3 ]);
  41.        };
  42.  
  43.        var resizeSlot = function() {
  44.            var width = $(window).width(),
  45.                height = $(window).height();
  46.            $("#foo").css('height', height * 0.50)
  47.                     .css("width", width * 0.90);
  48.            // Commenting this out eliminates the Painter warnings
  49.            doPlot();
  50.         };
  51.  
  52.        $(window).resize(resizeSlot);
  53.  
  54.        // Initial draw of the plot
  55.        doPlot();
  56.  
  57.    </script>
  58.  </body>
  59. </html>
  60. """
  61.  
  62.  
  63. def main():
  64.     app = QApplication(sys.argv)
  65.  
  66.     webView = QWebView()
  67.     webView.setHtml(HTML)
  68.     window = QMainWindow()
  69.     window.setCentralWidget(webView)
  70.     window.show()
  71.  
  72.     sys.exit(app.exec_())
  73.  
  74. if __name__ == "__main__":
  75.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement