How to solve the wxGrid class no "findWindowById" function? - erlang

In the wxframe, there is one button and one "wxGrid" object.
I want to "click“ the function to change the "wxGrid".
But wxStaticText hasn't function for "findWindowById". Now I solve as follows
-record(wx_ref, {ref, type, state=[]}).
button_debug_a_click(Event,Object)->
A = wxWindow:findWindowById(?CONST_EQUIPMENT_GRID_ID),
B = A#wx_ref{type = wxGrid},
lager:debug("find equipment grid object:\t~p\t~p",[A,B]),
wxGrid:hide(B),
ok.
Only after it is converted to {wx_ref,45, wxGrid,[]}, it can be used.
But “wx_ref” record's header file can't be visited.
Is there a better way to solve the problem (convert id to object)

Related

Access Properties of a new Stream in Esper

I'm starting a new stream by using the statement:
"insert into middleLayerStream select id, 'response' as constraint from[...]"
Afterwards I'm starting a SELECT-query to the middleLayerStream. In die update-function of my middleLayerStream I want du print out the properties of the stream.
This is my update Function:
public class MiddleLayerListener impplement UpdateListener{
public void update(EventBean[] newEvents, EventBean[] oldEvents){
EventBeant[] event = newEvents[0];
System.out.println(event.getUnderlying());
}
}
When the update-function is called, I don't get the properties but this stetement instead:
{a=MapEventBean eventType=com.espertech.esper.event.map.MapEventType#52500920, b=MapEventBean eventType=com.espertech.esper.event.map.MapEventType#52500920}
How do I get access to the properties?
I just found out, that event is not a simple EventBean but a MapEventBean. Maybe it's because two different types of events (but with the same properties) are inserted into the stream. But how can i handle a MapEventBean and get the properties out of it?
Thank you very much for your help.
The EventBean interface offers a "get" method that returns an event property value by name.
public void update(EventBean[] newEvents, EventBean[] oldEvents){
for (EventBean event : newEvents) {
System.out.println(event.get("id"));
}
}
You left off the "from" in your post so it wasn't possible to see what was selected. I assume that you have a pattern in the "from" such as "a=A -> b=B".
In the case of a pattern returning a nested event event.get("a.id") or event.get("a") or event.getFragment("a") or select a.id as id from [...] would do.
Ok I got it..
In my SELECT Query that ist starting the update function of MiddleLayerListener I selected * like
SELECT * from pattern[every a=.... -> b=...]
So of course there a both events in a MapEventBean (a and b).
By specifying the SELECT Query like:
SELECT a.id as id from pattern...
In now have only the wanted properties in my stream and can access them as normal.
Wow.. that took me a whole day of desperation :D
Thank your very much for your help :)

Odoo dynamic many2one domain

I want to apply dynamic filter to a many2one field (F1) based on another field (F2). I've done that using #api.change decorator, and it works but not as expected.
When i create a new entity, i change the value of F2, then go to F1, i find it filered, Oki no problem.
When i close the form, and then edit it again, and i go directly to the F1 field, i get again all available possibilities (not filtered), i need first to go to F2 and then choose the same value (already chosen previously) and then come back to F1.
Any idea ? (below the code: F1 = product_id which is inherited, and F2 = bom_id)
class ProductionLot(models.Model):
_inherit = "stock.production.lot"
company_id = fields.Many2one(default=lambda self: self.env['res.company']._company_default_get('account.invoice'))
bom_serial_number_line_ids = fields.One2many("mrp.bom.serialnumber.line", "parent_lot_id", "BoM Serial Numbers")
bom_id = fields.Many2one("mrp.bom", "BoM")
#api.onchange('product_id')
def update_bom_id_from_product_id(self):
for record in self:
if (record.product_id):
bom_complex_kit = record.product_id.env['mrp.bom']._bom_find(
product_tmpl=record.product_id.product_tmpl_id,
bom_type='complex_kit')
self.bom_id = bom_complex_kit
return {"domain": {"bom_id": [('product_tmpl_id.id', '=', record.product_id.product_tmpl_id.id),
('type', '=', 'complex_kit')]}}
As onchange filter will only be applied when the function is a trigger so it will only work when you change the on change value I guess what you need to do is this or combination of both onchange and default domain on field
def get_domain(self):
ids = self.env['stock.production.lot'].browse(self._context.get('active_ids'))
print("Here see all ids and use them accordingly",ids)
bom_id = fields.Many2one("mrp.bom", "BoM", domain = lambda self:self.get_domain())

