Generate document with plots based on template, Python3 - python

I have a Python3 GUI, where user selects certain values to be statistically evaluated and/or plotted (hist).
Out of this GUI on users request I want to create a report, prefferebly in DOC or/and ODT or/and PDF formats. The layout of the report is pretty much fixed, what will change is: the names of the selected measures and the corresponding values (there are always three measures to display - user selects which), matplotlib histogram (will change depending on the selected settings), user name, date etc.
In some older thread I found a reference to pod package which looks very close to my needs. But I didn't find any good illustration of the resulting documents. And what is most important, I'm not sure if images are allowed there - I would imagine reserving a place for the image somewhere in the corner of the document and update it when user request the report.
EDIT1: pod does NOT support Python3, also after 2to3 convertion and couple of small fixes. There was an advice to use LaTeX, but I'm not sure I understand how to implement this idea without going to the very low level of coding.
Any suggestions are greatly appreciated since the rest of the project is nearly done and this is the last big unsolved problem.
EDIT2: After some break I return to this problem. Since my GUI is in PyQt4, I finally decided to go with QTextDocument and print document to PDF. There are some unclear moments for me in this approach, like if I should use QTextCursor and programically create the document or create somehow HTML first. Also, I have to figure out how to create the document without displaying editor window. Any references with examples are welcome. So far I found only couple of examples in PyQt4\examples\richtext, but they don't answer all my questions.

I try to look at ReportLab now - it doesn't provide DOC (only PDF), but seems to be flexible. As I learned from FAQ, images are allowed, but I will have to save them from matplotlib in jpeg first (PIL is not available for Python3 yet). I hope I will not end up with extreme low level programming for report creation...

Finally solved the problem. It was not so difficult at the end, and I ended up using QTextDocument and its setHtml method to produce the desired document. Related question with the code is here

Related

How to programmatically sync anki flashcard database with local file?

I would like to have a script ran by cron or an anki background job that will automatically read in a file (e.g. csv, tsv) containing all my flashcards and update the flashcard database in anki automatically so that i don't have to manually import my flashcards 1000 times a week.
any have any ideas how this can be achieved ?
Some interesting links I've came across, including from answers, that might provide a lead towards solutions:
https://github.com/langfield/ki
https://github.com/patarapolw/ankisync
https://github.com/towercity/anki-cli
The most robust approach there is so far is to have your collection under git, and use Ki to make Anki behave like a remote repository, so it's very easy to synchronise. The only constraint is the format of your collection. Each card is kept as a single file, and there is no real way around this.
I'm the maintainer of ki, one of the tools you linked! I really appreciate the shout-out #BlackBeans.
It's hard to give you perfect advice without more details about your workflow, but it sounds to me like you've got the source-of-truth for your notes in tabular files, and you import these files into Anki when you've made edits or added new notes.
If this is the case, ki may be what you're looking for. As #BlackBeans mentioned, this tool allows you to convert Anki notes into markdown files, and more generally, handles moving your data from your collection to a git repository, and back.
Basically, if the reason why you've got stuff in tabular files is (1) because you want to version it, (2) because you want to use an external editor, or (3) because your content is generated programmatically, then you might gain some use from using ki.
Feel free to open an issue describing your use case in detail. I'd love to give you some support in figuring out a good workflow if you think it would be helpful. I am in need of more user feedback at the moment, so you'd be helping me out, too!

Documentation for XML code

