Keeping track of text position on pdf using FPDF and GetY - fpdf

I am trying to keep track of the current Y position on a PDF page created using FPDF so that I can correctly start a new page ensuring tables do not cross a page break. Firstly am I right in using GetY to monitor this and if so what is the correct syntax. I am trying
$currentYposition = GetY();
but it does not seem to work. Any advice?

No idea why this works - but it does:
If you just grab Y after the call, it seems to be the value before the MultiCell.
Grabbing it before and after and taking the difference gives you the height.
$oldY = $this->getY();
$this->MultiCell(150, 4, utf8_decode($description), 0, "L");
$newY = $this->getY();
$multiCellHeight = $newY-$oldY;

This one worked for me.
$y = $pdf->GetY();

I came to this question when programming in python and using the fpdf module. I'll post in case anyone else need this, I could not find this solution in the official documentation but for me following worked:
from fpdf import FPDF
pdf = FPDF()
pdf.add_page()
current_y = FPDF.get_y(pdf)

Related

QGIS: Get Layout's Grid CRS (QgsLayoutItemMapGrid)?

Still learning QGIS using Python, but getting there...thanks to this site!
I'm trying to extract the CRS of the GRID that my layout is using. I think the Class I need to use is QgsLayoutItemMapGrid but can't get there from my testing:
projectInstance = QgsProject.instance()
projectLayoutManager = projectInstance.layoutManager()
# I checked and mine is the 'first' layout, viz [0]
mylayout = projectLayoutManager.layouts()[0]
# found this method in the API reference, but doesn't seem to have CRS etc
mygrid = mylayout.gridSettings()
... but I can't get beyond this. Maybe a different starting point? Any tips? Thanks.

How do I clear an element before rendering?

I have inherited an older project using jquery.
I am modernising the code.
In particular this $(selector).html("<h1>lol</h1>"); which as far as I understand is a full replacement of the selectors content.
I always end up with an error if I try to render to a cleared element.
This code:
const appDiv: HTMLElement = document.getElementById('app');
appDiv.innerHTML = `<h1>TypeScript Starter</h1>`;
// trying to replace jquery $(selector).html("<h1>lol</h1>");
appDiv.innerHTML = '';
render(html`<h1>lol</h1>`, appDiv);
appDiv.innerHTML = '';
render(html`<h1>lol</h1>`, appDiv);
Or see my stackblitz
I always get the following error:
Error in lit-html.js (93:55)
Cannot read properties of null (reading 'insertBefore')
Do you know what I am missing? 🧐
Thanks!
Note: This is a duplicate of my question (and based on a suggested technique) from a closed Lit Github Issue
Note: Maybe I am talking rubbish. I can't find a clear answer if render REPLACES content or APPENDS content. A concrete answer on that would be fine!
Lit v1 will clear the container before rendering the first time. Lit v2 will not.
Only clear the existing container content once before using render. After that render will correctly update content from previous render calls.
const appDiv: HTMLElement = document.getElementById('app');
appDiv.innerHTML = `<h1>TypeScript Starter</h1>`;
// trying to replace jquery $(selector).html("<h1>lol</h1>");
appDiv.innerHTML = '';
render(html`<h1>lol</h1>`, appDiv);
render(html`<h1>lol2</h1>`, appDiv);

Karate: How to wait for a spinner to disappear? [duplicate]

