Initial (overdue) commit

TODO:
- enable dynamic loading of button labels and actions
This commit is contained in:
2020-08-27 17:21:17 -07:00
parent 6e83bfb9c5
commit c5b61eee0a
42 changed files with 2739 additions and 1 deletions

98
CMDRConsole/__init__.py Normal file
View File

@@ -0,0 +1,98 @@
import os
import pyautogui
from flask import Flask
from flask import (
Blueprint, flash, g, redirect, render_template, request, session, url_for
)
import CMDRConsole.config_parser
def create_app(test_config=None):
global cmds
global pages
global page
global keys
cmds = config_parser.get_cmds()
pages = config_parser.get_pages()
keys = config_parser.get_keys()
page = 'General'
# create and configure the app
app = Flask(__name__, instance_relative_config=True)
if test_config is None:
# load the instance config, if it exists, when not testing
app.config.from_pyfile('config.py', silent=True)
else:
# load the test config if passed in
app.config.from_mapping(test_config)
# ensure the instance folder exists
try:
os.makedirs(app.instance_path)
except OSError:
pass
@app.route('/', methods=['GET','POST'])
def render_default():
return render_template(pages[page])
@app.route('/General')
@app.route('/Mining')
@app.route('/Exploration')
@app.route('/SRV')
@app.route('/Assault')
@app.route('/Keyboard')
def render_page():
global page
rule = request.url_rule
page = rule.rule.replace('/','');
return render_template(pages[page])
@app.route('/mouse_move', methods=['POST'])
def move_mouse():
d_x = int(request.form['dx'])
d_y = int(request.form['dy'])
x, y = pyautogui.position()
new_x = max([x+d_x, 0])
new_y = max([y+d_y, 0])
try:
pyautogui.moveTo(new_x, new_y)
except:
pass
return "OK"
@app.route('/mouse_tap', methods=['POST'])
def click_mouse():
try:
pyautogui.click()
except:
pass
return "OK"
@app.route('/button_press', methods=['GET','POST'])
def button_press(key = None):
key = request.data.decode("utf-8")
print("'"+key+"'")
if not key:
error = 'Key cannot be blank.'
print(error)
elif key in cmds:
cmd = cmds[key]
pyautogui.press(cmd)
elif key in keys:
cmd = keys[key]
pyautogui.press(cmd)
else:
try:
pyautogui.press(key)
except:
pass
return "OK"
return app

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

5
CMDRConsole/colors.txt Normal file
View File

@@ -0,0 +1,5 @@
orange: 255 115 0
slate: 13 13 13
white: 251 255 255
button-bg: 34 13 13
blue 50 201 255

View File

@@ -0,0 +1,83 @@
import xml.etree.ElementTree as xml
import re
def get_labels():
return [['Speed Boost','75% Throttle','Full Stop','Full Reverse'],
['Hardpoints','Cargo Bay','Fuel Scoop','Landing Gear'],
['Drop Chaff','Shield Cell','Heat Sink','ECM'],
['Frameshift','Supercruise','Run Silent','Toggle Lights']]
def get_general_labels():
return {'Speed Boost':'UseBoostJuice',
'75% Throttle':'SetSpeed75',
'Full Stop':'SetSpeedZero',
'Full Reverse':'SetSpeedMinus100',
'Hardpoints':'DeployHardpointToggle',
'Cargo Bay':'ToggleCargoScoop',
'Night Vision':'NightVisionToggle',
'Landing Gear':'LandingGearToggle',
'Drop Chaff':'FireChaffLauncher',
'Shield Cell':'UseShieldCell',
'Heat Sink':'DeployHeatSink',
'ECM':'ChargeECM',
'Frameshift':'Hyperspace',
'Supercruise':'Supercruise',
'Run Silent':'',
'Toggle Lights':'ShipSpotLightToggle'}
def get_mining_labels():
def get_exploration_labels():
def get_srv_labels():
def get_assault_labels():
def get_cmds():
cmds = {}
tree = xml.ElementTree(file=XXX)
root = tree.getroot()
children = list(root)
regex = re.compile(r"(\w)([A-Z0-9])")
for child in children:
name = child.tag
if not child.findall('Primary')
continue
keys = child.getchildren()
if keys[0].attrib['Device'] == 'Keyboard':
cmd = name
key = keys[0].attrib['Key'].replace('Key_','')
cmds[cmd] = key
elif keys[1].attrib['Device'] == 'Keyboard':
cmd = name
key = keys[0].attrib['Key'].replace('Key_','')
cmds[cmd] = key
return cmds
# return {'Speed Boost':'j','75% Throttle':'\\','Full Stop':'x','Full Reverse':'p',
# 'Hardpoints':'u','Cargo Bay':'l','Fuel Scoop':'j','Landing Gear':'home',
# 'Drop Chaff':'7','Shield Cell':'8','Heat Sink':'9','ECM':'0',
# 'Frameshift':'j','Supercruise':'k','Run Silent':'m','Toggle Lights':'n'}
def get_pages():
return {'General':'general.html',
'Mining':'mining.html',
'Exploration':'exploration.html',
'SRV':'srv.html',
'Assault':'assault.html',
'Keyboard':'keyboard.html'}
def get_keys():
return {'BACK':'backspace',
'TAB':'\t',
'CAPS':'capslock',
'ENTER':'enter',
'SHIFT':'shift',
'ALT':'alt',
'CTRL':'ctrl',
'LT':'left',
'UP':'up',
'DN':'down',
'RT':'right',
'SPACE':' '}

