InDesign script labels in appscript python module - python

I'm using appscript to create an InDesign document from Database data, but I can't seem to figure out how to set the contents of the objects in my page. In older versions of ID (CS4 and earlier, if i'm correct) I could get the object with script label foo by calling spread.page_items['foo']. However, this does not seem to work anymore. spread.page_items.ID(<foo_id>).label.get() does show foo, so the script label is set correctly.
The Adobe documentation speaks of a label property, however I haven't yet figured out how to use that property to correctly select the right object.
If there is a way to obtain an object's ID easily, that might also do the trick.

I managed to solve this after finding this article about references in appscript. I had to use a filter, like so: spread.page_items[its.label == 'foo'].
Also, as suggested by Youngware below, the script labels support is indeed replaced by layer names.

Related

xlwings set alignments with api reference to pywin32

I am trying to align text in a cell inside of an excel file that was created with xlwings. I am aware that there isn't a top level function in xlwings to achieve that. However, in the documentation, it states that .api can be used to access the pywin32 (on windows) to achieve that goal and in the documentation for pywin32 there is a method called SetTextAlign.
My problem is that I cannot figure out how to call it or what arguments to pass into it. A good bit of info can be found here: http://timgolden.me.uk/pywin32-docs/PyCDC__SetTextAlign_meth.html
but that only helps me a tiny bit.
So, for example, my code could be:
self.sheet['A1'].value = 'test'
self.sheet['A1'].font.api ... # code here to set the alignment to center
Would be super appreciated if someone could help!
self.sheet['A1'].api.HorizontalAlignment = xlwings.constants.HAlign.xlHAlignCenter
Alignment is not a font property, but a Range property. A cell ('A1') is a Range.
You can find the Excel API here.
The PyCDC documentation you found is some internal Windows API, it is irrelevant for Excel features.

Where can I find all the properties for customization in matplotlib?

I'm trying to create my own style, like 'ggplot', and I'm looking for a dictionary or a guide where I can find all the customizable properties. At the end of this page of the documentation of matplotlib there is a file called 'matplotlibrc' and i want to know if that files contains all the possible options on customization or there is something else.
Yes, the example file contains all possible parameters. This file is embedded into each documentation built; and there is a test that ensures that whenever a new parameter is added or removed, this file is updated. So you can consider it being complete.
However, make sure to always refer to the version of the documentation that corresponds to your matplotlib version.
The most up to date version at any time is at
https://matplotlib.org/tutorials/introductory/customizing.html
while for example the version of matplotlib 3.0.3 would be available through
https://matplotlib.org/3.0.3/tutorials/introductory/customizing.html

How to use libchamplain to load local tiles or OSM XML in Python?

I am trying to use GTK and libchamplain to display a map from local map data. The application is to be run on computers with no internet connection.
After taking a look at the mapbox.py example it seems like one should replace the NetworkTileSource source with FileTileSource. So I used the minimal.py example to work with FileTileSource:
widget = GtkChamplain.Embed()
widget.set_size_request(640, 480)
tile_source = Champlain.FileTileSource.new_full(
ID,
NAME,
LICENSE_TEXT,
LICENSE_URL,
MIN_ZOOM,
MAX_ZOOM,
TILE_SIZE,
Champlain.MapProjection.MERCATOR,
Champlain.ImageRenderer())
tile_source.load_map_data("map.osm")
widget.get_view().set_map_source(tile_source)
Unfortunately, when running the application, the map is not being displayed, and I receive the following error message:
(minimal.py:26308): libchamplain-WARNING **: NULL pixbuf
Based on some C examples (one, two), I assume that there is a so-called renderer missing, called Memphis, which is C only. It seems like Champlain's ImageRenderer, despite its similar name, is not the right tool for this.
So my question is how I would continue at this point. There are quite a few OSM renderers besides Memphis, probably some written in Python as well, but which one(s) would integrate well with Champlain?
It doesn't have to be be OSM, either. A collection of pre-rendered PNG would be fine with me, too. It's just that the FileTileSource documentation specifically mentions "Loads the OpenStreetMap XML file at the given path", which is why I assume better support for OSM.
Any help is much appreciated.
I managed to do it in a very simplistic way: just organize your tiles respecting the #z#/#x/#y# logic as described in the docs, then don't change anything in that mapbox.py example except the URI. your case, for a file structure on the /tmp directory could look like:
MAX_ZOOM,
TILE_SIZE,
Champlain.MapProjection.MERCATOR,
"file:///tmp/tiles-#Z#/#X#/#Y#.png",
#"https://a.tiles.mapbox.com/v4/mapbox.streets/#Z#/#X#/#Y#.png?access_token=" + ACCESS_TOKEN,
Champlain.ImageRenderer())
still according to the docs, the FileTileSource is meant for using a single osm file. I'm not so sure how that works, I didn't yet try it.

