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

Use profile folder for settings #2

Merged
merged 4 commits into from Jun 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion commandeditwnd.py
Expand Up @@ -6,7 +6,6 @@
from mouseactioneditwnd import MouseActionEditWnd
from pauseactioneditwnd import PauseActionEditWnd
import json
import keyboard

class CommandEditWnd(QDialog):
def __init__(self, p_command, p_parent = None):
Expand Down
2 changes: 0 additions & 2 deletions keyactioneditwnd.py
Expand Up @@ -2,9 +2,7 @@
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from ui_keyactioneditwnd import Ui_KeyActionEditDialog
import json
import keyboard
import time
import threading

class KeyActionEditWnd(QDialog):
Expand Down
18 changes: 13 additions & 5 deletions main.py
Expand Up @@ -8,10 +8,9 @@
from profileexecutor import ProfileExecutor
import sys
import pickle
import time
import keyboard
import threading
import signal
import os
import shutil

class MainWnd(QWidget):
def __init__(self, p_parent = None):
Expand Down Expand Up @@ -48,12 +47,12 @@ def saveToDatabase(self):
w_profile = json.loads(w_jsonProfile)
w_profiles.append(w_profile)

with open("profiles.dat", "wb") as f:
with open(self.getSettingsPath("profiles.dat"), "wb") as f:
pickle.dump(w_profiles, f, pickle.HIGHEST_PROTOCOL)

def loadFromDatabase(self):
w_profiles = []
with open("profiles.dat", "rb") as f:
with open(self.getSettingsPath("profiles.dat"), "rb") as f:
w_profiles = pickle.load(f)

for w_profile in w_profiles:
Expand All @@ -63,6 +62,15 @@ def loadFromDatabase(self):

return len(w_profiles)

def getSettingsPath(self, setting):
home = os.path.expanduser("~") + '/.linvam/'
if not os.path.exists(home):
os.mkdir(home)
if not os.path.exists(home + setting):
shutil.copyfile(setting, home + setting)

return home + setting

def loadTestProfiles(self):

w_carProfileDict = {
Expand Down
1 change: 0 additions & 1 deletion mouseactioneditwnd.py
Expand Up @@ -2,7 +2,6 @@
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from ui_mouseactioneditwnd import Ui_MouseActionEditDialog
import json


class MouseActionEditWnd(QDialog):
Expand Down
1 change: 0 additions & 1 deletion pauseactioneditwnd.py
Expand Up @@ -2,7 +2,6 @@
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from ui_pauseactioneditwnd import Ui_PauseActionEditDialog
import json

class PauseActionEditWnd(QDialog):
def __init__(self, p_pauseAction, p_parent = None):
Expand Down
1 change: 0 additions & 1 deletion profileeditwnd.py
Expand Up @@ -5,7 +5,6 @@
from commandeditwnd import CommandEditWnd
import json
from profileexecutor import *
import sys

class ProfileEditWnd(QDialog):
def __init__(self, p_profile, p_parent = None):
Expand Down
18 changes: 13 additions & 5 deletions profileexecutor.py
Expand Up @@ -2,9 +2,8 @@
from pynput.mouse import Button, Controller
import time
import threading
import copy
import json
import sys, os, pyaudio
import os, pyaudio
import shutil
from pocketsphinx.pocketsphinx import *
from sphinxbase.sphinxbase import *

Expand All @@ -30,12 +29,21 @@ def __init__(self, p_profile = None):
# Process audio chunk by chunk. On keyword detected perform action and restart search
self.m_decoder = Decoder(self.m_config)

def getSettingsPath(self, setting):
home = os.path.expanduser("~") + '/.linvam/'
if not os.path.exists(home):
os.mkdir(home)
if not os.path.exists(home + setting):
shutil.copyfile(setting, home + setting)

return home + setting

def setProfile(self, p_profile):
self.m_profile = p_profile
if self.m_profile == None:
return

w_commandWordFile = open('command.list', 'w')
w_commandWordFile = open(self.getSettingsPath('command.list'), 'w')
w_commands = self.m_profile['commands']
i = 0
for w_command in w_commands:
Expand All @@ -44,7 +52,7 @@ def setProfile(self, p_profile):
w_commandWordFile.write(w_command['name'] + ' /1e-%d/' % w_command['threshold'])
i = i + 1
w_commandWordFile.close()
self.m_config.set_string('-kws', 'command.list')
self.m_config.set_string('-kws', self.getSettingsPath('command.list'))

def setEnableListening(self, p_enable):
self.m_listening = p_enable
Expand Down