Trasnparent Window in Maya 2017 - python

i found a script by SAFRONOV 3D (on youtube) that allows him to make the graph editor transparent inside Maya... The problem is that it works on Maya 2014 and i'm Trying to update it to 2017.
I know very little of opne maya and all that, i´m a beginner in pymel and some help would be great. What's Wrong? :
import maya.cmds as cmds
import maya.OpenMayaUI as mui
import shiboken2
import maya.mel as mel
from PySide2 import QtGui
mel.eval('GraphEditor')
def getGraphEditor():
ptr2 = mui.MQtUtil.findLayout("graphEditor1Window|TearOffPane")
return shiboken2.wrapInstance(long(ptr2), QtGui.QWidget)
graphEditor = getGraphEditor()
graphEditor.setWindowOpacity(0.5)
def ref(value):
graphEditor.setWindowOpacity(value)
cmds.floatSlider(p="graphEditor1Window|TearOffPane|graphEditor", min = 0.1 , max = 1.0, v = 0.7, dc = lambda x:ref(x))

Here is my updated script:
import maya.cmds as cmds
import maya.OpenMayaUI as mui
from PySide2 import QtWidgets
import shiboken2
if cmds.window("GEW", exists=True): cmds.deleteUI("GEW", window=True)
cmds.window( "GEW", title="Graph Editor +" )
cmds.paneLayout( configuration='single' )
cmds.scriptedPanel( type='graphEditor' )
cmds.columnLayout (adj=1)
cmds.floatSlider(min=0.1, max=1.0, v=0.7, dc=lambda x:ref(x))
cmds.showWindow("GEW")
GEQ = shiboken2.wrapInstance(long(mui.MQtUtil.findWindow( "GEW" )), QtWidgets.QWidget)
def ref(value): GEQ.setWindowOpacity(value)
GEQ.setWindowOpacity(0.7)

Related

How to safely go through components of QEntity in PyQt5?

Here if I run the code with components() line commented out I get a window with a purple torus as expected but if I just call the components() on the torus_entity (uncomment the line) the torus disappears.
I can print the components from the components() but trying to usem them returns an error saying it was deleted, for example: deleted torus_mesh.
The material variable which can be reused for various models also throws error saying the material was deleted if you try to use it on any line beyond the components() call.
Qt documentation: https://doc.qt.io/qt-5/qt3dcore-qentity.html#components
Documentation says components returns a list of QComponent nothing about the deletion, I don't know how to use this properly?
I'd like to go through the components and check them and change their properties, for example change position and/or scale through QTransform component.
I could go down the QT version to 5.12.12 but I don't know how to do this for PyQt5 so it builds against this QT version.
I've tried it in PyQt6, also in Qt5 (c++, but different version then the PyQt5 uses) and it works just fine in both, this might be a bug in PyQt5/Qt5? I wonder if there's a workaround for this (maybe making adjustments in some PyQt5 files?)?
import sys
from PyQt5.Qt3DCore import QEntity, QTransform, QAspectEngine
from PyQt5.QtCore import QPropertyAnimation, QVariant, QUrl
from PyQt5.QtGui import QVector3D, QQuaternion, QGuiApplication, QColor
from PyQt5.Qt3DRender import QCamera, QCameraLens, QRenderAspect, QDirectionalLight, QSceneLoader
from PyQt5.Qt3DInput import QInputAspect
from PyQt5.Qt3DExtras import QForwardRenderer, QMetalRoughMaterial, QCylinderMesh, QSphereMesh, QTorusMesh, \
Qt3DWindow, QOrbitCameraController, QPlaneMesh
def create_scene():
root_entity = QEntity()
d_light_entity = QEntity(root_entity)
direction_light = QDirectionalLight()
direction_light.setColor(QColor(255, 254, 245))
direction_light.setIntensity(2)
d_light_entity.addComponent(direction_light)
material = QMetalRoughMaterial(root_entity)
material.setBaseColor(QColor(160, 30, 160))
material.setRoughness(.5)
# Torus
torus_entity = QEntity(root_entity)
torus_mesh = QTorusMesh()
torus_mesh.setRadius(5)
torus_mesh.setMinorRadius(1)
torus_mesh.setRings(100)
torus_mesh.setSlices(20)
torus_transform = QTransform()
torus_transform.setScale3D(QVector3D(1.5, 1, 0.5))
torus_entity.addComponent(torus_mesh)
torus_entity.addComponent(torus_transform)
torus_entity.addComponent(material)
#components = torus_entity.components()
return root_entity
def main(argv):
app = QGuiApplication(argv)
view = Qt3DWindow()
view.defaultFrameGraph().setClearColor(QColor(39, 39, 39))
scene = create_scene()
camera = view.camera()
camera.lens().setPerspectiveProjection(45.0, 15.0/9.0, .1, 1000.0)
camera.setPosition(QVector3D(0, 0, 40.0))
camera.setViewCenter(QVector3D(0, 0, 0))
view.setRootEntity(scene)
view.show()
return sys.exit(app.exec())
if __name__ == '__main__':
main(sys.argv)

