Is Kivy strictly a GUI framework? - python

I'm thinking of using Kivy to develop my first mobile app (mainly because i don't want to have to learn any new languages). This app would require access to the user's music library files & metadata. I was looking through Kivy's API Reference and couldn't find anything that would fit as a solution. The Audio Module gave me the impression of background music or SFX functionality.
My question is, is Kivy strictly for creating GUI for applications? If not, could someone provide me an example of how one would go about accessing a user's music library on a mobile device using Kivy/python?
Thanks in advance.

If i understand you well, you want access to the place where the OS store the user's music, not just files provided by yourself, on that, kivy doesn't provide any abstraction, it's up to you either to know the one place they should be on your target plateforms (android/ios i guess), or how to ask the OS where they are, you could use pyjnius (for android) and pyobjus (for ios although it's less advanced right now), to ask for that through the native api, then use kivy api to play them, and if you want to read file metadata, use the usual python libs for that, and for library metadata, i guess that's the native api that should give them.
e.g:
http://developer.android.com/reference/android/media/MediaMetadataRetriever.html
http://developer.android.com/reference/android/media/MediaPlayer.TrackInfo.html
http://developer.android.com/reference/android/provider/MediaStore.Audio.Media.html
look promising, but i didn't experiment with them.
To answer the more general question, kivy targets the UI mainly, but try to provide abstractions for the plateforms different ways of doing thing where needed, we don't have everything yet, but at least low level things (notice how you use the same method to load/play an audio file on all plateforms? it's not a given :)), are here.

Related

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.

Howto store a project in a large wxpython application

I am developing a rather large python application (wxpython) that allows a workflow of data analysis. Performing all steps of the workflow can be quite long and the user is not likely to everything at once. More likely he would prefer to do different parts of the processing at different points in time. It would therefore be very handy to be able to store the application's current status with some sort of "save project" functionality. Opening the application and loading a project file would set up the application as it was previously and allow one to continue where he/she left off last time.
However I have a large amount of objects to save, most of which are imbued with attributes coming from wxpython. This causes pickle to fail with the following error:
TypeError: can't pickle PySwigObject objects
Does anyone has experience with this? What would be a best practice to obtain the required functionality? Are there libraries devoted to this?
Thanks you.
wxPython is a wrapper around a C++ library known as wxWidgets. So you cannot use normal Python serialization to save its state. However, you can use the persist library to save most widget's state: http://wxpython.org/Phoenix/docs/html/lib.agw.persist.html
I'm not sure when this library was added to wxPython, but I'm guessing it was with 2.9 or perhaps the latest version of 2.8. Otherwise you can probably find it in the latest version of 2.8's source.
As others have said, it's usually better to just save the process's state and then load that information back to the GUI when it's started.

