OSDN Git Service

File system path for statndalone version master
authorMahmoud Saghaei <mahmood.saghaei@gmail.com>
Mon, 21 Feb 2022 14:15:24 +0000 (17:45 +0330)
committerMahmoud Saghaei <mahmood.saghaei@gmail.com>
Mon, 21 Feb 2022 14:15:24 +0000 (17:45 +0330)
15 files changed:
MinimPy2.spec
about_minimisation.py
config.py
db.py
db/database.sql [changed mode: 0755->0644]
db/db.sql [changed mode: 0755->0644]
db/minimizer.db [changed mode: 0755->0644]
fa_IR.ts
freq_table.py
locales/fa_IR.qm
main_window.py
run_test.py
todos.txt [new file with mode: 0644]
ui_main_window.ui
utils.py [new file with mode: 0644]

index b7cde84..c961b07 100644 (file)
@@ -7,7 +7,8 @@ block_cipher = None
 a = Analysis(['main_window.py'],
              pathex=['/home/msaghaei/PycharmProjects/minimpy2'],
              binaries=[],
-             datas=[],
+             datas=[('db/database.sql', 'db'), ('images/*', 'images'), ('locales/*', 'locales'), ('fa_IR.ts', '.'),
+             ('minimisation_*.txt', '.'), ('start_*.html', '.'), ('locale_sources.ts', '.')],
              hiddenimports=[],
              hookspath=[],
              runtime_hooks=[],
index adb2cba..11f67ae 100755 (executable)
@@ -2,6 +2,7 @@ from PySide2 import QtWidgets as qtw
 from os import path
 
 from ui_about_minimisation import Ui_AboutMinimisationDialog
+from utils import resource_path
 
 
 class AboutMinimisationDialog(qtw.QDialog):
@@ -10,9 +11,9 @@ class AboutMinimisationDialog(qtw.QDialog):
         self.ui = Ui_AboutMinimisationDialog()
         self.ui.setupUi(self)
         lang = parent.settings.value('language', 'en_US', type=str)
-        filename = 'minimisation_{}.txt'.format(lang)
+        filename = resource_path('minimisation_{}.txt'.format(lang))
         if not path.exists(filename):
-            filename = 'minimisation_en_US.txt'
+            filename = resource_path('minimisation_en_US.txt')
             if not path.exists(filename):
                 return
         text = open(filename, encoding='utf8').read()
index a727794..e13bfc5 100755 (executable)
--- a/config.py
+++ b/config.py
@@ -3,6 +3,7 @@ import sys
 from PySide2 import QtWidgets as qtw
 
 from config_dialog import Ui_ConfigDialog
+from utils import resource_path
 
 
 class Config(qtw.QDialog):
@@ -11,7 +12,7 @@ class Config(qtw.QDialog):
         self.parent = parent
         self.ui = Ui_ConfigDialog()
         self.ui.setupUi(self)
-        lines = open('locales/languages.lst', encoding='utf8').readlines()
+        lines = open(resource_path('locales/languages.lst'), encoding='utf8').readlines()
         self.lang_codes = []
         cur_lang = self.parent.settings.value('language', 'en_US', type=str)
         cur_index = 0
diff --git a/db.py b/db.py
index ed42102..3b797c7 100755 (executable)
--- a/db.py
+++ b/db.py
@@ -1,12 +1,16 @@
-from PySide2 import QtSql as qts
+from PySide2 import QtSql as qts, QtWidgets
 from PySide2 import QtWidgets as qtw
 from PySide2 import QtCore as qtc
 
 import sys
 import os
+from os import path
 
 
 # noinspection PyTypeChecker
+from utils import resource_path
+
+
 class Database(qtc.QObject):
     __instance = None
 
@@ -26,7 +30,7 @@ class Database(qtc.QObject):
                 'open db: ' + self.db.lastError().text()
             )
             sys.exit(1)
-        all_sqls = open('db/database.sql', encoding='utf8').read().split(';')
+        all_sqls = open(resource_path('db/database.sql'), encoding='utf8').read().split(';')
         for sql in all_sqls:
             query = qts.QSqlQuery(self.db)
             query.prepare(sql)
@@ -43,8 +47,16 @@ class Database(qtc.QObject):
             raise Exception("This class is a singleton!")
         self.mainWindow = mainWindow
         self.db = qts.QSqlDatabase.addDatabase('QSQLITE')