Problem pulling values from Arduino to Python

I wrote a program in Python which pulls values from Arduino. However, when I have the GUI window up, Python can’t read the values from Arduino, and nothing happens on the GUI window. If I remove the code containing the GUI window, the program works and can pull the values from Arduino. Does anyone know why this is happening?
import serial # 引用pySerial模組
from os import close
from tkinter.font import Font
#from bluetooth.widcomm import stop_advertising
import cv2
import numpy as np
from tkinter import*
from tkinter.constants import BOTTOM
#from typing import Text#假設tk=tkinter
import tkinter
from PIL import Image, ImageTk
COM_PORT = 'COM7' # 指定通訊埠名稱
BAUD_RATES = 9600 # 設定傳輸速率
ser = serial.Serial(COM_PORT, BAUD_RATES) # 初始化序列通訊埠
while True:
win=Tk()#建立視窗
win.title("點餐系統")#標題
win.geometry("1540x1050")#寬X高
win.maxsize(width=1520,height=1050)
img1=PhotoImage(file="D:\PYTHON\PROJECT\大麥克.png")
img2=PhotoImage(file="D:\PYTHON\PROJECT\勁辣雞腿堡.png")
img3=PhotoImage(file="D:\PYTHON\PROJECT\雙層吉事堡.png")
img4=PhotoImage(file="D:\PYTHON\PROJECT\蕈菇黑牛堡.png")
print('aaa')
a='aaa'
btn=Button(text="雙層吉事堡")
btn.config(width=400,height=300)
btn.config(image=img3)
btn.place(x=300,y=480)
lb3=Label(fg="black",text="三號餐",font='30')
lb3.place(x=475,y=450)
while ser.in_waiting: # 若收到序列資料…
data_raw= ser.readline() # 讀取一行
data= data_raw.decode() # 用預設的UTF-8解碼
print('接收到的原始資料:', data_raw)
print('接收到的資料:', data)
if(bytes(data)=="solar1low"):
print('接收到的原始資料:', data_raw)
print('接收到的資料:', data)
win.destroy()#關閉舊視窗
win2=Tk()
win2.title("點餐系統")
win2.geometry("1540x1050")
image3=Image.open("D:\PYTHON\PROJECT\雙層吉事堡.png")
雙層吉事堡=ImageTk.PhotoImage (image3)
labelnext1=tkinter.Label(image=雙層吉事堡)
labelnext1.image=雙層吉事堡
labelnext1.config(width=650,height=650)
labelnext1.place(x=450,y=100)
btnnext1=Button(win2,text="確認餐點",fg='black',font='500',)
btnnext1.place(x=1400,y=700)
btnnext2=Button(win2,text="取消",fg='black',font='500')
btnnext2.place(x=1300,y=700)
lbnext2=Label(win2,fg="black",text="三號餐 100元",font='30')
lbnext2.place(x=700,y=50)
win2.mainloop()#常駐主視窗
win.mainloop()#常駐主視窗
This is what the code should look like:
import serial # 引用pySerial模組
from os import close
from tkinter.font import Font
#from bluetooth.widcomm import stop_advertising
import cv2
import numpy as np
from tkinter import*
from tkinter.constants import BOTTOM
#from typing import Text#假設tk=tkinter
import tkinter
from PIL import Image, ImageTk
COM_PORT = 'COM7' # 指定通訊埠名稱
BAUD_RATES = 9600 # 設定傳輸速率
ser = serial.Serial(COM_PORT, BAUD_RATES) # 初始化序列通訊埠
while True:
win=Tk()#建立視窗
win.title("點餐系統")#標題
win.geometry("1540x1050")#寬X高
win.maxsize(width=1520,height=1050)
img1=PhotoImage(file="D:\PYTHON\PROJECT\大麥克.png")
img2=PhotoImage(file="D:\PYTHON\PROJECT\勁辣雞腿堡.png")
img3=PhotoImage(file="D:\PYTHON\PROJECT\雙層吉事堡.png")
img4=PhotoImage(file="D:\PYTHON\PROJECT\蕈菇黑牛堡.png")
print('aaa')
a='aaa'
btn=Button(text="雙層吉事堡")
btn.config(width=400,height=300)
btn.config(image=img3)
btn.place(x=300,y=480)
lb3=Label(fg="black",text="三號餐",font='30')
lb3.place(x=475,y=450)
while ser.in_waiting: # 若收到序列資料…
data_raw= ser.readline() # 讀取一行
data= data_raw.decode() # 用預設的UTF-8解碼
print('接收到的原始資料:', data_raw)
print('接收到的資料:', data)
if(bytes(data)=="solar1low"):
print('接收到的原始資料:', data_raw)
print('接收到的資料:', data)
win.destroy()#關閉舊視窗
win2=Tk()
win2.title("點餐系統")
win2.geometry("1540x1050")
image3=Image.open("D:\PYTHON\PROJECT\雙層吉事堡.png")
雙層吉事堡=ImageTk.PhotoImage (image3)
labelnext1=tkinter.Label(image=雙層吉事堡)
labelnext1.image=雙層吉事堡
labelnext1.config(width=650,height=650)
labelnext1.place(x=450,y=100)
btnnext1=Button(win2,text="確認餐點",fg='black',font='500',)
btnnext1.place(x=1400,y=700)
btnnext2=Button(win2,text="取消",fg='black',font='500')
btnnext2.place(x=1300,y=700)
lbnext2=Label(win2,fg="black",text="三號餐 100元",font='30')
lbnext2.place(x=700,y=50)
win2.mainloop()#常駐主視窗
win.update()
Notice how at the end I call win.update() instead of win.mainloop(). Running win.update() simply updates the window, and then moves on. Calling win.mainloop() blocks your code from running until the window is closed.
If you are still having trouble, try repacing win2.mainloop() with win2.update() as well.

