프로젝트

일반

사용자정보

개정판 4af2f2de

ID4af2f2deb09b004d7a1aee3e0f3c979139c64382
상위 b41d1fca
하위 878530ba, be3e0c2d

humkyung 이(가) 약 6년 전에 추가함

issue #676:
- save selected theme name and apply last saved theme when load application

차이점 보기:

DTI_PID/DTI_PID/App.py
21 21
    """
22 22
    def __init__(self, args):
23 23
        super(App, self).__init__(args)
24
        appStyle = AppDocData.instance().loadAppStyle()
25
        self.setStyle(appStyle)
26
        self.loadStyleSheet(os.path.dirname(os.path.realpath(__file__)) + '\\coffee')
24
        app_doc_data = AppDocData.instance()
25
        app_style = app_doc_data.loadAppStyle()
26
        self.setStyle(app_style)
27

  
28
        configs = app_doc_data.getAppConfigs('app', 'stylesheet')
29
        if configs and len(configs) == 1:
30
            self.loadStyleSheet(os.path.dirname(os.path.realpath(__file__)) + '\\{}'.format(configs[0].value))
31
            self.stylesheet_name = configs[0].value
32
        else:
33
            self.loadStyleSheet(os.path.dirname(os.path.realpath(__file__)) + '\\coffee')
34
            self.stylesheet_name = 'coffee'
27 35

  
28 36
        self._mainWnd = None
29 37

  
DTI_PID/DTI_PID/AppDocData.py
176 176
        templateDbPath = os.path.join(path, 'Template.db')
177 177
        return templateDbPath
178 178

  
179
    def getAppDbPath(self):
180
        """
181
        @brief      Get application DB file path in ProgramData
182
        @author     humkyung
183
        @date       2018.10.01
184
        """
185

  
186
        path = os.path.join(os.getenv('ALLUSERSPROFILE'), 'Digital PID')
187
        app_database = os.path.join(path, 'App.db')
188
        return app_database 
189

  
179 190
    '''
180 191
        @brief  getter of colors 
181 192
        @author humkyung
......
1044 1055

  
1045 1056
        return res
1046 1057

  
1058
    def getAppConfigs(self, section, key=None):
1059
        """
1060
            @brief  get application configurations
1061
            @author humkyung
1062
            @date   2018.11.01
1063
        """
1064

  
1065
        res = []
1066

  
1067
        try:
1068
            # Creates or opens a file called mydb with a SQLite3 DB
1069
            dbPath = self.getAppDbPath()
1070
            conn = sqlite3.connect(dbPath)
1071
            # Get a cursor object
1072
            cursor = conn.cursor()
1073

  
1074
            if key is not None:
1075
                sql = "select * from configuration where section=? and key=?"
1076
                param = (section, key)
1077
            else:
1078
                sql = "select * from configuration where section=?"
1079
                param = (section,)
1080

  
1081
            cursor.execute(sql, param)
1082
            rows = cursor.fetchall()
1083
            for row in rows:
1084
                res.append(Config(row[0], row[1], row[2]))
1085
        # Catch the exception
1086
        except Exception as ex:
1087
            # Roll back any change if something goes wrong
1088
            conn.rollback()
1089
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
1090
        finally:
1091
            # Close the db connection
1092
            conn.close()
1093

  
1094
        return res
1095

  
1047 1096
    '''
1048 1097
        @brief      save configurations
1049 1098
        @author     humkyung
......
1078 1127
            # Close the db connection
1079 1128
            conn.close()
1080 1129

  
1130
    def saveAppConfigs(self, configs):
1131
        """
1132
        @brief      save application configurations
1133
        @author     humkyung
1134
        @date       2018.10.01
1135
        """
1136

  
1137
        try:
1138
            # Creates or opens a file called mydb with a SQLite3 DB
1139
            dbPath = self.getAppDbPath()
1140
            conn = sqlite3.connect(dbPath)
1141
            # Get a cursor object
1142
            cursor = conn.cursor()
1143

  
1144
            for config in configs:
1145
                value = config.value
1146
                if type(value) is str and "'" in value:
1147
                    value = value.replace("'", "''")
1148

  
1149
                sql = "insert or replace into configuration values(?,?,?)"
1150
                param = (config.section, config.key, value)
1151

  
1152
                cursor.execute(sql, param)
1153
            conn.commit()
1154
        # Catch the exception
1155
        except Exception as ex:
1156
            # Roll back any change if something goes wrong
1157
            conn.rollback()
1158
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
1159
        finally:
1160
            # Close the db connection
1161
            conn.close()
1162

  
1081 1163
    '''
1082 1164
        @brief  delete configurations
1083 1165
        @author humkyung
......
1107 1189
            # Close the db connection
1108 1190
            conn.close()
1109 1191

  
1192
    def deleteAppConfigs(self, section, key=None):
1193
        """
1194
        @brief  delete application configurations
1195
        @author humkyung
1196
        @date   2018.11.01
1197
        """
1198

  
1199
        try:
1200
            # Creates or opens a file called mydb with a SQLite3 DB
1201
            dbPath = self.getAppDbPath()
1202
            conn = sqlite3.connect(dbPath)
1203
            # Get a cursor object
1204
            cursor = conn.cursor()
1205

  
1206
            if key is not None:
1207
                sql = "delete from configuration where section='{}' and key='{}'".format(section, key)
1208
            else:
1209
                sql = "delete from configuration where section='{}'".format(section)
1210
            cursor.execute(sql)
1211

  
1212
            conn.commit()
1213
        # Catch the exception
1214
        except Exception as ex:
1215
            # Roll back any change if something goes wrong
1216
            conn.rollback()
1217
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
1218
        finally:
1219
            # Close the db connection
1220
            conn.close()
1221

  
1110 1222
    '''
1111 1223
        @brief      set area list
1112 1224
        @history    humkyung 2018.05.18 round area coordinate and dimension before saving
DTI_PID/DTI_PID/MainWindow.py
202 202
        self.resizeDocks({self.dockWidget}, {self.dockWidgetObjectExplorer.sizeHint().width()}, Qt.Horizontal)
203 203

  
204 204
        # load stylesheet file list
205
        stylesheet_name = QtWidgets.qApp.stylesheet_name
205 206
        files = [os.path.splitext(file)[0] for file in os.listdir(os.path.dirname(os.path.realpath(__file__))) if os.path.splitext(file)[1] == '.qss']
206 207
        for file in files:
207 208
            action = self.menuTheme.addAction(file)
209
            action.setCheckable(True)
210
            action.setChecked(True) if stylesheet_name == file else action.setChecked(False)
208 211
            action.triggered.connect(partial(self.load_stylesheet, file))
209 212
        # up to here
210 213

  
......
217 220

  
218 221
        QtWidgets.qApp.loadStyleSheet(os.path.join(os.path.dirname(os.path.realpath(__file__)), file))
219 222

  
223
        app_doc_data = AppDocData.instance()
224
        configs = [Config('app', 'stylesheet', file)]
225
        app_doc_data.saveAppConfigs(configs)
226
        
227
        for action in self.menuTheme.actions():
228
            if action.text() == file: continue
229
            action.setChecked(False)
230

  
220 231
    def onShowDetectSymbol(self):
221 232
        from DetectSymbolDialog import QDetectSymbolDialog
222 233

  

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)