Skip to content

Commit

Permalink
Merge pull request #1 from spacether/adds_tkinter_backend
Browse files Browse the repository at this point in the history
Adds tkinter backend
  • Loading branch information
spacether authored Dec 21, 2020
2 parents a9b2491 + fa17f7c commit dfe82ce
Show file tree
Hide file tree
Showing 45 changed files with 2,996 additions and 1,000 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 2.0.0
- Breaking: KeyboardLayout layout_name input type changed from str to LayoutName enum
- Fixed typo in readme code sample
- Python samples renamed to include pygame_ or tkinter_ prefix
- Adds init docstrings to KeyboardInfo, KeyInfo
- Adds Rect class used by the KeyboardLayoutInterface
- Adds a Key enum to store all possible keys for each backend
- Breaking: Changes update_key to ingest the Key enum
- Adds get_key method to get the key constant that is used to update keys
- Breaking KeyboardLayout class must now be imported from the pygame or tkinter submodules
- Breaking: pygame removed from the dependency list, if using the pygame backend
the developer must install it into their environment

# 1.0.0
- qwerty + azerty included
- dynamically generate a pygame sprite group showing a keyboard
- customize the keyboard with sizes, colors, key margin, padding, font, location, etc
- override the default KeyInfo by passing in overrides
- update a specific key with update_key
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: test dist
.PHONY: test dist docs

develop:
pip3 install -e .[dev]
Expand Down
67 changes: 34 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
# keyboardlayout
A python library to display different keyboards.
The keyboard layouts are created with pygame sprites.
PRs with additional layouts or graphics backends are welcome.
Works with pygame or tkinter.

If you need to show your users a graphic that shows a specific keyboard layout or a portion of a keyboard, this is the library for you.

## Features:
- qwerty + azerty included
- dynamically generate a pygame sprite group showing a keyboard
- shows a keyboard to the user
- keyboard layouts
- qwerty
- azerty laptop
- graphics backends
- pygame (uses sprite groups)
- tkinter (uses frames + labels)
- customize the keyboard with sizes, colors, key margin, padding, font, location, etc
- update a specific key with `update_key`
- can update key images when keys are pressed

## Changelog
https://github.com/spacether/keyboardlayout/tree/master/CHANGELOG.md

## Documentation
https://spacether.github.io/keyboardlayout/
Expand All @@ -31,54 +39,47 @@ pip install keyboardlayout
```

## Samples
- [qwerty](https://github.com/spacether/keyboardlayout/tree/master/samples/qwerty.py)
- [pressed keys with pygame](https://github.com/spacether/keyboardlayout/tree/master/samples/pressed_keys_pygame.py)
- [pygame, qwerty](https://github.com/spacether/keyboardlayout/tree/master/samples/pygame_qwerty.py)
- [pygame, pressed keys](https://github.com/spacether/keyboardlayout/tree/master/samples/pygame_pressed_keys.py)
- [tkinter, qwerty](https://github.com/spacether/keyboardlayout/tree/master/samples/tkinter_qwerty.py)
- [tkinter, pressed keys](https://github.com/spacether/keyboardlayout/tree/master/samples/tkinter_pressed_keys.py)

## Usage
### tkinter example
```
import keyboardlayout as kl
import pygame
import tkinter as tk
import tkinter.font as tkf
layout_name = 'qwerty'
pygame.init()
import keyboardlayout as kl
import keyboardlayout.tkinter as klt
layout_name = kl.LayoutName.QWERTY
key_size = 60
grey = pygame.Color('grey')
grey = '#bebebe'
dark_grey = '#414141'
keyboard_info = kl.KeyboardInfo(
position=(0, 0),
padding=2,
color=~grey
color=dark_grey
)
window = tk.Tk()
window.resizable(False, False)
key_info = kl.KeyInfo(
margin=10,
color=grey,
txt_color=~grey, # invert grey
txt_font=pygame.font.SysFont('Arial', key_size//4),
txt_color=dark_grey,
txt_font=tkf.Font(family='Arial', size=key_size//4),
txt_padding=(key_size//6, key_size//10)
)
letter_key_size = (key_size, key_size), # width, height
keyboard_layout = kl.KeyboardLayout(
letter_key_size = (key_size, key_size) # width, height
keyboard_layout = klt.KeyboardLayout(
layout_name,
keyboard_info,
letter_key_size,
key_info
key_info,
master=window
)
screen = pygame.display.set_mode(
(keyboard_layout.rect.width, keyboard_layout.rect.height))
screen.fill(pygame.Color('black'))
keyboard_layout.draw(screen)
pygame.display.update()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.display.quit()
running = False
pygame.quit()
window.mainloop()
```

## Local Installation
Expand Down
2 changes: 1 addition & 1 deletion docs/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 4466c069453c4a3c3533521ad93bfe29
config: bcac0a9de7c8fb8335ea30ea2ec837e6
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file modified docs/.doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/.doctrees/index.doctree
Binary file not shown.
Binary file modified docs/.doctrees/keyboardlayout.doctree
Binary file not shown.
10 changes: 6 additions & 4 deletions docs/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Overview: module code &#8212; keyboardlayout 1.0.0 documentation</title>
<title>Overview: module code &#8212; keyboardlayout 2.0.0 documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />

Expand All @@ -32,7 +31,10 @@
<div class="body" role="main">

<h1>All modules for which code is available</h1>
<ul><li><a href="keyboardlayout/keyboardlayout.html">keyboardlayout.keyboardlayout</a></li>
<ul><li><a href="keyboardlayout/common.html">keyboardlayout.common</a></li>
<li><a href="keyboardlayout/layouts.html">keyboardlayout.layouts</a></li>
<li><a href="keyboardlayout/pygame/keyboardlayout.html">keyboardlayout.pygame.keyboardlayout</a></li>
<li><a href="keyboardlayout/tkinter/keyboardlayout.html">keyboardlayout.tkinter.keyboardlayout</a></li>
</ul>

</div>
Expand Down Expand Up @@ -89,7 +91,7 @@ <h3 id="searchlabel">Quick search</h3>
&copy;2020, Justin Black.

|
Powered by <a href="http://sphinx-doc.org/">Sphinx 3.3.1</a>
Powered by <a href="http://sphinx-doc.org/">Sphinx 3.4.0</a>
&amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>

</div>
Expand Down
Loading

0 comments on commit dfe82ce

Please sign in to comment.