Sponsored Content
Top Forums Shell Programming and Scripting Kbd input processing with python Post 302920022 by sdohn on Monday 6th of October 2014 11:30:30 AM
Old 10-06-2014
Kbd input processing with python

Hi, I'm new to python, and I work on a little program fpr my rapsberry pi.
This scenario here is a little Midi sysex app for my Roland D-50 Synthesizer.
With an usb attached number keypad I can type numbers from 0 to 9 and the referenced Midi sysex file would be send out to my Roland D-50 Synthesizer.
This therefore works as expected. But now I want to improove my little python programm for the processing of 2 digits taken from the usb number keypad.

In theory the behavior should be as follow:
We check for 2 digits first, If one enters 23 we do in a "elif content == "23":" block the magic. But if one has typed only 1 digit we trigger the elif block for 1 digit. Problem for me is, I don't know how to check for 1 or 2 digits in the code.

Here is my code:

Code:
#!/usr/bin/env python
import select
import termios
import tty
import sys
import datetime
import os

class mylocontrol(object):
    def __init__(self):
        self.checkkeys()

    def showcontent(self,content):
        if content == "1":
            os.system("/usr/bin/amidi -p hw:1,0,0  -s /work/MIDI/d50_00.syx") 
        elif content == "2":
            os.system("/usr/bin/amidi -p hw:1,0,0  -s /work/MIDI/PND50-02.syx")
        
    def getkey(self):
        old_settings = termios.tcgetattr(sys.stdin)
        tty.setraw(sys.stdin.fileno())
        select.select([sys.stdin], [], [], 0)
        answer = sys.stdin.read(1)
        termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
        return answer

    def checkkeys(self):
        while True:
            answer=self.getkey()
            if "|" in answer:
                break
            else:
                ret = self.showcontent(answer)

mylo = mylocontrol()

Maybe someone could help me out!
 

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

giving input to a python wch has been called frm shell script....urgent

i'm calling a python script from shell script. the python needs Y as an input everytime. how can i giv it thru shell script. I tried below code for arg in `cat erd_gen_list.lst` do generateErdSql.py -S $arg << Y done This is giving me err : `<<' unmatched pls help. (1 Reply)
Discussion started by: vini
1 Replies

2. Solaris

Processing user input in .sh file

Hi, I am new to shell scripting. script should accept the user value and then compare that value with the null. If null then assign the value "*" to the variable else will use the user inputed value. How to do this ? With Regards (3 Replies)
Discussion started by: milink
3 Replies

3. Shell Programming and Scripting

[Python]StringVar() Class String processing

I have a requirement where I collect inputs from entry widget in gui(via variables a,b,c) and then output a string like this: -a a -b b -c c. Hence if I have given a=1 b=2 c=3, The output string is --> -a 1 -b 2 -c 3 or if I have given a=1 b=2 (c left blank) then the output is --> -a 1... (1 Reply)
Discussion started by: animesharma
1 Replies

4. Shell Programming and Scripting

Reducing the decimal points of numbers (3d coordinates) in a file; how to input data to e.g. Python

I have a file full of coordinates of the form: 37.68899917602539 58.07500076293945 57.79100036621094 The numbers don't always have the same number of decimal points. I need to reduce the decimal points of all the numbers (there are 128 rows of 3 numbers) to 2. I have tried to do this... (2 Replies)
Discussion started by: crunchgargoyle
2 Replies

5. Shell Programming and Scripting

If condition after raw input in python

Hi, I have a python script which is completely interactive. I have almost 10+ raw input statements like below which are collected from user one by one. req_number = raw_input("Please enter request number or Q to Quit: ") if (req_number in ): sys.exit() Is it possible for a more... (6 Replies)
Discussion started by: ctrld
6 Replies

6. Shell Programming and Scripting

Python problem with input

Hello everyone, I have just started python, and there is something that escapes me. I don't understand why my little script doesn't work. When I do, it work: my_string = "bonjour" if len(my_string) < "6": print(my_string + " < 6") else: print(my_string + " > 6") ... (2 Replies)
Discussion started by: Arnaudh78
2 Replies
DH_PYTHON(1)							     Debhelper							      DH_PYTHON(1)

NAME
dh_python - calculates Python dependencies and adds postinst and prerm Python scripts (deprecated) SYNOPSIS
dh_python [debhelperoptions] [-n] [-V version] [moduledirs...] DESCRIPTION
Note: This program is deprecated. You should use dh_pysupport or dh_pycentral instead. This program will do nothing if debian/pycompat or a Python-Version control file field exists. dh_python is a debhelper program that is responsible for generating the ${python:Depends} substitutions and adding them to substvars files. It will also add a postinst and a prerm script if required. The program will look at Python scripts and modules in your package, and will use this information to generate a dependency on python, with the current major version, or on pythonX.Y if your scripts or modules need a specific python version. The dependency will be substituted into your package's control file wherever you place the token ${python:Depends}. If some modules need to be byte-compiled at install time, appropriate postinst and prerm scripts will be generated. If already byte- compiled modules are found, they are removed. If you use this program, your package should build-depend on python. OPTIONS
module dirs If your package installs Python modules in non-standard directories, you can make dh_python check those directories by passing their names on the command line. By default, it will check /usr/lib/site-python, /usr/lib/$PACKAGE, /usr/share/$PACKAGE, /usr/lib/games/$PACKAGE, /usr/share/games/$PACKAGE and /usr/lib/python?.?/site-packages. Note: only /usr/lib/site-python, /usr/lib/python?.?/site-packages and the extra names on the command line are searched for binary (.so) modules. -V version If the .py files your package ships are meant to be used by a specific pythonX.Y version, you can use this option to specify the desired version, such as 2.3. Do not use if you ship modules in /usr/lib/site-python. -n, --noscripts Do not modify postinst/prerm scripts. CONFORMS TO
Debian policy, version 3.5.7 Python policy, version 0.3.7 SEE ALSO
debhelper(7) This program is a part of debhelper. AUTHOR
Josselin Mouette <joss@debian.org> most ideas stolen from Brendan O'Dea <bod@debian.org> 8.9.0ubuntu2.1 2012-06-12 DH_PYTHON(1)
All times are GMT -4. The time now is 08:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy