Skip to content

Commit ea10828

Browse files
author
2Cas
committed
Windows Bugfix Update
Caught compiler related exceptions. Fixed bugs on Windows GUI Cosmetic changes to Windows GUI New Windows Binary Updated to version 1.1.0a1 Tidied up backend + documentation Fixed bug related to opening program on windows with no console (and thus removed console)
1 parent 1713d94 commit ea10828

File tree

5 files changed

+154
-83
lines changed

5 files changed

+154
-83
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,5 @@ avr-gcc/
117117
*.tar.gz
118118
*.zip
119119
q2k/BUILD EXEC.lnk
120+
bin/*/q2k_out
121+
*.7z

bin/Win/q2k_util.exe

2.4 KB
Binary file not shown.

q2k/core.py

+64-37
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import argparse
2+
import copy
3+
import errno
24
import glob
5+
import os
36
import pathlib
47
import platform
5-
import errno
6-
import os
7-
import yaml
8-
import sys
98
import re
10-
import copy
119
import subprocess
10+
import sys
11+
import traceback
12+
import yaml
13+
import tempfile
1214
import pyparsing as pp
1315
import termcolor as tc
1416
import enum as en
@@ -22,19 +24,31 @@
2224
class defaults:
2325

2426
if getattr(sys, 'frozen', False):
25-
src = os.getcwd() # If Frozen - $Q2K = [cwd]
27+
frozen = True
28+
src = '' #os.getcwd() # If Frozen - $Q2K = [cwd]
2629
else: # If Live, use bundle_dir
2730
frozen = False
2831
src = os.path.dirname(os.path.abspath(__file__)) # else $Q2K is its own install dir, seperate from working directory
2932

3033
version = q2kversion
31-
# Directories
34+
# Directories
35+
libs = os.path.join(src, 'lib') # Local Libs Default is $Q2K/libs/
36+
cache = os.path.join(src, '.cache','cache_kb.yaml') # Cache Default is $Q2K/.cache/cache_kb.yaml
37+
38+
if frozen:
39+
qmk = os.path.join(src, 'qmk_firmware') # QMK Directory - To be provided by user Default is $Q2K/qmk_firmware/
40+
keyp = os.path.join(src, 'q2k_out','keyplus') # Output. This is a relative directory (default) Default is $Q2K/q2k_out/keyplus/ (Frozen)
41+
kbf = os.path.join(src, 'q2k_out','kbfirmware')
42+
else:
43+
qmk = os.path.join(os.getcwd(), 'qmk_firmware') # QMK Directory - To be provided by user Default is $Q2K/qmk_firmware/
44+
keyp = os.path.join(os.getcwd(),'q2k_out','keyplus') # Output. This is a relative directory. Default is [cwd]/q2k_out/keyplus/ (Live)
45+
kbf = os.path.join(os.getcwd(),'q2k_out','kbfirmware')
46+
47+
if platform.system() == 'Linux': # AVR-GCC Compiler.
48+
avr_gcc = 'avr-gcc' # avr-gcc for linux Default is avr-gcc (Linux)
49+
elif platform.system() == 'Windows':
50+
avr_gcc = os.path.join(src, 'avr-gcc', 'bin', 'avr-gcc.exe') # avr-gcc.exe for Windows Default is $Q2K/avr-gcc/bin/avr-gcc.exe (Windows)
3251

33-
libs = os.path.join(src, 'lib') # Local Libs - We want these to be in a single, FIXED directory. [Avoid using relative directories] Default is $Q2K/libs
34-
cache = os.path.join(src, '.cache','cache_kb.yaml') # Cache - We want this to be in a single, FIXED directory. [Avoid using relative directories] Default is $Q2K/.cache/cache_kb.yaml
35-
qmk = os.path.join(src, 'qmk') # QMK Directory - To be provided by user Default is [cwd]/qmk
36-
keyp = os.path.join(os.getcwd(),'q2k_out','keyplus') # Output. This can either be fixed in one location (defined by user) or be a relative directory (default) Default is [cwd]/q2k_out/keyplus
37-
kbf = os.path.join(os.getcwd(),'q2k_out','kbfirmware')
3852
# Lists
3953
qmk_nonstd_dir = ['handwired', 'converter',
4054
'clueboard', 'lfkeyboards'] # Currently only lfkeyboards causes any issues, however it is good to be verbose here
@@ -44,6 +58,11 @@ class defaults:
4458
# Misc
4559
invalid_kc = 'trns' # What to set invalid KC codes to
4660

61+
if platform.system() == 'Linux':
62+
print_lines = '─────────────────────────────────────────────────────────────────'
63+
elif platform.system() == 'Windows':
64+
print_lines = '──────────────────────────────────────────────────────────────'
65+
4766
# ===========================================================================================
4867
# Console Output
4968
# ===========================================================================================
@@ -279,12 +298,7 @@ def __preproc(self, kblibs, arg_list, DEBUG=False):
279298
# Setting up -I and custom define options
280299
qdir = os.path.join(self.__dirs['QMK dir'], 'keyboards')
281300
kb = self.__kb.name
282-
if platform.system() == 'Linux':
283-
cc = ['avr-gcc', '-E']
284-
elif platform.system() == 'Windows':
285-
avr_gcc = os.path.join(defaults.src, 'avr-gcc', 'bin', 'avr-gcc.exe')
286-
cc = [avr_gcc, '-E']
287-
301+
cc = [defaults.avr_gcc, '-E']
288302
kbdefine = 'KEYBOARD_'+'_'.join(kblibs)
289303
QMK_KEYBOARD_H = 'QMK_KEYBOARD_H=\"'+kb+'.h\"'
290304
libs = ['-D', kbdefine, '-D', QMK_KEYBOARD_H, '-I'+self.__dirs['Local libs']]
@@ -297,17 +311,34 @@ def __preproc(self, kblibs, arg_list, DEBUG=False):
297311
if DEBUG: print(' '.join(argv))
298312

299313
try:
300-
output = subprocess.check_output(argv)
314+
#app_stdout = sys.stdout
315+
#app_stderr = sys.stderr
316+
#sys.stdout = sys.__stdout__
317+
#sys.stderr = sys.__stderr__
318+
319+
#sys.stdout = app_stdout
320+
#sys.stderr = app_stderr
321+
322+
si = subprocess.STARTUPINFO()
323+
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
324+
325+
output = subprocess.check_output(argv, stdin=subprocess.PIPE, stderr=subprocess.PIPE, startupinfo=si)
326+
301327
return output
302328
except subprocess.CalledProcessError as e:
303329
err_num = e.returncode
304-
if err_num == 1:
305-
print(err_num)
330+
if err_num == errno.EPERM:
331+
self.__console.warning(['Compiler failed to read '+argv[-1]])
306332
output = e.output
307333
return output
308334
else:
309-
self.console.warning(['Potentially catastrophic segfault related compilation error'])
335+
print(traceback.format_exc(), file=sys.stderr)
310336
return
337+
except OSError as e:
338+
if e.errno == errno.ENOEXEC:
339+
self.__console.error(['Could not find avr-gcc compiler', 'Check if avr-gcc is installed in',defaults.avr_gcc])
340+
else:
341+
print(traceback.format_exc(), file=sys.stderr)
311342

312343
def preproc_header(self, path):
313344

@@ -375,7 +406,7 @@ def get_rev_info(self, rev):
375406
return r
376407
if r.name == 'n/a':
377408
return r
378-
#───────────────────────────────────────────────────────────────────────────────────────────
409+
# ===========================================================================================
379410
# KB and revision Information
380411
# ===========================================================================================
381412
class rev_info:
@@ -668,7 +699,7 @@ def __find(self):
668699
try:
669700
with open(self.__loc, 'r') as f:
670701
self.kbo_list = yaml.load(f)
671-
self.__console.note(['Using cached list from '+self.__loc, '--cache to reset'])
702+
self.__console.note(['Using cached list from '+self.__loc, '--cache to reset', defaults.print_lines])
672703
except:
673704
self.__console.warning(['Failed to load from '+self.__loc, 'Generating new cache_kb.yaml...'])
674705
self.__write()
@@ -753,9 +784,9 @@ def __write(self):
753784
if self.kbo_list:
754785
# Dump cache info to text file for faster processing in future
755786
self.__save_cache()
756-
self.__console.note(['New cache_kb.yaml successfully generated', 'Location: '+self.__loc])
787+
self.__console.note(['New cache_kb.yaml successfully generated', 'Location: '+self.__loc, defaults.print_lines])
757788
else:
758-
self.__console.warning(['No keyboard information found', 'Check QMK directory location in pref.yaml : '+self.__qmk])
789+
self.__console.warning(['No keyboard information found', 'Check QMK directory location in pref.yaml : '+self.__qmk, defaults.print_lines])
759790

760791

761792
def __find_layout_names(self, kbo):
@@ -806,15 +837,12 @@ def __find_layout_names(self, kbo):
806837

807838
def __save_cache(self):
808839
path = os.path.split(self.__loc)[0]
809-
print(self.__loc)
810-
print(path)
811-
#======================================================================================================================
812840
if not os.path.exists(path):
813841
try:
814842
os.makedirs(path)
815843
except OSError as e:
816844
if e.errno != errno.EEXIST and os.path.isdir(path):
817-
raise
845+
raise
818846
try:
819847
with open(self.__loc, 'w') as f:
820848
yaml.dump(self.kbo_list, f)
@@ -824,6 +852,7 @@ def __save_cache(self):
824852
def _clear_cache(self):
825853
if os.path.isfile(self.__loc):
826854
os.remove(self.__loc)
855+
self.kbo_list = []
827856

828857
def _keyboard_list(self,):
829858
kb_names = []
@@ -913,8 +942,7 @@ def __set_dirs(self):
913942
pref_yaml = os.path.join(defaults.src, 'pref.yaml')
914943
with open(pref_yaml, 'r') as f:
915944
self.dirs = yaml.load(f)
916-
917-
self.console.note(['─────────────────────────────────────────────────────────────────', 'Using preferences from '+pref_yaml, '--reset to reset to defaults'])
945+
self.console.note([defaults.print_lines, 'Using preferences from '+pref_yaml, '--reset to reset to defaults'])
918946

919947
except FileNotFoundError:
920948
self.__generate_dirs()
@@ -937,7 +965,7 @@ def __generate_dirs(self):
937965
with open(pref_yaml, 'w') as f:
938966
f.write('# Q2K Folder Locations\n')
939967
yaml.dump(dirs, f, default_flow_style = False)
940-
self.console.note(['─────────────────────────────────────────────────────────────────', 'New pref.yaml generated @ '+pref_yaml])
968+
self.console.note([defaults.print_lines, 'New pref.yaml generated @ '+pref_yaml])
941969

942970
except FileNotFoundError:
943971
self.console.error(['Failed to generate '+pref_yaml])
@@ -1025,9 +1053,9 @@ def set_kb(self, keyboard='', rev='', keymap='', template=''):
10251053
self.build_kb = build_kbo
10261054
self.build_rev = build_revo
10271055
if rev:
1028-
self.console.note(['─────────────────────────────────────────────────────────────────','Building '+keyboard+ os.sep +rev+':'+keymap+':'+template, '─────────────────────────────────────────────────────────────────'])
1056+
self.console.note([defaults.print_lines, 'Building '+keyboard+os.sep+rev+':'+keymap+':'+template, defaults.print_lines])
10291057
else:
1030-
self.console.note(['─────────────────────────────────────────────────────────────────','Building '+keyboard+':'+keymap+':'+template, '─────────────────────────────────────────────────────────────────'])
1058+
self.console.note([defaults.print_lines, 'Building '+keyboard+':'+keymap+':'+template, defaults.print_lines])
10311059
else:
10321060
print_kb_list = ', '.join(self.keyboard_list())
10331061
self.console.error(['Invalid Keyboard Name - '+keyboard, 'Valid Names: '+print_kb_list])
@@ -1510,7 +1538,7 @@ def __create_keyplus_yaml(self, DEBUG=False):
15101538
else:
15111539
path_list = kblibs + [keymap]
15121540
output_path = '_'.join(path_list)
1513-
output_yaml = out_dir+output_path+'.yaml'
1541+
output_yaml = os.path.join(out_dir, output_path+'.yaml')
15141542
if not os.path.exists(out_dir):
15151543
try:
15161544
os.makedirs(out_dir)
@@ -1548,4 +1576,3 @@ def q2keyplus_gui(keyboard, rev, keymap, template):
15481576
# Uncomment this to run as a traditional python script (Commnand Line Interface)
15491577
#if __name__ == '__main__':
15501578
#q2keyplus()
1551-

0 commit comments

Comments
 (0)