コード例 #1
0
 def Btn_Clicked(self, btn):
     '''
     slot function for UI components
     '''
     try:
         # custom switch check box
         if btn == self.ui.robocopySwitchesCheckBox:
             # get the default switches
             tmp = Settings.RobocopySwitches.split(' ')
             default_params = []
             for t in tmp:
                 a, _ = self.GetFlagText(t)
                 default_params.append(a)
             # enable/disable custom swtich group
             self.ui.grpOptions.setEnabled(btn.isChecked())
             if btn.isChecked():
                 # if enabled, apply txt box too
                 self.ui.txt_lev.setEnabled(self.ui.chk_lev.isChecked())
                 self.ui.txt_r.setEnabled(self.ui.chk_r.isChecked())
                 self.ui.txt_w.setEnabled(self.ui.chk_w.isChecked())
                 self.ui.txt_max.setEnabled(self.ui.chk_max.isChecked())
                 self.ui.txt_min.setEnabled(self.ui.chk_min.isChecked())
                 self.ui.txt_maxage.setEnabled(
                     self.ui.chk_maxage.isChecked())  # noqa
                 self.ui.txt_minage.setEnabled(
                     self.ui.chk_minage.isChecked())  # noqa
                 self.ui.txt_maxlad.setEnabled(
                     self.ui.chk_maxlad.isChecked())  # noqa
                 self.ui.txt_minlad.setEnabled(
                     self.ui.chk_minlad.isChecked())  # noqa
             else:
                 # if not, uncheck checkboxes
                 for sh in self.chks:
                     if sh.text().lower() in default_params:
                         sh.setChecked(True)
                     else:
                         sh.setChecked(False)
         # Source Folder cbhange
         elif btn == self.ui.sourceFolderTextBox:
             self.ui.btnExclude.setEnabled(
                 os.path.exists(self.ui.sourceFolderTextBox.text()))
         # OK button
         elif btn == self.ui.btnOK:
             # if can not apply, return
             if not self.Apply():
                 return
             self.accept()
         # Cancel Button
         elif btn == self.ui.btnCancel:
             self.reject()
         # Source Browser button
         elif btn == self.ui.btnBrowseSrc:
             # opens the file browser dialog
             path = QFileDialog(self).getExistingDirectory()
             path = path.replace('/', '\\')
             if len(path) > 0:
                 self.ui.sourceFolderTextBox.setText(path)
                 self._task.Source = path
         # Target Browser button
         elif btn == self.ui.btnBrowseDst:
             # opens the file browser dialog
             path = QFileDialog(self).getExistingDirectory()
             path = path.replace('/', '\\')
             if len(path) > 0:
                 self.ui.targetFolderTextBox.setText(path)
                 self._task.Target = path
         # Exclude Button
         elif btn == self.ui.btnExclude:
             # opens the Exclude Dialog
             dlg = DlgExclude(self, self._task)
             if dlg.exec_() != QDialog.Accepted:
                 return
             # update Exclude params
             self._task.ExcludedAttributes = dlg.ExcludedAttributes
             self._task.ExcludedFiles = dlg.ExcludedFiles
             self._task.ExcludedFolders = dlg.ExcludedFolders
         # update command arguments
         self.UpdateCmd()
     except Exception as e:
         print(f'Btn_Clicked err:{e}')
コード例 #2
0
 def Btn_Clicked(self, btn):
     '''
     slot funtion for UI components
     params:
     --------
     btn : QPushButton
         The button that sends signal
     '''
     try:
         # OK button
         if btn == self.ui.btnOK:
             self.Apply()
             self.accept()
         # Cancel button
         elif btn == self.ui.btnCancel:
             self.reject()
         # Brose File
         elif btn == self.ui.btnBrowseFile:
             # repeats until valid file is selcted
             while True:
                 file, _ = QFileDialog(
                     self,
                     '',
                     self.baseFolder).getOpenFileName()
                 if len(file) == 0:
                     break
                 if self.baseFolder in file:
                     sub_dir = file.replace(
                         self.baseFolder,
                         '').replace('/', '\\')
                     if len(sub_dir) > 0:
                         self.ui.excludedFilesControl.addItem(sub_dir)
                         break
                 QMessageBox.critical(
                     self,
                     Settings.EXCLUDE_DLG_INVALID_File_Caption,
                     Settings.EXCLUDE_DLG_INVALID_File_TEXT)
         elif btn == self.ui.btnFileWild:
             # removes the space
             txt = self.ui.txtFile.text().strip()
             if len(txt) == 0:
                 QMessageBox.information(
                     self,
                     Settings.EXCLUDE_DLG_INVALID_Wild_Caption,
                     Settings.EXCLUDE_DLG_INVALID_Wild_TEXT)
                 return
             self.ui.excludedFilesControl.addItem(txt)
         elif btn == self.ui.btnFolderWild:
             # removes the space
             txt = self.ui.txtFolder.text().strip()
             if len(txt) == 0:
                 QMessageBox.information(
                     self,
                     Settings.EXCLUDE_DLG_INVALID_Wild_Caption,
                     Settings.EXCLUDE_DLG_INVALID_Wild_TEXT)
                 return
             self.ui.excludedFoldersControl.addItem(txt)
         elif btn == self.ui.btnBrowseFolder:
             # repeats until valid file is selcted
             while True:
                 path = QFileDialog(self, "", self.baseFolder).getExistingDirectory()    # noqa
                 path = path.replace('/', '\\')
                 if len(path) == 0:
                     break
                 if self.baseFolder in path:
                     sub_dir = path.replace(self.baseFolder, '').replace('/', '\\')      # noqa
                     if len(sub_dir) > 0:
                         self.ui.excludedFoldersControl.addItem(sub_dir)
                         break
                 QMessageBox.critical(
                     self,
                     Settings.EXCLUDE_DLG_INVALID_SubDir_Caption,
                     Settings.EXCLUDE_DLG_INVALID_SubDir_TEXT)
         elif btn == self.ui.btnRemoveFile:
             index = self.ui.excludedFilesControl.currentIndex().row()
             # if selected index is valid
             if index >= 0:
                 self.ui.excludedFilesControl.takeItem(index)
         elif btn == self.ui.btnRemoveFolder:
             # if selected index is valid
             index = self.ui.excludedFoldersControl.currentIndex().row()
             if index >= 0:
                 self.ui.excludedFoldersControl.takeItem(index)
     except Exception as e:
         print(f'DlgExclude click err:{e}')