Firstly, Karate UI automation is really awesome tool. I am kind of enjoying it while writing the UI tests using Karate. I ran into a situation where in, i was trying to fetch the shadowRoot elements. I read few similar posts related to javascript executor with karate and learnt that it is already answered. it is recommended to use driver.eval. But in Karate 0.9.5 there is no eval, it has script() or scriptAll(). I have gone through documentation couple of times to figure out how i can fetch element inside an element but no luck.
Using traditional selenium+java, we can fetch shadowRoot like this way:
something like shadowRoot which sits inside a parent element like div or body.
//downloads-manager is the tagname and under that downloads-manager, a shadowRoot element exists
The HTML looks like this. it is from chrome://downloads.
<downloads-manager>
#shadow-root(open)
</download-manager>
WebElement downloadManager =driver.findElement(By.tagName("downloads-manager");
WebElement shadowRoot= (WebElement)((JavaScriptExecutor)driver)
.executeScript("return arguments[0].shadowRoot",downloadManager);
So i tried the following in Karate UI
script("downloads-manager","return _.shadowRoot"); //js injection error
script('downloads-manager', "function(e){ return e.shadowRoot;}"); // same injection error as mentioned above.
def shadowRoot = locate("downloads-manager").script("function(e){return e.shadowRoot};"); //returns an empty string.
I bet there is a way to get this shadowRoot element using Karate UI but i am kind of running out of options and not able to figure out this.
Can someone please look into this & help me?
-San
Can you switch to XPath and see if that helps:
* def temp = script('//downloads-manager', '_.innerHTML')
Else please submit a sample in this format so we can debug: https://github.com/intuit/karate/tree/develop/examples/ui-test
EDIT: after you posted the link to that hangouts example in the comments, I figured out the JS that would work:
* driver 'http://html5-demos.appspot.com/hangouts'
* waitFor('#hangouts')
* def heading = script('hangout-module', "_.shadowRoot.querySelector('h1').textContent")
* match heading == 'Paul Irish'
It took some trial and error and fiddling with the DevTools console to figure this out. So the good news is that it is possible, you can use any JS you need, and you do need to know which HTML element to call .shadowRoot on.
EDIT: for other examples of JS in Karate: https://stackoverflow.com/a/60800181/143475

how to move images in openoffice.org BASIC or LibreOfffice.org

After moving pictures in VBA using Shape.IncrementLeft and Shape.IncrementTop I would like to move pictures in openoffice.org BASIC code.
After searching internet with these keywords "move picture" and "openoffice.org" or "open BASIC" or "OOo BASIC" I did not find the answer.
I have found how to move pictures in Java, c++, android, but not in OpenOffice.org BASIC,
I read trough these guides
https://wiki.openoffice.org/wiki/Documentation/BASIC_Guide
http://www.pitonyak.org/OOME_3_0.pdf
I tried to find the answer through LIBRE OFFICE also, but without success.
I tried to record a macro, insert a picture, move it with the mouse and stop the macro.
When looking into the code, the answer of my question take me to the dispatcher and one of the UNO methods, I believe is has something to do with these keywords:
Properties in the com.sun.star.awt.UnoControlImageControlModel service
com.sun.star.drawing.GraphicObjectShape
BorderBottom
BorderLeft
BorderRight
BorderTop
oPoint = oShape.Position
getPosition()
setPosition(Point)
but I cannot find a clear answer and I do not know how to combine them to make the image (or it can be a shape inserted also) to move.
can anybody guide me how to find the answer?
first of all: https://wiki.openoffice.org/wiki/Extensions_development_basic is a good starting point. In particular the XRAY tool is very helpfully.
The following Code changes the position of a selected Image on a Calc Worksheet:
Sub Test
dim aNewPosition as new com.sun.star.awt.Point
oDoc = thisComponent
oSelection = oDoc.CurrentSelection(0)
if oSelection.supportsService("com.sun.star.drawing.Shape") then
aPosition = oSelection.Position
x = aPosition.X
y = aPosition.Y
aNewPosition.X = x + 100
aNewPosition.Y = y + 100
oSelection.setPosition(aNewPosition)
endif
End Sub
Greetings
Axel

decision tree in matlab - change font size

Could someone please assist:
Is there a way to change font size of classregtree in matlab?
How can I change the class labels?
Well, try this:
using an example from the docs:
load fisheriris;
t = classregtree(meas,species,...
'names',{'SL' 'SW' 'PL' 'PW'})
I was able to get the property-inspector:
tr=view(t)
inspect(tr)
..what didnt help a lot...
Now I took the handles of all children of tr, that are text-elements:
allHandles=findall(tr,'Type','text')
Next, I just changed the FontSize:
set(allHandles,'FontSize',16)
and there you go :) it is working!
To see and edit other properties, you could now use the inspect-method, as I was doing at my first try, but with the text-handles of course. normally, there should be all other properties available as for normal text-elements. Just check the docs for uicontrol + text.
Lucius's answer worked for me but instead of
tr=view(t)
I had to run this:
before = findall(groot,'Type','figure'); % Find all figures
view(t,'Mode','graph')
after = findall(groot,'Type','figure');
tr = setdiff(after,before); % Get the figure handle of the tree viewer
inspect(tr)