View File

View File

@@ -0,0 +1,113 @@
.header-grid {
display: grid;
grid-template-columns: repeat(5, 1fr);
grid-gap: 3px;
height: 8%;
width: 100%;
grid-auto-flow: row;
margin-bottom: 1%;
}
.header-button {
align-self: stretch;
background-color: #210c0c;
border: 1px solid #ff7200;
color: #ff7200;
font-weight: bold;
height: 100%;
width: 100%;
font-size: large;
font-weight: bold;
}
.button-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: repeat(4, 1fr);
grid-gap: 3px;
height: 90%;
width: 100%;
grid-auto-flow: row;
}
.grid-button {
text-align: center;
align-self: stretch;
background-color: #210c0c;
border: 1px solid #ff7200;
color: #ff7200;
font-weight: bold;
font-size: x-large;
height: 100%;
width: 100%;
}
.key-container {
display: grid;
grid-template-columns: repeat(59, 1fr);
grid-template-rows: repeat(5, 1fr);
grid-gap: 3px;
height: 50%;
width: 100%;
grid-auto-flow: row;
}
.track-container {
height: 40%;
width: 100%;
}
.track-button {
align-self: stretch;
background-color: #210c0c;
border: 1px solid #ff7200;
color: #ff7200;
height: 100%;
width: 100%;
}
.grid-key {
text-align: center;
align-self: stretch;
grid-column-end: span 4;
background-color: #210c0c;
border: 1px solid #ff7200;
color: #ff7200;
font-weight: bold;
height: 100%;
width: 100%;
font-size: large;
font-weight: bold;
}
.grid-key-empty {
text-align: center;
align-self: stretch;
grid-column-end: span 4;
height: 100%;
width: 100%;
background: #0c0c0c;
border: 0px;
visibility: hidden;
}
.grid-key:active {
background-color: #ff7200;
color: #210c0c;
}
body, .content, .container {
height: 100%;
width: 100%;
background: #0c0c0c;
}
body, html {
height: 100%;
width: 100%;
overflow-x: hidden;
overflow-y: hidden;
margin:0;
padding:0;
position: fixed;
}

View File

