Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

natlinkconfig programs now use logging #65

Merged
merged 18 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
a0ad16f
was lost in the flow, reentered from natlinkcore repository
quintijn Feb 2, 2024
cf994d4
entered getUnimacroGrammarsDirectory, and a lot of tidying up
quintijn Feb 2, 2024
eb6845c
multiple changes in natlinkstatus.py and natlinkconfigfunctions.py, l…
quintijn Feb 3, 2024
74f2554
add 2 tests execscriptest.py is ok, buttonclicktest.py fails. The cau…
quintijn Feb 3, 2024
3cfc5ce
the buttonclicktest.py shows the bug when natlink.playEvents is called.
quintijn Feb 4, 2024
2bf1f67
also enter dragonfly (dragonfly2) in the config procedure, including …
quintijn Feb 6, 2024
9b21667
add a few changes to nsformat.py (a\\determiner and I\\pronoun
quintijn Feb 8, 2024
10de328
small change in nsformat.py (formatPassword)
quintijn Feb 8, 2024
4cf7806
use pythong logging module to report output of pip etc.
dougransom Feb 17, 2024
15f8045
command line uses logging.
dougransom Feb 17, 2024
c53e016
logging to cli.
dougransom Feb 17, 2024
9932390
Merge branch 'dr16issues' of https://github.com/dougransom/natlinkcor…
dougransom Feb 17, 2024
761393e
tweak.
dougransom Feb 17, 2024
981733c
a few documentation details...
quintijn Feb 21, 2024
99b196a
try to catch an error when unloading a grammar, when it is not (corre…
quintijn Feb 21, 2024
c94dfe0
adapt load_or_reload_module function with force_load, so it works fro…
quintijn Feb 21, 2024
46d3213
Merge branch 'dr16issues' of github.com:dougransom/natlinkcore into d…
quintijn Feb 21, 2024
a82ff71
Merge branch 'main' into dr16issues
quintijn Feb 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies= [
"pysimplegui>=4.60.3",
"pydebugstring",
"dtactions>=1.5.7",
"platformdirs >= 4.2.0"
]
classifiers=[
"Development Status :: 4 - Beta",
Expand Down
5 changes: 5 additions & 0 deletions src/natlinkcore/configure/foo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ERROR: Could not find a version that satisfies the requirement foobar32 (from versions: none)
ERROR: No matching distribution found for foobar32

[notice] A new release of pip available: 22.3.1 -> 24.0
[notice] To update, run: python.exe -m pip install --upgrade pip
14 changes: 14 additions & 0 deletions src/natlinkcore/configure/loggert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import logging
import sys
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
#formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
#handler.setFormatter(formatter)

root = logging.getLogger()
root.addHandler(handler)
root.setLevel(logging.DEBUG)
logging.debug("A")
logging.info("B")
logging.log(logging.DEBUG,"C")
print("\nD E")
21 changes: 20 additions & 1 deletion src/natlinkcore/configure/natlinkconfig_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,25 @@
import os
import os.path
from natlinkcore.configure import extensions_and_folders

from platformdirs import user_log_dir
from pathlib import Path
from natlinkcore.configure import natlinkconfigfunctions
import logging
appname="natlink"
logdir = Path(user_log_dir(appname=appname,ensure_exists=True))
logfilename=logdir/f"cli_log.txt"
file_handler = logging.FileHandler(logfilename)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_handler.setFormatter(formatter)
logfile_logger = logging.getLogger()

handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
logfile_logger.addHandler(handler)

file_handler.setLevel(logging.DEBUG)
logfile_logger.addHandler(file_handler)
logfile_logger.setLevel(logging.DEBUG)

def _main(Options=None):
"""Catch the options and perform the resulting command line functions
Expand All @@ -17,6 +34,8 @@ def _main(Options=None):
etc., usage above...

"""


cli = CLI()
cli.Config = natlinkconfigfunctions.NatlinkConfig()
shortOptions = "DVNOHKaAiIxXbBuqe"
Expand Down
65 changes: 62 additions & 3 deletions src/natlinkcore/configure/natlinkconfig_gui.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
#pylint:disable=W0621, W0703
#pylint:disable=W0621, W0703, W0603
import sys
import platform

import PySimpleGUI as sg
import logging
from platformdirs import user_log_dir
from pathlib import Path
appname="natlink"
logdir = Path(user_log_dir(appname=appname,ensure_exists=True))
logfilename=logdir/"config_gui_log.txt"
file_handler = logging.FileHandler(logfilename)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_handler.setFormatter(formatter)
logfile_logger = logging.getLogger()

#always leave at debug. So we have this if there is ever a problem.
file_handler.setLevel(logging.DEBUG)
logfile_logger.addHandler(file_handler)
logfile_logger.setLevel(logging.DEBUG)



# https://www.pysimplegui.org/en/latest/
from natlinkcore.configure.natlinkconfigfunctions import NatlinkConfig
from natlinkcore import natlinkstatus
Expand All @@ -14,6 +32,8 @@
Config = NatlinkConfig()
Status = natlinkstatus.NatlinkStatus()



SYMBOL_UP = '▲'
SYMBOL_DOWN = '▼'

Expand Down Expand Up @@ -47,6 +67,8 @@ def collapse(layout, key, visible):
[sg.T('Natlink GUI Output')],
[sg.Output(size=(40,10), echo_stdout_stderr=True, expand_x=True, key='-OUTPUT-')]]



#### Main UI Layout ####
layout = [[sg.T('Environment:', font='bold'), sg.T(f'Windows OS: {osVersion.major}, Build: {osVersion.build}'), sg.T(f'Python: {pyVersion}'), sg.T(f'Dragon Version: {Status.getDNSVersion()}')],
#### Projects Checkbox ####
Expand All @@ -61,6 +83,23 @@ def collapse(layout, key, visible):

window = sg.Window('Natlink configuration GUI', layout, enable_close_attempted_event=True)

#this is for the GUI logging.
#set the level on this corresponding to the natlink levels later.
#This must be created after the window is created, or nothing gets logged.

#and we don't add the handler until just before the window is read the first time
#because a write during this period will cause a problem.

handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
try:
ll=Config.config_get("settings","log_level")
if ll != "Debug":
handler.setLevel(logging.INFO)
except Exception as ee:
logging.debug(f"{__file__} failed to get log_level {ee} ")


def ThreadIsRunning():
global Thread_Running
Thread_Running = not Thread_Running
Expand All @@ -69,6 +108,13 @@ def ThreadIsRunning():
# Natlink
def SetNatlinkLoggingOutput(values, event):
Config.setLogging(values['Set_Logging_Natlink'])
#also if natlink is not debug level, use info for logging in this application also.
try:
ll=Config.config_get("settings","log_level")
if ll != "Debug":
handler.setLevel(logging.INFO)
except Exception as ee:
logging.debug(f"{__file__} failed to get log_level {ee} ")

# Dragonfly2
def Dragonfly2UserDir(values, event):
Expand Down Expand Up @@ -112,11 +158,24 @@ def OpenNatlinkConfig(values, event):
unimacro_dispatch = {'Set_UserDir_Unimacro': UnimacroUserDir, 'Clear_UserDir_Unimacro': UnimacroUserDir}
autohotkey_dispatch = {'Set_Exe_Ahk': AhkExeDir, 'Clear_Exe_Ahk': AhkExeDir, 'Set_ScriptsDir_Ahk': AhkUserDir,'Clear_ScriptsDir_Ahk': AhkUserDir}


#### Event Loop ####
try:
#we want to set the logger up just before we call window.read()
#because if something is logged before the first window.read() there will be a failure.



#this would be a good spot to change the logging level, based on the natlink logging level
#note the natlink logging level doesn't correspond one to one with the logging module levels.
logfile_logger.addHandler(handler)

handler.setLevel(logging.DEBUG)
#do not change the logger level from debug
#change it in the handler. Because a file handler logs everything.
while True:
event, values = window.read()
if (event == '-WINDOW CLOSE ATTEMPTED-' or event == 'Exit') and not Thread_Running:
if (event in ['-WINDOW CLOSE ATTEMPTED-', 'Exit']) and not Thread_Running:
break
# Hidden Columns logic
# TODO: if project is enabled, update the project state to enabled.
Expand All @@ -140,7 +199,7 @@ def OpenNatlinkConfig(values, event):
Thread_Running = not Thread_Running

elif Thread_Running:
choice = sg.popup(f'Please Wait: Pip install is in progress', keep_on_top=True, custom_text=('Wait','Force Close'))
choice = sg.popup('Please Wait: Pip install is in progress', keep_on_top=True, custom_text=('Wait','Force Close'))
if choice == 'Force Close':
break

Expand Down
Loading
Loading