Ask Your Question
0

How to enable screen refreshing during a calc (python) macro?

asked 2016-05-06 04:40:57 +0200

yonkiman gravatar image

A lot of people want to stop their screen from refreshing while their macro is running but I want the opposite. I'd like to update my spreadsheet periodically to let the user know the script is running and calc has not locked up. My macro can take a minute or two to run, so after 10 seconds or so the screen dims and it looks like an app that's frozen.

Looking into this, I've seen people refer to ThisComponent.lockControllers and ThisComponent.unLockControllers, but I haven't been able to get those functions to work. From my limited understand of the API it seems like from com.sun.star.lang import XComponent should get me there but I'm getting an AttributeError when I try to call either function.

And I'm not 100% convinced that I'm barking up the right tree - it sounds like (from all the people who are trying to turn lock it to prevent screen refreshes) like the controller should be unlocked by default.

So any tips on visually updating the spreadsheet while a macro is running are appreciated. Ideally in python, since I haven't been able to convert the basic examples successfully.

edit retag flag offensive close merge delete

Comments

How about to use Status Indicator? This is the standard way to notify the user that the process is still ongoing (just oFrame.createStatusIndicator(), .start(status_text, maxValue) and .setValue(nextStep) )

JohnSUN gravatar imageJohnSUN ( 2016-05-09 09:26:06 +0200 )edit

Just tried that - it ran with no errors, but no progress bar (or anything else) appeared. Edit: Actually I'm sure it did appear - I was expecting a pop-up progress box so I missed the subtle change in the bottom left status line. This is the same method you suggest in your answer below - I don't want people thinking these are two different methods.

yonkiman gravatar imageyonkiman ( 2016-05-10 20:33:55 +0200 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2016-05-12 19:10:12 +0200

JohnSUN gravatar image

OK, please try code from this file - C:\fakepath\demoStatusIndicator.ods

edit flag offensive delete link more

Comments

Much better - I get the "please wait" indicator and I get "some" of the progress bar. In my code there are 17 iterations, calling the same sIndicator.setValue(index) after each iteration. Usually only a few of those 17 show on the progress bar. So it's often 0%, 6%, 12%, 18%, then nothing until the code finishes. One time in about 10 tries the progress bar seemed to show all the steps. It's as if my code's running at a much higher priority. Is there a python equivalent to "DoEvents"?

yonkiman gravatar imageyonkiman ( 2016-05-12 21:49:39 +0200 )edit

Interesting - the above comment was running under Windows 10 - progress bar updates seem intermittent.

Under linux (Ubuntu 16.04), the progress bar consistently updates for all 17 segments, although the screen still dims, indicating the process is not responding (I'd prefer it not do that).

yonkiman gravatar imageyonkiman ( 2016-05-12 23:31:02 +0200 )edit

I'll tell you more: run the same macro on the same operating system at LibreOffice 4.4.5.2, 5.0.4.2, 5.1.1.3 and OpenOffice 4.1.2 - is different. I have trained myself to treat this as a natural disaster - storm rains or a flock of mosquitoes: we cannot change it - so will endure

JohnSUN gravatar imageJohnSUN ( 2016-05-13 05:24:11 +0200 )edit

Got it. :-) And thanks!

yonkiman gravatar imageyonkiman ( 2016-05-18 23:21:09 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-05-06 04:40:57 +0200

Seen: 901 times

Last updated: May 12 '16