Display BLOB data from sqlite On Pyqt5 DESIGN

I have database include BLOB Column named (IMG)
What I need that when search by code, the item image displayed , but the result always be like that
(caV\xd6\xf7\xd0\xec]c\x1b\x95\xe2\xa4\x00\xe3\xd3\x82L\xc9L\xa2W8H\xaf\xe4\xe0\x9f\xcb\x7f\xb5\xbautm]\x94\'\xb6\xb7p\xa7{\xbffU\xb7Q\xd5\x8d\xe3\xe1\xb....etc)
import io
import base64
from PyQt5 import QtGui
from ui import Ui_MainWindow
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import ast
import sqlite3
import sys
class HmcProject ( QMainWindow, Ui_MainWindow ): # ,FORM_CLASS
def __init__(self):
QMainWindow.__init__ ( self )
super ( HmcProject, self ).__init__ ()
self.setupUi ( self )
self.Handle_Buttons ()
self.Db_Connect ()
self.Image_Retrive()
def Db_Connect(self):
self.connection = sqlite3.connect ( 'deals_db.db' )
cursor = self.connection.cursor ()
def Handle_Buttons(self):
self.pushButton.clicked.connect(self.Image_Retrive)
def Image_Retrive(self):
try:
cursor = self.connection.cursor ()
itemsearch = self.lineEdit_Item_NameS_3.text ()
sql = ('''
SELECT IMG FROM deals_data
WHERE ITEM_CODE= ?
''')
cursor.execute ( sql,[(itemsearch)])
data = cursor.fetchone ()
print ( data [0])
pix= QPixmap.loadFromData(data[0])
self.label.setPixmap(pix)
except:
pass
def main():
app = QApplication ( sys.argv )
window = HmcProject ()
window.show ()
app.exec_ ()
if __name__ == '__main__':
main ()
You're trying to load the pixmap using loadFromData() as a static function, but it's not.
Also, that function returns a bool, reporting if the loading has been successful.
You have to create a new QPixmap instance first, then load the data, and finally show it in the label if it has been loaded:
pix = QPixmap()
if pix.loadFromData(data[0]):
self.label.setPixmap(pix)
PS: avoid space characters around parentheses, they are unnecessary and distracting; also, don't confuse and mix calls on the base classes, in python3 it's enough to call super().__init__() just once,
even for multiple inheritance classes

