Pyqt4 MDI no clean mdiarea - pyqt4

I am new to PyQt, I am developing an application like MDI, I use the QDesigner to build the forms (I come from Visual Basic), so far so good, but it is costing me horrors to run the application well, when I close a window, erase everything, but the frame remains on the mdi-area, click on the x and close. I attach the code.
With this I knock at the window:
def ordentrabajo(self):
self.cot = FichaOrdenTrabajo()
subwindow = QtGui.QMdiSubWindow()
self.cot.mdiarea = self.ventana.mdiArea
subwindow.setWidget(self.cot)
subwindow.setGeometry(0, 0, 595, 490)
self.ventana.mdiArea.addSubWindow(subwindow)
subwindow.showventana = self.cot.show()
And within the FichaOrdenTrabajo I close with:
def closeEvent(self, QCloseEvent):
self.emit(QtCore.SIGNAL('cerrar'))
general.saveposic('ctrlordentrabajo', self.x(), self.y())
self.subwindow.close = self.cdeta.close()
self.cdeta.hide()
# del self.subwindow
self.subwindow = None
leaving the main window in this state:
The question is how to do so that when closing the mdi-area is clean?
Thank you

Related

Why does my turtle window close immediately?

import turtle
ved_turtle = turtle.Turtle()
def square():
ved_turtle.forward(100)
ved_turtle.right(90)
ved_turtle.forward(100)
ved_turtle.right(90)
ved_turtle.forward(100)
ved_turtle.right(90)
ved_turtle.forward(100)
ved_turtle.right(90)
elephant_weight = 3000
ant_weight = 0.1
if elephant_weight < ant_weight:
square()
else:
ved_turtle.forward(0)
Why does my turtle window close immediately after opening in the community edition of Visual Studio 2019, but it does not close immediately in repl.it ?
Add input() at the end of the script to make it wait for the Enter key.

How to access popup menu from hidden system tray icon

I use following code to access hidden icon and to show its popup menu and to click on "Sign Off" menuitem:
import time
from pywinauto.application import Application
app = Application(backend="uia").connect(path="explorer.exe")
st = app.window(class_name="Shell_TrayWnd")
t = st.child_window(title="Notification Chevron").wrapper_object()
t.click()
time.sleep(0.25)
list_box = Application(backend="uia").connect(class_name="NotifyIconOverflowWindow")
list_box_win = list_box.window(class_name="NotifyIconOverflowWindow")
list_box_win.wait('visible', timeout=30, retry_interval=3)
list_box_win.child_window(title="Citrix Workspace").click_input(button='right').menu_item('Sign Out').click_input()
Popup menu is shown, but I got error: AttributeError: 'NoneType' object has no attribute 'menu_item'
When I tried to add this code (instead of .menu_item('Sign Out').click_input()) :
connector = Application()
connector.connect(path="C:\\Program Files (x86)\\Citrix\\ICA Client\\SelfServicePlugin\\SelfService.exe")
connector.PopupMenu.MenuItem("Sign Out").ClickInput()
path is reflecting application that responsible for icon in system tray.
I got error: MatchError: Could not find 'PopupMenu' in 'dict_keys([])'. So I can I access menuitem in popup window?
BTW: It is run on windows 10 64 bit with python 3.6.
Unpolished/optimized (but working) code looks like this:
import pywinauto.application
import time
taskbar = pywinauto.application.Application(backend="uia").connect(path="explorer.exe")
windows_tray = taskbar.window(class_name="Shell_TrayWnd")
tray = windows_tray.child_window(title="Notification Chevron").wrapper_object()
tray.click()
time.sleep(1)
app_list_box = pywinauto.application.Application(backend="uia").connect(class_name="NotifyIconOverflowWindow")
app_list_box_win = app_list_box.window(class_name="NotifyIconOverflowWindow")
target_app = app_list_box_win.child_window(title = "Citrix Workspace")
target_app.click_input(button = "right")
citrix = pywinauto.application.Application().connect(path='Receiver.exe')
sign = citrix.PopupMenu.menu().get_menu_path("Sign In...")[0]
sign.click_input()
Where 'Receiver.exe' is executable of application running in system tray and "Citrix Workspace" title of of it.

Error using checkmouse