@@ -0,0 +1,74 @@
var x;
var y;
var timer;
var scale = 1.0;
var lastFired = new Date().getTime();
function touchStartEventHandler(e) {
x = e.touches[0].clientX;
y = e.touches[0].clientY;
}
function touchMoveEventHandler(e) {
clearTimeout(timer);
var now = new Date().getTime();
if (now < lastFired + 200) {
timer = setTimeout(function() {
touchMoveEventHandler(e);
}, lastFired - now + 100);
return;
}
var new_x = e.touches[0].clientX;
var new_y = e.touches[0].clientY;
var d_x = (new_x - x) / scale;
var d_y = (new_y - y) / scale;
x = new_x;
y = new_y;
var request = new XMLHttpRequest();
request.open("POST", "/mouse_move", true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
console.log("dx=" + d_x + "&dy=" + d_y);
request.send("dx=" + d_x + "&dy=" + d_y);
lastFired = now;
e.stopPropagation();
e.preventDefault();
}
function tapEventHandler(e) {
var request = new XMLHttpRequest();
request.open("POST", "/mouse_tap", true);
request.send();
}
function keyEventHandler(e) {
e.preventDefault();
var clickedButton = e.target;
var command = clickedButton.innerHTML ;
var request = new XMLHttpRequest();
request.open("POST", "/button_press", true);
request.send(command);
}
addEventListener("DOMContentLoaded", function() {
// Set grid and key buttons to send to server without refresh
var buttons = document.querySelectorAll(".grid-button, .grid-key");
for (var ii=0, ll=buttons.length; ii<ll; ii++) {
var btn = buttons[ii];
btn.addEventListener("click", keyEventHandler);
}
var trackpad = document.querySelector(".track-button");
if (trackpad != null) {
trackpad.addEventListener("touchstart", touchStartEventHandler, true);
trackpad.addEventListener("touchmove", touchMoveEventHandler, true);
trackpad.addEventListener("click", tapEventHandler, true);
}
}, true);

View File

@@ -0,0 +1,28 @@
{% extends 'base.html' %}
{% block title %}Assault{% endblock %}
{% block buttons %}
<div class="button-grid">
<button class="grid-button">Speed Boost</button>
<button class="grid-button">Hardpoints</button>
<button class="grid-button">Drop Chaff</button>
<button class="grid-button">Frameshift</button>
<button class="grid-button">75% Throttle</button>
<button class="grid-button">Cargo Bay</button>
<button class="grid-button">Shield Cell</button>
<button class="grid-button">Supercruise</button>
<button class="grid-button">Full Stop</button>
<button class="grid-button">Fuel Scoop</button>
<button class="grid-button">Heat Sink</button>
<button class="grid-button">Run Silent</button>
<button class="grid-button">Full Reverse</button>
<button class="grid-button">Landing Gear</button>
<button class="grid-button">ECM</button>
<button class="grid-button">Toggle Lights</button>
</container>
{% endblock %}

View File

@@ -0,0 +1,21 @@
<!doctype html>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}{% endblock %} - CMDRConsole</title>
<link href="{{ url_for('static', filename='CMDRConsole.css') }}" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="{{ url_for('static', filename='CMDRConsole.js') }}"></script>
<div class="container">
<div class="header-grid">
<a href="/General"><button class="header-button">General</button></a>
<a href="/Mining"><button class="header-button">Mining</button></a>
<a href="/Exploration"><button class="header-button">Exploration</button></a>
<a href="/SRV"><button class="header-button">SRV</button></a>
<a href="/Keyboard"><button class="header-button">Keyboard</button></a>
</div>
{% block buttons %}{% endblock %}
</div>

View File

@@ -0,0 +1,28 @@
{% extends 'base.html' %}
{% block title %}Exploration{% endblock %}
{% block buttons %}
<div class="button-grid">
<button class="grid-button">Speed Boost</button>
<button class="grid-button">Hardpoints</button>
<button class="grid-button">Drop Chaff</button>
<button class="grid-button">Frameshift</button>
<button class="grid-button">75% Throttle</button>
<button class="grid-button">Cargo Bay</button>
<button class="grid-button">Shield Cell</button>
<button class="grid-button">Supercruise</button>
<button class="grid-button">Full Stop</button>
<button class="grid-button">Fuel Scoop</button>
<button class="grid-button">Heat Sink</button>
<button class="grid-button">Run Silent</button>
<button class="grid-button">Full Reverse</button>
<button class="grid-button">Landing Gear</button>
<button class="grid-button">ECM</button>
<button class="grid-button">Toggle Lights</button>
</container>
{% endblock %}

View File

@@ -0,0 +1,27 @@
{% extends 'base.html' %}
{% block title %}General{% endblock %}
{% block buttons %}
<div class="button-grid">
<button class="grid-button">Speed Boost</button>
<button class="grid-button">Hardpoints</button>
<button class="grid-button">Drop Chaff</button>
<button class="grid-button">Frameshift</button>
<button class="grid-button">75% Throttle</button>
<button class="grid-button">Cargo Bay</button>
<button class="grid-button">Shield Cell</button>
<button class="grid-button">Supercruise</button>
<button class="grid-button">Full Stop</button>
<button class="grid-button">Fuel Scoop</button>
<button class="grid-button">Heat Sink</button>
<button class="grid-button">Run Silent</button>
<button class="grid-button">Full Reverse</button>
<button class="grid-button">Landing Gear</button>
<button class="grid-button">ECM</button>
<button class="grid-button">Toggle Lights</button>
</container>
{% endblock %}

View File

