Cool VL Viewer forum

View unanswered posts | View active topics It is currently 2025-08-10 02:08:36



Reply to topic  [ 18 posts ]  Go to page Previous  1, 2
Notifications manager 
Author Message

Joined: 2009-03-17 18:42:51
Posts: 6030
Reply with quote
g0rd0ngrfr33mailgr wrote:
Oh, I would certainly love that. But that would require that, for every notice received, its information is displayed on a custom xml floater (with buttons to deal with), while at the same time removed from the viewer's notification stack. I don't know if/how that is possible.
All you need to do is to create a small Lua floater, with a list and a few buttons... Then RTFM ! :lol: (*)


(*) Hints: in the above example for OnGroupNotification(), replace the printing and cancellation code with code for opening your Lua floater (if not already opened), and inserting the notification data into its list. Then, setup actions for your buttons, which would operate on the selected list elements (notifications).


2025-04-05 18:01:38
Profile WWW

Joined: 2010-03-14 21:12:58
Posts: 92
Reply with quote
Henri Beauchamp wrote:
New OnGroupNotification() Lua callback and new GroupNotificationAcceptOffer() Lua function implemented for next release. CancelNotification() will also be usable to cancel (close) group notifications.


Oh, that is awesome, Henri. Thank you so much! :D


2025-04-07 00:46:37
Profile

Joined: 2011-09-27 11:18:31
Posts: 244
Reply with quote
Henri Beauchamp wrote:
g0rd0ngrfr33mailgr wrote:
Hints: in the above example for OnGroupNotification(), replace the printing and cancellation code with code for opening your Lua floater (if not already opened), and inserting the notification data into its list. Then, setup actions for your buttons, which would operate on the selected list elements (notifications).

Thank you!!! I didn't know that that is what lists do! It's very rudimentary for now and the buttons won't work, but so far I have something:
https://i.imgur.com/nF2XdpH.png
I'll keep working on it! <3


2025-04-07 07:19:50
Profile

Joined: 2011-09-27 11:18:31
Posts: 244
Reply with quote
My progress so far:
Image

floater_lua_gnm.xml:
Code:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<floater name="lua_floater_gnm" title="Group Notifications Manager"
 can_close="true" can_drag_on_left="false" can_minimize="true" can_resize="true" width="650" height="340" min_width="700" min_height="250">
    <scroll_list name="list1" multi_select="true" background_visible="true" draw_border="true" draw_stripes="true" draw_heading="true" left="12" right="-12" width="700" top="-20" bottom="20" height="180" follows="left|top|right">
        <column name="col0" label="group_name" width="70" />
        <column name="col1" label="group_id" width="70" />
        <column name="col2" label="dialog_id" width="70" />
        <column name="col3" label="time" width="70" />
        <column name="col4" label="sender" width="70" />
        <column name="col5" label="subject" width="100" />
        <column name="col6" label="message" dynamicwidth="true" />
        <column name="col7" label="inventory" width="30" />
    </scroll_list>
        <button name="button1" label="Show" font="SansSerif" left="12" bottom="0" width="42" height="20" follows="bottom|right" />
</floater>


automation.lua
Code:
function OnGroupNotification(group_name, group_id, dialog_id, timestamp, sender, subject, message, inventory)
    local notice
        notice = group_name .. "|" .. group_id .. "|" .. dialog_id .. "|" .. GetTimeStamp(-8,'%H:%M:%S') .. "|" .. sender .. "|" .. subject.. "|" .. message .. "|" .. inventory
    OpenLuaFloater("gnm")
    SetLuaFloaterValue("gnm", "list1", notice)
    CancelNotification(dialog_id)
end


and in OnLuaFloaterAction:
Code:
      if name == "gnm" then
          SetLuaFloaterCommand("gnm","button1","print(GetLuaFloaterValues('gnm','list1')[message])")
      end


But that's where the problem is: the button's command returns "nil", so I presume I'm using the command wrong. It says in the manual it gives a "table of arrays", which I take to mean something like {"this" "that"} but it doesn't seem to work. Could you give me another pointer please?


2025-04-09 15:43:51
Profile

Joined: 2009-03-17 18:42:51
Posts: 6030
Reply with quote
g0rd0ngrfr33mailgr wrote:
floater_lua_gnm.xml:
Labels are free-form: I'd rather use "Group name" instead of "group_name", for example. Also, I doubt that you care much about seeing the group and dialog Ids, so you could either not use them at all, or shrink their width to 0 to hide them in the list (which leaves more room for other columns too).

g0rd0ngrfr33mailgr wrote:
automation.lua
Code:
function OnGroupNotification(group_name, group_id, dialog_id, timestamp, sender, subject, message, inventory)
.../...
end
You might want to add GroupNotificationAcceptOffer(dialog_id) before CancelNotification(dialog_id), since you are closing the dialogs systematically and would loose the offered inventory when there is one...

g0rd0ngrfr33mailgr wrote:
and in OnLuaFloaterAction:
Code:
      if name == "gnm" then
          SetLuaFloaterCommand("gnm","button1","print(GetLuaFloaterValues('gnm','list1')[message])")
      end

