Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
George Ciesinski committed Jan 17, 2020
2 parents 0d1b91b + 397196d commit 69f8f69
Show file tree
Hide file tree
Showing 10 changed files with 278 additions and 36 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.1.0] - 2020-01-17
### Added
- Statistics tracking for shortcuts used, total shortcut characters typed, and total textblock characters pasted
- Help and Exit commands have been added

## [1.0.0] - 2020-01-16
### Added
- Debugging print lines removed
Expand Down
13 changes: 13 additions & 0 deletions Config/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[TEXTSCRIPT]
version = 1.1.0

[HISTORY]
shortcutsused = 2
shortcutchars = 13
textblockchars = 692

[DIRECTORIES]
defaultdirectory = Textblocks/
localdirectory = None
remotedirectory = None

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# text-script
An app that runs in the background and replaces text shortcuts with pre-saved blocks of text.

## Planned future updates
- Save whatever the latest clipboard item is and replace it after shortcut is used. Currently the last textblock used fills the last clipboard spot
- Create #reload command which reloads the shortcut list with all the latest updates.
135 changes: 135 additions & 0 deletions Settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import configparser
from Logger import Logger
from os import path


class Setup:

# TODO: Create check to ensure config file has the right categories and values

def __init__(self, log, text_script_version):

# Creates instance of current version variable
self.version = text_script_version

# TODO: Check if version has changed, update config

# Creates instance wide log object
self.log = log.log

# Creates instance of ConfigParser object
self.config = configparser.ConfigParser(allow_no_value=True)

# Config Directory
self.config_dir = 'Config/config.ini'

self.log.debug("Setup initialized successfully.")

def config_exists(self):
"""
Checks if Config file exists
"""

if path.exists("Config/config.ini"):

self.log.debug("Config file found.")

else:

self.log.debug("No config file exists. Creating new config file.")

# Creates new config file
self.create_config()

def create_config(self):
"""
Creates a new config file
"""

self.config['TEXTSCRIPT'] = {
'version': self.version
}

self.config['HISTORY'] = {}
self.config.set('HISTORY', '; Tracks key strokes saved history')
self.config.set('HISTORY', 'shortcutsused', 0)
self.config.set('HISTORY', 'shortcutchars', 0)
self.config.set('HISTORY', 'textblockchars', 0)

self.config['DIRECTORIES'] = {
'defaultdirectory': 'Textblocks/',
'localdirectory': 'None',
'remotedirectory': 'None'
}

with open(self.config_dir, 'w') as configfile:
self.config.write(configfile)

self.log.debug(f"{self.config_dir} file created successfully.")

def find_directories(self):
"""
Finds the directories in the config file
"""

self.config.read(self.config_dir)
default_directory = self.config['DIRECTORIES']['defaultdirectory']

return default_directory


class UpdateConfig:

def __init__(self, log):

# Creates instance wide log variable
self.log = log.log

# Creates instance of ConfigParser
self.config = configparser.ConfigParser(allow_no_value=True)

# Config Directory
self.config_dir = 'Config/config.ini'

self.log.debug("Setup initialized successfully.")

def update_history(self, shortcut, textblock):
"""
Updates the shortcuts used, total shortcut characters typed, and total textblock characters pasted
"""

# Read config file for the shortcuts used, shortcut characters, and textblock characters
self.config.read(self.config_dir)
shortcuts_used = int(self.config['HISTORY']['shortcutsused'])
shortcut_chars = int(self.config['HISTORY']['shortcutchars'])
textblock_chars = int(self.config['HISTORY']['textblockchars'])

# Increase shortcuts used by 1
shortcuts_used += 1

# Increase shortcut characters by the length of the current shortcut
shortcut_chars += len(shortcut)

# Increase textblock characters by the length of the current textblock
textblock_chars += len(textblock)

# Update the config categories with the updated data
self.config.set('HISTORY', 'shortcutsused', str(shortcuts_used))
self.config.set('HISTORY', 'shortcutchars', str(shortcut_chars))
self.config.set('HISTORY', 'textblockchars', str(textblock_chars))

# Write to the config file
with open(self.config_dir, 'w') as configfile:
self.config.write(configfile)


if __name__ == "__main__":

# Initialize Logger
L = Logger()

L.log.debug("Program started from Settings.py.")

s = Setup(L)