@@ -0,0 +1,87 @@
{% extends 'base.html' %}
{% block title %}Keyboard{% endblock %}
{% block buttons %}
<div class="track-container">
<button class="track-button"></button>
</div>
<div class="key-container">
<button class="grid-key" style="">`</button>
<button class="grid-key" style="">1</button>
<button class="grid-key" style="">2</button>
<button class="grid-key" style="">3</button>
<button class="grid-key" style="">4</button>
<button class="grid-key" style="">5</button>
<button class="grid-key" style="">6</button>
<button class="grid-key" style="">7</button>
<button class="grid-key" style="">8</button>
<button class="grid-key" style="">9</button>
<button class="grid-key" style="">0</button>
<button class="grid-key" style="">-</button>
<button class="grid-key" style="">=</button>
<button class="grid-key" style="grid-column-end: span 7">BACK</button>
<button class="grid-key" style="grid-column-end: span 7">TAB</button>
<button class="grid-key" style="">q</button>
<button class="grid-key" style="">w</button>
<button class="grid-key" style="">e</button>
<button class="grid-key" style="">r</button>
<button class="grid-key" style="">t</button>
<button class="grid-key" style="">y</button>
<button class="grid-key" style="">u</button>
<button class="grid-key" style="">i</button>
<button class="grid-key" style="">o</button>
<button class="grid-key" style="">p</button>
<button class="grid-key" style="">[</button>
<button class="grid-key" style="">]</button>
<button class="grid-key" style="">\</button>
<button class="grid-key" style="grid-column-end: span 8">CAPS</button>
<button class="grid-key" style="">a</button>
<button class="grid-key" style="">s</button>
<button class="grid-key" style="">d</button>
<button class="grid-key" style="">f</button>
<button class="grid-key" style="">g</button>
<button class="grid-key" style="">h</button>
<button class="grid-key" style="">j</button>
<button class="grid-key" style="">k</button>
<button class="grid-key" style="">l</button>
<button class="grid-key" style="">;</button>
<button class="grid-key" style="">'</button>
<button class="grid-key" style="grid-column-end: span 7">ENTER</button>
<!--<button class="grid-key" style="grid-column-end: span 10">SHIFT</button>-->
<button class="grid-key-empty" style="grid-column-end: span 2"></button>
<button class="grid-key" style="">_</button>
<button class="grid-key" style="">|</button>
<button class="grid-key" style="">z</button>
<button class="grid-key" style="">x</button>
<button class="grid-key" style="">c</button>
<button class="grid-key" style="">v</button>
<button class="grid-key" style="">b</button>
<button class="grid-key" style="">n</button>
<button class="grid-key" style="">m</button>
<button class="grid-key" style="">,</button>
<button class="grid-key" style="">.</button>
<button class="grid-key" style="">/</button>
<button class="grid-key" style="">:</button>
<button class="grid-key" style="">?</button>
<button class="grid-key-empty" style="grid-column-end: span 1"></button>
<!--<button class="grid-key" style="grid-column-end: span 9">SHIFT</button>-->
<button class="grid-key" style="grid-column-end: span 5">CTRL</button>
<button class="grid-key" style="">ALT</button>
<button class="grid-key" style="grid-column-end: span 25">SPACE</button>
<button class="grid-key" style="">ALT</button>
<button class="grid-key" style="grid-column-end: span 5">CTRL</button>
<button class="grid-key" style="">LT</button>
<button class="grid-key" style="">UP</button>
<button class="grid-key" style="">DN</button>
<button class="grid-key" style="">RT</button>
</div>
{% endblock %}

View File

@@ -0,0 +1,27 @@
{% extends 'base.html' %}
{% block title %}Mining{% endblock %}
{% block buttons %}
<div class="button-grid">
<button class="grid-button">Speed Boost</button>
<button class="grid-button">Hardpoints</button>
<button class="grid-button">Drop Chaff</button>
<button class="grid-button">Frameshift</button>
<button class="grid-button">75% Throttle</button>
<button class="grid-button">Cargo Bay</button>
<button class="grid-button">Shield Cell</button>
<button class="grid-button">Supercruise</button>
<button class="grid-button">Full Stop</button>
<button class="grid-button">Fuel Scoop</button>
<button class="grid-button">Heat Sink</button>
<button class="grid-button">Run Silent</button>
<button class="grid-button">Full Reverse</button>
<button class="grid-button">Landing Gear</button>
<button class="grid-button">ECM</button>
<button class="grid-button">Toggle Lights</button>
</container>
{% endblock %}

View File

@@ -0,0 +1,28 @@
{% extends 'base.html' %}
{% block title %}SRV{% endblock %}
{% block buttons %}
<div class="button-grid">
<button class="grid-button">Speed Boost</button>
<button class="grid-button">Hardpoints</button>
<button class="grid-button">Drop Chaff</button>
<button class="grid-button">Frameshift</button>
<button class="grid-button">75% Throttle</button>
<button class="grid-button">Cargo Bay</button>
<button class="grid-button">Shield Cell</button>
<button class="grid-button">Supercruise</button>
<button class="grid-button">Full Stop</button>
<button class="grid-button">Fuel Scoop</button>
<button class="grid-button">Heat Sink</button>
<button class="grid-button">Run Silent</button>
<button class="grid-button">Full Reverse</button>
<button class="grid-button">Landing Gear</button>
<button class="grid-button">ECM</button>
<button class="grid-button">Toggle Lights</button>
</container>
{% endblock %}