Considerations for python gui toolkit for app that queries remote database? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I know this question has been asked before but those questions typically lack specific details and result in answers that say something like "It depends what you are trying to do..." so the main gist of this app is that it retrieves remote data (ex. text) and object (ex. images).
Since PHP and python are the two programming languages I feel comfortable with I felt python was more suited for desktop gui apps. I'm creating a desktop music player and here are some of the technical specs I want to include:
A sign in construct that authenticates user credentials (Like
spotify, skype, league of legends) against a remote database (This
will be in mysql.) My thinking is to create a web api for the client to query via HTTP/HTTPS GET/POST
A client side SQLite database that stores the filename, filepath and
id3 tags of the song so upon launching, the application displays each song in a row with the song length, artist, album, genre (Like iTunes)
Retrieve remote images and display them within the application's frame (Like skype displays a person's profile picture.)
Must be cross-platform (At least in Windows and Mac), look native in different OS's but the native look and feel should be easily overridden with custom styles (Ex. rounded buttons with gradients.)
Compilation for Windows and Mac should be relatively straightforward
Of the popular python gui toolkits like PyQt, PyGTK, Tkinter, wxPython, Pyjamas, PyGObject and PySide which are well suited for my application and why? Why are the others not well suited for these specs? Which have good documentation and active communities?
Welcome to a fun area:
Watch out for urllib2: it doesn't check the certificate or the certificate chain. Use requests instead or use ssl library and check it yourself. See Urllib and validation of server certificate Sometimes a little ZeroMQ (0mq) can simplify your server.
You should consider shipping a self signed certificate with your application if you are a private server/private client pair. At that point, validating the certificate eliminates a host of other possible problems.
While you could read a lot about security issues, like Crypto 101, the short version is use TLS (the new name for SSL) to transmit the data and GPG to store the data. TLS keeps others from seeing and altering the data when moving it. GPG keeps others from seeing and altering the data when storing or retreiving it. See also: How to safely keep a decrypted temporary data? Enough about security!
SqlLite3, used with gpg, is fine until you get too large. After that, you can move to MariaDB (the supported version of MySQL), PostGreSQL, or something like Mongo. I'm a proponent of doing things that don't scale and getting something working now is worthwhile.
For the GUI, you'll hate my answer: HTML/CSS/JavaScript. The odds that you will need a portal or mobile app or remote access or whatever are compelling. Use jQuery (or one of its lightweight cousins like Zepto). Then run your application as a full screen application without a browser bar or access to other sites. You can use libraries to emulate the native look and feel, but customers almost always go "oh, I know how to use that" and stop asking.
Still hate the GUI answer? While you could use Tcl/Tk or Wx but you will forever be fighting platform bugs. For example, OS/X (Mac) users need to install ActiveState's Tcl/Tk instead of the default one. You will end up with a heavy solution for the images (PIL or ImageMagick) instead of just the HTML image tag. There is a huge list of other GUIs to play with, including some using the new 'yield from' construct. Still, you do better with HTML/CSS/JavaScript for now. Watch the "JavaScript: the Good Parts" and then adopt an attitude of ship it as it works.
Push hard to use either Python 2,7 or Python 3.3+. You don't want to be fighting the rising tide of better support when you making a complicated application.
I do this stuff for FUN!
GUI library
First of all, please leverage the work people have done to compile this GuiProgramming list.
One one the packages that stood out to me was Kivy. You should definitely check it out (at least the videos / intro). The Kivy project has some nice
introduction. I have to say I haven't followed it in full but it looks very promising. As for your requirements to be cross-platforms you can do that.
Packaging
There is an extensive documentation on how to package your app for the different platforms. For MacOSX and Windows it uses PyInstaller, but there are instructions for Android and iOS.
Client-side database
Yes, sqlite3 is the way to go. You can use sqlite3 with Kivy. You can also use SQLAlchemy if you need to connect to your sqlite database or if you need to connect to a remote one.
Retrieving content
The requests library is awesome to do http requests and IMHO is much simpler to use than a combination of httplib, urllib2.
Both PySide and WxPython support all five of your requirements. WxPython uses actual native widgets and also has custom extensions and widgets built on top. It has goodies like wx.CallAfter which'll allow you to run your background tasks in a separate thread and hop back on the UI thread easily.
PySide has a nicer API but draws its own widgets that imitate the underlying OS's UI. It's not as mature as WxPython and packaging it with tools like cx_freeze and PyInstaller is slightly more involved.
Also I recommend that you use an ORM like peewee over plain Sqlite3 for the data storage, it makes managing the data a lot easier and plays well with the freezing tools.
Of course the answer always remains; it depends on your needs and wants, but putting that aside I would say; go with Qt/QML. Qt with QML has been gaining a lot of traction lately, and with PyQt5 just release, it definitely seems like a good and future-proof option. It is cross platform, easy to work with and supports theming.
I highly recommend you watch this video in which they seem to do exactly what you want. In less than an hour they build a simple application that retrieves data (including images) from an outside source and list them on screen. It is also easy to make responsive applications (scaling easily to different screen sizes).
Lastly, I don't know what your license requirements are. PyQt is licensed either under the GPL, or under a commercial license. So if your application is open source, PyQt is perfectly fine. If your application will be proprietary you'dd be better off using PySide, which is LGPL.
Good luck!
I only got expirience with Qt-based Python GUI-toolkits, and found them to be very powerful, well documented and simple to use (as long as you stay away from model-view framework). And they can do all the things you mentioned. So my recomendation would be PyQt or PySide. PySide's advantage is it's license - LGPL, so if your stuff is proprietary - go for PySide. PySide has some troubles however, as it is basically abandoned as of writing this, so you will have to dodge some bugs (nothing realy critical IMO). PyQt is more actively maintained and developed, but it's GPL or commercial (about 400 euros). So if your stuff is free, you should choose PyQt. And yes, use ORM, if possible. Just my 2 cents.

How to prevent decompilation or inspecting python code?