s.config_exists()
97 changes: 84 additions & 13 deletions TextController.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@
from pynput.keyboard import Controller, Key, Listener
import pyperclip
from Logger import Logger
from Settings import UpdateConfig


# Class catches individual words as they are typed
class WordCatcher:

def __init__(self, log, keyboard, shortcut_list, file_dir_list):

# Creates instance wide log variable
# Creates instance wide log object
self.log = log.log

# Creates instance wide UpdateConfig object
self.update = UpdateConfig(log)

# Creates instance wide keyboard variable
self.keyboard = keyboard

# List of Text-Script commands
self.commands = [
"#help",
"#exit",
"#reload"
]

# Creates instance wide shortcut_list & file_dir_list
self.shortcut_list = shortcut_list
self.file_dir_list = file_dir_list
Expand All @@ -35,6 +46,7 @@ def __init__(self, log, keyboard, shortcut_list, file_dir_list):

self.log.debug("WordCatcher initialized.")

# TODO: Look into self.listener.join and why this is even working. Might need to be changed.
# Start self.listener
with Listener(on_press=self.word_builder) as self.listener:
self.listener.join()
Expand Down Expand Up @@ -148,20 +160,12 @@ def check_shortcut(self):
Checks list of shortcuts for a match. Sets text block if match is found.
"""

# Exit program if user typed in #exit
if self.current_word == "#exit":

exit_text = "Text-Script exited."

self.keyboard.delete_shortcut(self.current_word)

self.keyboard.paste_block(exit_text)

self.log.debug("The user has typed #exit. Exiting program.")
# If shortcut is in command list, determine which command was used
if self.current_word in self.commands:

# Close the program with no error
sys.exit(0)
self.determine_command()

# If shortcut is in shortcut_list, determine which shortcut was used
if self.current_word in self.shortcut_list:

# Finds index of self.current_word on shortcut list
Expand All @@ -173,9 +177,71 @@ def check_shortcut(self):
# Deletes the typed out shortcut
self.keyboard.delete_shortcut(self.current_word)

# Update history
self.update.update_history(self.current_word, self.textblock)

# Passes the textbox to the keyboard
self.keyboard.paste_block(self.textblock)

def determine_command(self):

# Exit program if user typed in #exit
if self.current_word == "#exit":

self.log.debug("The user has typed #exit. Exiting program.")
self.exit_program()

# Paste help menu if user typed in #help
elif self.current_word == "#help":

self.log.debug("The user has typed in #help. Pasting help menu.")
self.help_menu()

elif self.current_word == "#reload":

self.log.debug("The user has typed in #reload. Reloading shortcut_list and file_dir_list.")
pass

def exit_program(self):
"""
Exits the program
"""

exit_text = "Text-Script exited."

self.keyboard.delete_shortcut(self.current_word)

self.keyboard.paste_block(exit_text)

# Close the program with no error
sys.exit(0)

def help_menu(self):

help_text = """Help Menu:
How to make a shortcut:
1. Navigate to the program folder, and go to the Textblocks folder
2. Either navigate to an existing folder in Textblocks, or create a new one
3. Create a new text file here. The naming convention is #____.txt where ____ is the shortcut you will type
4. Open the text file and put your text block / signature / template in here
5. Click "Save As" and select the same text file, but change encoding to unicode
Note: Other formats may still work, but this is designed to read unicode text files.
To exit Text-Script, type: #exit
"""

self.keyboard.delete_shortcut(self.current_word)

self.keyboard.paste_block(help_text)

def update_shortcuts(self):

# TODO: Create update_shortcuts method
pass

def find_file_directory(self, index):
"""
Finds the directory of the Textblock file.
Expand Down Expand Up @@ -268,9 +334,14 @@ def paste_block(self, textblock):
paste_block copies the textblock into the clipboard and pastes it using pyinput controller.
"""

# TODO: Determine why pyperclip can't save clipboard item and paste back into clipboard later

try:
pyperclip.copy(textblock)

# TODO: Look up Pyperclip documentation for OSX & Linux implementation

# TODO: Test pyperclip.paste()
self.c.press(Key.ctrl_l)
self.c.press('v')
self.c.release(Key.ctrl_l)
Expand Down
Binary file added Textblocks/Examples/#example.txt
Binary file not shown.
13 changes: 0 additions & 13 deletions Textblocks/Examples/#help.txt

This file was deleted.

Loading

0 comments on commit 69f8f69

Please sign in to comment.