How do I find out what I can do with the Pelican signals? I'm trying to write a plugin

The signals are sort-of described here but, then what?
For example, one of the signals is desribed:
invoked before writing each article, the article is passed as content
How do I change that content? How do I access it? What functions are available?
I've been looking at examples in the pelican plugins repo on github, but I'm still confused. (How did those people even learn how to write those plugins?)
I hardly know where to start.
You have to look at the source code of pelican. I think there is no better way.
For example, search for the signal you are interested in, e.g. article_generator_write_article: https://github.com/getpelican/pelican/search?utf8=%E2%9C%93&q=article_generator_write_article
Then, look into the search result, e.g. generators.py and click on the line number containing your signal. Of course, you could also create a clone and do all this locally. This depends on your way of working.
Surrounding code:
def generate_articles(self, write):
"""Generate the articles."""
for article in chain(self.translations, self.articles):
signals.article_generator_write_article.send(self, content=article)
write(article.save_as, self.get_template(article.template),
self.context, article=article, category=article.category,
override_output=hasattr(article, 'override_save_as'), blog=True)
As you can see, the signal call provides you with an article object. You can now 1) look in the source code to find the respective python class of this object to find out about its inner workings, methods and attributes or 2) go the hacky path and simply print the object's members print(article.__dict__).
I suppose, without having looked in the code, that article has an attribute content which contains the HTML code generated from your source file. This is where your desired change comes in.
Note that if you want to change the source code before processing this is not that easy. I just wrote a little plugin which is capable of doing this.
There you can also see the signal API in action. You simply have to connect a handler function to the desired signal.
I hope this helps :)

Automating powerpoint using python. How to access format axis objects

Currently I'm working on Python to automate a powerpoint file. I'm using win32com.client to access the various objects needed. However I haven't been able to find any documentation on chart objects. can someone point me in the right direction.
import win32com.client
PPTApplication = win32com.client.Dispatch("PowerPoint.Application")
PPTApplication.Visible = True
PPTFile = PPTApplication.Presentations.Open("D:\test.pptx")
x=PPTFile.Slides(1).Shapes("Chart1").Chart.ChartData.Workbook.Sheets(1).Range("A1","C13").Value
The code above allows me to access the data for chart1.
How do I access the format axis options????
Or where can I find the documentation for the same.
The PowerPoint Chart object API is documented here:
https://msdn.microsoft.com/EN-US/library/office/ff746468.aspx
The direction you'll want to head is Chart.Axes(), perhaps Chart.Axes(xlValue).
Once you have the axis you want, you have the properties and methods listed here available to you:
https://msdn.microsoft.com/EN-US/library/office/ff745187.aspx
In my experience, it sometimes takes some digging to come up with the path to the right attribute, but that's the general procedure.
Usually when I don't find what I'm looking for I search on 'vba powerpoint chart font color' or whatever specific call I'm looking for and the example VBA code shows the "path" through the object hierarchy to the property I need.

Categories

Resources