let us assume that there is a big, commercial project (a.k.a Project), which uses Python under the hood to manage plugins for configuring new control surfaces which can be attached and used by Project.
There was a small information leak, some part of the Project's Python API leaked to the public information and people were able to write Python scripts which were called by the underlying Python implementation as a part of Project's plugin loading mechanism.
Further on, using inspect module and raw __dict__ readings, people were able to find out a major part of Project's underlying Python implementation.
Is there a way to keep the Python secret codes secret?
Quick look at Python's documentation revealed a way to suppres a import of inspect module this way:
import sys
sys.modules['inspect'] = None
Does it solve the problem completely?
No, this does not solve the problem. Someone could just rename the inspect module to something else and import it.
What you're trying to do is not possible. The python interpreter must be able to take your bytecode and execute it. Someone will always be able to decompile the bytecode. They will always be able to produce an AST and view the flow of the code with variable and class names.
Note that this process can also be done with compiled language code; the difference there is that you will get assembly. Some tools can infer C structure from the assembly, but I don't have enough experience with that to comment on the details.
What specific piece of information are you trying to hide? Could you keep the algorithm server side and make your software into a client that touches your web service? Keeping the code on a machine you control is the only way to really keep control over the code. You can't hand someone a locked box, the keys to the box, and prevent them from opening the box when they have to open it in order to run it. This is the same reason DRM does not work.
All that being said, it's still possible to make it hard to reverse engineer, but it will never be impossible when the client has the executable.
There is no way to keep your application code an absolute secret.
Frankly, if a group of dedicated and determined hackers (in the good sense, not in the pejorative sense) can crack the PlayStation's code signing security model, then your app doesn't stand a chance. Once you put your app into the hands of someone outside your company, it can be reverse-engineered.
Now, if you want to put some effort into making it harder, you can compile your own embedded python executable, strip out unnecessary modules, obfuscate the compiled python bytecode and wrap it up in some malware rootkit that refuses to start your app if a debugger is running.
But you should really think about your business model. If you see the people who are passionate about your product as a threat, if you see those who are willing to put time and effort into customizing your product to personalize their experience as a danger, perhaps you need to re-think your approach to security. Assuming you're not in the DRM business, or have a similar model that involves squeezing money from reluctant consumers, consider developing an approach that involves sharing information with your users, and allowing them to collaboratively improve your product.
Is there a way to keep the Python secret codes secret?
No there is not.
Python is particularly easy to reverse engineer, but other languages, even compiled ones, are easy enough to reverse.
You cannot fully prevent reverse engineering of software - if it comes down to it, one can always analyze the assembler instructions your program consists of.
You can, however, significantly complicate the process, for example by messing with Python internals. However, before jumping to how to do it, I'd suggest you evaluate whether to do it. It's usually harder to "steal" your code (one needs to fully understand them to be able to extend them, after all) than code it oneself. A pure, unobfuscated Python plugin interface, however, can be vital in creating a whole ecosystem around your program, far outweighing the possible downsides to having someone peek in your maybe not perfectly designed coding internals.

I want to make a temporary answerphone which records MP3s

An artistic project will encourage users to ring a number and leave a voice-mail on an automated service. These voice-mails will be collected and edited into a half-hour radio show.
I want to make a temporary system (with as little as possible programming) which will:
Allow me to establish a public telephone number (preferably in the UK)
Allow members of the public to call in and receive a short pre-recorded message
Leave a message of their own after the beep.
At the end of the project I'd like to be able to download and convert the recorded audio into a format that I can edit with a free audio-editor.
I do not mind paying to use a service if it means I can get away with doing less programming work. Also it's got to be reliable because once recorded it will be impossible to re-record the audio clips. Once set up the whole thing will run for at most 2 weeks.
I'm a python programmer with some basic familiarity with VOIP, however I'd prefer not to set up a big complex system like Asterisk since I do not ever intend to use the system again once the project is over. Whatever I do has to be really simple and disposable. Also I have access to Linux and FreeBSD systems (no Windows, sorry).
Thanks!
I use twilio, very easy, very fun.
Skype has a voicemail feature which sounds perfect for this and I suppose you would need a SkypeIn number as well
You may want to check out asterisk. I don't think it will become any easier than using an existing system.
Maybe you can find someone in the asterisk community to help set up such a system.
Take a look at Sipgate.co.uk, they provide a free UK dial in number and free incoming calls. Not so relavant for you but they also have a python api.
They are a SIP provider and there are many libraries (e.g. http://trac.pjsip.org/repos/wiki/Python_SIP_Tutorial ) for sip in python - so you could set up a python application to login to your sipgate account, pick up and incoming calls and dump the sound to a wav/mp3 whatever.

Categories