Lua - table won't insert from function

I have a Lua function where I build a table of value and attempt to add it to a global table with a named key.
The key name is pulled from the function arguments. Basically, it's a filename, and I'm pairing it up with data about the file.
Unfortunately, the global table always comes back nil. Here's my code: (let me know if you need to see more)
(Commented parts are other attempts, although many attempts have been deleted already)
Animator = Class{}
function Animator:init(atlasfile, stringatlasfriendlyname, totalanimationstates, numberofframesperstate, booleanstatictilesize)
-- Define the Animator's operation mode. Either static tile size or variable.
if booleanstatictilesize ~= false then
self.isTileSizeStatic = true
else
self.isTileSizeStatic = false
end
-- Define the total animation states (walking left, walking right, up down, etc.)
-- And then the total frames per state.
self.numAnimationStates = totalanimationstates or 1
self.numAnimationFrames = numberofframesperstate or 2
-- Assign the actual atlas file and give it a programmer-friendly name.
self.atlasname = stringatlasfriendlyname or removeFileExtension(atlasfile, 'animation')
generateAnimationQuads(atlasfile, self.atlasname, self.numAnimationStates, self.numAnimationFrames)
end
function generateAnimationQuads(atlasfile, atlasfriendlyname, states, frames)
spriteWidthDivider = atlasfile:getWidth() / frames
spriteHeightDivider = atlasfile:getHeight() / states
animationQuadArray = generateQuads(atlasfile, spriteWidthDivider, spriteHeightDivider)
animationSetValues = {atlasarray = animationQuadArray, width = spriteWidthDivider, height = spriteHeightDivider}
--gAnimationSets[#gAnimationSets+1] = atlasfriendlyname
gAnimationSets[atlasfriendlyname] = animationSetValues
--table.insert(gAnimationSets, atlasfriendlyname)
end
Note: when using print(atlasfriendlyname) and print(animationSetValues), neither are empty or nil. They both contain values.
For some reason, the line(s) that assign the key pair to gAnimationSets does not work.
gAnimationSets is defined a single time at the top of the program in main.lua, using
gAnimationSets = {}
Animator class is called during the init() function of a character class called Bug. And the Bug class is initialized in the init() function of StartState, which extends from BaseState, which simply defines dummy init(), enter(), update() etc. functions.
StartState is invoked in main.lua using the StateMachine class, where it is passed into StateMachine as a value of a global table declared in main.lua.
gAnimationSets is declared after the table of states and before invoking the state.
This is using the Love2D engine.
Sorry that I came here for help, I've been picking away at this for hours.
Edit: more testing.
Trying to print the animationQuadArray at the index gTextures['buganimation'] always returns nil. Huh?
Here's gTextures in Main.lua
gTextures = {
['background'] = love.graphics.newImage('graphics/background.png'),
['main'] = love.graphics.newImage('graphics/breakout.png'),
['arrows'] = love.graphics.newImage('graphics/arrows.png'),
['hearts'] = love.graphics.newImage('graphics/hearts.png'),
['particle'] = love.graphics.newImage('graphics/particle.png'),
['buganimation'] = love.graphics.newImage('graphics/buganimation.png')
}
Attempting to return gTextures['buganimation'] returns a file value as normal. It's not empty.
My brain is so fried right now I can't even remember why I came to edit this. I can't remember.
Global table in Main.lua, all other functions can't access it.
print(gTextures['buganimation']) works inside the function in question. So gTextures is absolutely accessible.
Table isn't empty. AnimationSetValues is not empty.
I'm adding second answer because both are correct in context.
I ended up switching IDE's to VS Code and now the original one works.
I was originally using Eclipse LDT with a Love2D interpreter and in that environment, my original answer is correct, but in VS Code, the original is also correct.
So Dimitry was right, they are equivalent, but something about my actual Eclipse setup was not allowing that syntax to work.
I switched to VS Code after I had another strange syntax problem with the interpreter where goto syntax was not recognized and gave a persistent error. The interpreter thought goto was the name of a variable.
So I switched, and now both things are fixed. I guess I just won't use LDT for now.
Solution: Lua syntax. Brain Fry Syndrome
I wrote:
animationSetValues = {atlasarray = animationQuadArray, width = spriteWidthDivider, height = spriteHeightDivider}
Should be:
animationSetValues = {['atlasfile']=atlasfile, ['atlasarray']=animationQuadArray, ['width']=spriteWidthDivider, ['height']=spriteHeightDivider}
Edit: I'm fully aware of how to use answers. This was posted here to reserve my spot for an answer so I could edit it later when I returned back home, which is exactly what I'm doing right now. I'll keep the old post for archival purposes.
Original:
I solved it. I apologize for not posting the solution right now. My brain is melted into gravy.
I will post it tomorrow. Just wanted to "answer" saying no need to help. Solved it.
Solution is basically, "oh it's just one of those Lua things". Wonderful. I'm having so much fun with this language - you can tell by my blank expression.
From the language without line endings or brackets, but forced print parentheses... ugh. I'm going back to C# when this class is done.

Navigation with OData properties

I want to use a table for navigation purposes. Therefore I use the following code (the table looks good, all datas are complete):
// Admin.view.xml View
<Table id="objectsTable" itemPress="onSelectionChange">
// Admin.controller.js Controller
onSelectionChange: function(event) {
// After call undefined
var partnerId = event.getSource().getBindingContext().getProperty("BUSINESS_PARTNER_ID");
// After call defined and correct
var objectId = event.getSource().getBindingContext().getProperty("ID");
var router = this.getOwnerComponent()
.getRouter();
router.navTo("adminDetails", {
partner: partnerId,
object: objectId
});
After debugging I found out, that the value objectIdis undefined (while ID is present). This causes the navigation to not work properly.
So I looked at the data source (oData), which looks as follows :
ID | BUSINESS_PARTNER_ID | ADDRESS | FILES (oData association/navigation) |
.... All records are available, including the BUSINESS_PARTNER_ID
Why is the variable BUSINESS_PARTNER_IDundefined while all the data from the records are displayed correctly? I can query it, except BUSINESS_PARTNER_ID. Does anybody know how I can fix this?
Do partnerId and objectId have values? If the values for these are there then we need to check the routing and your manifest files. If partnerId and ObjectId are blank.
If these fields are blank i can think of another fix. Instead of binding the event from table, i believe you must have a columnlistitem or objectlistitem under your table. You can assign the press event on that and move this code to that.
Basically i am triggering the event from list item instead of table.
Thanks and Regards,
Veera
"Just" change my query to
event.getParameter("listItem").getBindingContext().getProperty("XYZ");

Is it possible to use a record as a record element

I want to define a large record using a composite of smaller records, in an attempt to make the declaration more readable.
I'm trying to do something like this:
-record(molly, {xx=0, yy=1}).
-record(harry, {#molly, zz=2}.
The above of course does not compile :-(
Is there some way to do this ??
Finally found the answer in a tutorial.....
-record(name, {first = "Robert", last = "Ericsson"}).
-record(person, {name = #name{}, phone}).
Thanks ...
Yes, there is -- wxErlang uses this a lot for event messages. The use syntax looks like
#wx{id=1, event=#wxCommand{}}
where the event field of the outer record is set to an empty wxCommand.
The corresponding declaration is
%% #type wx() = #wx{id=integer(), obj=wx:wxObject(), userData=term(), event=Rec}. Rec is a event record.
-record(wx, {id, %% Integer Identity of object.
obj, %% Object reference that was used in the connect call.
userData, %% User data specified in the connect call.
event}).%% The event record

Resources