How to access nested widgets properties in Awesome - lua

I'm trying to access the properties of the following widget:
local cpu_widget = wibox.widget{
{
max_value = 100,
paddings = 1,
border_width = 2,
widget = wibox.widget.progressbar,
},
{
font = beautiful.font_type .. "8",
widget = wibox.widget.textbox,
},
forced_height = 100,
forced_width = 20,
direction = 'east',
layout = wibox.container.rotate,
}
I've tried through the conventional way, using cpu_widget[1].value or cpu_widget[2].text, but that didn't work.
Any thoughts on how I could do that?

See the "Accessing Widgets" on https://awesomewm.org/doc/api/documentation/03-declarative-layout.md.html (I can't seem to link to this section directly)
Basically: You can add id = "bar" and id = "text" to your widgets and use these identifiers to retrieve the widgets again.
In case Elv13 ever sees this answer: You did great work on the docs!

Related

Trying to figure out how to Grab part of a table. (hard to explain fully)

So, what i am trying to do is... well it's best to show. oh and This is with Fivem and trying to modify an existing resource, but...
`BMProducts = {
{
["lostItems"] = {
[1] = { name = "weapon_shotgun", price = 1500, crypto = 2500, amount = 1 },
},
}
}
table.insert(BMProducts, {
["ballasItems"] = {
[1] = { name = "weapon_pistol", price = 1500, crypto = 2500, amount = 1 },
},
})
Config.Products = BMProducts`
And I have a another config, that i need to pull the Correct table, but now sure entirely how
`["products"] = Config.Products["ballasItems"],`
Is what I have but it won't read it, due to what I assume is what i saw when debugging, that when inserting to the table, it assigns a number, ie;
[1] = {lostitems = {... [2] = {ballasItems = {...
One that works, but what my ultimate goal is to make the code plug and play with the table inserts, is this
`BMProducts =
{
["lostItems"] = {
[1] = { name = "weapon_pistol", price = 1500, crypto = 2500, amount = 1 },
},
["ballasItems"] = {
[1] = { name = "weapon_pistol", price = 1500, crypto = 2500, amount = 1 },
},
}`
which works with the config above because the way just above does not assign numbers and not inserting into a table. Any ideas how i can go about setting that config for the correct Products table?
When i try it with the table insert, and with the
`["products"] = Config.Products["ballasItems"],`
It can't find the table, which is due to what i assume the table format being different than what it was, which was the code block at the bottom
so my main thing, is to get
`["products"] = Config.Products["ballasItems"],`
to = the correct table when there is a table insert.
If you don't want to table.insert, then don't table.insert:
BMProducts["ballasItems"] = {
{ name = "weapon_pistol", price = 1500, crypto = 2500, amount = 1 },
}
Now I think you told to not modify the config, so another approach is to just use that additional array index when indexing:
["products"] = Config.Products[2]["ballasItems"]
Which obviously assumes that the config never changes and the entry with ballasItems is on index 2.
If you do not know the index, you may want to iterate over Config.Products and look for the right product.
for i,v in ipairs(Config.Products) do
if v["ballasItems"] then
end
end
You may also consider the case where two or more products match.

Nvim-cmp is adding multiple times the same sources

I'm using nvim-cmpto have a contextual window to display my LSP suggestions and my snippets but when I open multiple buffers, I have an issue : the same source is added multiple times to nvim-cmp causing the same result to be repeated in the popup.
For example, here is the result of :CmpStatus: after a few minutes of work.
# ready source names
- vsnip
- buffer
- nvim_lsp:pylsp
- vsnip
- nvim_lsp:pylsp
- nvim_lsp:pylsp
Here is my nvim-cmpconfig :
cmp.setup({
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
...
sources = {
{ name = 'vsnip' },
{ name = 'nvim_lua' },
{ name = 'nvim_lsp' },
{ name = 'buffer', keyword_length = 3 }
},
}
Does anyone know how to adress this issue ? Is it a problem with my configuration ?
In your cmp configuration, you can use the dup keyword for vim_item with the formatting option / format function. See help for complete-item for explanations (:help complete-item).
cmp.setup({
formatting = {
format = function(entry, vim_item)
vim_item.menu = ({
nvim_lsp = '[LSP]',
vsnip = '[Snippet]',
nvim_lua = '[Nvim Lua]',
buffer = '[Buffer]',
})[entry.source.name]
vim_item.dup = ({
vsnip = 0,
nvim_lsp = 0,
nvim_lua = 0,
buffer = 0,
})[entry.source.name] or 0
return vim_item
end
}
})
You can see details in this feature request for nvim-cmp plugin.
I had the same problem and managed to solve the issue by realizing that cmp is somehow installed twice.
Try removing or better first renaming the cmp-packages in the plugged directory, for example
cmp-nvim-lsp to cmp-nvim-lsp_not
cml-nvim-buffer to cmp-nvim-buffer_not
etc.
This did the job for me.

How do I use information from Roblox Games API?

So I am trying to make some code that gets information about games using the Roblox API. I do get data back when I send a request, but I can't figure out a way to use the data in the code. Because when I decode it, it looks like this:
{
["data"] = ▼ {
[1] = ▼ {
["allowedGearCategories"] = {},
["allowedGearGenres"] = ▶ {...},
["copyingAllowed"] = false,
["createVipServersAllowed"] = false,
["created"] = <creation date>,
["creator"] = ▶ {...},
["description"] = "",
["favoritedCount"] = 0,
["genre"] = "Comedy",
["id"] = <the id>,
["isAllGenre"] = false,
["isFavoritedByUser"] = false,
["isGenreEnforced"] = true,
["maxPlayers"] = 10,
["name"] = <the name>,
["playing"] = 0,
["rootPlaceId"] = <the id>,
["studioAccessToApisAllowed"] = false,
["universeAvatarType"] = "PlayerChoice",
["updated"] = <update date>,
["visits"] = 0
}
}
}
I censored some of the information about which game it is, but that information isn't important here. The important thing is that it says "1" under "data", and if I type that into the code, it uses it as a number. So I can't access anything further down in the list than "data".
Here is my code, if it helps:
local universe = Proxy:Get("https://api.roblox.com/universes/get-universe-containing-place?placeid="..placeId).body
local universeDecoded = http:JSONDecode(universe)
local universeId = universeDecoded.UniverseId
local placeInfo = http:JSONDecode(Proxy:Get("https://games.roblox.com/v1/games?universeIds="..universeId).body)
print(placeInfo.data)
Also, sorry for not knowing a lot of programming words, so I say stuff like "further down in the list". But I hope it's clear what I mean.
I figured it out myself. I just had to write
print(placeInfo.data[1])

LUA and table data - finding data in a nested loop

I have the following table
scavenging =
{
{
type = "Greenskin|16",
fast_levelup = 20, --Number of levels with 75% chance to level up after required level
normal_levelup = 40, --Number of levels with 50% chance to level up after fast_levelup + required level
slow_levelup = 40, --Number of levels with 25% chance
drops = --Drops
{
{items = {"Linen", "Bolt of Linen", "Coarse Thread", "Feather", "Cotton"}, droprates = {60, 10, 10, 10, 2}},
},
},
}
This is one data value in a series. I use
function scavenge_meta(scavenge_name)
for _, meta in pairs(scavenging) do
if string.match(meta.type, scavenge_name) then
return meta
end
end
end
to pull the needed data. The question is, is there an easy way to get to the droprates value without having to do a few for (pairs)? Right now for example I can use:
local founditem = scavenge_meta("Greenskin|16")
And this works, and then I can use founditem.fast_levelup etc. I was hoping to access the drops table with founditem.drops.items for example, but this doesn't work, I need to do a pairs(founditem.drops) then pairs(valuefound.items) /etc.
Maybe there is a better way of doing this?
if you can change the table then do:
scavenging =
{
["Greenskin|16"] = {
type = "Greenskin|16",
fast_levelup = 20,
normal_levelup = 40,
slow_levelup = 40,
drops =
{
{items = {"Linen", "Bolt of Linen", "Coarse Thread", "Feather", "Cotton"}, droprates = {60, 10, 10, 10, 2}},
},
},
}
and get data directly by index
print(scavenging["Greenskin|16"].fast_levelup)
otherwise, just by searching as you did.

How to vary the width of TextBox views using Rikulo Anchor Layout

I am new to Dart and Rikulo.
class NameView extends Section
{
View parentVu;
// the inputs
DropDownList titleDdl, suffixDdl;
TextBox firstNameTBox, middleNameTBox, lastNameTBox;
// the labels
TextView titleLbl, firstNameLbl, middleNameLbl, lastNameLbl, suffixLbl;
List<String> titles = [ 'Dr', 'Hon', 'Miss', 'Mr', 'Mrs', 'Prof', 'Sir' ];
List<String> suffixes = ['I', 'II', 'III', 'IV', 'Junior', 'Senior'];
NameView()
{
parentVu = new View()
..style.background = 'cyan'
..addToDocument();
titleLbl = new TextView( 'Title' );
parentVu.addChild( titleLbl );
titleDdl = new DropDownList( model : new DefaultListModel( titles ) )
..profile.anchorView = titleLbl
..profile.location = 'east center';
parentVu.addChild( titleDdl );
firstNameLbl = new TextView( 'First' )
..profile.anchorView = titleDdl
..profile.location = 'east center';
parentVu.addChild(firstNameLbl );
firstNameTBox = new TextBox( null, 'text' )
..profile.anchorView = firstNameLbl
..profile.location = 'east center';
//..profile.width = 'flex';
parentVu.addChild( firstNameTBox );
}
The program renders. However, it does not uses the entire width of the browser (FireFox).
I have tried for the TextBoxes
profile.width = 'flex'
but it does not work.
Any help is appreciated.
Firefox? Did you test it with Dartium? Notice that you have to compile it to JS before you can test it with browsers other than Dartium.
BTW, from your implementation, NameView seems not related to parentVu at all. If it is just a controller, it needs not to extend from Section (i.e., it doesn't have to be a view).
If a view is anchored to another, both location and size will depend on the view it anchors. In your case, if specifying flex to TextBox, its width will be the same as FirstNameLb1. It is why it is so small.
You can listen to the layout event such as:
firstNameTBox.on.layout.listen((_) {
firstNameTBox.width = parentVu.width;
});
Note: You need to do some calculation to get the right width.
See also Layout Overview

Resources