Re: [code] Possible GTK init problem

From: Markus F.X.J. Oberhumer <markus.att.oberhumer.com>
Date: Thu, 20 Oct 2016 10:55:32 +0200

Hi Mitchell,

thanks, but the following does not work for me:

local function gui_ready()
  if buffer.lines_on_screen > 0 then
    -- disconnect immediately to avoid recursion
    events.disconnect(events.UPDATE_UI, gui_ready)
    local l = string.format('%d', buffer.lines_on_screen)
    buffer:append_text('lines_on_screen='..l..'\n')
  end
end

events.connect(events.UPDATE_UI, gui_ready)

I think the problem here is that disconnect inside an event handler
is somewhat flaky.

~Markus

On 2016-10-19 15:55, Mitchell wrote:
> Hi Markus,
>
> On Mon, 19 Sep 2016, Markus F.X.J. Oberhumer wrote:
>
>> Hi Mitchell,
>>
>> On 2016-09-19 16:00, Mitchell wrote:
>>> Hi Markus,
>>>
>>> On Mon, 19 Sep 2016, Markus F.X.J. Oberhumer wrote:
>>>
>>>> I'm hitting a problem in the INITIALIZED event caused by the fact
>>>> that buffer.lines_on_screen is not set.
>>>>
>>>> It works correctly in the Curses version, but the GTK version
>>>> always prints "lines_on_screen=0".
>>>>
>>>> This could be some sort of initialization problem in textadept.c.
>>>>
>>>> Any ideas?
>>>
>>> GTK's event loop has not started and processed any pending draw events yet
>>> when `events.INITIALIZED` has been fired. (Thus, the editor widget does not
>>> know how big it is yet.)
>>
>> thanks for the explanation - that makes sense.
>>
>>> Try putting your code on a brief timeout with `timeout()`[1].
>>
>> Using timeout() will probably do the trick. Still, this is a little bit
>> hacky, so would it be hard to add a proper GUI_INITIALIZED event ?
>
> I've come up with a less-hacky method involving the `events.UPDATE_UI` event
> for your `~/.textadept/init.lua`:
>
> local function gui_ready()
> if buffer.lines_on_screen > 0 then
> print('ready', buffer.lines_on_screen)
> events.disconnect(events.UPDATE_UI, gui_ready)
> end
> end
> events.connect(events.UPDATE_UI, gui_ready)
>
> This will run until the first successful paint of a GUI buffer.
>
> Cheers,
> Mitchell

-- 
Markus Oberhumer, <markus@oberhumer.com>, http://www.oberhumer.com/
-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Thu 20 Oct 2016 - 04:55:32 EDT

This archive was generated by hypermail 2.2.0 : Thu 20 Oct 2016 - 06:52:57 EDT