Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

09 August, 2017

Appjar Evening Coding Session


During this evening's coding session I created a primitive GUI in Python with Appjar. I just wanted to try out Appjar. Using it is a charm compared to the GLADE GUI builder or Tkinter.

For the code: click here.

08 August, 2017

Appjar

radioAppjar.py - stream running

appJar GUI (very primitive, but WTH)

Notes from my first fumbling with appjar. I'm looking for something that's more intuitive than Tkinter or Glade. Appjar is promising, at least for those of us with web programming experience. The code is somehow akin to JavaScript or even CSS.

The images above is my first GUI made in appJar. The files are available on Github.

Appjar is not standard Python, so the first task is:

Install appjar



# pip install appjar

The First File

# import the library
from appJar import gui
# create a GUI variable called app
app = gui()

# add & configure widgets - widgets get a name, to help referencing them later
app.addLabel("title", "My first Apphar")
app.setLabelBg("title", "green")

# start the GUI
app.go()

Get a value from a widget

  • .getEntry(title)
    This will return the contents of the specified entry box.
    NB. numericEntries always return a float.
  • .getAllEntries()
    This will return the contents of all entries in the app, as a dictionary.
    NB. numericEntries always return a float.

27 January, 2016

Python and MySQL on Linux Mint

Got an error because the MySQLdb package wasn't found. Solution:

# apt-cache search MySQLdb

python-mysqldb - Pythongrænseflade for MySQL
python-mysqldb-dbg - Pythonbrugerflade til MySQL (fejlsøgningsudvidelse)
bibus - Bibliografisk database
mysql-utilities - collection of scripts for managing MySQL servers
petj-HP-EliteBook-850-G1 ~ # apt-get install python-mysqldb

Then

# sudo apt-get install python-mysqldb

Then everything worked like a charm. 

13 January, 2016

How to make an icon for a Python App

The files and the icon.


So now I have some Python GUIs for my Philips HUE, but I'd like to have a nice Desktop Icon, like any other Linux App. How can I do this?

In Ubuntu - and probably most Linux systems the paths to executable programs are stored in hidden .desktop files.

First create a file and save it as .myApp.desktop

The content of the file could look like this:


[Desktop Entry]
Name=Test
Exec=/home/per/Dokumenter/bin/bin/hue/python/tkinterNoter/tkEntry.py
Icon=/home/per/Dokumenter/bin/bin/hue/python/tkinterNoter/multimusen.png
Terminal=false
Type=Application
GenericName="Python tkEntry Exp"

There are more possible setting, see here.

The next step is to make your file executable, write these commands in the terminal window:

# chmod a+x .myApp.desktop
# chmod a+x tkEntry.py
# cp .*desktop ~/.local/share/applications/

In order to give all system user access to your program, you can:

# cp .*desktop /usr/share/applications

Now you'll see an icon with the chosen picture in the folder. You can drag this icon to e.g. the menu. And now you can run your GUI as you would run any program.

The line Terminal can be true or false. If it's true the program will launch in a terminal window.

11 January, 2016

Json Parsing in Python (Philips Hue Sample)

Import libraries:

import requests
import json
from urllib import urlopen

Here's a class that will print out the names of the scenes:

    ''' AUTORUN METHOD '''
    def __init__(self,master):

        self.apiUrl = "http://192.168.0.11/api"
        self.user = "xxxxxxxxxxxxxxxxxxxxxxxxx"

        self.a = urlopen(self.apiUrl 
            + "/" 
            + self.user 
            + "/" 
            + "scenes").read()
        self.a = json.loads(self.a)
 
        for thing in self.a:
            self.theName = self.a.get( thing ).get('name')
            print self.theName

The function will print out a list of scene names.

19 April, 2014

Python - start a webserver in any dir

Miniserver - en Debian netbook med ekstern harddisk.


LAN-server
# python -m SimpleHTTPServer 8000

Start så en browser ... sådan:

# http://localhost:8000/index.htm

WAN-server på WWW
Miniserveren kan i øvrigt åbnes for internettet. Det kræver at http porten åbnes. På routeren kan det være nødvendigt at åbne port 80 og at knytte porten til en bestemt computers ip. Serveren startes fx sådan:

# cd /media/myDisk/someDir/
# sudo python -m SimpleHTTPServer 80

Herefter er en simpel webserver klar - og online. 

Sikkerhedsmæssigt vil det være klogt at lukke for port 80 igen, når den ikke bruges.

16 March, 2011

10.000 linjer om forskning

Strøtanker: har netop modtaget en cdrom fra Bento software med wordfiler på mindst 10.000 linjer med oplysning om forskningsartikler. En linje pr. artikel samt en slags tags. Efterhånden som filen vokser (den er monsterstor nu) bliver det jo et upraktisk med et monolitisk filformat. Komplekse søgninger er ikke muligt i en wordfil.

En databaseløsning med et python-Glade / web interface....?

Hvordan konverterer man .doc på en fornuftig måde, så resultatet kan håndteres af en database? Redaktøren er ofte off-line, så her må man finde en løsning til offline redigering... hmmm... tænke, tænke....

Første løsning: konverter .doc til alment tekstformat. Så kan man:
# cat AQC-Index-2010.txt | grep spam > eggs.txt

En python / glade GUI burde kunne udføre samme nummer.

13 March, 2011

Python og MySQLdb

Overvejede at lave en blog, der anvendte et php-script som interface til en database; men det ville jo være lettere, hvis man bare åbnede databasen og kommunikerede direkte via Python. Det kræver at man installerer MySQLdb modulet:

Installer pakken python-mysqldb via Synaptic (eller på anden vis). Derefter:

import MySQLdb

Eftersom pakken ikke er noget, der følger med ved en standardinstallation er det nok smart at tjekke, altså:

try:
import MySQLdb
except:
print "O dear, the MySQLdb is missing, I'm afraid."