-        self.db.setDatabaseName('db/minimizer.db')
-        if not os.path.exists('db/minimizer.db'):
+        db_path = mainWindow.settings.value('db_path', None, type=str)
+        if db_path is None or not path.exists(db_path):
+            db_path = QtWidgets.QFileDialog.getExistingDirectory(mainWindow, 'Select a folder to store your data', '.', QtWidgets.QFileDialog.ShowDirsOnly)
+            if db_path is None or len(db_path.strip()) == 0:
+                exit(1)
+            mainWindow.settings.setValue('db_path', db_path)
+        if not path.exists(db_path):
+            os.mkdir(db_path)
+        self.db.setDatabaseName('{}/minimizer.db'.format(db_path))
+        if not os.path.exists('{}/minimizer.db'.format(db_path)):
             self.create_db()
         else:
             if not self.db.open():
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
index 6035d77..6f340a6
Binary files a/db/minimizer.db and b/db/minimizer.db differ
index d5ba4c0..abb69bf 100755 (executable)
--- a/fa_IR.ts
+++ b/fa_IR.ts
@@ -954,6 +954,7 @@ Click and then type over the trial title or code to edit it</source>
     <message>
         <location filename="main_window.py" line="37"/>
         <source>Type of subject identifier. It can be Numeric, Alpha or Alphanumeric.
+Once a subject is enrolled, you can not change identifier type
 </source>
         <translation>نوع شناسه نمایش داده شده برای سوژه ها. گزینه های موجود عددی، حرفی و یا حرفی عددی می باشند.\nهنگامی که اولین سوژه وارده مطالعه شد، دیگر نمی توان نوع شناسه را تغییر دارد
 </translation>
index ebd20c9..673c7ed 100755 (executable)
@@ -3,6 +3,8 @@ from PySide2 import QtWidgets as qtw
 from PySide2 import QtCore as qtc
 from PySide2 import QtGui as qtg
 
+from utils import resource_path
+
 
 class FreqTable:
     def __init__(self, parent, ui, trial_id):
@@ -30,11 +32,11 @@ class FreqTable:
             return
         preload = self.extract_counts()
         if self.valid_counts(preload):
-            pixmap = qtg.QPixmap("images/tick_mark.png")
+            pixmap = qtg.QPixmap(resource_path("images/tick_mark.png"))
             self.database.clear_preload(self.trial_id)
             self.database.save_preload(self.trial_id, preload)
         else:
-            pixmap = qtg.QPixmap("images/error.png")
+            pixmap = qtg.QPixmap(resource_path("images/error.png"))
         self.valid_preload_image.setPixmap(pixmap)
 
     def add_to_preload(self):
index 692ca8c..e7f58fa 100644 (file)
Binary files a/locales/fa_IR.qm and b/locales/fa_IR.qm differ
index d663814..8e2cf60 100644 (file)
@@ -18,6 +18,8 @@ from run_test import RunTest
 from trial import *
 import sys
 from tendo import singleton
+from utils import resource_path
+
 
 # noinspection PyTypeChecker
 class MainWindow(qtw.QMainWindow):
@@ -57,17 +59,19 @@ class MainWindow(qtw.QMainWindow):
         self.ui = Ui_MainWindow()
         self.ui.setupUi(self)
         lang = settings.value('language', 'en_US', type=str)
-        filename = 'start_{}.html'.format(lang)
+        if lang != 'en_US':
+            self.setLayoutDirection(qtc.Qt.RightToLeft)
+        filename = resource_path('start_{}.html'.format(lang))
         start_str = open(filename, encoding='utf8').read()
         self.ui.textEdit.setHtml(start_str)
-        self.ui.actionNew.setIcon(qtg.QIcon('images/add.png'))
-        self.ui.actionDelete.setIcon(qtg.QIcon('images/delete.png'))
-        self.ui.actionLevels.setIcon(qtg.QIcon('images/levels.png'))
-        self.ui.actionSave.setIcon(qtg.QIcon('images/save.png'))
-        self.ui.actionHelp.setIcon(qtg.QIcon('images/help.png'))
-        self.ui.actionQuit.setIcon(qtg.QIcon('images/exit.png'))
-        self.ui.actionConfig.setIcon(qtg.QIcon('images/config.png'))
-        self.ui.actionAbout_MinimPy2.setIcon(qtg.QIcon('images/about.png'))
+        self.ui.actionNew.setIcon(qtg.QIcon(resource_path('images/add.png')))
+        self.ui.actionDelete.setIcon(qtg.QIcon(resource_path('images/delete.png')))
+        self.ui.actionLevels.setIcon(qtg.QIcon(resource_path('images/levels.png')))
+        self.ui.actionSave.setIcon(qtg.QIcon(resource_path('images/save.png')))
+        self.ui.actionHelp.setIcon(qtg.QIcon(resource_path('images/help.png')))
+        self.ui.actionQuit.setIcon(qtg.QIcon(resource_path('images/exit.png')))
+        self.ui.actionConfig.setIcon(qtg.QIcon(resource_path('images/config.png')))
+        self.ui.actionAbout_MinimPy2.setIcon(qtg.QIcon(resource_path('images/about.png')))
         self.database = Database.get_instance(self)
         self.trial = None
 
@@ -117,8 +121,8 @@ class MainWindow(qtw.QMainWindow):
 
         self.ui.editPreloadCheckBox.toggled.connect(self.on_edit_preload)
         self.ui.convertPreloadButton.clicked.connect(self.on_convert_preload)
