How to work with the text in the SOM 2. There is a code. I do not understand what went wrong.
bmpfont = sdl2.ext.BitmapFont(surface, (width, height))
software_renderer = sdl2.ext.SoftwareSpriteRenderSystem(window)
factory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE)
sprite = factory.create_software_sprite((40, 40))
surf = bmpfont.render("4").surface
sprite.surface = surf
software_renderer.render(sprite, 0, 0)
gives an error message:
ctypes.ArgumentError: argument 1: <class 'TypeError'>: expected LP_SDL_Surface instance instead of SoftwareSprite
Exception ignored in:
LP_ is a ctypes indicator for long pointers. You'll need to call the contents method on the LP object to get the object you want.
Related
Hi im doing a bluetooth project using bluetooth toolbox in matlab, and encountered a problem. So I have been following one of the example from https://www.mathworks.com/help/bluetooth/ug/noncollaborative-bluetooth-le-coexistence-with-wlan-signal-interference.html this error occurred.
ble_wlan_interference
Argument to dynamic structure reference must evaluate to a valid field
name.
Error in helperBluetoothChannelClassification (line 102)
obj.(varargin{idx}) = varargin{idx+1};
Error in ble_wlan_interference (line 58)
classifierObj = helperBluetoothChannelClassification(centralNode,peripheralNode,PERThreshold=50);
At line 102 of helperBluetoothChannelClassification.m is as follows,
methods
% Constructor
function obj = helperBluetoothChannelClassification(varargin)
% Set name-value pairs
for idx = 1:2:nargin
obj.(varargin{idx}) = varargin{idx+1};
end
At line 58 of main code is as follows,
%enable channel classification
enableChannelClassification = true;
if enableChannelClassification
classifierObj = helperBluetoothChannelClassification(centralNode,peripheralNode,PERThreshold=50);
classifyFcn = #(varargin) classifierObj.classifyChannels;
userData = []; % User data needed to be passed to the callback function
callAt = 0; % Absolute simulation time, in seconds
periodicity = 125e-3; % In seconds
scheduleAction(networkSimulator,classifyFcn,userData,callAt,periodicity); % Schedule channel classification
end
I think the centralNode and peripheralNode parameter is not recognizable in helperBluetoothChannelClassification function, but don't know what is a problem.. Thanks :)
I have this function who supposed to change the label of polygon (code below), where "nom_com" and "statutpro" are fields in a layer.
def ETIQUETAGE(self):
layer = self.COUCHE_DEPARTEMENT_SELECTIONNEE() #return a vector layer
deco = QgsPalLayerSettings()
deco.enabled = True
isExpression = True
if self.ChoixEtiquetage.currentText() == "COMMUNE":
deco.fieldName = '\'nom :\' +"nom_com"'
if self.ChoixEtiquetage.currentText() == "COMMUNE ET STATUT PROSPECTION":
deco.fieldName = '"nom_com" + \'\\n\' +"statutpro"'
labeler = QgsVectorLayerSimpleLabeling(deco)
layer.setLabeling(labeler)
layer.setLabelsEnabled(True)
layer.triggerRepaint()
When I run it everything ok (i don't have any error), the problem is for the display. The function change the label charateristic in the properties window but there is no display until I press aply in the properties window.
When I put only one argument the display work perfectly. for example
deco.fieldName = "nom_com"
Is there a particular syntax when it's a expression ?
I just see where my error was, it was a syntaxe error.
If the label is expression based we must put
deco.isExpression
for the plugin to display something in the canvas
def ETIQUETAGE(self):
layer = self.COUCHE_DEPARTEMENT_SELECTIONNEE() #return a vector layer
deco = QgsPalLayerSettings()
deco.enabled = True
deco.isExpression = True
if self.ChoixEtiquetage.currentText() == "COMMUNE":
deco.fieldName = "concat('nom : ', nom_com)"
if self.ChoixEtiquetage.currentText() == "COMMUNE ET STATUT PROSPECTION":
deco.fieldName = "concat('nom : ', nom_com, '\\n', 'Statut prospection : ', statutpro)"'
labeler = QgsVectorLayerSimpleLabeling(deco)
layer.setLabeling(labeler)
layer.setLabelsEnabled(True)
layer.triggerRepaint()
hope it will help people
I'm trying, without success, to access the data of a mesh from a MeshInstance node.
I've imported a 3d object, opened it as "New Inherited", turned it as "Unique" and saved it as foo.mesh. Then, on a new scene, I did create a MeshInstance and loaded the foo.mesh as its Mesh.
The Script is attached to the very MeshInstance, kinda like follows:
extends MeshInstance
func _ready():
var themesh = Mesh
var mdt = MeshDataTool.new()
if mdt.create_from_surface(themesh, 0):
print("Ok!!")
print(mdt.get_vertex_count()) # get_vertex_count() returns 0
else:
print("Failed...")
It doesn't work for built in meshes. Needs to be an imported mesh, that I also save as a Godot .mesh.
Reference links: Facebook, Mesh Data Tool, Mesh Class
I was mistaking pointing to Mesh class instead of mesh attribute to get the mesh reference. And the if test needs to check pass, because "create_from_surface()" returns a non zero when an error occours.
extends MeshInstance
func _ready():
var themesh = mesh # Same as bellow, points to same object in memory
var themesh2 = self.get_mesh() # Same as above, points to same object in memory
print("Mesh surface count: " + str(themesh.get_surface_count()))
var mdt = MeshDataTool.new()
if mdt.create_from_surface(themesh, 0) == OK: # Check pass
print("Ok!!")
print(mdt.get_vertex_count())
else:
print("Fail...")
var aMeshVerts = []
for i in range(mdt.get_vertex_count()):
aMeshVerts.append(mdt.get_vertex(i)) # Storing the vertices positions
mdt.set_vertex(0, Vector3(1, 2, 1)) # Changing a vertice position
themesh.surface_remove(0)
mdt.commit_to_surface(themesh)
mdt.clear()
Question
I'm trying to find NET_WM_NAME property for each of the window/client that X11 reports. Problem is that there's nothing returned - number of items is 0 and returned data results in empty string. I've looked at multiple code examples through out github and examples written in C and C++ , specifically Why is XGetWindowProperty returning null? as well as Xlib XGetWindowProperty Zero items returned , however I cannot find where is the problem with my code. Seemingly everything is fine, order of parameters passed to XGetWindowProperty function is in accordance with documentation, and the function returns success status, but results are empty. Where is the problem with my code ?
Code
Below is the code I am working with. The issue is xgetwindowproperty function. The other parts below it work fine, and are provided only for completeness.
#! /usr/bin/env python3
import sys
from ctypes import *
def xgetwindowproperty(display,w):
actual_type_return = c_ulong()
actual_format_return = c_int()
nitems_return = c_ulong()
bytes_after_return = c_ulong()
prop_return = POINTER(c_ubyte)()
wm_name = Xlib.XInternAtom(display,'_NET_WM_NAME',False)
utf8atom = Xlib.XInternAtom(display,'UTF8_STRING',False)
print('_NET_WM_NAME',wm_name, 'UTF8_STRING',utf8atom)
# AnyPropertyType = c_long(0)
status = Xlib.XGetWindowProperty(
display,
w,
wm_name,
0,
65536,
False,
utf8atom,
byref(actual_type_return),
byref(actual_format_return),
byref(nitems_return),
byref(bytes_after_return),
byref(prop_return)
)
print(nitems_return.value) # returns 0
# empty string as result
print( 'Prop', ''.join([ chr(c) for c in prop_return[:bytes_after_return.value] ]) )
Xlib.XFree(prop_return)
print('#'*10)
# -------
Xlib = CDLL("libX11.so.6")
display = Xlib.XOpenDisplay(None)
if display == 0:
sys.exit(2)
w = Xlib.XRootWindow(display, c_int(0))
root = c_ulong()
children = POINTER(c_ulong)()
parent = c_ulong()
nchildren = c_uint()
Xlib.XQueryTree(display, w, byref(root), byref(parent), byref(children), byref(nchildren))
for i in range(nchildren.value):
print("Child:",children[i])
xgetwindowproperty(display,children[i])
I usually have sandbox where I try snippets of code out.
When I run the following code in my sandbox it works as expected
tuple_current_time = time.localtime(time.time())
print("tuple_current_time = ", tuple_current_time)
But when I run it in the module I am developing I get the error
AttributeError: 'str' object has no attribute 'localtime'
if not (sched_time) == "TIME":
print("Its not equal", sched_time)
#print ("Variable Type : ", type (tuple_current_time))
#Create a tuple of current time
tuple_current_time = time.localtime(time.time())
print("tuple_current_time = ", tuple_current_time)
tuple_website = newtuple=(tuple_current_time[0], tuple_current_time[1], tuple_current_time[2], sched_hour, sched_min, 0, 0, 0, 0)
print("tuple_website = ", tuple_website)
if tuple_website > tuple_current_time:
#print("Website tuple is newer than current time tuple")
else:
#print("Current time tuple is newer than website time tuple")
Please can anybody advise what I am doing wrong?
Thanks