Skip to content

Commit

Permalink
command line parsing began; using python click
Browse files Browse the repository at this point in the history
  • Loading branch information
iacchus committed May 10, 2017
1 parent 08cd876 commit 086dcfc
Show file tree
Hide file tree
Showing 19 changed files with 6,949 additions and 56 deletions.
119 changes: 63 additions & 56 deletions birdears/__main__.py
@@ -1,3 +1,5 @@
import click

from . import _Getch
from . import INTERVALS
from . import DEBUG
Expand Down Expand Up @@ -57,11 +59,14 @@ def print_stuff_dictation(question):
padd,
))

dictate_notes = 4

@click.group()
def cli():
pass

def main():
@cli.command()
def melodic_dictation():
from .questions.melodicdictation import MelodicDictationQuestion
dictate_notes = 4
getch = _Getch()

new_question_bit = True
Expand Down Expand Up @@ -121,58 +126,60 @@ def main():
elif user_input == 'r':
question.question.play()

# wait_keys = 1
# def main():
#
# from .questions.harmonicinterval import HarmonicIntervalQuestion
# from .questions.melodicinterval import MelodicIntervalQuestion
# getch = _Getch()
#
# new_question_bit = True
#
# while True:
# if new_question_bit is True:
#
# new_question_bit = False
#
# #input_keys = []
# #question = HarmonicIntervalQuestion(mode='major')
# #question = MelodicIntervalQuestion(mode='major',descending=True)
# #question = MelodicIntervalQuestion(mode='major',chromatic=True,n_octaves=2,descending=True)
# #question = HarmonicIntervalQuestion(mode='major',chromatic=True)
# question = HarmonicIntervalQuestion(mode='major', n_octaves=1)
#
#
# # debug
# if DEBUG:
# print_stuff(question)
#
# question.question.play()
#
# user_input = getch()
#
# if user_input in question.keyboard_index:
# response = question.check_question(user_input)
#
# if response['is_correct']:
# print("Correct!.. it is “{}”".\
# format( response['user_interval']))
# else:
# print("It is incorrect... correct is {}.. you said {}".\
# format(question.interval.data,
# response['user_interval']))
#
# question.resolution.play()
#
# new_question_bit = True
#
# # q - quit
# elif user_input == 'q':
# exit(0)
#
# # r - repeat interval
# elif user_input == 'r':
# question.question.play()
@cli.command()
def melodic_interval():

wait_keys = 1
from .questions.harmonicinterval import HarmonicIntervalQuestion
from .questions.melodicinterval import MelodicIntervalQuestion
getch = _Getch()

new_question_bit = True

while True:
if new_question_bit is True:

new_question_bit = False

#input_keys = []
#question = HarmonicIntervalQuestion(mode='major')
#question = MelodicIntervalQuestion(mode='major',descending=True)
#question = MelodicIntervalQuestion(mode='major',chromatic=True,n_octaves=2,descending=True)
#question = HarmonicIntervalQuestion(mode='major',chromatic=True)
question = HarmonicIntervalQuestion(mode='major', n_octaves=1)


# debug
if DEBUG:
print_stuff(question)

question.question.play()

user_input = getch()

if user_input in question.keyboard_index:
response = question.check_question(user_input)

if response['is_correct']:
print("Correct!.. it is “{}”".\
format( response['user_interval']))
else:
print("It is incorrect... correct is {}.. you said {}".\
format(question.interval.data,
response['user_interval']))

question.resolution.play()

new_question_bit = True

# q - quit
elif user_input == 'q':
exit(0)

# r - repeat interval
elif user_input == 'r':
question.question.play()

if __name__ == "__main__":
main()
# main()
cli()
38 changes: 38 additions & 0 deletions birdears/click/LICENSE
@@ -0,0 +1,38 @@
Copyright (c) 2014 by Armin Ronacher.

Click uses parts of optparse written by Gregory P. Ward and maintained by the
Python software foundation. This is limited to code in the parser.py
module:

Copyright (c) 2001-2006 Gregory P. Ward. All rights reserved.
Copyright (c) 2002-2006 Python Software Foundation. All rights reserved.

Some rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* The names of the contributors may not be used to endorse or
promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
98 changes: 98 additions & 0 deletions birdears/click/__init__.py
@@ -0,0 +1,98 @@
# -*- coding: utf-8 -*-
"""
click
~~~~~
Click is a simple Python module that wraps the stdlib's optparse to make
writing command line scripts fun. Unlike other modules, it's based around
a simple API that does not come with too much magic and is composable.
In case optparse ever gets removed from the stdlib, it will be shipped by
this module.
:copyright: (c) 2014 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
"""

# Core classes
from .core import Context, BaseCommand, Command, MultiCommand, Group, \
CommandCollection, Parameter, Option, Argument

# Globals
from .globals import get_current_context

# Decorators
from .decorators import pass_context, pass_obj, make_pass_decorator, \
command, group, argument, option, confirmation_option, \
password_option, version_option, help_option

# Types
from .types import ParamType, File, Path, Choice, IntRange, Tuple, \
STRING, INT, FLOAT, BOOL, UUID, UNPROCESSED, FloatRange

# Utilities
from .utils import echo, get_binary_stream, get_text_stream, open_file, \
format_filename, get_app_dir, get_os_args

# Terminal functions
from .termui import prompt, confirm, get_terminal_size, echo_via_pager, \
progressbar, clear, style, unstyle, secho, edit, launch, getchar, \
pause

# Exceptions
from .exceptions import ClickException, UsageError, BadParameter, \
FileError, Abort, NoSuchOption, BadOptionUsage, BadArgumentUsage, \
MissingParameter

# Formatting
from .formatting import HelpFormatter, wrap_text

# Parsing
from .parser import OptionParser


__all__ = [
# Core classes
'Context', 'BaseCommand', 'Command', 'MultiCommand', 'Group',
'CommandCollection', 'Parameter', 'Option', 'Argument',

# Globals
'get_current_context',

# Decorators
'pass_context', 'pass_obj', 'make_pass_decorator', 'command', 'group',
'argument', 'option', 'confirmation_option', 'password_option',
'version_option', 'help_option',

# Types
'ParamType', 'File', 'Path', 'Choice', 'IntRange', 'Tuple', 'STRING',
'INT', 'FLOAT', 'BOOL', 'UUID', 'UNPROCESSED', 'FloatRange'

# Utilities
'echo', 'get_binary_stream', 'get_text_stream', 'open_file',
'format_filename', 'get_app_dir', 'get_os_args',

# Terminal functions
'prompt', 'confirm', 'get_terminal_size', 'echo_via_pager',
'progressbar', 'clear', 'style', 'unstyle', 'secho', 'edit', 'launch',
'getchar', 'pause',

# Exceptions
'ClickException', 'UsageError', 'BadParameter', 'FileError',
'Abort', 'NoSuchOption', 'BadOptionUsage', 'BadArgumentUsage',
'MissingParameter',

# Formatting
'HelpFormatter', 'wrap_text',

# Parsing
'OptionParser',
]


# Controls if click should emit the warning about the use of unicode
# literals.
disable_unicode_literals_warning = False


__version__ = '7.0-dev'

0 comments on commit 086dcfc

Please sign in to comment.