Can I use html&css in kivy and python3? - python

I am currently developing an embedded multi-touch kivy program with python 3.52 in linux. Kivy is good, but I find GUI developing is quite difficult in some way, and animations are often quite laggy.
Also, I found that the program gets quite slow if I put many widgets in a single page. My program contains a lot of widgets so I am also thinking implementing a webview could help.
So I am looking for html and css views in particular screens for better look and feel (and maybe improvement of animation by using transition?).
I've found Cefpython, but it says it works only for python 2.7 and says it is not stable. And it seemed like it is just getting url from the internet not bringing html and css from a file system. (Correct me if I am wrong.)
Actually, I don't even need a function as a browser, and all I need is html & css for UI/UX development for couple of screens.
My embedded system doesn't always support internet(meaning it should work without internet). So I can't put any url in it. Once again, I am only trying to use them for styling. Is there a good way of doing it? Or there is no such thing that I want?
Or is there any other recommendation?

No, unless you are willing to implement html and css parsers and a web renderers, of course. I would say it's better to find why you find it difficult to do certain things with kivy, and how to remedy that. I've yet to find an UI/layout/template that is easier to do with the web technologies than with kivy, but i'm way more profficient at kivy than at web front end, so i might be biased.

Related

Python and Bridge for JS

Im starting a new project for personal porpuse!
Im working personally in finance, I decided to create personal chart viewing software to suit my needs. I thought I'd create a good part of the backend in Python as it is a language I know quite well. Use Javascript for the graphic side, and use a webview in a windows form to make everything available as if it were software.
As for the graphics I thought of using: Lightweight Library for JS, I find that today it is the most avant-garde library compared to the classic plotly, matplotlib.
Use pywebview as a bridge between Python and JS and to redirect everything in a windows form.
However I find it a bit difficult to use this library (pywebview), there is a poor documentation around and not very clear to me (my level of JS is really basic). However, I believe it is one of the most convenient solutions.
I would have thought of using pyscript, but it still seems early to use this library in production.
Questions:
Do you think such a job is feasible?
Do you know other libraries/better solutions to do such jobs?
What kind of approach would you use if you were to do such work?
What I am trying to achieve is to write most of the functions in python and use only JS to make calls through buttons or to get data from various inputs.
Wandering around the web I found a work already partially created by this guy (if you are reading, Thanks Filipe you have been very helpful! here you can see his project hosted on Github) but unfortunately it is difficult for me to get my hands on a code not produced by me.

Is it possible to create a python program that controls my web pages?

I have been wondering about this since I could really benefit from a program that makes actions on websites that I use for my job that require the same command over and over again.
I know some python and I love to learn new things.
I tried looking for it on google but I guess I'm not sure how to find it.
I would love it if you could direct me to a guide or something like that.
Thank you very much!
Selenium interacts with a web browser directly, although you can hide the browser window in the code (look up Selenium in --headless mode). This is a good choice for filling out a lot of forms or interacting with graphical user interface elements.
However, if you need to request information from websites, you don't always need to interact with the web browser directly. You can use the package called Requests. This doesn't depend on any web browsers and can run silently in the background.
I think you can do it with Python and some packages like selenium. Also you need some html knowledge to search in the html source code of the specific wegpage.
I found an interesting use case, maybe that helps you:
https://towardsdatascience.com/controlling-the-web-with-python-6fceb22c5f08

Is Python ideal for this web project?

I'm working on a school project which I would like to showcase in a web browser or application.
I would like the user to control the work with a mouse or keyboard. I want to show a unique image based on where the curser is over a visible grid. An additional feature is the ability to switch to a different "stack" of images upon user input from the scroll wheel or in a dialog.
I have a beginner-intermediate understanding of Python.
Theoretically, I could write this using Sage, but I would like the feedback to be instant - a change shouldn't require a new calculation, just show a new image.
Additionally, I would like to create a feature which takes the user on a "tour" based on information attached to an image.
My first thought was to use an online website builder (Webflow), though an opportunity to learn a new language or expand upon my knowledge of Python is my first choice.
What language is best suited for this?
This is possible in Python, as nearly everything is (Python is a Genral Purpose Language), so you could certainly implement this in Python.
The best language for this, however,IMO, would be JavaScript.
Python will almost certainly get in your way or at least hinder you slightly in comparison.
An 'online website builder' is not likely to provide you with the required amount to control needed to implement you project - most of these are painfully simplistic drag-and-drog tools where any real control only comes from adding your own CSS/HTML/JS anyways.
JS is an incredibly useful language and also very well suited for nearly all web/browser projects, so use this opportunity to learn it !
Further, React Native can let you use JS for mobile apps too, if that's what you meant by 'applications' or you could simply keep it a web app.
PS. This may also be possible with HTML5, which is perhaps simpler and easier to learn, but I'm no a web dev so that will have to be confirmed by someone else.
I am sure, though, that this is very efficiently doable in JS.

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.

