Ask Your Question

yonkiman's profile - activity

2016-12-19 08:10:17 +0200 received badge  Famous Question (source)
2016-08-10 06:53:28 +0200 received badge  Famous Question (source)
2016-06-11 11:57:44 +0200 received badge  Famous Question (source)
2016-05-24 21:14:25 +0200 received badge  Notable Question (source)
2016-05-18 23:21:09 +0200 commented answer How to enable screen refreshing during a calc (python) macro?

Got it. :-) And thanks!

2016-05-12 23:31:02 +0200 commented answer How to enable screen refreshing during a calc (python) macro?

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).

2016-05-12 21:49:39 +0200 commented answer How to enable screen refreshing during a calc (python) macro?

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"?

2016-05-12 20:28:32 +0200 received badge  Popular Question (source)
2016-05-10 20:33:55 +0200 commented question How to enable screen refreshing during a calc (python) macro?

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.

2016-05-10 01:25:25 +0200 received badge  Enthusiast
2016-05-07 21:04:39 +0200 received badge  Notable Question (source)
2016-05-06 23:36:04 +0200 received badge  Popular Question (source)
2016-05-06 20:20:30 +0200 received badge  Supporter (source)
2016-05-06 19:53:17 +0200 commented answer Why does calc get confused by .setFormula('=MAX(4.5,3)')?

That did it! I'm not gonna ask why but I'm delighted to have a solution!

2016-05-06 04:40:57 +0200 asked a question How to enable screen refreshing during a calc (python) macro?

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.

2016-05-06 03:51:23 +0200 received badge  Notable Question (source)
2016-05-06 03:50:56 +0200 asked a question Why does calc get confused by .setFormula('=MAX(4.5,3)')?

I've been using setFormula in my python calc macro for a few days, and it's worked fine with all the '=(A4 * B4) -D3' formulas I've needed. But now I need to use some functions, and it's acting flaky. For the line:

sheet.getCellByPosition(column, row).setFormula('=MAX(4)')

The cell content is 4 (as expected).

sheet.getCellByPosition(column, row).setFormula('=MAX(4,3)')

The cell content is #NAME? That is not what I expected.

If I double=click on the #NAME? cell, I see the correct formula (=MAX(4,3)). If I then ^A to select the formula, ^X to cut it, and ^V to immediately paste the formula back in, then hit Enter, the cell responds with the correct value of 4.

This is the simplest form of the problem I could find. I found it because this much longer formula:

setFormula('=-' + quantity_cell + '*100*MAX(((0.25*' + underlying_cell + ')+MAX(' + underlying_cell + '-' + strike_cell + ',0) +' + price_cell + '), (0.15*' + strike_cell + '+' + price_cell + '))')

Behaves the same way, except instead of #NAME?, the error in the cell is Err:508. Again, an in-place cut and paste will make the formula work, but I'd like to have calc display it correctly without the intervention.

I suspect this is a bug, but perhaps there's a work-around?

This is LO 5.1.2.2, and the problem occurs under Ubuntu 16.04 and Windows 10.

2016-05-03 01:37:39 +0200 received badge  Famous Question (source)
2016-04-30 17:54:33 +0200 commented question Which directory do I put Python macros in LibreOffice on the Mac

One would think the answer is ~/.config/libreoffice/4/user/Scripts/python/, but that doesn't work. My recent question morphed into this same question.

2016-04-30 17:53:11 +0200 edited question Python macros on LibreOffice on OS X

My setup is LibreOffice 5.1.1.3 running under OS X 10.11.4. When I open Tools/Macros/Organize Macros/python..., Create and Edit are ghosted. However if I go to LibreOffice Macros/HelloWorldPython, "Run" gets unghosted and if I click on it, the macro seems to run and a new Text Document appears with the words "Hello World (in Python)".

So python seems to be installed and working, but I can't create or edit any python macros. I then used Spotlight to search my entire harddrive for any .py files that might be associated with LibreOffice but couldn't find anything.