-        self.ui.factorTableWidget.cellDoubleClicked.connect(self.factor_coloumn_dblclicked)
-        self.ui.subjectTableWidget.cellDoubleClicked.connect(self.subject_coloumn_dblclicked)
+        self.ui.factorTableWidget.cellDoubleClicked.connect(self.factor_column_dblclicked)
+        self.ui.subjectTableWidget.cellDoubleClicked.connect(self.subject_column_dblclicked)
 
         self.ui.trialIdentifierLengthSpinBox.valueChanged.connect(self.on_identifier_length)
         self.ui.trialBaseProbabilitySlider.valueChanged.connect(self.on_base_prob_change)
@@ -174,6 +178,10 @@ class MainWindow(qtw.QMainWindow):
             self.ui.showAtStartCheckBox.setChecked(True)
         self.ui.showAtStartCheckBox.toggled.connect(self.toggle_show_at_start)
 
+    def on_identifier_length(self, value):
+        self.trial.identifier_length = value
+        self.update_sample_size_label()
+
     def toggle_show_at_start(self, check):
         self.settings.setValue('show_tutorial_at_start', not check)
 
@@ -241,7 +249,7 @@ class MainWindow(qtw.QMainWindow):
     def on_base_prob_change(self, value):
         self.ui.baseProbLabel.setText('{:4.2f}'.format(value / 100.0))
 
-    def on_identifier_length(self, value):
+    def on_idenqdialogbuttonboxtifier_length(self, value):
         self.trial.identifier_length = value
         self.update_sample_size_label()
 
@@ -367,7 +375,7 @@ class MainWindow(qtw.QMainWindow):
             return
         self.update_subjects_progress()
 
-    def subject_coloumn_dblclicked(self, row, col):
+    def subject_column_dblclicked(self, row, col):
         button = qtw.QMessageBox.question(self, self.tr("Warning"),
                                           self.tr('''Are you sure you want to edit subject at row "{}" ?\n
 Editing subject may invalidate your research and the result of minimisation''').format(row),
@@ -1014,7 +1022,7 @@ ALL subjects will be deleted'''),
             self.add_factor_row(factor)
         self.ui.factorTableWidget.blockSignals(False)
 
-    def factor_coloumn_dblclicked(self, row, col):
+    def factor_column_dblclicked(self, row, col):
         if col != 2:
             return
         self.factor_levels()
@@ -1264,12 +1272,12 @@ def start_app():
         app = qtw.QApplication(sys.argv)
     except RuntimeError:
         app = qtc.QCoreApplication.instance()
-    app.setWindowIcon(qtg.QIcon('images/logo.png'))
+    app.setWindowIcon(qtg.QIcon(resource_path('images/logo.png')))
     settings = qtc.QSettings('net.saghaei', 'minimpy2')
     lang = settings.value('language', 'en_US', type=str)
     if lang != 'en_US':
         translator = qtc.QTranslator()
-        translator.load('locales/{}'.format(lang))
+        translator.load(resource_path('locales/{}'.format(lang)))
         app.installTranslator(translator)
     mw = MainWindow(settings)
     app.mainWindow = mw
index 0487797..85c59e8 100755 (executable)
@@ -4,6 +4,7 @@ import sys
 
 class RunTest:
     def __init__(self, sequence, v1, v2):
+        #sequence = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1]
         self.sequence = sequence
         self.v1, self.v2 = v1, v2
 
diff --git a/todos.txt b/todos.txt
new file mode 100644 (file)
index 0000000..65c6615
--- /dev/null
+++ b/todos.txt
@@ -0,0 +1,9 @@
+ایرادات 
+MinimPy2
+تغییر عنوان بلافاصله نشان داده نمی شود
+
+تعداد سوژه های وارد شده در Progressbar بروزرسانی نمیشود
+
+فیلترها در صفحه سوژه ها بصورت منو باشد
+
+تولید لیست رندومیزه
index 0b2a2f1..1d5b5d1 100755 (executable)
@@ -18,7 +18,7 @@
     <item>
      <widget class="QTabWidget" name="tabWidget">
       <property name="currentIndex">
-       <number>7</number>
+       <number>1</number>
       </property>
       <widget class="QWidget" name="tab">
        <attribute name="title">
             <rect>
              <x>0</x>
              <y>0</y>
-             <width>760</width>
-             <height>422</height>
+             <width>98</width>
+             <height>28</height>
             </rect>
            </property>
            <layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0">
diff --git a/utils.py b/utils.py
new file mode 100644 (file)
index 0000000..b921573
--- /dev/null
+++ b/utils.py
@@ -0,0 +1,12 @@
+import sys
+import os
+
+
+def resource_path(relative_path):
+    """ Get absolute path to resource, works for dev and for PyInstaller """
+    try:
+        # PyInstaller creates a temp folder and stores path in _MEIPASS
+        base_path = sys._MEIPASS
+    except Exception:
+        base_path = os.path.abspath(".")
+    return os.path.join(base_path, relative_path)