I'm trying to use checkmouse in order to undraw something from my window. When someone clicks the button it should undraw the text and write something else. I'm using checkMouse and getX() and getY() to do this but i keep receiving this error that states:
File "C:\Users\User\Documents\python\project2.py", line 71, in panel
if (clicknew.getX()>90 and clicknew.getX()<210) and (clicknew.getY()>35 and clicknew.getY() < 0):
AttributeError: 'NoneType' object has no attribute 'getX'
this code that i have done so far is as follows:
from graphics import *
#creating the game panel window
def panel():
#grey window, with coordinates flipped, with banners etc
win = GraphWin("Start Panel", 300,200)
win.setCoords(0,0,300,200)
win.setBackground("light grey")
#drawing the BoilerMazer banner with text
boilermazer = Rectangle(Point(0,200),Point(300,160))
boilermazer.setFill("white")
boilermazer.draw(win)
#text inside
banner1 = Text(Point(150,180),"BoilerMazer")
banner1.setStyle("bold")
banner1.setSize(20)
banner1.draw(win)
#initial game panel is going to have two buttons and a top scores object
#top score "screen"
toprec = Rectangle(Point(60,140),Point(240,50))
toprec.setFill("white")
toprec.draw(win)
#text inside toprec
topscores = Text(Point(150,130),"TOP SCORES")
topscores.setSize(8)
topscores.draw(win)
border = Text(Point(150,120),"======")
border.draw(win)
bigmac = Text(Point(150,110),"Big Mac 21")
bigmac.setSize(8)
bigmac.draw(win)
tt = Text(Point(150,90),"T.T 23")
tt.setSize(8)
tt.draw(win)
cshell = Text(Point(150,75),"C-Shell 25")
cshell.setSize(8)
cshell.draw(win)
macmac = Text(Point(150,55),"MacMac 27")
macmac.setSize(8)
macmac.draw(win)
#new player button that will eventually be clicked
new1 = Point(90,35)
new2 = Point(210,0)
newrec = Rectangle(new1,new2)
newrec.setFill("chartreuse2")
newrec.draw(win)
#new player button text
newplayer = Text(Point(150,18),"NEW PLAYER")
newplayer.draw(win)
#reset button
resetrec = Rectangle(Point(240,35),Point(300,0))
resetrec.setFill("red")
resetrec.draw(win)
#resettext
reset = Text(Point(270,18),"RESET")
reset.draw(win)
#secondary panel window is the game panel after they click new player
#set up points that we check between for the new player button first
#setting up the checkmouse
clicknew = win.checkMouse()
if (clicknew.getX()>90 and clicknew.getX()<210) and (clicknew.getY()>35 and clicknew.getY() < 0):
newplayer.undraw()
you can find the graphics window here:http://mcsp.wartburg.edu/zelle/python/graphics.py
I don't understand what I'm doing wrong, is there some other method that I'm supposed to be using? Thanks for your help
According to the docs, checkMouse() returns None if no mouse click has been detected priorly. So that seems to be the case.
You could put a loop around the call to checkMouse and keep checking if clicknew is not None and only in that case go on in your program. But maybe there's a better way...
UPDATE:
Example:
while True:
clicknew = win.getMouse()
if clicknew:
break
else:
time.sleep(0.1) # avoid busy waiting
# clicknew is set now => use it

pyside qdialog box or qaction icon is closing app

The issue is a combination of setting an icon on the action in the toolbar (or qpushbutton) and showing a qmessagebox when triggered. If I remove the icon, the message box displays. And if I remove the message box but keep the icon, the app stays open. The other odd thing is, if I add the icon to the push button but not the action, and click on the action, it still closes the app. The doubly odd thing is if I add main.qpush_button_clicked before qapplication.exec_(), the message box is displayed. However, the next time I click on either, it closes the app.
I have looked at multiple posts and some of the ideas were to use setQuitOnLastWindowClosed, but that did not fix the issue. I also implemented event to see what was happening. When I click on either of the items, it triggers a ChildAdded event, then closes.
Also, this only does not work when I use cx_Freeze on a Mac. I have not tried on Win. It works properly when run using Eclipse or from CLI.
Does anyone have any ideas on what might be causing this, or how to fix it besides not using icons.
The icon I used is from Android icon pack.
I can add the crash log if you need it.
class Main(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.qicon = QIcon('../ic_add_black_24dp_1x.png')
self.tool_bar = self.addToolBar('main')
qaction = QAction(self)
self.tool_bar.addAction(qaction)
qaction.setText('add')
qaction.setIcon(self.qicon)
qaction.triggered.connect(self.qpush_button_clicked)
qpush_button = QPushButton('add')
self.setCentralWidget(qpush_button)
qpush_button.setIcon(self.qicon)
qpush_button.clicked.connect(self.qpush_button_clicked)
def qpush_button_clicked(self, *args, **kwargs):
QMessageBox.critical(self, 'test', 'testing')
if __name__ == '__main__':
qapplication = QApplication(sys.argv)
main = Main()
main.show()
main.raise_()
qapplication.exec_()
And here is the setup file
name = 'dialog'
version = '0.1'
description = 'description'
packages = ('os',)
excludes = ('tkinter',)
include_files = ('ic_add_black_24dp_1x.png',)
build_exe = dict(packages=packages,
excludes=excludes,
include_files=include_files)
options = dict(build_exe=build_exe)
base = 'Win32GUI' if sys.platform == 'win32' else None
script = 'dialog.py'
executables = (Executable(script, base=base),)
setup(name=name,
version=version,
description=description,
options=options,
executables=executables)
PySide Version : 1.2.2
PySide Component: : (1, 2, 2, 'final', 0)
PySide Compiled Qt : 4.8.7
PySide Qt Component: (4, 8, 7)
Running Qt Version : 4.8.7

How to manually set the toggle state of wxpython platebutton

I am building an application using platebutton iin wxpython. The problem is that I am not able to manually SetState of the toogle buton. I used SetState(0) but it does not change the state of toggle button. Any help would be great. Thanks. Sample code:
self.infinity= platebutton.PlateButton(self._ribbon,wx.ID_NEW, bmp = wx.Bitmap('infinity.bmp'), pos = (0,0), size = (38,18), style= platebutton.PB_STYLE_NOBG |platebutton.PB_STYLE_TOGGLE)
def OnInfinityToggled(self,event):
if event.GetEventObject().IsPressed():
self.popupmenu = wx.Menu()
Session = self.popupmenu.Append(-1, "Session")
self.Bind(wx.EVT_MENU, self.SessionMenu, Session)
self.PopupMenu(self.popupmenu,(2,23))
else:
pass
def SessionMenu(self, event):
print 5
self.infinity.SetState(0)
self.infinity.Raise()
PLATE_NORMAL = 0
PLATE_PRESSED = 1
PLATE_HIGHLIGHT = 2
SetState(0) means set to normal.
Here's how I managed to toggle state:
btn._ToggleState()
btn._pressed = True
I had the same problem. Playing around I managed to resolve my problem with
button._SetState(ix)
button.Refresh()
where ix = your choice of state.

Resources