A good Python web framework for existing console program?

I hope I'm asking on the right StackExchange site.
I've written a console program in Python onto which I'd like to put a web interface, but I'm having a hard time deciding what web framework to choose. I don't need much, but I'd like to avoid unnecessary work in trying to use it. I don't have a need for a database (for now), so that's not important to me at all.
I've looked at Django, Web2py, bottle.py, and web.py.
Django and Web2py seem to be great if I were starting out from scratch, but I'm not, and seems a little difficult to integrate into existing code.
bottle.py and web.py almost seem like they could work out, but they're so basic, I'm hoping there's something else out there that wouldn't require so much in the way of templating as these seem to do.
I don't simply want to make a carbon copy of the console interface put into a browser, but rather customize it for a web interface, so I'm not necessarily looking for anything that would simply wrap a console application into a web interface (although that would be interesting too.)
That's a sort of hard problem... Personally I don't see web.py as all that 'basic' as you put it. It should be really easy to wrap your code in some classes with GET and POST functions and be done.
Also, Django can be 'minified' as it were: How do I write a single-file Django application? is a whole conversation about this.
I would say, what is too 'basic' for you? You mentioned 'templating', but how would something magically template for you? There are open source templates for web apps, things like twitter bootstrap come to mind, that kind of give you a ready-made template for your next web app. Also YUI, and dojo do similar sorts of things (tho have a much different focus, since they are full blown JS frameworks).
That said, there is a brand new project called 'shovel' (here): https://github.com/seomoz/shovel
I haven't used it yet, but it seems to do the wrapping of commands into a web interface for you. which you said would be 'interesting'.
Personally I use web.py for all my web stuff.
I suggest Django. I've used Django both for simple mostly static sites and for sites with a lot of forms and I can't say Django imposes any restrictions or forces you to write hundreds LoC even for simple things. Instead you get nice auto generated administrative interface, built-in ORM, internationalization tools and many other things. Thereby, you have great opportunities to grow functionality of your app. In addition it has such vital thing as up-to-date documentation for every module.
Tutorial takes few hours and gives enough information to start developing full-blown sites.
Thanks the continuation which is implemented in the Nagare framework, you can develop a Web application like a console or desktop UI application: put the console code in a component.Task, then create some components for each interaction, i.e. some views that show the data that you print in your console application and receive some user input back. Then, the Nagare framework takes care of the rest: no need to declare URLS, to pass the context from a page to next...
PyQT can be handy if you are looking to implement it, to quote from the RiverBank PyQT website listed below:
"The QtWebKit module implements a web browser engine based on the WebKit open source browser engine used by Apple's Safari. It allows the methods and properties of Python objects to be published and appear as JavaScript objects to scripts embedded in HTML pages."
Source: http://www.riverbankcomputing.co.uk/software/pyqt/intro
Also, do not give up hope if that does not do the trick, as there is also "Pyjamas" which is very handy! Here is a brief description of it:
"Pyjamas is a Rich Internet Application (RIA) Development Platform for both Web and Desktop.
It contains a Python-to-Javascript compiler, an AJAX framework and a Widget Set API. Pyjamas started life as a Python port of Google Web Toolkit, the Java-to-Javascript compiler. Read the FAQ and the list of features."
source: http://pyjs.org
found via: google.com
I would say that when you are always looking to see what the best to use is, ask your question in google, and look on multiple sites and compare the top results of multiple sites to your question, also, it really depends on what you need and what your strong hand plays better in.

Categories