At this moment I am searching documentations or trying to make documentations for the XML-Code which builds the script boxes in Choregraphe. For example, like you could see in the next images (1 and 2): what does „Input name="Multiplicand" type="2" type_size="1" nature="1" inner="0"“mean in the basic script boxes just like “Multiply.py”? It would mean one variable as input value in type number with "onEvent" in choregraphe graphic interface according to the image3, I guess.
It's very hard to find them on the official documentation website from Aldebaran or even by Google results. In principle I could already find it out with just trying to change the values and see the changes in choregraphe, but it's not very smart and takes a while. At this point, I’m really forward to hearing from you. That would be very helpful for the next students who want to understand more about choregraphe and who want to build choregraphe script boxes by themselves in Python code level.
Yes, that "Multiplicand" you see in the xml is the input you can edit via the gui.
You can create and edit Choregraphe boxes entirely through the GUI, editing their inputs, outputs and parameters; I recommend doing that instead of touching the XML; because the exact format used in the .xar file may change in future versions. I have used Choregraphe quite a bit and have never felt the need to directly edit the .xar (except maybe when resolving git conflicts, but that was years ago and since then we've been avoiding having to ever merge a .xar file).

Making an interactive network topology diagram using Python or something else?

I've got masses of network information held in a SQLite database. I want to draw a diagram based on this information in the style a network diagram.
I want it to be interactive, in a sense that at the highest level only network range communication can be seen, and as you move deeper into the diagram you begin to see individual nodes (switches, routers, firewalls, hosts, servers, etc) all linked together.
I'd like this process to be as smooth as possible, allowing you to zoom in using the scroll wheel in a location of the diagram and it expands as you do so. Allowing you to then click and drag around the map. However I'd like to get basics down first, so thinking that I should start with drawing the diagram in HTML and have hyper-links for nodes allowing the user to move around and deeper into the diagram using a browser.
It is also crucial that the user would be able to able to capture their view as a still image, which I'd guess would be far more easily done in HTML.
To get to the point I'm asking where I might start to do this. I've looked at PyQT, Graphviz, outputting to HTML etc. I'm just trying to decide what to use and generally how to go about doing this. I'm reasonably good with Python but I am open to suggestion of other languages.
If you guys think Python can do this, which Python? 2.7 or 3? I've been considering making a move to 3 for a while, is it time?
Thanks in advance!
The important thing here is that you want something dynamic and that can be captured by the user.
My answer will be fairly similar to this question.
Export your graph to a standard format such as GEXF and use a Javascript graph drawing library to make your graph interactive such as: SigmaJs, or VivaGraphJs.
The big advantage is that you can script your graph to respond to user event such as zoom, save as a picture or display information dynamically about nodes and edges, etc.
To resume:
First you a python graph library such as Networkx, then export your graph with its properties as JSON or GEXF.
Load the graph using a javascript graph library using the examples as baselines. List of examples using sigma.js, tutorial for VivaGraphJs.
Concerning the python version, it is really dependent on other libraries you may use. For scientific use, I wouldn't recommend to switch to Py3k but for anything else you're good to go.
I've faced in the past something similar to your problem. We have tons of routers documented in a MySQL database. We actually use Racktables and that tool stores all the information in such a way.
At one point we needed to plot networking topologies. If you want, please have a look at this:
https://notedisabbia.wordpress.com/2016/06/17/first-blog-post/
https://github.com/RackTables/racktables-contribs/tree/master/python-graph-topology
The first link is a blog I've written in order to explain what my python program (second link) does in terms of connecting to Racktables, gathering information and plotting network diagrams.
Hope this helps.
Cheers,
Lucas
I would recommend looking at library d3graph. It does not allow you to zoom using the scroll wheel but does have other features like breaking edges.
More information can be found in this blog.

QTextEdit Paginating

I'm trying to write simple PyQT report editor and what I need is to exactly know what sizes the page has, MS-Word like.
Today I found the following link:
How to access QTextDocument pages
that shows how to use an QPrinterPreviewDialog, and it seems to be the answer to my question, but I don't know how to transform it to Python. I have no idea how to implement QPrinterPreviewDialog into a QTextEdit. I tried to read the docs but without a example it's very hard to start.

How to: Python script that will 'click' on a portion of my screen, and then do key commands?

Python noobie.
I'm trying to make Python select a portion of my screen. In this case, it is a small window within a Firefox window -- it's Firebug source code. And then, once it has selected the right area, control-A to select all and then control-C to copy. If I could figure this out then I would just do the same thing and paste all of the copies into a .txt file.
I don't really know where to begin -- are there libraries for this kind of thing? Is it even possible?
I would look into PyQt or PySide which are Python wrapper on TOp of Qt.
Qt is a big monster but it's very well documented and i'm sure it will help you further in your project once you grabbed your screen section.
As you've mentioned in the comments, the data is all in the HTML to start (I'm guessing it's greyed out in your Firebug screenshot since it's a hidden element). This approach avoids the complexity of trying to automate a browser. Here's a rough outline of how I would get the data:
Download the HTML for the whole page - I'd do this manually at first (i.e. File > Save from a browser), and if there are a bunch of pages you want to process, figure out how to download all the pages you want later. If you want to use python for this part, I'd recommend urllib2. The URLs for each page are probably pretty structured, so you could easily store them in a list, and download each one and save it locally. .
Write a script to parse the HTML - don't use regex. Since you're using Python, use something like Beautiful Soup, which will create a nice object representation of the page, and then you can get the elements you want.
You mention you're new to python, so there's definitely going to be a learning curve around this, but this actually sounds like a pretty doable project to use to learn some more python.
If you run into specific obstacles with each step, start a new question with a bit of sample code, showing what you're trying to accomplish, and people will be more than willing to help out.

Categories