Milind,

  The new dialog FOCUS_CB (available in SVN only) will simplify that a lot.
It is specially useful for creating non modal dialogs with IupShow that
when loses its focus can be automatically closed.

Best,
Scuri


On Fri, Dec 2, 2016 at 4:49 PM, Milind Gupta <milind.gu...@gmail.com> wrote:

> Hi Ulrich,
>           I wrote a module to adapt any dialog to close if it lost focus.
> You can probably change the closing action to minimize action. The way I am
> doing it is by creating a timer and checking whether any of the controls in
> the dialog has focus. If none of them have it then the dialog is not in
> focus anymore and I close it. I have pasted it below for your reference if
> that helps.
>
> Regards,
> Milind
>
> -----------------------------------------------------------------
>
> --****h* iupcFocusDialog
> -- ! Module
> -- Module that provides functionality to present any dialog as a temporary
> item which disappears when it looses focus
> -- ! Creation Date
> -- 9/6/2015
> --@@END@@
>
> local iup = iup or require("iuplua")
> local tostring = tostring
> local type = type
> local tonumber = tonumber
>
> local print = print
>
> -- Create the module table here
> local M = {}
> package.loaded[...] = M
> _ENV = M -- Lua 5.2+
>
> _VERSION = "1.15.9.7"
>
> -- dialog is the handle for the dialog
> -- xmy are the screen coordinates relative to shich the dialog has to be
> displayed
> function popup(dlg,x,y)
> if not x or type(x) ~= "number" then
> x = iup.CENTER
> end
> if not y or type(y) ~= "number" then
> y = iup.CENTER
> end
> -- Create list of controls in the dialog
> local controls = {tostring(dlg)}
> local done
> local currControl = dlg
> while not done do
> if not iup.GetChild(currControl,0) then
> -- Check the sibling
> if not iup.GetBrother(currControl) then
> -- Go back up the hierarchy
> done = true
> while iup.GetParent(currControl) do
> currControl = iup.GetParent(currControl)
> if iup.GetBrother(currControl) then
> currControl = iup.GetBrother(currControl)
> controls[#controls + 1] = tostring(currControl)
> done = nil
> break
> end
> end
> else
> -- There is a brother
> currControl = iup.GetBrother(currControl)
> controls[#controls + 1] = tostring(currControl)
> end
> else
> -- This has a child
> currControl = iup.GetChild(currControl,0)
> controls[#controls + 1] = tostring(currControl)
> end
> end
> for i = 1,#controls do
> print(controls[i])
> end
> -- Timer to check if any of the elements have focus
> local tim = iup.timer{time=10,run="NO"}
> function tim:action_cb()
> tim.run = "NO"
> --print("timer")
> --[[
> if dlg.visible == "NO" then
> tim:destroy()
> return
> end
> ]]
> local fc = tostring(iup.GetFocus())
> --print(fc)
> -- Check if it matches any of the controls
> local match
> for i = 1,#controls do
> if controls[i] == fc then
> match = true
> break
> end
> end
> if not match then
> --print("lost focus")
> dlg:hide()
> tim:destroy()
> else
> tim.run = "YES"
> end
> --tim.run = "YES"
> end
> -- Show the dialog appropriately
> local w,h = iup.GetGlobal("FULLSIZE"):match("(.-)x(.+)")
> w,h = tonumber(w),tonumber(h)
> dlg:map()
> local dw,dh = dlg.rastersize:match("(.-)x(.+)")
> dw,dh = tonumber(dw),tonumber(dh)
> if y+dh >= h then
> y = y-dh
> end
> if x+dw >= w then
> x = x-dw
> end
> dlg:showxy(x,y)
> tim.run = "YES"
> end
>
>
>
> On Mon, Nov 28, 2016 at 7:06 AM, Antonio Scuri <antonio.sc...@gmail.com>
> wrote:
>
>>   Hi,
>>
>>  The KILLFOCUS_CB is problematic, because it will also be called when a
>> button inside that dialog gets the focus. Recently I committed to the SNV a
>> new callback called FOCUS_CB for the dialog that will be called when
>> another dialog (or its children) gets the focus. But it will work only if
>> another dialog on the same application gets the focus.
>>
>>   In Windows I think that WM_ACTIVE can handle a situation like this. But
>> there is no equivalente in GTK.
>>
>> Best,
>> Scuri
>>
>> On Sun, Nov 27, 2016 at 10:05 PM, Ulrich Schmidt <u.sch...@gmx.de> wrote:
>>
>>>
>>>
>>> Am 28.11.2016 um 00:36 schrieb Germán Arias:
>>> > Hi,
>>> >
>>> > El dom, 27-11-2016 a las 17:30 +0100, Ulrich Schmidt escribió:
>>> >> Hi.
>>> >> I use a iup.dialog as main window on Windows. All working well so
>>> >> far.
>>> >> It is a kind of window popping up when some event occurs. I want to
>>> >> minimize
>>> >> this window when the user activates a different window/program and my
>>> >> dialog
>>> >> is no longer the topmost window.
>>> >> Any suggestions?
>>> >>
>>> >> TIA.
>>> >> Ulrich.
>>> >
>>> >
>>> > Try with the common callback KILLFOCUS_CB:
>>> >
>>> > http://webserver2.tecgraf.puc-rio.br/iup/en/call/iup_killfocus_cb.html
>>> >
>>> > Germán
>>> >
>>> Hi Germán.
>>>
>>> I have read this before. Its about keyboard focus. I don't change
>>> keyboard
>>> focus, lets say, from bytton1 in my dialog to button2 in my dialog. I
>>> want to
>>> activate a different window (eg. my email app or my text editor) and this
>>> window becomes topmost and hides my dialog from being seen.
>>> The background for my question is, i placed a icon in the tray. Clicking
>>> this
>>> icon opens or hides my dialog. In case my dialog is state normal and
>>> covered
>>> by a different app window, the 1st click on my tray icon minimizes/hides
>>> my
>>> dialog but bring it topmost visible and i need a second click.
>>> I found a different solution: I set 'topmost = "yes"' for my dialog and
>>> so my
>>> dialog can't be covered by a different window and clicking my tray icon
>>> works
>>> like expected.
>>>
>>> Thanks.
>>> Ulrich.
>>>
>>> ------------------------------------------------------------
>>> ------------------
>>> _______________________________________________
>>> Iup-users mailing list
>>> Iup-users@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/iup-users
>>>
>>
>>
>> ------------------------------------------------------------
>> ------------------
>>
>> _______________________________________________
>> Iup-users mailing list
>> Iup-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/iup-users
>>
>>
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> Iup-users mailing list
> Iup-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/iup-users
>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Iup-users mailing list
Iup-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/iup-users

Reply via email to