There are several problems here:
  1. OnLuaFloaterAction() is not the right callback to setup an UI element floater command (i.e. associate a Lua command to the commit callback of an UI element): setting commands can be done either directly in the floater XUI definition, using the lua_command attribute (see the example in Appendix B of the Lua manual, for spinner "spin1", for example), or via SetLuaFloaterCommand() in the OnLuaFloaterOpen() callback (i.e. you set the Lua commands when the floater gets opened; here again, see Appendix B of the manual for a example).
  2. The command you are using for button1 cannot work: for a list, GetLuaFloaterValues() only returns the selected lines indices in the list, not the columns contents for those selected lines...
  3. You are using an array key (message) which you fail to quote: valid syntax would be some_table["message"] or some_table.message, but since there is no such key returned by GetLuaFloaterValues('gnm','list1') anyway, you would get nil as well.

To deal with the "Show" (button1) action, it would be simpler to test for the control string in OnLuaFloaterAction(name, control, value): test name against "gnm" and control against "button1" and when they match, execute your code.
It would be possible to retrieve the "message" column contents for the list line at index GetLuaFloaterValues('gnm','list1'), but it would involve more complex code using the (non Lua-floater specific) GetFloaterList() function (and GetFloaterInstances("floater_lua_gnm") to get your Lua floater Id that GetFloaterList() needs), but this is complicating things uselessly.

My advice is to store the messages inside a global array defined in automation.lua (for example, outside of any function definition, use group_messages = {} on a line).
Then, in OnGroupNotification(), use that array to store incoming messages, and when you get a button click event, display the message corresponding to the selected line in the floater:
Code:
group_messages = {}
function OnGroupNotification(group_name, group_id, dialog_id, timestamp, sender, subject, message, inventory)
    group_messages[#group_messages + 1] = message
    local notice
    notice = group_name .. "|" .. group_id .. "|" .. dialog_id .. "|" .. GetTimeStamp(-8,'%H:%M:%S') .. "|" .. sender .. "|" .. subject.. "|" .. message .. "|" .. inventory
    OpenLuaFloater("gnm")
    SetLuaFloaterValue("gnm", "list1", notice)
    GroupNotificationAcceptOffer(dialog_id)
    CancelNotification(dialog_id)
end

function OnLuaFloaterAction(name, control, value)
    if name == "gnm" and control == "button1" then
        -- Reminder: XUI list indices start at 0, Lua indices start at 1
        print(group_messages[GetLuaFloaterValue(name, 'list1') + 1])
    end
end

function OnLuaFloaterClose(name, parameter)
    if name == "gnm" then
       group_messages = {}
    end
end


2025-04-09 19:10:08
Profile WWW

Joined: 2011-09-27 11:18:31
Posts: 244
Reply with quote
Henri Beauchamp wrote:
The command you are using for button1 cannot work: for a list, GetLuaFloaterValues() only returns the selected lines indices in the list, not the columns contents for those selected lines...

Ah, I see. I had hoped it would be a way to get the content of the current "cell", or at least a table of strings containing the contents of the current line per column.

Henri Beauchamp wrote:
It would be possible to retrieve the "message" column contents for the list line at index GetLuaFloaterValues('gnm','list1'), but it would involve more complex code using the (non Lua-floater specific) GetFloaterList() function (and GetFloaterInstances("floater_lua_gnm") to get your Lua floater Id that GetFloaterList() needs), but this is complicating things uselessly.

I will read into that, because it seems more natural to me: in maths, in matrices we simply call A_(ij) :lol: But programming is not maths…

Quote:
My advice is to store the messages inside a global array defined in automation.lua (for example, outside of any function definition, use group_messages = [ ] on a line).
Then, in OnGroupNotification(), use that array to store incoming messages, and when you get a button click event, display the message corresponding to the selected line in the floater:

Thank you, Henri. I have something a little more complicated in mind, actually, but I'll work from that onwards.

By the way, shouldn't group_messages = [ ] be group_messages = {}?

Also, if I replace the print() with OpenNotification("2", …), it doesn't work. I get bad argument #2 to 'OpenNotification' (string expected, got nil) and of course putting quotes around it just prints the content of the quotes. But why nil? It's not nil, it's the element of an array, you just printed it.


2025-04-10 11:50:10
Profile

Joined: 2009-03-17 18:42:51
Posts: 6030
Reply with quote
g0rd0ngrfr33mailgr wrote:
Ah, I see. I had hoped it would be a way to get the content of the current "cell", or at least a table of strings containing the contents of the current line per column.
And I just implemented GetLuaFloaterListLine() for this purpose, for next release...

g0rd0ngrfr33mailgr wrote:
By the way, shouldn't group_messages = [ ] be group_messages = {}?
Yes, my bad (fixed in my above post).

g0rd0ngrfr33mailgr wrote:
Also, if I replace the print() with OpenNotification("2", …), it doesn't work.
Which is normal... The first parameter for OpenNotification() must be an integer, so you must use OpenNotification(2, ...). Please, RTFM ! :lol:
You might also prefer notification type 1 (script-menu-like) instead of 2 (modal alert dialog) for this...


2025-04-10 13:06:09
Profile WWW

Joined: 2011-09-27 11:18:31
Posts: 244
Reply with quote
Henri Beauchamp wrote:
And I just implemented GetLuaFloaterListLine() for this purpose, for next release...

Oh, thank you! <3

Henri Beauchamp wrote:
Which is normal... The first parameter for OpenNotification() must be an integer, so you must use OpenNotification(2, ...). Please, RTFM ! :lol:

It works either way actually (2 or "2"), but in this case it doesn't.


2025-04-10 14:32:10
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 18 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.