Skip to content

Commit

Permalink
added executing python and terminal commands from config.ini
Browse files Browse the repository at this point in the history
  • Loading branch information
janinainfa committed May 26, 2024
1 parent 5c822c4 commit 38e12f1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
7 changes: 7 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[otwórz terminal]
type = command_line
command = gnome-terminal

[zakończ]
type = python
command = window.close()
2 changes: 1 addition & 1 deletion main_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def setupUi(self, MainWindow):
self.stateLabel = QtWidgets.QLabel(self.centralwidget)
self.stateLabel.setLayoutDirection(QtCore.Qt.LeftToRight)
self.stateLabel.setAutoFillBackground(False)
self.stateLabel.setText("")
self.stateLabel.setAlignment(QtCore.Qt.AlignHCenter|QtCore.Qt.AlignTop)
self.stateLabel.setObjectName("stateLabel")
self.verticalLayout.addWidget(self.stateLabel)
Expand Down Expand Up @@ -54,7 +55,6 @@ def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Mex Assistant"))
self.speakButton.setText(_translate("MainWindow", "Mów"))
self.stateLabel.setText(_translate("MainWindow", "Ładowanie..."))
self.menu_Plik.setTitle(_translate("MainWindow", "&Plik"))
self.action_Ustawienia.setText(_translate("MainWindow", "&Ustawienia"))
self.action_Zakoncz.setText(_translate("MainWindow", "&Zakończ"))
19 changes: 19 additions & 0 deletions process_command.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
import configparser
import re
import subprocess

from voice_operations import *

class CommandProcessing():
def __init__(self):
pass

def loadConfig(self):
config = configparser.ConfigParser()
config.read("config.ini")
self.config = config

def processCommand(self, window):
command = takeVoice(3, window)
window.stateLabel.setText(command)
command = command.lower()
self.loadConfig()
for i in self.config:
if re.search(i, command):
if self.config[i]["type"] == "command_line":
subprocess.Popen(self.config[i]["command"])
if self.config[i]["type"] == "python":
exec(self.config[i]["command"])


6 changes: 6 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import configparser
#Read config.ini file
config_obj = configparser.ConfigParser()
config_obj.read("config.ini")
for i in config_obj:
print(i)
2 changes: 1 addition & 1 deletion ui/Main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<bool>false</bool>
</property>
<property name="text">
<string>Ładowanie...</string>
<string/>
</property>
<property name="alignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
Expand Down

0 comments on commit 38e12f1

Please sign in to comment.