PyQt5 QLabel errors

In PyQT4 there is a QLabel()
While when I use it in PyQT5 it throws an undefined error.
Can anyone one tell me what is Qlabel in the PyQT4 ?
Or maybe I am wrong?
Here is my code:
import sys
import time
from PyQt5.QtCore import *
from PyQt5.QtGui import *
app = QGuiApplication(sys.argv)
try:
due = QTime.currentTime()
message = "Alert!"
if len(sys.argv) < 2 :
raise ValueError
hours, min = sys.argv[1].split(":")
due = Qtime(int(hours), int(min))
if not due.isValid():
raise ValueError
if len(sys.argv) > 2 :
message = " ".join(sys.argv[2:])
except ValueError :
message = "Alert: alert.pyw"
if QTime.currentTime() < due :
time.sleep(20) #20 Seconds
label = QLabel("<p>Message</p>")
You should read the docs I posted. Add this import statement with the others:
from PyQt5.QtWidgets import *
Because QLabel() is in PyQt5.QtWidgets, please try following :
from PyQt5.QtWidgets import QLabel

How can I implement global hot key in Python .app on Mac OS X?

I'm currently modifying an app that was written by someone within my organization that no longer is able to maintain it. I am attempting to implement a system-wide global hot key that will simply bring the app window into focus when pressed.
The only implementation of this I came across online was through PyObjC in their HotKeyPython example. That example uses Carbon though, and did not appear to function at all when I was testing it.
Here's what I was trying which did not appear to work:
from Foundation import *
from AppKit import *
from Carbon.CarbonEvt import RegisterEventHotKey
from Carbon.Events import cmdKey, controlKey, optionKey, shiftKey
import objc, AppLauncher
import platform
import struct
IS_SNOW_LEOPARD = platform.mac_ver()[0].startswith('10.6')
if IS_SNOW_LEOPARD:
from Quartz import *
kEventHotKeyPressedSubtype = 6
kEventHotKeyReleasedSubtype = 9
class AppLauncher(NSObject):
window = objc.IBOutlet()
view = objc.IBOutlet()
field = objc.IBOutlet()
def awakeFromNib(self):
self.window.makeFirstResponder_(self.field)
self.field.selectText_(self)
self.field.setDelegate_(self)
self.controlTextDidChange_(None)
def applicationDidFinishLaunching(self):
# register cmd-control-J
self.hotKeyRef = RegisterEventHotKey(38, cmdKey + controlKey, (0, 0),
sendEvent_(), 0)
def sendEvent_(self, theEvent):
if theEvent.type() == NSSystemDefined and \
theEvent.subtype() == kEventHotKeyPressedSubtype:
self.activateIgnoringOtherApps_(True)
NSRunAlertPanel(u'Hot Key Pressed', u'Hot Key Pressed',
None, None, None)
super(AppLauncher, self).sendEvent_(theEvent)
Any thoughts on how I can get this working (preferably without getting Carbon involved)?
Thanks a lot.

Categories

Resources