I'm trying to select a DC with a HBITMAP, but I seem to get an error. I'm using Pywin32 for Win32 functions as well as ctypes for the VirtualAlloc function.
data = VirtualAlloc(0, (x*y+x)*512,MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE)
hbm = CreateBitmap(x,y,1,32,data)
SelectObject(hdcdc, hbm)
Here's the error that occours when the code is executed:
Traceback (most recent call last):
File "...", line 32, in <module>
SelectObject(hdcdc, hbm)
TypeError: The object is not a PyHANDLE object
Thanks for any help!
You should invoke CreateDCFromHandle to create a DC object then use it's SelectObject method.
dc_hwnd = win32gui.GetWindowDC(desk_hwnd)
desk_dc = win32ui.CreateDCFromHandle(dc_hwnd)
pen = win32ui.CreatePen(win32con.PS_SOLID, 10, win32api.RGB(255, 0, 0))
old_pen = desk_dc.SelectObject(pen)
Related
I am trying to execute the following code that creates a cube in mesh:
import pygmsh as pg
import numpy as np
def generate():
geom = pg.Geometry()
geom.add_box(0, 1, 0, 1, 0, 1, 0.05)
return geom
if __name__ == '__main__':
import meshio
points, cells = pg.generate_mesh(generate())
meshio.write('cube.vtu', points, cells)
I'm getting the following error:
Traceback (most recent call last):
File "C:/Users/200498/PycharmProjects/untitled/pygmsh.py", line 17, in
<module>
points, cells = pg.generate_mesh(generate())
AttributeError: module 'pygmsh' has no attribute 'generate_mesh'
How can I fix that?
You've called your own script "pygmsh", so it's hiding the library you installed. Rename your file to something else.
Extremely confused here... trying to select all items in a QListWidget. Strangely enough I have done this before fine with this code, but this time it is barking back at me?
# Error: 'PySide.QtGui.QListWidget' object has no attribute 'setItemSelected'
# Traceback (most recent call last):
# File "<maya console>", line 2, in <module>
# ...............
# self.locListWidget.setItemSelected(item, True)
# AttributeError: 'PySide.QtGui.QListWidget' object has no attribute 'setItemSelected' #
if (sizeDimensionLocators > 0):
for loc in dimensionLocators:
self.locListWidget.addItem(loc)
for i in range(self.locListWidget.count()):
item = self.locListWidget.item(i)
self.locListWidget.setItemSelected(item, True) <---------- Issue Here
QListWidget doesn't have a setItemSelected:
https://srinikom.github.io/pyside-docs/PySide/QtGui/QListWidget.html#PySide.QtGui.QListWidget
http://doc.qt.io/archives/qt-4.8/qlistwidget.html#selectedItems
You can do this though:
item.setSelected(true)
http://doc.qt.io/qt-5/qlistwidgetitem.html#setSelected
You might also need to review the selection mode:
https://srinikom.github.io/pyside-docs/PySide/QtGui/QAbstractItemView.html#PySide.QtGui.PySide.QtGui.QAbstractItemView.setSelectionMode
I'm attempting to make a simple platformer game, however, I can't show the "Game Over" message because tkinder, and more specifically, tkfont, or tkinder.font, is a module, and cannot be called.
Code here. The full traceback is:
Traceback (most recent call last):
File "C:\Users\iD Student\Desktop\Connor M\Endless platformer.py", line
31, in <module>
helv36 = tkinter.font(family="Helvetica",size=36,weight="bold")
TypeError: 'module' object is not callable
tkinter.font.Font throws this traceback:
Traceback (most recent call last):
File "C:\Users\iD Student\Desktop\Connor M\Endless platformer.py", line
31, in <module>
helv36 = tkinter.font.Font(family="Helvetica",size=36,weight="bold")
File "C:\Python35\lib\tkinter\font.py", line 93, in __init__
tk.call("font", "create", self.name, *font)
AttributeError: 'NoneType' object has no attribute 'call'
which I assume to be an error in tkinter itself. Relevant code:
import tkinter
from tkinter.font import *
helv36 = tkinter.font.Font(family="Helvetica",size=36,weight="bold")
def draw_text(display_string, font, surface, x_pos, y_pos):
text_display = font.font(display_string, 1, (0, 0, 0))
surface.blit(text_display, (x_pos, y_pos))
#Ends the game if the player dies
if y >640:
endgame = True
if endgame:
draw_text("GAME OVER", helv36, screen, 50, 50)
You can't create a font until after you've created a root window.
from weka.clusterers import Clusterer
import weka.core.converters as converters
data = converters.load_any_file("/home/ubuntu/test.csv")
data.class_is_last()
clusterer = Clusterer(classname="weka.clusterers.SimpleKMeans", options=["-N", "3"])
clusterer.build_clusterer(data)
print(clusterer)
# cluster the data
for inst in data:
cl = clusterer.cluster_instance(inst) # 0-based cluster index
dist = clusterer.distribution_for_instance(inst) # cluster membership distribution
print("cluster=" + str(cl) + ", distribution=" + str(dist))
I used the above code for doing k means custering i am not able to execute the program
The following are the errors I get
Traceback (most recent call last):
File "clus.py", line 6, in <module>
data = converters.load_any_file("/home/ubuntu/hello.csv")
File "/usr/local/lib/python2.7/dist-packages/weka/core/converters.py", line 255, in load_any_file
loader = loader_for_file(filename)
File "/usr/local/lib/python2.7/dist-packages/weka/core/converters.py", line 239, in loader_for_file
"(Ljava/lang/String;)Lweka/core/converters/AbstractFileLoader;", filename)
File "/usr/local/lib/python2.7/dist-packages/javabridge/jutil.py", line 932, in static_call
fn = make_static_call(class_name, method_name, sig)
File "/usr/local/lib/python2.7/dist-packages/javabridge/jutil.py", line 903, in make_static_call
klass = env.find_class(class_name)
AttributeError: 'NoneType' object has no attribute 'find_class'
I don't know why I am getting these errors. Can someone help me with this?
As described in the python-weka-wrapper API you have to import and start the Java Virtual Machine:
import weka.core.jvm as jvm
jvm.start()
It should solve your problem.
I got an error while run python proxy.py
$ python proxy.py
INFO - [Sep 28 14:59:19] getting appids from goagent plus common appid pool!
Traceback (most recent call last):
File "proxy.py", line 2210, in <module>
main()
File "proxy.py", line 2180, in main
pre_start()
File "proxy.py", line 2157, in pre_start
common.set_appids(get_appids())
File "proxy.py", line 94, in get_appids
fly = bytes.maketrans(
AttributeError: type object 'str' has no attribute 'maketrans'
The proxy.py file in https://code.google.com/p/smartladder/,
def get_appids():
fly = bytes.maketrans(
b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
b"nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM"
)
f = urllib.request.urlopen(url="http://lovejiani.com/v").read().translate(fly)
d = base64.b64decode(f)
e = str(d, encoding='ascii').split('\r\n')
random.shuffle(e)
return e
You are running code written for Python 3, with Python 2. This won't work.
maketrans is a classmethod on the bytes built-in type, but only in Python 3.
# Python 3
>>> bytes
<class 'bytes'>
>>> bytes.maketrans
<built-in method maketrans of type object at 0x10aa6fe70>
In Python 2, bytes is an alias for str, but that type does not have that method:
# Python 2.7
>>> bytes
<type 'str'>
>>> bytes.maketrans
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: type object 'str' has no attribute 'maketrans'
Run your code with Python 3 instead, or translate all code in this project to Python 2; the latter requires in-depth knowledge of how Python 2 and 3 differ and is likely a major undertaking.
Just the illustrated function, translated to Python 2, would be:
import string
import urllib2
import base64
import random
def get_appids():
fly = string.maketrans(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
"nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM"
)
f = urllib2.urlopen("http://lovejiani.com/v").read().translate(fly)
d = base64.b64decode(f)
e = unicode(d, encoding='ascii').split(u'\r\n')
random.shuffle(e)
return e