I'm making a clone of windows 98's start menu. I have the program almost finished I just need to get the buttons to open some programs. However for some reason the windows98 lookalike start menu keeps forcing me to start from the beginning in order to get through the menus. Each "tab" it's a docked borderless window because i was not sure how to make the program the shape it needed to be to appear over the operating system and over any open programs like how the old start menu should be. when i made it all one program it sat in the background when opened or it sat on top of the enter operating system making it really unrealistic. Start menu was only able to be placed on top as submenus when each window was created and destroyed using onenter and on exit when hovering over labels. so each tab is filled with labels that when the mouse hovers over it trades the image for the blue one and if it is a label that has a submenu like for example the programs part of the first start window it opens the next label (or in tkinter's world a new window)
as you can see in the video below the on hover events do not stay once the mouse leaves the window
(I created a transparent window in the background so that when the user clicks out of the start menu the program is aware of it and can handle closing the entire program to look like the start menu is just being closed)
the labels also do not turn blue when trying to backtrack to the previous window.
I am wishing for any kind soul here to assist me in solving these mysteries.
Here is a video showing the issue
https://youtu.be/KeK_qfV_X6s
I want to post the code for the program but the editor says that it is using too many characters to post it here.
I will send an example of how the new tabs are created and hope it's enough. I can send the script itself to someone who needs it.
'''code'''
def createProgramsTab():
global ProgramsTabWindow
ProgramsTabWindow = Toplevel(ClickToExitBackground)
ProgramsTabWindow.geometry("+205+270")
ProgramsTabWindow.geometry("150x147")
ProgramsTabWindow.configure(bg='#c0c0c0')
ProgramsTabWindow.deiconify()
EmptyProgramsTabLabelImage = ImageTk.PhotoImage(Image.open(r'assets/StartMenuPrograms.png'))
EmptyProgramsTabLabel = Label(ProgramsTabWindow, image=EmptyProgramsTabLabelImage)
EmptyProgramsTabLabel.photo = EmptyProgramsTabLabelImage
EmptyProgramsTabLabel.place(x=0,y=0)
HomeBaseaccessoriesButtonImage = ImageTk.PhotoImage(Image.open(r'assets/startaccessoriesdefault.png'))
HomeBaseaccessoriesButton = Button(ProgramsTabWindow, image=HomeBaseaccessoriesButtonImage, borderwidth=-10, highlightthickness=-10, relief=FLAT,bd=-10,bg="#c0c0c0")
HomeBaseaccessoriesButton.photo = HomeBaseaccessoriesButtonImage
HomeBaseaccessoriesButton.place(x=3,y=3, bordermode=INSIDE)
HomeBaseProgramsButtonImage = ImageTk.PhotoImage(Image.open(r'assets/startprogramsdefault.png'))
HomeBaseProgramsButton = Button(HomeBaseWindow, image=HomeBaseProgramsButtonImage, borderwidth=-10, highlightthickness=-10, relief=FLAT,bd=-10,bg="#c0c0c0")
HomeBaseProgramsButton.photo = HomeBaseProgramsButtonImage
HomeBaseProgramsButton.place(x=25,y=44, bordermode=INSIDE)
def onEnterPrograms(event):
global HomeBaseProgramsButtonImage
HomeBaseProgramsButtonImage = ImageTk.PhotoImage(Image.open(r'assets/startprogramsblue.png'))
HomeBaseProgramsButton.config(image=HomeBaseProgramsButtonImage)
HomeBaseProgramsButton.photo = HomeBaseProgramsButtonImage
createProgramsTab()
destroyfavoritesTab()
destroysettingsTab()
destroyaccessoriesTab()
destroydevotionalservicesTab()
destroyinitiationTabWindow()
destroydocumentsTab()
def onLeavePrograms(event):
global HomeBaseProgramsButtonImage
HomeBaseProgramsButtonImage = ImageTk.PhotoImage(Image.open(r'assets/startprogramsdefault.png'))
HomeBaseProgramsButton.config(image=HomeBaseProgramsButtonImage)
HomeBaseProgramsButton.photo = HomeBaseProgramsButtonImage
HomeBaseProgramsButton.bind('<Enter>', onEnterPrograms)
HomeBaseProgramsButton.bind('<Leave>', onLeavePrograms)
HomeBaseWindow.attributes('-type', 'dock')
HomeBaseWindow.wait_visibility(HomeBaseWindow)
HomeBaseWindow.wm_attributes('-alpha', 1.0)
'''code'''
thank you again for any help
Billie
Related
I have been searching everywhere on how to do this specifically but to no avail.
Let's say I want to get a list of all the open windows/apps on my device:
The next thing I want to do is to search for a window with a name "Notepad", or maybe "Facebook", then switch and maximize those window as the main window on the screen.
I've been using pyautogui module for switching tabs by automatically pressing alt + tab keys with the module. However, I believe it'll be prone to mistakes if I have no way of checking which tab/window is currently selected or maximized.
I was thinking of a solution that I can just continuously automate pressing alt + tab until the target window name is in the current active window, but I don't know how to get the name of the current active window as well.
Thank you for the help in advance.
I just found out that pyautogui has a method to get the active window title as well.
import pyautogui
import time
target_window = 'notepad'
count = 0
while True:
window_title = pyautogui.getActiveWindowTitle()
if target_window not in window_title:
count += 1
with pyautogui.hold('alt'):
for _ in range(0, count):
pyautogui.press('tab')
time.sleep(0.25)
I was trying to send scroll commands to a window in the background, when I encountered strange behaviours that I don't really understand.
The Script
I wrote a script to illustrate what I encountered. To have it work, I used a Windows 10 system, and had one mail window and one command prompt window open in the background (not minimised). The script sends a scroll command to both windows with the mouse pointer located at the middle of the window.
In both windows, the cursor should hover over a region that allows for scrolling. The difference lies in the fact that for the mail window, only a portion of the window allows for scrolling (I used these windows because it is most likely that everyone using Windows has these applications).
import win32gui as wgui
import win32api as wapi
import win32con as wcon
# This script is meant to try sending scroll messages to a window.
def callback(hwnd, win_list):
""" Callback for win32gui.EnumWindows : appends the hwnd to win_list."""
win_list.append(hwnd)
def find_specific_window(tag):
""" This function finds a specific window and returns its handle and name.
:param tag: A key word that describes the window we look for.
.. note:
Always stops at the first match.
"""
win_list = []
wgui.EnumWindows(callback, win_list)
# Find the first window with the tag in its name:
hwnd = None
name = None
for h in win_list:
n = wgui.GetWindowText(h)
if tag in n:
name = n
hwnd = h
break
return hwnd, name
def scroll_bg(hwnd, pointer_x, pointer_y, child=True, delta=1):
""" Performs a scroll on a background window with handle hwnd (might need to use FindWindowEx).
:param pointor_x: relative horizontal position of the mouse (y is vertical).
:param child: Boolean telling whether to operate on the top child window or the main window.
"""
# Take the top child window handle
if child:
hwnd = wgui.FindWindowEx(hwnd, None, None, None)
# Transform the mouse coordinates into pixels for the given window.
# Obtain the window dimensions
rect = wgui.GetWindowRect(hwnd)
w = rect[2] # Width
h = rect[3] # Height
x_pix = int(round(w * pointer_x))
y_pix = int(round(h * pointer_y))
print("In scroll_bg: the coordinates for the window {} are : ({}, {})".format(hwnd, x_pix, y_pix))
# Transform them for the function
lparam = wapi.MAKELONG(x_pix, y_pix)
# Transform into wparam
wparam = wapi.MAKELONG(0, - delta * wcon.WHEEL_DELTA)
# Hover to the pointer position.
wgui.PostMessage(hwnd, wcon.WM_MOUSEMOVE, 0, lparam)
# Scroll
wgui.PostMessage(hwnd, wcon.WM_MOUSEWHEEL, wparam, lparam)
wgui.PostMessage(hwnd, wcon.WM_MOUSEMOVE, 0, lparam)
if __name__ == '__main__':
window1_tag = "Mail"
window2_tag = "Command"
hwnd1 = find_specific_window(window1_tag)
hwnd2 = find_specific_window(window2_tag)
print("first window handle: {}, second window handle: {}".format(hwnd1, hwnd2))
# In both windows we set the pointer at the middle.
scroll_bg(hwnd1[0], 1/2, 1/2)
scroll_bg(hwnd2[0], 1/2, 1/2, False)
In the script, I defined a scroll_bg function that can send the scroll instruction to a given window, identified by hwnd, or its first child (by setting child=True).
My Script Result
Running this script I can observe that the scroll has correctly been sent to the Command Prompt window, but nothing changed for the Mail window, despite targetting scrollable areas in both windows. I must note that I also tried sending the scroll message to the parent window, by running scroll_bg(hwnd1[0], 1/2, 1/2, False), but it didn't work either.
More Details
I must also note that I observed this issue in the same context as this question. I wanted to send scroll commands instead of dragging, and managed to successfully scroll in certain areas while not in others (for the same game).
I further observed that giving a scroll command would do the same animation as a click. The weird part about it is that changing the position of pointer_x didn't change the position of the animation, and it occurred at the left border of the window (horizontal pixel = 0). It looks like the pointer_x is set to 0, and this would explain the script results.
An other point worth mentioning is that maybe the scroll commands can only be interpreted by some other child window and that the wgui.PostMessage function sends the scroll commands to the wrong window thus they are not interpreted correctly. I'm a bit confused as to which window I should send the commands to. For instance, in the case of the game, posting messages to the parent window would not work and I had to send them to the first child. So, perhaps, the results of the script could be explained by the fact that I'm not sending to the correct child.
Versions I am using:
pywin32 v: 300
python v: 3.7.1
Thank you for your time, and any advice is welcome ! :)
I have a function call on button click which is used to display a number of cuboids. However i want the ability to rotate my frame on user mouse drag so as to get the desired viewing angle (as preferred by user)
However, i cant seem to rotate as well as zoom on my display window.
Edit: What i found was upon a right click drag it changes the viewing angle. However it does not get reflected. Weirdly enoughn it is reflected only after i maximize and then restore the screen. Is there some setting i can do to make it work seamlessly.
Also, the first display happens after i move the window from its initial position. Else its just blank upon launch!! Please advise
def testDraw():
global containers
myscene = display(title='Diagram')
#myscene.material = materials.wood
myscene.select()
myscene.exit=False
#myscene.userspin = True
myscene.userspin = 1
myscene.forward = (.1, -.3, -1)
mybox = [['','','','','','','',''] for x in range(len(containers))]
for x in range(len(containers)):
for y in range(len(containers[x])):
mybox[x]=box(pos=(float(containers[x][1])+float(containers[x][2])/2,float(containers[x][3])+float(containers[x][4])/2,float(containers[x][5])+float(containers[x][6])/2),width=float(containers[x][6]),height=float(containers[x][4]),length=float(containers[x][2]))
#,color='color.'+containers[x][7]
#mybox = box(pos=(2.5,1,5), length=10, height=2, width=5,color=color.blue)
#mybox2 = box(pos=(12.5,1,5), length=10, height=2, width=5,color=color.green)
#Name,length0,length1,height0,height1,width0,width1,color
containers=[['Container_1','`enter code here`0','2','0','7','0','2','blue'],
['Container_2','2','5','0','10','0','2','green'],
['Container_3','7','10','0','5','0','2','red']]
I don't understand what is meant by "it does not get reflected". What is "it"? Also, you haven't provided a runnable program, so it' difficult to know what the context is.
I'll advertise that a better place to pose VPython questions is in the VPython forum at
https://groups.google.com/forum/?fromgroups&hl=en#!forum/vpython-users
Not sure where I'm going wrong:
mm = list(r.findAll(rButton))# find all rButtons on main screen
print len(mm) #check how many are detected
for x in range(0,len(mm)):
r.click(mm[x])
if(not r.exists(rButtonDisabled)):
print "this is a test"
r.wait(BeginTask,FOREVER)
r.click(BeginTask)
r.wait(rButton,FOREVER)
else: click(Cancel)
There are 2 screens. Let's call them main screen and screen2. On main screen there are identical buttons, rButton. I want to find all visible rButtons and then start clicking them. Ideally I want it to click on first rButton, which takes it to screen2, if the button on screen2 is disabled, click on cancel which moves us back to main screen, then go to the second rButton on main screen, which again takes us to screen2. Depending on rButtons on main screen, buttons on screen2 can be either disabled or enabled.
My code isn't working to that effect. Not sure where I'm going wrong.
I'm not sure how you've defined Region 'r', but as a default, Sikuli won't search outside the screen that is native to the OS. You need to first make sikuli find the other screen, then define the bounds of that screen.
As it appears now, you're searching Region 'r' no matter what screen you intended... You should define the two screens separately, or Sikuli won't know to switch screens to look for the button you want. For example, you can use the Screen class to define which screen is which--
numScreens = getNumberScreens()
r = SCREEN #in all caps, this is the reserve word for the whole screen native to the OS
#can also use r = Screen(0)
if numScreens > 0 #make sure second screen was counted by sikuli
r2 = Screen(1).getBounds()
else: raise the appropriate error
#Here's your code with some adjustments for multiple monitors
#on main screen
mm = list(r.findAll(rButton))# find all rButtons on main screen
print len(mm) #check how many are detected
for x in range(0,len(mm)):
r.click(mm[x])
#on secondary screen
if(not r2.exists(rButtonDisabled)):
print "this is a test"
r2.wait(BeginTask,FOREVER)
r2.click(BeginTask)
#back to main screen
r.wait(rButton,FOREVER)
#click the cancel button on secondary screen
else: r2.click(Cancel) # <-- the defining region was missing here in your original code
Here's the Sikuli documentation on multi-monitor environments
I have a python Gtk application, with the GUI designed in Glade. It has a "scan" feature which will scan the network for a few seconds and then report its results to the user. During the scanning I want a popup window to appear stealing the focus from the parent until scanning is done.
I use a threading.Lock to synchronize the GUI and the scan thread, which makes the popup to last exactly the right time I want (see scanLock.acquire() ). It seems straightforward to me to implement something like a show() and hide() call before and after the scanLock.acquire(). I did use waitPopupShow and waitPopupHide instead of just calling the window.show() and window.hide() because I also may want to set the Label in the popup or start/stop the GtkSpinner. Here is some code from the GUI class:
def scan(self):
sT = scannerThread(self,self.STagList)
self.dataShare.threadsList.append(sT)
sT.start() # start scanning
self.waitPopupShow('Scanning... Please Wait')
self.scanLock.acquire() # blocks here until scan is finished
self.waitPopupHide()
def waitPopupShow(self, msg): # shows a GtkSpinner until the semaphore is cleared
self.waitDialogLabel.set_text(msg)
self.waitDialogBox.show_all()
self.waitDialog.show()
self.waitDialogSpinner.start()
def waitPopupHide(self):
# how to get the handle to the spinner and stop it?
self.waitDialogSpinner.stop()
self.waitDialog.hide()
def getAll(self):
# GUI
self.builder = Gtk.Builder()
self.builder.add_from_file(path to main GUI)
# ... getting stuff from a first glade file
# getting stuff from the waitDialog glade file
self.builder.add_from_file(path to waitDialog GUI)
self.waitDialog = self.builder.get_object("waitDialog") # GtkWindow
self.waitDialogBox = self.builder.get_object("waitDialogBox") # GtkBox
self.waitDialogLabel = self.builder.get_object("waitDialogLabel") # GtkLabel
self.waitDialogSpinner = self.builder.get_object("waitDialogSpinner") # GtkSpinner
self.waitDialog.hide()
I'm trying hardly since a couple of days to show a dialog with a label and a Gtk.Spinner. The best I obtain at the moment is to have the window showing up with no content. Please note that the self.waitDialog.hide() right after getting it with self.builder.get_object is needed because I set the property of the waitDialog Gtkwindow to Visibile. If I stop with the debugger before .hide() the waitDialog shows up perfectly. Afterwards its broken.
This is the waitDialog GUI file: http://pastebin.com/5enDQg3g
So my best guess is that I'm dooing something wrong, and I could find nothing on creating a new Gtk window over the main one, only basic examples and dialogs. A pointer to the documentation saying a bit about this would be a good starting point...