Comments (4)
You can write such function in MRI macro like the following.
Store the following code into a file placed in the directory specified at
Tools - Configuration... - Macros Directory.
After reloading the Macros menu of the MRI window, you can use the macro.
__all__ = [
"store_state",
]
import traceback
import uno
from mytools_Mri.unovalues import TypeClass, TypeClassGroups
def select_files(mri):
def create(name):
return mri.create_service(name, nocode=True)
fp = create("com.sun.star.ui.dialogs.OfficeFilePicker")
fp.initialize((1,))
fp.appendFilter('All Files (*.*)', '*.*')
fp.appendFilter('Text Files (*.txt)', '*.txt')
fp.setCurrentFilter('All Files (*.*)')
ret = None
if fp.execute() == 1:
ret = fp.getFiles()[0]
fp.dispose()
return ret
def store_state(mri):
""" Store current
Store property values of the current object into file. """
file_url = select_files(mri)
if file_url is None:
return
file_path = uno.fileUrlToSystemPath(file_url)
NUMERIC = TypeClassGroups.NUMERIC
STRING = TypeClassGroups.STR
BOOLEAN = TypeClass.BOOLEAN
entry = mri.current
target = entry.target
with open(file_path, "w") as f:
imple_name = mri.engine.get_imple_name(entry)
f.write("IMPLE_NAME: {}\n".format(imple_name))
props = mri.engine.get_properties_info(entry)
for prop in sorted(props):
name = prop[0]
value = prop[2]
type = prop[1]
type_class = prop[6]
if type_class in NUMERIC or type_class == BOOLEAN:
f.write("{}\t{}\t{}\n".format(name, type, value))
elif type_class == STRING:
try:
_value = getattr(target, name)
except:
_value = value
if _value is None:
_value = "None"
else:
_value = _value.replace("\t", "\\t").replace("\n", "\\n").replace("\r", "\\r")
f.write("{}\t{}\t{}\n".format(name, type, _value.encode("utf-8")))
else:
f.write("{}\t{}\t{}\n".format(name, type, " "))
from mri.
Okay, sorry for the long delay. I just tried to run it, and I'm getting an error:
com.sun.star.uno.RuntimeExceptionError during invoking function store_state in module file:///home/constantine/.config/libreoffice/4/user/Scripts/python/savestate.py (<class 'TypeError'>: store_state() missing 1 required positional argument: 'mri'
/usr/lib/libreoffice/program/pythonscript.py:869 in function invoke() [ret = self.func( *args )]
)
Sorry, I don't know if there's some trick that should be used to execute the code — I'm just trying it from the «Tools → Macros → Run Macro…»
from mri.
It seems I've forgot to mention about how to execute the macro. It have to be executed through MRI.
Choose MRI window - Main menu - Macros - state.py - Store current.
You have to pu the script file in the Macros directory specified in the configuration of the MRI settings. See the post above where to pulace the code.
from mri.
Ah, sorry, I was wondering btw why doesn't I see the option you mentioned in the first comment ☺ So, it meant to be in MRI.
Okay, I just tried it. It was a bit tricky — MRI for some reason doesn't save the directory path, and when I tried to create the directory that is by default written, MRI just ignores it.
But I found that I could save the macro to the
/home/constantine/.config/libreoffice/4/user/uno_packages/cache/uno_packages/lu325eqol1h.tmp_/MRI-1.2.5.oxt/macros/
And now everything works :з
However, it seems that the macro saves a small part of the state. I made a test document, saved the state, next applied some transformations — changed a style of the first paragraph, changed the first page style, made a direct formatting to the first paragraph… But the only moment when the state changed was when I tried to add more text — that was just a count of characters and words.
from mri.
Related Issues (20)
- Faild to open help files. HOT 2
- MRI 1.1.4 doesn't install on LibreOffice 5.4.4.2 as packaged by Debian HOT 2
- MRI version 1.1.4 does not work on LibreOffice from LibreOffice extension repository HOT 3
- Failed to update from AOO 4.1.5 HOT 1
- Help system not working in LibO 6.1 HOT 2
- MRI 1.3.4 hangs on install in LibO 6.1 HOT 2
- MRI 1.3.4 on LibO6.2(+) - OSX Mojave
- Cannot access menu items of MRI on LibreOffice 6.0 HOT 7
- Remember window size
- MRI 1.3.4 opening help fails with message "Fix your browser configuration" HOT 4
- Support link to Doxygen based IDL reference from LibreOffice HOT 4
- MRI version 1.3.4 hides error bars on scatter plot
- Did not work for me at all. HOT 3
- Full support of link with anchor to methods having multiple arguments for Doxygen based API reference HOT 2
- MRI 1.2.1 doesn't work with LibreOffice 5.1 HOT 3
- Even the MRI-1.3.1.oxt doesn't work in LO 5.1 HOT 2
- How to install? HOT 2
- Install/help issues w/ LO 5.2.3.3 / 5.2.2.2 and MRI 1.3.2 / 1.3.3 HOT 6
- web.py doesn't initialize with AOO 4.1.2 on Win7 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mri.