Okay so I'm seriously lost here and any guidance would be appreciated. I have a program that displays all the wafer maps within a given time range.[image shown below] when I input the the dates 9/1/18- 9/15/18 it outputs fine . When I do 9/15/18-9/30/18 it also works fine but when I query the whole month I get an error. I'm starting to think this might be a memory related issues but I'm not too knowledgeable about memory. I do know that python handles memory by itself. Also I do have 16GB of RAM and working on a 64bit architecture. The setup is a GUI that allows you to pick a file and pick 2 dates then another wx.frame appears displaying the wafer maps.
the error that I receive when I query a larger date is the following
image = bitmap.ConvertToImage()
wx._core.wxAssertionError: C++ assertion "hbmp" failed at ..\..\src\msw\dib.cpp(139) in wxDIB::Create(): wxDIB::Create(): invalid bitmap
here's the parent function where that is being called from
def SetBitmapLabel(self, bitmap, createOthers=True):
"""
Set the bitmap to display normally.
This is the only one that is required.
If `createOthers` is ``True``, then the other bitmaps will be generated
on the fly. Currently, only the disabled bitmap is generated.
:param wx.Bitmap `bitmap`: the bitmap for the normal button appearance.
.. note:: This is the bitmap used for the unselected state, and for all other
states if no other bitmaps are provided.
"""
self.bmpLabel = bitmap
if bitmap is not None and createOthers:
image = bitmap.ConvertToImage()
imageutils.grayOut(image)
self.SetBitmapDisabled(wx.Bitmap(image))
and here's where that function above is called
def SetBitmap(self, bmp):
"""
Sets the bitmap representation of the current selected colour to the button.
:param wx.Bitmap `bmp`: the new bitmap.
"""
self.SetBitmapLabel(bmp)
self.Refresh()
any help would be greatly appreciated because at this point I have no idea where to go from here. Maybe the GUI im working w/ is only operating at 32bit ? not sure. Not sure if the image is needed but here is below
EDIT
thanks to the guys below I discovered that the reason this is happening is because my GDI objects reach 10,000 for the script which is the limitations set by windows. Now I have to find a work around for this. Will probably post another question to dive into this
It looks like you could be running out of GDI resources, i.e. creating the actual bitmap object (HBITMAP) fails. Unfortunately there is not too much that can be done in this case other than obvious: create fewer (and/or smaller) bitmaps.
Also check that you don't leak any bitmaps, i.e. if the problem only starts appearing after you run your application for some time, this could well be the case. Many diagnostic tools under Windows (e.g. Process Explorer) can show you GDI resources consumed by your process, check if they don't grow while the program is running.
As VZ said, it seems that you are running out of GDI resources (i.e. bitmap), which has nothing to do with available RAM, but with OS.
If this is the case, I'd go this route:
Store your images in wxImage's objects. They will use RAM, but not GDI resources.
Handle each window paint event. In this handler, convert the wxImage to a bitmap and blit it to the window. The bitmap can be released now.
Encounter the same problem. Simple solution solves the problem:
import subprocess, time
while True:
cd = "py img_get_xp.py"
subprocess.Popen(cd)
time.sleep(600)
subprocess.Popen('tasklist>task.txt', shell=True).communicate()
tasks = open('task.txt')
lines = tasks.read()[::-1]
pos = lines.find("exe.nohtyp")
pid = lines[pos - 22:pos - 18][::-1]
subprocess.call(['taskkill', '/F', '/T', '/PID', pid])
Related
I'm trying to create a script that would automate a workflow with Python, I'm using PyAutoGui to find a image on screen and it locates and clicks on it.
The problem is that it will work with machines with my display settings (1920x1080, 100% scale), and will fail to locate when the scaling is changed (resolution can change, and it will work fine though). There's a good answer explaining how it works here: Running Pyautogui on a different computer with different resolution.
If the problem is with scaling, how can I programmatically do this step-by-step, that would work with any kind of display settings? I couldn't find any definitive answers so far:
Something that could do this with Python:
Start the program, get and save current scaling to variable
Change scaling to 100%
..... Code
Change scaling back to how it was and end the program
enter image description here
enter image description here
I want to draw a figure on another application as above. How can I do that? I tried using a window handle in c#, so I didn't get the result I wanted.
You could draw a transparent window on top of your target application, effectively creating an overlay. This would most likely involve quite a bit direct usage of the Win32 API. See for example enumerating windows of another application.
But it will likely be an unreliable solution since there is a whole bunch of things you need to take into account:
Ensure that the target application still receives all input events.
Ensure that your transparent window stays on top of the target application
Monitor the target application for any window size change, or minimizing/maximizing
Many more things that you will likely discover later
Note that this will likely not work for full screen applications, and while this should allow for an overlay, any data on what or where to draw things need to come from somewhere else.
I've created a gameboy color emulator using C++ and am ready to start developing the frontend that will display the emulator's viewport, emit audio, and also display some debug information.
I'm looking into using Kivy to create the UI frontend and boost.python (which looks pretty promising) to interop between the C++ core and the python UI.
What I would like to have in my front end are:
A window to show the emulator graphics. More specifically something that let's me update a raw bitmap (i.e. raw pixel data) on each frame.
A window to display some debug information. More specifically I want a large scrollable text box to show the disassembled code and another one to show the memory.
A way to emit audio that's generated by the emulator. The core doesn't support audio yet so I'm not sure what it'll look like on the C++ side.
Accept keyboard input to control the game.
Will Kivy allow me to do all of this? I see that it has dependencies on glew and sdl2 which should take care of the graphics and audio requirements, right? Are there widgets that will let me create the disassembly and memory viewer?
A window to show the emulator graphics, update a raw bitmap on each frame
Not sure how exactly, but you have access to textures and to a huge part of OpenGL through Kivy and Python, so this could be doable.
A window to display some debug information, large scrollable text box
Use RecycleView and Label's core. There's an example for ListView, but since the new changes it's kind of broken. However, in a similar way it could be done for RecycleView
A way to emit audio that's generated by the emulator
Should work without problems if you can pass it to the provider. The only issue I see with built-in audio support in Kivy is pause and seek, because those afaik either aren't implemented (most probably) or are broken. However with Gstreamer it should work.
Accept keyboard input to control the game.
Keyboard and multitouch work out of the box with Kivy, you only need to (for keyboard) extend one method and (for touch) check for collisions with Widgets
Are there widgets that will let me create the disassembly and memory viewer?
No. At least none that I know will do that out of the box. If by disassembly you mean text, dump it into a widget that can handle text. Memory viewer however isn't there and you'll need to create your own widget. That's not hard if you work with Kivy at least for a while.
Kivy by default doesn't do 3D. There are "plugins" that can allow you such thing, but I don't see any that's still maintained so there's this thing. Also I see the code isn't C, but C++ so I'm not sure how to bind those together. Cython should be the rescue here ^^
I am trying to capture the pixels of a game to script a bot. I have a simple function:
def printPixel():
while True:
flags, hcursor, (x,y) = win32gui.GetCursorInfo()
print x,y,':',ImageGrab.grab().getpixel((x,y))
This prints the current x,y coords and the RGB value of that pixel. This works as expected on my desktop hovering over various icons and such, but the same function does not work in-game. Any thoughts?
edit: When I save the image to a file and perform this same operation on the saved image, it works perfectly in-game. However, it is way slower. I'd like to operate on the image in memory, and not from a file.
Video games often deal with th graphical system directly for performance reasons, so some of the typical windows apis might not work on them. Try and take a screenshot by pressing the print screen button. If that captures your screen than you can take a screenshot in python and check the image you have captured taking into account the cursor position.
To take a screenshot on windows you can check out this answer to the question Fastest way to take a screenshot with python on windows it uses the win32gui library as you are using.
Frustrated by lack of a simple ACDSee equivalent for OS X, I'm looking to hack one up for myself. I'm looking for a gui library that accommodates:
Full screen image display
High quality image fit-to-screen (for display)
Low memory usage
Fast display
Reasonable learning curve (the simpler the better)
Looks like there are several choices, so which is the best? Here are some I've run across:
PyOpenGL
PyGame
PyQT
wxpython
I don't have any particular experience with any of these, nor any strong desire to become an expert - I'm looking for the simplest solution.
What do you recommend?
[Update]
For those not familiar with ACDSee, here's what it does that I care about:
Simple list/thubmnail display of images in a directory
Sort by name/size/type
Ability to view images full screen
Single-key delete while viewing full screen
Move to next/previous image while viewing full screen
Ability to select a group of images for:
move to / copy to directory
delete
resize
ACDSee has a bunch of niceties as well, such as remembering directories you've moved images to in the past, remembering your resize settings, displaying the total size of the images you've selected, etc.
I've tried most of the options I could find (including Xee) and none of them quite get there. Please keep in mind that this is a programming/library question, not a criticism of any of the existing tools.
I will recommend using wxPython to create such a viewer, wxPython is easy to learn, free, cross platform and blends well in OSX. Even if you want to use pyopengl, wxPython would be good with pyopengl.
see such tutorials http://showmedo.com/videotutorials/video?name=1790000&fromSeriesID=179
and there is already cornice written in wxpython/PIL, may be you can modify that. It has been inspired by the famous Windows-only ACDSee :)
it's not an answer to your coding question but for (a big part of) the lack of ACDsee equivalent (requires OSX 10.5+):
Simple list/thubmnail display of images in a directory: Finder.app
Sort by name/size/type: Finder.app will do name & type, not image size (but does file size)
Ability to view images full screen: quick preview (spacebar / eye icon)
Single-key delete while viewing full screen: command-backspace while viewing in quickpreview, both windowed and fullscreen
Move to next/previous image while viewing full screen: both quickprewiew (after selecting a group of images or whole directory with cmd-a) and Preview.app
Ability to select a group of images for[...]: Finder.app will does all but resize
seems like you have everything except resize just pressing the spacebar while in finder.
Preview.app will resize both a single image or multiple ones in one batch.
Use an App like Picasa (now available on mac). Use AppleScript through Python to control it from your application.
Failing that, use PyObjC to create Cocoa image display component and dialogs, and so on.
I ended up using PyGame, has been pretty good so far.