Searching the web there are some potential solutions that include a lot of command line adding of packages, etc., but I don't want to do that until I've exhausted the simple solutions (since python for LibreOffice already seems to be installed and working, and LibreOffice clearly knows it's there).

Any ideas about what's going on?

4/30 Update:

Back to OS X after a month of successful macro development in Windows and linux. Per karolus's suggestion, I tried putting my macro in ~/.config/libreoffice/4/user/Scripts/python/. That's what works for Ubuntu 16.04 (and a similar directory for Win 10), but macros placed there don't appear in as calc macros under OS X.

So I thought I'd try putting my macro where I know calc does find macros.
find /Applications/ -name 'HelloWorld.py' returns
/Applications//LibreOffice Vanilla.app/Contents/Resources/Scripts/python/HelloWorld.py, but
ls -l /Applications//LibreOffice Vanilla.app/Contents/Resources/Scripts/python/
tells me "No such file or directory".

I think there's some sort of weird outside-standard-*nix file structure going on. In any case this is clearly not the correct path for user macros.

So still stuck. Like this guy from over a year ago.

2016-04-30 17:28:55 +0200 commented answer Python macros on LibreOffice on OS X

See update to original question

2016-04-29 22:22:11 +0200 received badge  Scholar (source)
2016-04-29 22:22:06 +0200 commented answer Converting a LibreOffice VBA macro to python - problem with object types

Worked perfectly and is super-clean - thanks! (Will upvote when/if I get enough karma.)

2016-04-29 21:23:42 +0200 received badge  Popular Question (source)
2016-04-29 01:01:10 +0200 received badge  Editor (source)
2016-04-29 00:58:51 +0200 asked a question Converting a LibreOffice VBA macro to python - problem with object types

I'm writing a python macro that needs to call LibreOffice Calc's Sort function. Python documentation is scarce, but I found a clear VBA example that I'm trying to convert to python.

It was going well until Section 1 and Section 2 below. VBA creates an oSortFields() object array, but the python interpreter would not accept oSortFields(). oSortFields was as close as I could get.

So when it calls the sort command in Section 3, the mismatch causes an AttributeError.

What is the python equivalent of VBA's oSortFields() object?

#VBA# Dim oSortFields(1) As New com.sun.star.util.SortField
from com.sun.star.util import SortField
oSortFields = SortField

#VBA# Dim oSortDesc(0) As New com.sun.star.beans.PropertyValue
from com.sun.star.beans import PropertyValue
oSortDesc = PropertyValue

#VBA# oSheet = ThisComponent.Sheets.getByName("Sheet1")
oSheet = ThisComponent.getSheets().getByIndex(0)

#VBA# REM Get the cell range to sort
#VBA# oCellRange = oSheet.getCellRangeByName("A1:C5")
oCellRange = oSheet.getCellRangeByName("B1:M30")

################# Section 1 ################# 
#VBA# REM Sort column B (column 1) descending.
#VBA# oSortFields(0).Field = 1
#VBA# oSortFields(0).SortAscending = FALSE
oSortFields.Field = 11  # close as I could get
oSortFields.SortAscending = False

################# Section 2 ################# 
#VBA# REM If column B has two cells with the same value,
#VBA# REM then use column A ascending to decide the order.
#VBA# oSortFields(1).Field = 0 ### Skipped and prayed
#VBA# oSortFields(1).SortAscending = True
# Now I'm really in trouble

#VBA# oSortDesc(0).Name = "SortFields"
#VBA# oSortDesc(0).Value = oSortFields() 
oSortDesc.Name = "SortFields"
oSortDesc.Value = oSortFields

################# Section 3 ################# 
#VBA# REM Sort the range.
#VBA# oCellRange.Sort(oSortDesc())
oCellRange.Sort(oSortDesc())
# Gemerates Error:  
#   <class 'AttributeError'>: Sort StockDataFromYahoo.py:212
#   in function StockOptionParty() [oCellRange.Sort(oSortDesc())]
#   pythonscript.py:870 in function invoke() [ret = self.func( *args )]
2016-04-05 23:38:56 +0200 received badge  Notable Question (source)