Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

python save document in xournal++

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
peer
Posts: 441
Joined: 2017-03-26 10:14
Has thanked: 7 times
Been thanked: 19 times

python save document in xournal++

#1 Post by peer »

I am running xournal++ in a separate workspace. When I close down the computer I always forget to save the document in xournal++. When I reboot my changes in the document are gone. I have a python shutdown script/program

I would like to add the following to my shutdown program:
1. check if xournal is running
2. save the current document (this is the hard part)
3. close the program

User avatar
oswaldkelso
df -h | grep > 20TiB
df -h | grep > 20TiB
Posts: 1486
Joined: 2005-07-26 23:20
Location: UK
Has thanked: 1 time
Been thanked: 55 times

Re: python save document in xournal++

#2 Post by oswaldkelso »

enable auto saving.

edit > preferences :shock:
Free Software Matters
Ash init durbatulûk, ash init gimbatul,
Ash init thrakatulûk agh burzum-ishi krimpatul.
My oldest used PC: 1999 imac 333Mhz 256MB PPC abandoned by Debian

peer
Posts: 441
Joined: 2017-03-26 10:14
Has thanked: 7 times
Been thanked: 19 times

Re: python save document in xournal++

#3 Post by peer »

auto saving is enabled. But xournal++ uses a different name for the autosaved file.
xournal++ is automatically started at boot with the document notes.xopp
The name of the autosaved document is notes.autosave.xopp

But I want to close xournal++ properly

User avatar
s3a
Posts: 831
Joined: 2008-07-17 22:13
Has thanked: 6 times
Been thanked: 2 times

Re: python save document in xournal++

#4 Post by s3a »

Instead of starting xournal++ automatically, perhaps make it run a (bash, for example) script automatically which renames (mv notes.autosave.xopp notes.xopp (maybe coupled with an if statement to check that the autosaved file does indeed exist)) the file right before launching xournal++?

Also, maybe running the killall -SIGTERM name_of_process command is what you need to terminate the process gracefully?

I don't use Python, but this should help with running Bash commands in Python.:
https://www.geeksforgeeks.org/how-to-ru ... in-python/
Use Mnemosyne to Study for School!

peer
Posts: 441
Joined: 2017-03-26 10:14
Has thanked: 7 times
Been thanked: 19 times

Re: python save document in xournal++

#5 Post by peer »

s3a wrote: 2022-06-01 09:53 Instead of starting xournal++ automatically, perhaps make it run a (bash, for example) script automatically which renames (mv notes.autosave.xopp notes.xopp (maybe coupled with an if statement to check that the autosaved file does indeed exist)) the file right before launching xournal++?
This is exactly how I am doing it now. This works.

Code: Select all

#! /bin/bash

#update notes.xopp
if test -f "/home/peer/Documenten/xournal/.notes.autosave.xopp"; then
    mv "/home/peer/Documenten/xournal/.notes.autosave.xopp" "/home/peer/Documenten/xournal/notes.xopp"
fi

#start devilspie2 and xournal++
/usr/bin/devilspie2 &
/usr/bin/xournalpp /home/peer/Documenten/xournal/notes.xopp &
But my question remains. I have xournal++ running with the document notes.xopp. How can I save the document and close xournal++ in a python program

User avatar
canci
Global Moderator
Global Moderator
Posts: 2497
Joined: 2006-09-24 11:28
Has thanked: 135 times
Been thanked: 134 times

Re: python save document in xournal++

#6 Post by canci »

Learn Python and tell us.
Seruouse, what do you expect people to do? Write Python scripts for you or give you 10 lessons worth of python programming in 1 forum post?

The entitlement here is staggering.
Image Stable / Asus VivoBook X421DA / AMD Ryzen 7 3700U / Radeon Vega Mobile Gfx (Picasso) / 8 GB RAM / 512GB NVMe

READ THIS:

* How to Post a Thread Here
* Other Tips and Great Resources

User avatar
s3a
Posts: 831
Joined: 2008-07-17 22:13
Has thanked: 6 times
Been thanked: 2 times

Re: python save document in xournal++

#7 Post by s3a »

But my question remains. I have xournal++ running with the document notes.xopp. How can I save the document and close xournal++ in a python program
I don't think I can help you do things in a "perfect" way without doing a lot of reading myself, but as a "good enough" solution, if you run the Bash commands through Python then you can use the Xournal++ app's autosave functionality (which you're already using) along with the if and mv to handle the autosave functionality (indirectly, by running the Bash script through Python as shown in this link https://www.geeksforgeeks.org/how-to-ru ... in-python/ ).

Then using the teachings of that link ( https://www.geeksforgeeks.org/how-to-ru ... in-python/ ) again, you can run the killall -SIGTERM xournalpp command via Python too (which should make the OS tell Xournal++ to close itself gracefully / properly).

(Notice how I said killall -SIGTERM and not killall -SIGKILL, so it wouldn't be "pulling the rug from under the app"; i'd be telling the app to close itself properly.)
Use Mnemosyne to Study for School!

peer
Posts: 441
Joined: 2017-03-26 10:14
Has thanked: 7 times
Been thanked: 19 times

Re: python save document in xournal++

#8 Post by peer »

@canci:
Sorry but I did not like your comment. I think you misunderstood my question.
I am not a programmer but I did create working gui programs in java and python. I also make easy scripts in bash.

@s3a:
Thanks for you reaction. I tried killall -SIGTERM. It closes the program but it did not save or ask for saving the document. The autosave file still exists. Normally the autosave file is deleted when the document is saved.
The solution that you suggested with the startup script (which I also found) is a good working solution. So I will stick to that.

Post Reply