Pyton2.7 GTK webkit enable hardware acceleration - python-2.7

I'm working on some python2.7 widgets for a Digital signage using GTK and webkit and I was wondering How can I enable 2d hardware acceleration?
I'm running Raspbian OS.
import gtk
import webkit
import time
view = webkit.WebView()
sw = gtk.ScrolledWindow()
sw.add(view)
time.sleep(4)
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
win.set_default_size(400, 896)
win.set_decorated(0)
win.add(sw)
win.move(1920, 72)
win.show_all()
view.open("http://yahoo.com")
gtk.main()

Python 3.7 webkit2 was the solution, It looks like the WebKit API for python 2.7 is obsolete.

Related

import Qt ui to Maya2020

Last week I started learning Python for Maya, following the 'CGCircuit - Learn Python Inside Maya'.
Now I'm trying to make a simple UI for Maya2020 using Qt. The tutorial itself is pretty outdated, a lot has changed since Maya2015.
I checked a lot of forums and it seems I’m not the only one having problems. This is what I learned so far:
Qt designer is not a part of Maya anymore, so I downloaded Qt Creator 4.14.0 (Community)
I used pip to install: shiboken2-5.15.2-5.15.2-cp35.cp36.cp37.cp38.cp39-none-win_amd64.whl
If I'm correct, Maya2020 has Pyside2 pr-installed, but I also Installed Pyside2 on Windows10
QtGui.QDialog is replaced by QWidget
Currently I ‘m using Python 2.7.17 on my Windows system, but I also have Python3.8 available in my Environment Variable
When I call the py script inside Maya, like this:
import geomGenerator
reload(geomGenerator)
geomGenerator.getMayaWindow()
geomGenerator.run()
I get this error:
Error: NameError: file C:/Users/12213119/Documents/maya/2020/scripts\geomGenerator.py line 12: global name 'shiboken2' is not defined #
Not sure what this means or how I can solve it. I looked all over the internet, please let me know what I'm doing wrong. Thx in regard.
from PySide2 import QtGui, QtCore, QtUiTools, QtWidgets
from shiboken2 import wrapInstance
import maya.cmds as mc
import maya.OpenMayaUI as omui
def getMayaWindow():
""" pointer to the maya main window
"""
ptr = omui.MQtUtil.mainWindow()
if ptr is not None:
return shiboken2.wrapInstance2(long(ptr), QtWidgets.QWidget)
def run():
""" builds our UI
"""
global win
win = GeometryGenerator(parent=getMayaWindow())
win.show()
class GeometryGenerator(QtWidgets.QWidget):
def __init__(self,parent=None):
super(GeometryGenerator,self).__init__(parent)
I guess you need to run you script with python that comes with Maya, and use pip that comes with maya to install packages.

python 2.7 / pyqt5 and pyinstaller : sip module error

after trying pyqt5 with python3.+ i had some problems with the code than i used python2.7 + pyqt5(for python2.7) and everything worked fine from pycharm and when i run the script from cmd.
now the problem with pyinstaller
pyqt4 / python 2.7 : pyinstaller compile the script and worked fine
pyqt5 / python 2.7 : pyinstaller compile the script but don't work and i capture an error that no module named sip.
the last version of sip 4.19 available only for python3.
if add : import sip to the code i see another error message :
application faild to start because it could not find or load th Qt platform plugin "windows"
all these versions the same problem :
python 2.7.1 / python 2.7.9 / anaconda(python2.7) / winpython(python2.7)
the code :
import sys
import sip
from PyQt5 import QtWidgets
app = QtWidgets.QApplication(sys.argv)
button = QtWidgets.QPushButton("Hello")
button.setFixedSize(100, 50)
button.show()
app.exec_()

kivy gives 'Unable to get a Window'

I installed kivy on my Window 7, Python 2.7. When I run the following code:
import kivy
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
def build(self):
return Label(text='Hello World!')
if __name__ == '__main__':
MyApp().run()
it gives the following error:
Unable to get a Window, abort.
I tried on Python 3.4, same error.
There is an option that sdl2 can't find dlls needed to load *.png
Try to find libpng16-16.dll
on my PC is here: C:\Python27\share\gstreamer\bin
Add it to PATH
set PATH=C:\Python27\share\gstreamer\bin;%PATH%
This is temporary solution but it works for me
If you use Windows 10 then you may have two windows 10 installed on that same laptop which then has made it difficult for Python, Kivy and Kivmd to find the Windows to execute the program with so it gives an error.
That is why this commonly happens to partitioned laptops so check your laptop again to know how many windows are installed and delete one of the windows or you can also format your laptop properly to solve these issues. In my case my laptop was formatted.

matplotlib plots do not show on Anaconda for Linux

I've read these and tried the solutions but still not getting anything to show:
matplotlib show nothing although i called show
Why doesn't pyplot.show() work? [duplicate]
matplotlib does not show my drawings although I call pyplot.show()
I'm using Python 2.7.6 |Anaconda 1.9.0 (64-bit) on Ubuntu 12.04.
How can I go about diagnosing the problem and trying to solve it?
EDIT:
-First I edited matplotlibrc and change the backend to GtkAgg (was set to QtAgg).
-Then I tried to change the backend via code: matplotlib.rcParams['backend'] = "GtkAgg"
EDIT2 - adding detail from the Spyder console (no plot is shown at the end):
Python 2.7.6 |Anaconda 1.9.0 (64-bit)| (default, Jan 17 2014, 10:13:17)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Imported NumPy 1.8.0, SciPy 0.13.3, Matplotlib 1.3.1
Type "scientific" for more details.
>>> scientific
This is a standard Python interpreter with preloaded tools for scientific
computing and visualization. It tries to import the following modules:
>>> import numpy as np # NumPy (multidimensional arrays, linear algebra, ...)
>>> import scipy as sp # SciPy (signal and image processing library)
>>> import matplotlib as mpl # Matplotlib (2D/3D plotting library)
>>> import matplotlib.pyplot as plt # Matplotlib's pyplot: MATLAB-like syntax
>>> from pylab import * # Matplotlib's pylab interface
>>> ion() # Turned on Matplotlib's interactive mode
Within Spyder, this interpreter also provides:
* special commands (e.g. %ls, %pwd, %clear)
* system commands, i.e. all commands starting with '!' are subprocessed
(e.g. !dir on Windows or !ls on Linux, and so on)
>>> plot(range(3))
[<matplotlib.lines.Line2D object at 0x3f3cd50>]
>>> show()
I ended up solving by doing this in Spyder:
Preferences -> Console -> External modules -> check Install Spyder's input hook for Qt
In order for your matplotlib backend choice to work, you need to have the Python bindings for that backend installed. You may be running a GTK-based windows manager like GNOME, for example, but still not have the Python bindings around. According to this, the proper Ubuntu package is python-gtk. So, open up your favorite Terminal emulator and enter
sudo apt-get install python-gtk
(you'll need admin privileges to do it). Restart your python/matplotlib session, and you should be good to go.
I'm on Mavericks, solved the problem by changing backend to Qt4Agg in matplotlibrc. (as instructed in another answer here: Why doesn't pyplot.show() work?)

QGraphicsScene crashes PyQt4

Windows XP
Python 2.7
PyQt 4
When I run the following code inside the python interactive shell
from PyQt4 import QtGui
QtGui.QGraphicsScene()
python crashes.
Why?
You need to create a QApplication first before you can use any of the Qt GUI elements.
Usually it's done like this:
from PyQt4 import QtGui
import sys
qapp = QtGui.QApplication(sys.argv)
scene = QtGui.QGraphicsScene()
...
qapp.exec_()