Example #1
0
File: gui.py Project: tinavas/FSERP
 def __init__(self):
     self.mainwindow = QMainWindow()
     settings.get_settings()
     self.access = tuple(settings.access.items())
     self.progress = QProgressDialog("Setting up modules...", "cancel", 0,
                                     7, self.mainwindow)
     self.progress.setWindowTitle(
         QApplication.translate("MainWindow", str(settings.company), None,
                                QApplication.UnicodeUTF8))
    def buildImageDataList(self):
        """
        Build the image list with meta data to be constructed into pdf
        """
        markerName = ""
        shotStatus = ""
        markerIndex = 1
        self.fileList = []
        self.tempFileDir = tempfile.gettempdir()

        numFiles = len(self.shotCutList)
        progress = QProgressDialog("Generating PDF...", "Cancel Export", 0, numFiles, hiero.ui.mainWindow())
        progress.setWindowModality(Qt.WindowModal)
        tc = Timecode()
        timecodeStart = self.sequence.timecodeStart()
        timecodeDisplayMode = Timecode().kDisplayTimecode
        fps = self.sequence.framerate()

        count = 1
        for shot in self.shotCutList:
            thumbPath = os.path.join(self.tempFileDir,"%s_%s.jpg" % (shot.name(), self.currentTimeString()))

            thumbnailFrame = self.getThumbFrameForShot(shot)

            # Try and get a thumbnail, assuming the media is present etc...
            try:
                thumb = shot.thumbnail( thumbnailFrame ).save(thumbPath)
            except:
                shutil.copy(self.offlineLogoPath, thumbPath)

            if not os.path.isfile(thumbPath) or progress.wasCanceled():
                self.cleanUpTempFiles()
                progress.cancel()
                break

            # This file list gets cleaned up after the PDF save finishes
            self.fileList += [thumbPath]

            dataDict = {'show':self.project,
                        'sequence':self.sequence,
                        'editVersion':"*Version*",
                        'setup':"*setup*",
                        'timeString': tc.timeToString(shot.timelineIn() + timecodeStart, fps, timecodeDisplayMode) + ", %if" % shot.duration(),
                        'name': self.validString(shot.name()),
                        'version':"*version*",
                        'path': thumbPath, 
                        'track': self.validString(shot.parentTrack().name()),
                        'shot': self.validString(shot.source().name()),
                        'shotLabel': self.validString(shot.name()),
                        'shotStatus': "*ShotStatus*",
            }
            
            self.imageDataList.append(dataDict)
            progress.setValue(count)
            count += 1
Example #3
0
    def buildImageDataList(self):
        """
        Build the image list with meta data to be constructed into pdf
        """
        markerName = ""
        shotStatus = ""
        markerIndex = 1
        self.fileList = []
        self.tempFileDir = tempfile.gettempdir()

        numFiles = len(self.shotCutList)
        progress = QProgressDialog("Generating PDF...", "Cancel Export", 0, numFiles, hiero.ui.mainWindow())
        progress.setWindowModality(Qt.WindowModal)
        tc = Timecode()
        timecodeStart = self.sequence.timecodeStart()
        timecodeDisplayMode = Timecode().kDisplayTimecode
        fps = self.sequence.framerate()

        count = 1
        for shot in self.shotCutList:
            thumbPath = os.path.join(self.tempFileDir, "%s_%s.jpg" % (shot.name(), self.currentTimeString()))

            # Try and get a thumbnail, assuming the media is present etc...
            try:
                thumb = shot.thumbnail(shot.sourceIn()).save(thumbPath)
            except:
                shutil.copy(self.offlineLogoPath, thumbPath)

            if not os.path.isfile(thumbPath) or progress.wasCanceled():
                self.cleanUpTempFiles()
                progress.cancel()
                break

            # This file list gets cleaned up after the PDF save finishes
            self.fileList += [thumbPath]

            dataDict = {
                "show": self.project,
                "sequence": self.sequence,
                "editVersion": "*Version*",
                "setup": "*setup*",
                "timeString": tc.timeToString(shot.timelineIn() + timecodeStart, fps, timecodeDisplayMode)
                + ", %if" % shot.duration(),
                "name": self.validString(shot.name()),
                "version": "*version*",
                "path": thumbPath,
                "track": self.validString(shot.parentTrack().name()),
                "shot": self.validString(shot.source().name()),
                "shotLabel": self.validString(shot.name()),
                "shotStatus": "*ShotStatus*",
            }

            self.imageDataList.append(dataDict)
            progress.setValue(count)
            count += 1
Example #4
0
 def load(self, fileNames):
     ''' unpickles data and add elements to tree view
     in case loading takes a while, a progress bar shows current status 
     '''
     progress = QProgressDialog("Loading files...", "Abort Copy", 0, len(fileNames), self)
     progress.setWindowModality(Qt.WindowModal)
     i = 0
     for fileName in fileNames:
         with open(fileName, 'rb') as ifile:
             tmp = pickle.load(ifile)
             if os.path.isfile(fileName[:-2] + "oni"):
                 tmp = tmp + (fileName[:-2]+"oni",)
             if isinstance(tmp, pyHPF.pyHPF):
                 self.datas.append(tmp)
             else:
                 self.datas.append(extendedPyHPF(tmp))
             self.updateTree(fileName[-5:])
             
             i+=1
             progress.setValue(i)
Example #5
0
 def doit(self):
     """Creates the report."""
     d = QProgressDialog(
             self.tr("Generating Diagrams..."), self.tr("Cancel"),
             0, len(self._connections) * len(self._diagramnames))
     d.setWindowModality(Qt.WindowModal)
     d.show()
     aborted = False
     for c in self._connections:
         aborted = self._createDiagrams(c, d)
     d.hide()
     if not aborted:
         self._collectInterpretations()
         self._generateReport()
Example #6
0
    def copy_files(self):
        """Initiate copy process. File size is calculated first to
        check that there is enough space in the destination.
        If there is enough space then we start the copy of the files
        to their destination.
        Input:
            None
        Output:
            None"""
        self.copyButton.setEnabled(False)
        self.copyWorker.must_run = True
        self.connect(self.copyWorker, SIGNAL("copyProgress(QString, QString, QString)"), self.copy_progress, Qt.QueuedConnection)
        dest_dir = self.lblDestPath.text()
        if dest_dir == '':
            QMessageBox.critical(self, "Destination not set", "Please specify a destination path", WindowModility=True)
        else:
            copy_filelist = []
            for selection in self.treeView.selectedIndexes():
                indexItem = self.model.index(selection.row(), 0, selection.parent())
                copy_filelist.append(self.model.filePath(indexItem))
            if self.cbOWDest.isChecked():
                if self.rbOWEither.isChecked():
                    overwrite_option = 'either'
                elif self.rbOWLarger.isChecked():
                    overwrite_option = 'larger'
                elif self.rbOWNewer.isChecked():
                    overwrite_option = 'newer'
                else:
                    QMessageBox.critical(self,
                        "Overwrite option missing",
                        """You did not select an overwrite option.""",
                        WindowModility=True)
                    self.copyButton.setEnabled(True)
                    return
            else:
                overwrite_option = None
            if not self.ckbxTrimDir.isChecked():
                flattencount = 0
            else:
                flattencount = self.trimdirCount.value()

            self.progress = QProgressDialog("Copy in progress.", "Cancel", 0, 100, modal=True)
            self.progress.canceled.connect(self.cancel_copy)
            self.progress.setWindowTitle('Copy Progress')
            var_values = {'destdir': dest_dir, 'filelist': copy_filelist, 'flattencount': flattencount, 'overwrite_opt': overwrite_option}
            self.socket.send(json.dumps(var_values))
            self.copyWorker.start()
 def __init__(self, params):
     loader = QUiLoader()
     infile = QFile("gui/ui/Setup.ui")
     infile.open(QFile.ReadOnly)
     self.window = loader.load(infile, None)
     
     self.loadPrefs()
     
     self.window.quitButton.clicked.connect(self.closeApp)
     self.window.saveButton.clicked.connect(self.savePrefs)
     self.window.runButton.clicked.connect(self.runSV)
     
     self.splash = QProgressDialog("Loading", "Cancel", 0, 100, parent=None)
     self.splash.setWindowModality(Qt.WindowModal)
     self.splash.setAutoReset(False)
     self.splash.setAutoClose(False)
     self.splash.hide()
     self.canceled = False
     
     self.window.show()
     self.runningApp = None
Example #8
0
  def installUpdate(self):
    try:
      # setup progress dialog
      self._progressDlg = QProgressDialog(self)
      self._progressDlg.setWindowModality(Qt.WindowModal)
      self._progressDlg.setAutoClose(True)
      self._progressDlg.setMinimum(0)
      self._progressDlg.setMaximum(100)
      self._progressDlg.setLabelText("Auto-Updating")
      self._progressDlg.setCancelButton(None)
      self._progressDlg.setValue(0)

      self._app.auto_update(self.autoUpdateCallback)

      appexe = esky.util.appexe_from_executable(sys.executable)
      os.execv(appexe, self._appargs)
      QMessageBox.information(None, "Updating", "Update complete!")
      self._app.cleanup()
      self._progressDlg.reset()
      sys.exit()
    except Exception, e:
      print("ERROR AUTO-UPDATING APP: {0}".format(e))
Example #9
0
class UpdatesView(QDialog, Ui_UpdatesView):
  def __init__(self, parent, appargs):
    QDialog.__init__(self, parent)
    self.setupUi(self)
    self._app = esky.Esky(sys.executable,
        "http://10.78.55.218/pyrite/downloads")
    self._appargs = appargs

    self.connectActions()
    self.updateView()

  def connectActions(self):
    self.btnCheckForUpdates.clicked.connect(self.updateView)
    self.btnInstallUpdate.clicked.connect(self.installUpdate)
    self.btnClose.clicked.connect(self.reject)

  def updateView(self):
    self.lblCurrentVersion.setText("You are currently running Pyrite version:"
        " {0}".format(version.version))
    update = self._app.find_update()
    if update is not None:
      self.lblAvailableUpdate.setText("Pyrite version {0} is available for"
          " download".format(update))
      self.btnInstallUpdate.setEnabled(True)
    else:
      self.lblAvailableUpdate.setText("There are no new updates available at"
          " this time.")

  def installUpdate(self):
    try:
      # setup progress dialog
      self._progressDlg = QProgressDialog(self)
      self._progressDlg.setWindowModality(Qt.WindowModal)
      self._progressDlg.setAutoClose(True)
      self._progressDlg.setMinimum(0)
      self._progressDlg.setMaximum(100)
      self._progressDlg.setLabelText("Auto-Updating")
      self._progressDlg.setCancelButton(None)
      self._progressDlg.setValue(0)

      self._app.auto_update(self.autoUpdateCallback)

      appexe = esky.util.appexe_from_executable(sys.executable)
      os.execv(appexe, self._appargs)
      QMessageBox.information(None, "Updating", "Update complete!")
      self._app.cleanup()
      self._progressDlg.reset()
      sys.exit()
    except Exception, e:
      print("ERROR AUTO-UPDATING APP: {0}".format(e))
Example #10
0
 def DownloadNotes(self, notebook_guid):
     #set progress dialog
     progress = QProgressDialog("Read data from server...", "Abort downloading", 0, 100)
     progress.setWindowModality(Qt.WindowModal)
     #read note data from server
     note_filter = NoteStore.NoteFilter()
     note_filter.notebookGuid = notebook_guid
     offset = 0
     note_list = self.note_store.findNotes(self.authToken, note_filter, 0, 10000)
     full_note_list = note_list.notes
     progress.setMaximum(note_list.totalNotes + 1)
     while(len(full_note_list) < note_list.totalNotes):
         progress.setValue(offset)
         offset = offset + len(note_list.notes)
         note_list = self.note_store.findNotes(self.authToken, note_filter, offset, 10000)
         full_note_list.extend(note_list.notes)
     #set content of progress dialog
     progress.setMaximum(len(full_note_list))
     progress.setLabelText("Downloading content of notebook...")
     #download the content of note
     if(not hasattr(self, 'note_list')):
         self.note_list = []
         self.timestamp_list = dict()
         guid_list = []
     else:
         guid_list = [note.guid for note in self.note_list]
         
     count = 0
     for note in full_note_list:
         #load content
         if(note.guid not in guid_list):
             #add new note
             note.content = self.note_store.getNoteContent(self.authToken, note.guid)
             self.note_list.append(note)
             self.timestamp_list[note.guid] = [date.today(), 0]
         else:
             #update existed note
             note_index = guid_list.index(note.guid)
             if(self.note_list[note_index].updated < note.updated):
                 self.note_list[note_index].content = self.note_store.getNoteContent(self.authToken, note.guid)
         #set counter
         progress.setValue(count)
         count = count + 1
         if(progress.wasCanceled()):
             raise RuntimeError("Downloading was canceled")
     #save note_list to file
     saved_file = open(self.notebook_base_path + notebook_guid, 'w')
     pickle.dump(self.note_list, saved_file)
     saved_file.close()
     #save timestamp file
     timestamp_file = open(self.notebook_base_path + 'time_' + notebook_guid, 'w')
     pickle.dump(self.timestamp_list, timestamp_file)
     timestamp_file.close()
Example #11
0
    def collectNoise(self, seconds):
        """
        Collect noise data and update ``noiseData``.
        Uses the processes/threads started in :func:`startSnifferAndAdder`.

        :param seconds: Amount of seconds to capture noise

        :return: True if noise was captured. False if the user pressed "Cancel"
        """

        self.noiseData = []
        # Setup the ProgressDialog
        progressDialog = QProgressDialog(
            Strings.filterTabCollectingNoiseMessageBoxText, "Cancel", 0,
            seconds)

        progressDialog.setMinimumDuration(0)
        progressDialog.setMinimum(0)
        progressDialog.setMaximum(seconds)
        progressDialog.adjustSize()
        progressDialog.setFixedSize(progressDialog.width() + 40,
                                    progressDialog.height())

        # Users still can click on the "X"
        progressDialog.setCancelButton(None)

        # Start collecting
        self.startSnifferAndAdder(adderMethod=self.addSniffedNoise)

        progressDialog.open()

        secondsToCollect = seconds
        while secondsToCollect > 0 and not progressDialog.wasCanceled():
            time.sleep(0.5)
            secondsToCollect -= 0.5
            self.updateNoiseCollectProgress(progressDialog,
                                            seconds - secondsToCollect)

        self.stopSnifferAndAdder()
        return not progressDialog.wasCanceled()
def notifyRun(vcfPath, vcfAttributes, xAttribute, yAttribute, softFilters, forcedCategoricals, featurePaths):
    global canceled, splash, window
    splash = QProgressDialog("Loading %s" % os.path.split(vcfPath)[1], "Cancel", 0, 1000, parent=None)
    splash.setWindowModality(Qt.WindowModal)
    splash.setAutoReset(False)
    splash.setAutoClose(False)
    splash.show()
    canceled = False
    
    vData = variantData(vcfPath, vcfAttributes, forcedCategoricals)
    vParams = variantLoadingParameters(passFunction=vData.addVariant,
                                     rejectFunction=None,
                                     callbackArgs={},
                                     tickFunction=tick,
                                     tickInterval=0.1,
                                     individualsToInclude=[],
                                     individualAppendString="",
                                     lociToInclude=None,
                                     mask=None,
                                     invertMask=False,
                                     attributesToInclude=None,
                                     attributeAppendString="",
                                     skipGenotypeAttributes=True,
                                     returnFileObject=False,
                                     alleleMatching=allele.STRICT,
                                     attemptRepairsWhenComparing=True)
    try:
        variantFile.parseVcfFile(vcfPath, vParams)
    except cancelButtonException:
        splash.close()
        window.window.show()
        return
    
    if softFilters == None:
        softFilters = {}
        for k in vData.axisLookups.iterkeys():
            if k == xAttribute or k == yAttribute:
                if vData.axisLookups[k].hasNumeric:
                    fivePercent = 0.05*(vData.axisLookups[k].maximum-vData.axisLookups[k].minimum)
                    ranges = [(vData.axisLookups[k].maximum-fivePercent,vData.axisLookups[k].maximum)]
                else:
                    ranges = None
                values = []
            else:
                ranges = None
                values = None
            softFilters[k] = valueFilter(values=values,
                                         ranges=ranges,
                                         includeNone=True,
                                         includeBlank=True,
                                         includeInf=True,
                                         includeNaN=True,
                                         includeMissing=True,
                                         includeAlleleMasked=True,
                                         listMode=valueFilter.LIST_INCLUSIVE)
    intMan = interactionManager(vData,softFilters)
    
    # TODO
    fData = featureData(featurePaths)
    if canceled:
        splash.close()
        window.window.show()
        return

    splash.close()
    appWindow = appWidget(vData,fData,intMan,xAttribute,yAttribute)
    intMan.setApp(appWindow)
Example #13
0
class RunnerDialog(QDialog):

    options_added = Signal(Options)
    options_running = Signal(Options)
    options_simulated = Signal(Options)
    options_error = Signal(Options, Exception)
    results_saved = Signal(Results, str)
    results_error = Signal(Results, Exception)

    def __init__(self, parent=None):
        QDialog.__init__(self, parent)
        self.setWindowTitle('Runner')
        self.setMinimumWidth(750)

        # Runner
        self._runner = None

        self._running_timer = QTimer()
        self._running_timer.setInterval(500)

        # Widgets
        self._dlg_progress = QProgressDialog()
        self._dlg_progress.setRange(0, 100)
        self._dlg_progress.setModal(True)
        self._dlg_progress.hide()

        lbl_outputdir = QLabel("Output directory")
        self._txt_outputdir = DirBrowseWidget()

        max_workers = cpu_count() #@UndefinedVariable
        lbl_workers = QLabel('Number of workers')
        self._spn_workers = QSpinBox()
        self._spn_workers.setRange(1, max_workers)
        self._spn_workers.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        lbl_max_workers = QLabel('(max: %i)' % max_workers)

        self._chk_overwrite = QCheckBox("Overwrite existing results in output directory")
        self._chk_overwrite.setChecked(True)

        self._lbl_available = QLabel('Available')
        self._lst_available = QListView()
        self._lst_available.setModel(_AvailableOptionsListModel())
        self._lst_available.setSelectionMode(QListView.SelectionMode.MultiSelection)

        tlb_available = QToolBar()
        spacer = QWidget()
        spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        tlb_available.addWidget(spacer)
        act_open = tlb_available.addAction(getIcon("document-open"), "Open")
        act_open.setShortcut(QKeySequence.Open)
        tlb_available.addSeparator()
        act_remove = tlb_available.addAction(getIcon("list-remove"), "Remove")
        act_clear = tlb_available.addAction(getIcon("edit-clear"), "Clear")

        self._btn_addtoqueue = QPushButton(getIcon("go-next"), "")
        self._btn_addtoqueue.setToolTip("Add to queue")
        self._btn_addtoqueue.setEnabled(False)

        self._btn_addalltoqueue = QPushButton(getIcon("go-last"), "")
        self._btn_addalltoqueue.setToolTip("Add all to queue")
        self._btn_addalltoqueue.setEnabled(False)

        self._lbl_options = QLabel('Queued/Running/Completed')
        self._tbl_options = QTableView()
        self._tbl_options.setModel(_StateOptionsTableModel())
        self._tbl_options.setItemDelegate(_StateOptionsItemDelegate())
        self._tbl_options.setSelectionMode(QListView.SelectionMode.NoSelection)
        self._tbl_options.setColumnWidth(1, 60)
        self._tbl_options.setColumnWidth(2, 80)
        header = self._tbl_options.horizontalHeader()
        header.setResizeMode(0, QHeaderView.Interactive)
        header.setResizeMode(1, QHeaderView.Fixed)
        header.setResizeMode(2, QHeaderView.Fixed)
        header.setResizeMode(3, QHeaderView.Stretch)

        self._btn_start = QPushButton(getIcon("media-playback-start"), "Start")

        self._btn_cancel = QPushButton("Cancel")
        self._btn_cancel.setEnabled(False)

        self._btn_close = QPushButton("Close")

        self._btn_import = QPushButton("Import")
        self._btn_import.setEnabled(False)

        # Layouts
        layout = QVBoxLayout()

        sublayout = QGridLayout()
        sublayout.addWidget(lbl_outputdir, 0, 0)
        sublayout.addWidget(self._txt_outputdir, 0, 1)
        sublayout.addWidget(lbl_workers, 1, 0)

        subsublayout = QHBoxLayout()
        subsublayout.addWidget(self._spn_workers)
        subsublayout.addWidget(lbl_max_workers)
        sublayout.addLayout(subsublayout, 1, 1)
        layout.addLayout(sublayout)

        sublayout.addWidget(self._chk_overwrite, 2, 0, 1, 3)

        sublayout = QGridLayout()
        sublayout.setColumnStretch(0, 1)
        sublayout.setColumnStretch(2, 3)
        sublayout.addWidget(self._lbl_available, 0, 0)
        sublayout.addWidget(self._lst_available, 1, 0)
        sublayout.addWidget(tlb_available, 2, 0)

        subsublayout = QVBoxLayout()
        subsublayout.addStretch()
        subsublayout.addWidget(self._btn_addtoqueue)
        subsublayout.addWidget(self._btn_addalltoqueue)
        subsublayout.addStretch()
        sublayout.addLayout(subsublayout, 1, 1)

        sublayout.addWidget(self._lbl_options, 0, 2)
        sublayout.addWidget(self._tbl_options, 1, 2)
        layout.addLayout(sublayout)

        sublayout = QHBoxLayout()
        sublayout.addStretch()
        sublayout.addWidget(self._btn_import)
        sublayout.addWidget(self._btn_start)
        sublayout.addWidget(self._btn_cancel)
        sublayout.addWidget(self._btn_close)
        layout.addLayout(sublayout)

        self.setLayout(layout)

        # Signal
        self._running_timer.timeout.connect(self._onRunningTimer)

        act_open.triggered.connect(self._onOpen)
        act_remove.triggered.connect(self._onRemove)
        act_clear.triggered.connect(self._onClear)

        self._btn_addtoqueue.released.connect(self._onAddToQueue)
        self._btn_addalltoqueue.released.connect(self._onAddAllToQueue)
        self._btn_start.released.connect(self._onStart)
        self._btn_cancel.released.connect(self._onCancel)
        self._btn_close.released.connect(self._onClose)
        self._btn_import.released.connect(self._onImport)

        self.options_added.connect(self._onOptionsAdded)
        self.options_running.connect(self._onOptionsRunning)
        self.options_simulated.connect(self._onOptionsSimulated)
        self.options_error.connect(self._onOptionsError)
        self.results_error.connect(self._onResultsError)

        # Defaults
        settings = get_settings()
        section = settings.add_section('gui')
        if hasattr(section, 'outputdir'):
            self._txt_outputdir.setPath(section.outputdir)
        if hasattr(section, 'maxworkers'):
            self._spn_workers.setValue(int(section.maxworkers))
        if hasattr(section, 'overwrite'):
            state = True if section.overwrite.lower() == 'true' else False
            self._chk_overwrite.setChecked(state)

    def _onDialogProgressProgress(self, progress, status):
        self._dlg_progress.setValue(progress * 100)
        self._dlg_progress.setLabelText(status)

    def _onDialogProgressCancel(self):
        self._dlg_progress.hide()
        if self._options_reader_thread is None:
            return
        self._options_reader_thread.cancel()
        self._options_reader_thread.quit()
        self._options_reader_thread.wait()

    def _onDialogProgressException(self, ex):
        self._dlg_progress.hide()
        self._options_reader_thread.quit()
        self._options_reader_thread.wait()
        messagebox.exception(self, ex)

    def _onRunningTimer(self):
        self._tbl_options.model().reset()

    def _onOpen(self):
        settings = get_settings()
        curdir = getattr(settings.gui, 'opendir', os.getcwd())

        filepath, namefilter = \
            QFileDialog.getOpenFileName(self, "Open", curdir,
                                        'Options [*.xml] (*.xml)')

        if not filepath or not namefilter:
            return
        settings.gui.opendir = os.path.dirname(filepath)

        if not filepath.endswith('.xml'):
            filepath += '.xml'

        self._options_reader_thread = _OptionsReaderWrapperThread(filepath)
        self._dlg_progress.canceled.connect(self._onDialogProgressCancel)
        self._options_reader_thread.resultReady.connect(self._onOpened)
        self._options_reader_thread.progressUpdated.connect(self._onDialogProgressProgress)
        self._options_reader_thread.exceptionRaised.connect(self._onDialogProgressException)
        self._options_reader_thread.start()

        self._dlg_progress.reset()
        self._dlg_progress.show()

    def _onOpened(self, options):
        self._dlg_progress.hide()
        self._options_reader_thread.quit()
        self._options_reader_thread.wait()
        self._options_reader_thread = None

        try:
            self._lst_available.model().addOptions(options)
        except Exception as ex:
            messagebox.exception(self, ex)

    def _onRemove(self):
        selection = self._lst_available.selectionModel().selection().indexes()
        if len(selection) == 0:
            QMessageBox.warning(self, "Queue", "Select an options")
            return

        model = self._lst_available.model()
        for row in sorted(map(methodcaller('row'), selection), reverse=True):
            model.popOptions(row)

    def _onClear(self):
        self._lst_available.model().clearOptions()

    def _onAddToQueue(self):
        selection = self._lst_available.selectionModel().selection().indexes()
        if len(selection) == 0:
            QMessageBox.warning(self, "Queue", "Select an options")
            return

        model = self._lst_available.model()
        for row in sorted(map(methodcaller('row'), selection), reverse=True):
            options = model.options(row)
            try:
                self._runner.put(options)
            except Exception as ex:
                messagebox.exception(self, ex)
                return

    def _onAddAllToQueue(self):
        model = self._lst_available.model()
        for row in reversed(range(0, model.rowCount())):
            options = model.options(row)
            try:
                self._runner.put(options)
            except Exception as ex:
                messagebox.exception(self, ex)
                return

    def _onStart(self):
        outputdir = self._txt_outputdir.path()
        if not outputdir:
            QMessageBox.critical(self, 'Start', 'Missing output directory')
            return
        max_workers = self._spn_workers.value()
        overwrite = self._chk_overwrite.isChecked()
        self.start(outputdir, overwrite, max_workers)

    def _onCancel(self):
        self.cancel()

    def _onClose(self):
        if self._runner is not None:
            self._runner.close()
        self._running_timer.stop()
        self.close()

    def _onImport(self):
        list_options = self._lst_available.model().listOptions()
        if not list_options:
            return

        # Select options
        dialog = _OptionsSelector(list_options)
        if not dialog.exec_():
            return
        options = dialog.options()

        # Start importer
        outputdir = self._runner.outputdir
        max_workers = self._runner.max_workers
        importer = LocalImporter(outputdir, max_workers)

        importer.start()
        importer.put(options)

        self._dlg_progress.show()
        try:
            while importer.is_alive():
                if self._dlg_progress.wasCanceled():
                    importer.cancel()
                    break
                self._dlg_progress.setValue(importer.progress * 100)
        finally:
            self._dlg_progress.hide()

    def _onOptionsAdded(self, options):
        logging.debug('runner: optionsAdded')
        self._tbl_options.model().addOptions(options)

    def _onOptionsRunning(self, options):
        logging.debug('runner: optionsRunning')
        self._tbl_options.model().resetOptions(options)

    def _onOptionsSimulated(self, options):
        logging.debug('runner: optionsSimulated')
        self._tbl_options.model().resetOptions(options)

    def _onOptionsError(self, options, ex):
        logging.debug('runner: optionsError')
        self._tbl_options.model().resetOptions(options)

    def _onResultsError(self, results, ex):
        logging.debug('runner: resultsError')
        self._tbl_options.model().reset()

    def closeEvent(self, event):
        if self.is_running():
            message = 'Runner is running. Do you want to continue?'
            answer = QMessageBox.question(self, 'Runner', message,
                                          QMessageBox.Yes | QMessageBox.No)
            if answer == QMessageBox.No:
                event.ignore()
                return

        self.cancel()
        self._dlg_progress.close()

        settings = get_settings()
        section = settings.add_section('gui')

        path = self._txt_outputdir.path()
        if path:
            section.outputdir = path
        section.maxworkers = str(self._spn_workers.value())
        section.overwrite = str(self._chk_overwrite.isChecked())

        settings.write()

        event.accept()

    def addAvailableOptions(self, options):
        self._lst_available.model().addOptions(options)

    def removeAvailableOptions(self, options):
        self._lst_available.model().removeOptions(options)

    def clearAvailableOptions(self):
        self._lbl_available.model().clearOptions()

    def start(self, outputdir, overwrite, max_workers):
        self._runner = LocalRunner(outputdir=outputdir,
                                   overwrite=overwrite,
                                   max_workers=max_workers)

        self._tbl_options.setModel(_StateOptionsTableModel(self._runner))

        self._spn_workers.setEnabled(False)
        self._txt_outputdir.setEnabled(False)
        self._chk_overwrite.setEnabled(False)
        self._btn_addtoqueue.setEnabled(True)
        self._btn_addalltoqueue.setEnabled(True)
        self._btn_start.setEnabled(False)
        self._btn_cancel.setEnabled(True)
        self._btn_close.setEnabled(False)
        self._btn_import.setEnabled(True)

        self._runner.options_added.connect(self.options_added.emit)
        self._runner.options_running.connect(self.options_running.emit)
        self._runner.options_simulated.connect(self.options_simulated.emit)
        self._runner.options_error.connect(self.options_error.emit)
        self._runner.results_saved.connect(self.results_saved.emit)
        self._runner.results_error.connect(self.results_error.emit)

        self._running_timer.start()
        self._runner.start()

    def cancel(self):
        if self._runner is None:
            return
        self._runner.cancel()
        self._running_timer.stop()

        self._runner.options_added.disconnect(self.options_added.emit)
        self._runner.options_running.disconnect(self.options_running.emit)
        self._runner.options_simulated.disconnect(self.options_simulated.emit)
        self._runner.options_error.disconnect(self.options_error.emit)
        self._runner.results_saved.disconnect(self.results_saved.emit)
        self._runner.results_error.disconnect(self.results_error.emit)

        self._runner = None

        self._spn_workers.setEnabled(True)
        self._txt_outputdir.setEnabled(True)
        self._chk_overwrite.setEnabled(True)
        self._btn_addtoqueue.setEnabled(False)
        self._btn_addalltoqueue.setEnabled(False)
        self._btn_start.setEnabled(True)
        self._btn_cancel.setEnabled(False)
        self._btn_close.setEnabled(True)
        self._btn_import.setEnabled(False)

    def is_running(self):
        return self._runner is not None and self._runner.is_alive()
Example #14
0
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)
        self.setWindowTitle('Runner')
        self.setMinimumWidth(750)

        # Runner
        self._runner = None

        self._running_timer = QTimer()
        self._running_timer.setInterval(500)

        # Widgets
        self._dlg_progress = QProgressDialog()
        self._dlg_progress.setRange(0, 100)
        self._dlg_progress.setModal(True)
        self._dlg_progress.hide()

        lbl_outputdir = QLabel("Output directory")
        self._txt_outputdir = DirBrowseWidget()

        max_workers = cpu_count() #@UndefinedVariable
        lbl_workers = QLabel('Number of workers')
        self._spn_workers = QSpinBox()
        self._spn_workers.setRange(1, max_workers)
        self._spn_workers.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        lbl_max_workers = QLabel('(max: %i)' % max_workers)

        self._chk_overwrite = QCheckBox("Overwrite existing results in output directory")
        self._chk_overwrite.setChecked(True)

        self._lbl_available = QLabel('Available')
        self._lst_available = QListView()
        self._lst_available.setModel(_AvailableOptionsListModel())
        self._lst_available.setSelectionMode(QListView.SelectionMode.MultiSelection)

        tlb_available = QToolBar()
        spacer = QWidget()
        spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        tlb_available.addWidget(spacer)
        act_open = tlb_available.addAction(getIcon("document-open"), "Open")
        act_open.setShortcut(QKeySequence.Open)
        tlb_available.addSeparator()
        act_remove = tlb_available.addAction(getIcon("list-remove"), "Remove")
        act_clear = tlb_available.addAction(getIcon("edit-clear"), "Clear")

        self._btn_addtoqueue = QPushButton(getIcon("go-next"), "")
        self._btn_addtoqueue.setToolTip("Add to queue")
        self._btn_addtoqueue.setEnabled(False)

        self._btn_addalltoqueue = QPushButton(getIcon("go-last"), "")
        self._btn_addalltoqueue.setToolTip("Add all to queue")
        self._btn_addalltoqueue.setEnabled(False)

        self._lbl_options = QLabel('Queued/Running/Completed')
        self._tbl_options = QTableView()
        self._tbl_options.setModel(_StateOptionsTableModel())
        self._tbl_options.setItemDelegate(_StateOptionsItemDelegate())
        self._tbl_options.setSelectionMode(QListView.SelectionMode.NoSelection)
        self._tbl_options.setColumnWidth(1, 60)
        self._tbl_options.setColumnWidth(2, 80)
        header = self._tbl_options.horizontalHeader()
        header.setResizeMode(0, QHeaderView.Interactive)
        header.setResizeMode(1, QHeaderView.Fixed)
        header.setResizeMode(2, QHeaderView.Fixed)
        header.setResizeMode(3, QHeaderView.Stretch)

        self._btn_start = QPushButton(getIcon("media-playback-start"), "Start")

        self._btn_cancel = QPushButton("Cancel")
        self._btn_cancel.setEnabled(False)

        self._btn_close = QPushButton("Close")

        self._btn_import = QPushButton("Import")
        self._btn_import.setEnabled(False)

        # Layouts
        layout = QVBoxLayout()

        sublayout = QGridLayout()
        sublayout.addWidget(lbl_outputdir, 0, 0)
        sublayout.addWidget(self._txt_outputdir, 0, 1)
        sublayout.addWidget(lbl_workers, 1, 0)

        subsublayout = QHBoxLayout()
        subsublayout.addWidget(self._spn_workers)
        subsublayout.addWidget(lbl_max_workers)
        sublayout.addLayout(subsublayout, 1, 1)
        layout.addLayout(sublayout)

        sublayout.addWidget(self._chk_overwrite, 2, 0, 1, 3)

        sublayout = QGridLayout()
        sublayout.setColumnStretch(0, 1)
        sublayout.setColumnStretch(2, 3)
        sublayout.addWidget(self._lbl_available, 0, 0)
        sublayout.addWidget(self._lst_available, 1, 0)
        sublayout.addWidget(tlb_available, 2, 0)

        subsublayout = QVBoxLayout()
        subsublayout.addStretch()
        subsublayout.addWidget(self._btn_addtoqueue)
        subsublayout.addWidget(self._btn_addalltoqueue)
        subsublayout.addStretch()
        sublayout.addLayout(subsublayout, 1, 1)

        sublayout.addWidget(self._lbl_options, 0, 2)
        sublayout.addWidget(self._tbl_options, 1, 2)
        layout.addLayout(sublayout)

        sublayout = QHBoxLayout()
        sublayout.addStretch()
        sublayout.addWidget(self._btn_import)
        sublayout.addWidget(self._btn_start)
        sublayout.addWidget(self._btn_cancel)
        sublayout.addWidget(self._btn_close)
        layout.addLayout(sublayout)

        self.setLayout(layout)

        # Signal
        self._running_timer.timeout.connect(self._onRunningTimer)

        act_open.triggered.connect(self._onOpen)
        act_remove.triggered.connect(self._onRemove)
        act_clear.triggered.connect(self._onClear)

        self._btn_addtoqueue.released.connect(self._onAddToQueue)
        self._btn_addalltoqueue.released.connect(self._onAddAllToQueue)
        self._btn_start.released.connect(self._onStart)
        self._btn_cancel.released.connect(self._onCancel)
        self._btn_close.released.connect(self._onClose)
        self._btn_import.released.connect(self._onImport)

        self.options_added.connect(self._onOptionsAdded)
        self.options_running.connect(self._onOptionsRunning)
        self.options_simulated.connect(self._onOptionsSimulated)
        self.options_error.connect(self._onOptionsError)
        self.results_error.connect(self._onResultsError)

        # Defaults
        settings = get_settings()
        section = settings.add_section('gui')
        if hasattr(section, 'outputdir'):
            self._txt_outputdir.setPath(section.outputdir)
        if hasattr(section, 'maxworkers'):
            self._spn_workers.setValue(int(section.maxworkers))
        if hasattr(section, 'overwrite'):
            state = True if section.overwrite.lower() == 'true' else False
            self._chk_overwrite.setChecked(state)
Example #15
0
class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.build_dir_tree()
        self.setWindowIcon(QIcon('favicon.png'))
        self.actionAbout.triggered.connect(self.about)
        self.destButton.clicked.connect(self.destination_chooser)
        self.actionChoose_Destination.triggered.connect(
            self.destination_chooser)
        self.copyButton.clicked.connect(self.copy_files)
        self.actionStart_Copy.triggered.connect(self.copy_files)
        self.ckbxTrimDir.toggled.connect(self.update_table_view)
        self.treeView.expanded.connect(self.resize_tree_column)
        self.treeView.collapsed.connect(self.resize_tree_column)
        self.treeView.clicked.connect(self.update_table_view)
        self.trimdirCount.valueChanged.connect(self.update_table_view)

        self.listWidget.doubleClicked.connect(self.unselectItem)

        self.copyButton.setEnabled(False)
        self.lblTrimDir.setVisible(False)
        self.trimdirCount.setVisible(False)
        self.rbOWNewer.setVisible(False)
        self.rbOWLarger.setVisible(False)
        self.rbOWEither.setVisible(False)
        self.context = zmq.Context()
        self.socket = self.context.socket(zmq.PAIR)
        self.socket.bind("tcp://*:%s" % zmq_port)

        self.copyWorker = CopyWorker()
        self.connect(
            self.copyWorker,
            SIGNAL("copyComplete(QString, QString, QString, QString)"),
            self.copy_complete, Qt.QueuedConnection)
        self.connect(self.copyWorker, SIGNAL("spaceProblem(int, int)"),
                     self.space_problem, Qt.QueuedConnection)

    def unselectItem(self, item):
        ##need to figure out how to remove from the model
        self.listWidget.takeItem(item.row())

    def copy_complete(self, filecount, filesize, runtime, run_seconds):
        self.progress.setValue(self.progress.maximum())
        transfer_rate = round((float(filesize) * 1024) / float(run_seconds), 3)
        filesize = round(float(filesize), 3)
        QMessageBox.information(
            self,
            "File Copy Complete",
            """Your file copy has been successfully completed.\n
            Files processed:\t%s\n
            Data copied:\t%sGB\n
            Total runtime:\t%s\n
            Transfer Rate:\t%sMB/Sec""" %
            (filecount, filesize, runtime, transfer_rate),
            WindowModility=True)
        self.copyButton.setEnabled(True)

    def space_problem(self, dirsize, filesize):
        """Display a dialog to the user advising that there is not enough space in the destination
        directory.
        Input:
            dirsize :   integer - amount of space available in the destination directory
            filesize:   integer - size of the selected files
        Output:
            None, dialog is displayed to the user."""
        ##TODO: Set the messagebox modal property to true
        required_space = (filesize / 1024.00 / 1024.00 /
                          1024.00) - (dirsize / 1024.00 / 1024.00 / 1024.00)
        QMessageBox.critical(
            self,
            "Not enough space",
            """You do not have enough space in your selected destination to complete this operation\n
                             %s more GB space required""" % required_space,
            WindowModility=True)
        self.copyWorker.quit()
        self.copyButton.setEnabled(True)

    def build_dir_tree(self):
        """Add a directory tree listing to the QTreeView and set the root
        to the drive that it was run from.
        Input:
            None
        Output:
            None"""
        ##TODO: add linux support for the model root drive.
        self.model = QFileSystemModel(self)
        if sys.platform == 'win32':
            self.model.setRootPath(os.path.splitdrive(os.getcwd())[0])
        self.tree = self.treeView
        self.tree.setModel(self.model)
        self.tree.setAnimated(False)
        self.tree.setIndentation(20)
        self.tree.setSortingEnabled(True)

    def update_table_view(self):
        """Refresh listview with selected items in the treeView using
        the shared model.
        Input:
            None
        Output:
            None"""
        itemlist = [
            os.path.abspath(
                self.model.filePath(
                    self.model.index(selection.row(), 0, selection.parent())))
            for selection in self.treeView.selectedIndexes()
        ]
        self.listWidget.clear()
        self.listWidget.addItems(itemlist)

        nitemlist = []
        fileops = FileOperations()
        if not self.ckbxTrimDir.isChecked():
            flattencount = 0
        else:
            flattencount = self.trimdirCount.value()
        if self.lblDestPath.isEnabled():
            self.previewView.clear()
            for item in itemlist:
                nitemlist.append(
                    fileops.get_dest_filepath(item, self.lblDestPath.text(),
                                              flattencount))
            self.previewView.addItems(nitemlist)
        else:
            self.previewView.clear()
            self.previewView.addItems(['No destination folder selected'])

        self.resize_tree_column()

    def resize_tree_column(self):
        """Resize the treeView column to fit the contents.
        Input:
            None
        Output:
            None"""
        self.treeView.resizeColumnToContents(0)

    def copy_files(self):
        """Initiate copy process. File size is calculated first to
        check that there is enough space in the destination.
        If there is enough space then we start the copy of the files
        to their destination.
        Input:
            None
        Output:
            None"""
        self.copyButton.setEnabled(False)
        self.copyWorker.must_run = True
        self.connect(self.copyWorker,
                     SIGNAL("copyProgress(QString, QString, QString)"),
                     self.copy_progress, Qt.QueuedConnection)
        dest_dir = self.lblDestPath.text()
        if dest_dir == '':
            QMessageBox.critical(self,
                                 "Destination not set",
                                 "Please specify a destination path",
                                 WindowModility=True)
        else:
            copy_filelist = []
            for selection in self.treeView.selectedIndexes():
                indexItem = self.model.index(selection.row(), 0,
                                             selection.parent())
                copy_filelist.append(self.model.filePath(indexItem))
            if self.cbOWDest.isChecked():
                if self.rbOWEither.isChecked():
                    overwrite_option = 'either'
                elif self.rbOWLarger.isChecked():
                    overwrite_option = 'larger'
                elif self.rbOWNewer.isChecked():
                    overwrite_option = 'newer'
                else:
                    QMessageBox.critical(
                        self,
                        "Overwrite option missing",
                        """You did not select an overwrite option.""",
                        WindowModility=True)
                    self.copyButton.setEnabled(True)
                    return
            else:
                overwrite_option = None
            if not self.ckbxTrimDir.isChecked():
                flattencount = 0
            else:
                flattencount = self.trimdirCount.value()

            self.progress = QProgressDialog("Copy in progress.",
                                            "Cancel",
                                            0,
                                            100,
                                            modal=True)
            self.progress.canceled.connect(self.cancel_copy)
            self.progress.setWindowTitle('Copy Progress')
            var_values = {
                'destdir': dest_dir,
                'filelist': copy_filelist,
                'flattencount': flattencount,
                'overwrite_opt': overwrite_option
            }
            self.socket.send(json.dumps(var_values))
            self.copyWorker.start()

    def copy_progress(self, percentage_complete, filecount, filecomplete):
        """Display the progress bar with a completed percentage.
        Input:
            percentage_complete :   integer - the amount complete in percent.
            filecount           :   integer - the total number of files being processed.
            filecomplete        :   integer - the number of files that have already been processed.
        Output:
            None, dialog is updated"""
        ##TODO: display the current transfer rate
        ##TODO: display the current file being transferred and possibly the progress thereof.
        ##Perhaps use the statusbar method for this
        self.progress.setValue(int(percentage_complete))

    def cancel_copy(self):
        """Slot for the cancel command on the progress dialog.
        The must_run variable of the copyWorker class is set to False to terminate the copy.
        Input:
            None
        Output:
            None"""
        self.copyWorker.must_run = False
        self.copyButton.setEnabled(True)

    def statusbar_msg(self, msg):
        """Update the statusbar on the bottom of the screen.
        Input:
            msg     : string - Message that you would like displayed on the form.
        Output:
            None
        """
        self.statusbar.clearMessage()
        self.statusbar.showMessage(msg)

    def destination_chooser(self):
        """Show folder chooser dialog and update lblDestPath with path selected.
        Input:
            None
        Output:
            None"""
        dialog = QFileDialog()
        dialog.setFileMode(QFileDialog.Directory)
        dialog.setOption(QFileDialog.ShowDirsOnly)
        dialog.exec_()
        self.lblDestPath.setEnabled(True)
        self.lblDestPath.setText(
            os.path.abspath(dialog.directory().absolutePath()))
        self.update_table_view()
        self.copyButton.setEnabled(True)

    def about(self):
        """Popup a box with about message.
        Input:
            None
        Output:
            None"""
        QMessageBox.about(
            self,
            "About MClub Mover",
            """This program is designed to help make the process of copying \
files from multiple directories much easier and simpler.\n
This software is provided as is with absolutely no warranties.""",
            WindowModility=True)
Example #16
0
    def copy_files(self):
        """Initiate copy process. File size is calculated first to
        check that there is enough space in the destination.
        If there is enough space then we start the copy of the files
        to their destination.
        Input:
            None
        Output:
            None"""
        self.copyButton.setEnabled(False)
        self.copyWorker.must_run = True
        self.connect(self.copyWorker,
                     SIGNAL("copyProgress(QString, QString, QString)"),
                     self.copy_progress, Qt.QueuedConnection)
        dest_dir = self.lblDestPath.text()
        if dest_dir == '':
            QMessageBox.critical(self,
                                 "Destination not set",
                                 "Please specify a destination path",
                                 WindowModility=True)
        else:
            copy_filelist = []
            for selection in self.treeView.selectedIndexes():
                indexItem = self.model.index(selection.row(), 0,
                                             selection.parent())
                copy_filelist.append(self.model.filePath(indexItem))
            if self.cbOWDest.isChecked():
                if self.rbOWEither.isChecked():
                    overwrite_option = 'either'
                elif self.rbOWLarger.isChecked():
                    overwrite_option = 'larger'
                elif self.rbOWNewer.isChecked():
                    overwrite_option = 'newer'
                else:
                    QMessageBox.critical(
                        self,
                        "Overwrite option missing",
                        """You did not select an overwrite option.""",
                        WindowModility=True)
                    self.copyButton.setEnabled(True)
                    return
            else:
                overwrite_option = None
            if not self.ckbxTrimDir.isChecked():
                flattencount = 0
            else:
                flattencount = self.trimdirCount.value()

            self.progress = QProgressDialog("Copy in progress.",
                                            "Cancel",
                                            0,
                                            100,
                                            modal=True)
            self.progress.canceled.connect(self.cancel_copy)
            self.progress.setWindowTitle('Copy Progress')
            var_values = {
                'destdir': dest_dir,
                'filelist': copy_filelist,
                'flattencount': flattencount,
                'overwrite_opt': overwrite_option
            }
            self.socket.send(json.dumps(var_values))
            self.copyWorker.start()
Example #17
0
class setupApp:
    def __init__(self, params):
        loader = QUiLoader()
        infile = QFile("gui/ui/Setup.ui")
        infile.open(QFile.ReadOnly)
        self.window = loader.load(infile, None)
        
        self.loadPrefs()
        
        self.window.quitButton.clicked.connect(self.closeApp)
        self.window.saveButton.clicked.connect(self.savePrefs)
        self.window.runButton.clicked.connect(self.runSV)
        
        self.splash = QProgressDialog("Loading", "Cancel", 0, 100, parent=None)
        self.splash.setWindowModality(Qt.WindowModal)
        self.splash.setAutoReset(False)
        self.splash.setAutoClose(False)
        self.splash.hide()
        self.canceled = False
        
        self.window.show()
        self.runningApp = None
    
    def loadPrefs(self):
        infile = open(PREFS_FILE,'r')
        self.window.textEdit.setPlainText(infile.read())
        infile.close()
    
    def savePrefs(self):
        outfile=open(PREFS_FILE,'w')
        outfile.write(self.window.textEdit.toPlainText())
        outfile.close()
    
    def showProgressWidget(self, estimate=100, message="Loading..."):
        self.splash.setLabelText(message)
        self.splash.setMaximum(estimate)
        self.splash.setValue(0)
        self.splash.show()
    
    def tickProgressWidget(self, numTicks=1, message=None):
        if self.canceled:
            return
        if message != None:
            self.splash.setLabelText(message)
        newValue = min(self.splash.maximum(),numTicks+self.splash.value())
        self.splash.setValue(newValue)
        self.canceled = self.splash.wasCanceled()
        return self.canceled
    
    def runSV(self, params=PREFS_FILE):
        self.savePrefs()
        self.window.hide()
        
        appPrefs = prefs.generateFromText(self.window.textEdit.toPlainText())
        
        self.showProgressWidget(appPrefs.maxTicks, "Loading files...")
        
        self.canceled = False
        vData = appPrefs.loadDataObjects(callback=self.tickProgressWidget)
        if self.canceled:
            self.splash.hide()
            self.window.show()
            return
        
        self.showProgressWidget(vData.estimateTicks(), "Writing files...")
        
        success = vData.dumpVcfFile(path='/Users/Home/Desktop/chr3-seq_parsed.vcf',callback=self.tickProgressWidget)
        if not success:
            self.splash.hide()
            self.window.show()
            return
        
        sys.exit(0)
        # TODO write to file
    
    def closeApp(self):
        self.window.reject()
Example #18
0
class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.build_dir_tree()
        self.setWindowIcon(QIcon('favicon.png'))
        self.actionAbout.triggered.connect(self.about)
        self.destButton.clicked.connect(self.destination_chooser)
        self.actionChoose_Destination.triggered.connect(self.destination_chooser)
        self.copyButton.clicked.connect(self.copy_files)
        self.actionStart_Copy.triggered.connect(self.copy_files)
        self.ckbxTrimDir.toggled.connect(self.update_table_view)
        self.treeView.expanded.connect(self.resize_tree_column)
        self.treeView.collapsed.connect(self.resize_tree_column)
        self.treeView.clicked.connect(self.update_table_view)
        self.trimdirCount.valueChanged.connect(self.update_table_view)

        self.listWidget.doubleClicked.connect(self.unselectItem)

        self.copyButton.setEnabled(False)
        self.lblTrimDir.setVisible(False)
        self.trimdirCount.setVisible(False)
        self.rbOWNewer.setVisible(False)
        self.rbOWLarger.setVisible(False)
        self.rbOWEither.setVisible(False)
        self.context = zmq.Context()
        self.socket = self.context.socket(zmq.PAIR)
        self.socket.bind("tcp://*:%s" % zmq_port)

        self.copyWorker = CopyWorker()
        self.connect(self.copyWorker, SIGNAL("copyComplete(QString, QString, QString, QString)"), self.copy_complete, Qt.QueuedConnection)
        self.connect(self.copyWorker, SIGNAL("spaceProblem(int, int)"), self.space_problem, Qt.QueuedConnection)

    def unselectItem(self, item):
        ##need to figure out how to remove from the model
        self.listWidget.takeItem(item.row())

    def copy_complete(self, filecount, filesize, runtime, run_seconds):
        self.progress.setValue(self.progress.maximum())
        transfer_rate = round((float(filesize) * 1024) / float(run_seconds), 3)
        filesize = round(float(filesize), 3)
        QMessageBox.information(self, "File Copy Complete",
            """Your file copy has been successfully completed.\n
            Files processed:\t%s\n
            Data copied:\t%sGB\n
            Total runtime:\t%s\n
            Transfer Rate:\t%sMB/Sec""" % (filecount, filesize, runtime, transfer_rate),
            WindowModility=True)
        self.copyButton.setEnabled(True)

    def space_problem(self, dirsize, filesize):
        """Display a dialog to the user advising that there is not enough space in the destination
        directory.
        Input:
            dirsize :   integer - amount of space available in the destination directory
            filesize:   integer - size of the selected files
        Output:
            None, dialog is displayed to the user."""
        ##TODO: Set the messagebox modal property to true
        required_space = (filesize / 1024.00 / 1024.00 / 1024.00) - (dirsize / 1024.00 / 1024.00 / 1024.00)
        QMessageBox.critical(self,
                             "Not enough space",
                             """You do not have enough space in your selected destination to complete this operation\n
                             %s more GB space required""" % required_space,
                             WindowModility=True)
        self.copyWorker.quit()
        self.copyButton.setEnabled(True)

    def build_dir_tree(self):
        """Add a directory tree listing to the QTreeView and set the root
        to the drive that it was run from.
        Input:
            None
        Output:
            None"""
        ##TODO: add linux support for the model root drive.
        self.model = QFileSystemModel(self)
        if sys.platform == 'win32':
            self.model.setRootPath(os.path.splitdrive(os.getcwd())[0])
        self.tree = self.treeView
        self.tree.setModel(self.model)
        self.tree.setAnimated(False)
        self.tree.setIndentation(20)
        self.tree.setSortingEnabled(True)

    def update_table_view(self):
        """Refresh listview with selected items in the treeView using
        the shared model.
        Input:
            None
        Output:
            None"""
        itemlist = [os.path.abspath(
            self.model.filePath(
                self.model.index(selection.row(),
                    0,
                    selection.parent()
                    )
                )
            )
            for selection in self.treeView.selectedIndexes()]
        self.listWidget.clear()
        self.listWidget.addItems(itemlist)

        nitemlist = []
        fileops = FileOperations()
        if not self.ckbxTrimDir.isChecked():
            flattencount = 0
        else:
            flattencount = self.trimdirCount.value()
        if self.lblDestPath.isEnabled():
            self.previewView.clear()
            for item in itemlist:
                nitemlist.append(fileops.get_dest_filepath(item, self.lblDestPath.text(), flattencount))
            self.previewView.addItems(nitemlist)
        else:
            self.previewView.clear()
            self.previewView.addItems(['No destination folder selected'])

        self.resize_tree_column()

    def resize_tree_column(self):
        """Resize the treeView column to fit the contents.
        Input:
            None
        Output:
            None"""
        self.treeView.resizeColumnToContents(0)

    def copy_files(self):
        """Initiate copy process. File size is calculated first to
        check that there is enough space in the destination.
        If there is enough space then we start the copy of the files
        to their destination.
        Input:
            None
        Output:
            None"""
        self.copyButton.setEnabled(False)
        self.copyWorker.must_run = True
        self.connect(self.copyWorker, SIGNAL("copyProgress(QString, QString, QString)"), self.copy_progress, Qt.QueuedConnection)
        dest_dir = self.lblDestPath.text()
        if dest_dir == '':
            QMessageBox.critical(self, "Destination not set", "Please specify a destination path", WindowModility=True)
        else:
            copy_filelist = []
            for selection in self.treeView.selectedIndexes():
                indexItem = self.model.index(selection.row(), 0, selection.parent())
                copy_filelist.append(self.model.filePath(indexItem))
            if self.cbOWDest.isChecked():
                if self.rbOWEither.isChecked():
                    overwrite_option = 'either'
                elif self.rbOWLarger.isChecked():
                    overwrite_option = 'larger'
                elif self.rbOWNewer.isChecked():
                    overwrite_option = 'newer'
                else:
                    QMessageBox.critical(self,
                        "Overwrite option missing",
                        """You did not select an overwrite option.""",
                        WindowModility=True)
                    self.copyButton.setEnabled(True)
                    return
            else:
                overwrite_option = None
            if not self.ckbxTrimDir.isChecked():
                flattencount = 0
            else:
                flattencount = self.trimdirCount.value()

            self.progress = QProgressDialog("Copy in progress.", "Cancel", 0, 100, modal=True)
            self.progress.canceled.connect(self.cancel_copy)
            self.progress.setWindowTitle('Copy Progress')
            var_values = {'destdir': dest_dir, 'filelist': copy_filelist, 'flattencount': flattencount, 'overwrite_opt': overwrite_option}
            self.socket.send(json.dumps(var_values))
            self.copyWorker.start()

    def copy_progress(self, percentage_complete, filecount, filecomplete):
        """Display the progress bar with a completed percentage.
        Input:
            percentage_complete :   integer - the amount complete in percent.
            filecount           :   integer - the total number of files being processed.
            filecomplete        :   integer - the number of files that have already been processed.
        Output:
            None, dialog is updated"""
        ##TODO: display the current transfer rate
        ##TODO: display the current file being transferred and possibly the progress thereof.
        ##Perhaps use the statusbar method for this
        self.progress.setValue(int(percentage_complete))

    def cancel_copy(self):
        """Slot for the cancel command on the progress dialog.
        The must_run variable of the copyWorker class is set to False to terminate the copy.
        Input:
            None
        Output:
            None"""
        self.copyWorker.must_run = False
        self.copyButton.setEnabled(True)

    def statusbar_msg(self, msg):
        """Update the statusbar on the bottom of the screen.
        Input:
            msg     : string - Message that you would like displayed on the form.
        Output:
            None
        """
        self.statusbar.clearMessage()
        self.statusbar.showMessage(msg)

    def destination_chooser(self):
        """Show folder chooser dialog and update lblDestPath with path selected.
        Input:
            None
        Output:
            None"""
        dialog = QFileDialog()
        dialog.setFileMode(QFileDialog.Directory)
        dialog.setOption(QFileDialog.ShowDirsOnly)
        dialog.exec_()
        self.lblDestPath.setEnabled(True)
        self.lblDestPath.setText(os.path.abspath(dialog.directory().absolutePath()))
        self.update_table_view()
        self.copyButton.setEnabled(True)

    def about(self):
        """Popup a box with about message.
        Input:
            None
        Output:
            None"""
        QMessageBox.about(self, "About MClub Mover",
                """This program is designed to help make the process of copying \
files from multiple directories much easier and simpler.\n
This software is provided as is with absolutely no warranties.""",
                WindowModility=True)
Example #19
0
    def getWorkingDialog(text):
        """
        Generates a working dialog object which blocks the UI.

        :param text: Text to display while working
        :return: The created working dialog widget
        """

        progressDialog = QProgressDialog(text,
                                         "",
                                         0,
                                         0,
                                         parent=Globals.ui.tabWidgetMain)

        progressDialog.setMinimumDuration(0)
        progressDialog.setMinimum(0)
        progressDialog.setMaximum(0)
        progressDialog.setRange(0, 0)

        progressDialog.setFixedSize(progressDialog.width(),
                                    progressDialog.height())

        # No cancel button <:
        progressDialog.setCancelButton(None)
        # No X button
        progressDialog.setWindowFlags(progressDialog.windowFlags()
                                      & ~QtCore.Qt.WindowCloseButtonHint)

        progressBar = progressDialog.findChild(QProgressBar)
        # :S:S
        progressBar.setMinimumWidth(progressDialog.width() + 20)

        return progressDialog
Example #20
0
def make_progress(msg,total_steps):
    progress = QProgressDialog(msg, None, 0, total_steps, None)
    progress.setWindowTitle("Horse")
    progress.setMinimumDuration(0)
    progress.setWindowModality(Qt.WindowModal)
    progress.setValue( progress.value() + 1)
    progress.show()
    return progress
Example #21
0
    def reload(self, order_overview_widget, all_ops, all_operations, sort=1):

        # mainlog.debug("reload...")
        progress = QProgressDialog(_("Collecting data..."), None, 0,
                                   len(all_ops) + 3, order_overview_widget)
        progress.setWindowTitle("Horse")
        progress.setMinimumDuration(0)
        progress.setWindowModality(Qt.WindowModal)
        progress.setValue(progress.value() + 1)
        progress.show()

        for i in self.items():
            self.removeItem(i)

        self.posts_offsets = dict()
        self.drawn_operations_data = dict()

        self.cursor = QGraphicsRectItem(0, 0, 50, 300)
        self.cursor.setBrush(QBrush(QColor(208, 208, 255, 255)))
        self.cursor.setPen(QPen(Qt.transparent))
        self.addItem(self.cursor)

        bar_width = 8
        bar_height = int(bar_width * 60.0 / 8.0)

        ascent = QFontMetrics(self.base_font).ascent()
        ascent_big = QFontMetrics(self.base_font_big).ascent()

        post_ops = {}

        # mainlog.debug("reload...2")

        # z = 0
        # for op,order_part,parts in all_operations:
        #     z = op.planned_hours
        #     z = order_part.deadline
        #     z = order_part.qty
        #     z = order_part.human_identifier

        # all_operations = map(lambda i:i[0],all_operations)

        y = 0
        for opdef in all_ops:
            progress.setValue(progress.value() + 1)

            operations = filter(
                lambda op: op.operation_definition_id == opdef.
                operation_definition_id, all_operations)

            # We're only interested in the effort/time that remains
            # to be put on an operation. We're only interested in
            # the future.

            # We want the oeprations that are either
            # - ongoing
            # - ready to start.
            # In all cases we're only interested in operations
            # that are "active"

            if sort == 1:
                operations = sorted(
                    operations, key=lambda op: op.deadline or date(3000, 1, 1))
            elif sort == 2:
                operations = sorted(
                    operations,
                    key=lambda op: op.planned_hours * op.qty - op.done_hours)
            else:
                # Don't sort
                pass

            maximum = 16.0  #float !
            small_hours = 0
            op_ndx = 0
            current_x = 50
            bar_drawn = False

            total_done_hours = total_estimated = 0

            # --------------------------------------------------------------
            # Started operations

            bars_line = BarsLine(16, bar_width, bar_height, current_x, y, self,
                                 order_overview_widget)
            total_hours_to_do = 0

            for op in filter(lambda op: op.done_hours > 0, operations):
                hours_to_do = max(
                    0, op.planned_hours * op.qty -
                    op.done_hours)  # max protects against reporting errors
                total_hours_to_do += hours_to_do

                total_estimated += op.planned_hours * op.qty
                total_done_hours += op.done_hours

                bars_line.add_bar(hours_to_do, QBrush(Qt.green),
                                  self._operation_hoover_description(op),
                                  False,
                                  None)  # op.production_file.order_part)

            # --------------------------------------------------------------
            bars_line_unstarted_operations = BarsLine(16, bar_width,
                                                      bar_height,
                                                      current_x + 30, y, self,
                                                      order_overview_widget)
            total_hours_to_do_on_unstarted_operations = 0
            for op in filter(lambda op: op.done_hours == 0, operations):

                hours_to_do = op.planned_hours * op.qty
                total_hours_to_do_on_unstarted_operations += hours_to_do

                total_estimated += hours_to_do

                bars_line_unstarted_operations.add_bar(
                    hours_to_do, QBrush(Qt.yellow),
                    self._operation_hoover_description(op), False,
                    None)  #op.production_file.order_part)

            y_start = y

            total = total_hours_to_do + total_hours_to_do_on_unstarted_operations

            if total > 0:

                self.drawn_operations_data[
                    opdef.operation_definition_id] = "{}h".format(
                        int(round(total_estimated)))

                gi = QGraphicsSimpleTextItem(
                    _("{} - Estimated to do : {}h; done : {}h").format(
                        opdef.description, int(round(total)),
                        int(round(total_done_hours))))
                gi.setFont(self.base_font_big)
                gi.setPos(0, y - gi.boundingRect().height())
                self.addItem(gi)

                th = gi.boundingRect().height()

                gi = QGraphicsLineItem(-ascent_big, y, 1024 + 2 * ascent_big,
                                       y)
                gi.setPen(QPen(Qt.black))
                self.addItem(gi)

                y += th
            else:
                continue

            y_bars = y

            if total_hours_to_do > 0:
                # There's something to draw

                head = QGraphicsSimpleTextItem(_("Started"))
                head.setFont(self.base_font)
                head.setPos(current_x, y)
                self.addItem(head)
                y += head.boundingRect().height()

                y += bar_height
                bars_line.set_start_pos(current_x, y)
                bars_line.finish_bar()

                foot = QGraphicsSimpleTextItem(
                    _("{}h").format(int(total_hours_to_do + 0.5)))
                foot.setFont(self.base_font)
                foot.setPos(current_x, y)
                self.addItem(foot)
                y += foot.boundingRect().height()

                current_x = max(current_x + bars_line.estimate_width(),
                                head.boundingRect().right(),
                                foot.boundingRect().right())

                bar_drawn = True

            if total_hours_to_do_on_unstarted_operations > 0:

                if bars_line_unstarted_operations.estimate_width(
                ) + current_x > 1200:
                    x = 50
                    y += ascent_big
                else:
                    y = y_bars
                    x = current_x + 50

                head = QGraphicsSimpleTextItem(_("Not started yet"))
                head.setFont(self.base_font)
                head.setPos(x, y)
                self.addItem(head)
                y += head.boundingRect().height()

                y += bar_height
                bars_line_unstarted_operations.set_start_pos(x, y)
                bars_line_unstarted_operations.finish_bar()

                foot = QGraphicsSimpleTextItem(
                    _("{}h").format(
                        int(total_hours_to_do_on_unstarted_operations + 0.5)))
                foot.setFont(self.base_font)
                foot.setPos(x, y)
                self.addItem(foot)
                y += foot.boundingRect().height()

                bar_drawn = True

            y += 3 * ascent_big

            r = self.sceneRect()
            self.posts_offsets[opdef.operation_definition_id] =  \
                QRectF(r.x() - 2*ascent_big, y_start - 1.5*ascent_big,
                       r.width() + 4*ascent_big, (y - ascent_big) - (y_start - 1.5*ascent_big) )
            y += ascent_big

        # mainlog.debug("reload...3")
        import functools
        max_width = functools.reduce(lambda acc, po: max(acc, po.width()),
                                     self.posts_offsets.values(), 0)
        map(lambda po: po.setWidth(max_width), self.posts_offsets.values())

        # for r in self.posts_offsets.values():
        #     gi = QGraphicsLineItem(r.x(),r.y(),r.x()+r.width(),r.y())
        #     gi.setPen(QPen(Qt.lightGray))
        #     self.addItem(gi)

        progress.close()
Example #22
0
File: gui.py Project: tinavas/FSERP
class Gui():
    """main gui class"""
    def __init__(self):
        self.mainwindow = QMainWindow()
        settings.get_settings()
        self.access = tuple(settings.access.items())
        self.progress = QProgressDialog("Setting up modules...", "cancel", 0,
                                        7, self.mainwindow)
        self.progress.setWindowTitle(
            QApplication.translate("MainWindow", str(settings.company), None,
                                   QApplication.UnicodeUTF8))

    def setup(self):
        """initializes the uio of the erp client"""
        self.progress.setFixedWidth(1000)
        self.progress.setCancelButton(None)
        # self.progress.setWindowModality(Qt.WindowModal)
        self.progress.setValue(1)
        self.mainwindow.setObjectName("MainWindow")
        self.mainwindow.resize(832, 668)
        self.mainwindow.setStyleSheet(
            "QToolBar{\n"
            "background: qlineargradient(x1:0, y1:0, x2:1, y2:1,\n"
            "stop:0 rgba(0,0,0),stop:1 rgb(162, 162, 162, 162));\n"
            "border: 0px;\n"
            "}\n"
            "QToolBar > QWidget{\n"
            "color:white;\n"
            "}\n"
            "QToolBar > QWidget:hover {\n"
            "background:transparent;\n"
            " }\n"
            "QToolBar > QWidget:checked {\n"
            "background:transparent;\n"
            " }\n"
            "#MainWindow{\n"
            "background: qlineargradient(x1:0, y1:0, x2:1, y2:1,\n"
            "stop:0 rgba(0,0,0),stop:1 rgb(162, 162, 162, 162));\n"
            "border: 0px;\n"
            "}\n"
            "")
        self.centralWidget = QWidget(self.mainwindow)
        self.centralWidget.setObjectName("centralWidget")
        self.gridLayout_2 = QGridLayout(self.centralWidget)
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.stackedWidget = QStackedWidget(self.centralWidget)
        self.stackedWidget.setStyleSheet("")
        self.stackedWidget.setObjectName("stackedWidget")
        self.shortcut = NewShortcut()
        scroll = QScrollArea()
        scroll.setWidget(self.shortcut.shortcut_setting)
        self.stackedWidget.addWidget(self.shortcut.shortcut_setting)
        self.home_page = QWidget()
        self.home_page.setObjectName("home_page")
        self.gridLayout = QGridLayout(self.home_page)
        self.gridLayout.setObjectName("gridLayout")
        self.billing_frame_2 = QFrame(self.home_page)
        self.billing_frame_2.setStyleSheet(
            "background-image:url(:/images/billing_frame.png);\n"
            "background-repeat: no-repeat;\n"
            "background-position: center;\n"
            "background-color:#6CBED2;")
        self.billing_frame_2.setFrameShape(QFrame.StyledPanel)
        self.billing_frame_2.setFrameShadow(QFrame.Raised)
        self.billing_frame_2.setObjectName("billing_frame_2")
        self.verticalLayout_4 = QVBoxLayout(self.billing_frame_2)
        self.verticalLayout_4.setObjectName("verticalLayout_4")
        spacerItem = QSpacerItem(20, 217, QSizePolicy.Minimum,
                                 QSizePolicy.Expanding)
        self.verticalLayout_4.addItem(spacerItem)
        self.label_10 = QLabel(self.billing_frame_2)
        self.label_10.setStyleSheet("background:transparent;")
        self.label_10.setObjectName("label_10")
        self.verticalLayout_4.addWidget(self.label_10)
        self.gridLayout.addWidget(self.billing_frame_2, 0, 1, 1, 1)
        self.employee_frame_3 = QFrame(self.home_page)
        self.employee_frame_3.setStyleSheet(
            "background-image:url(:/images/employee_frame.png);\n"
            "background-repeat: no-repeat;\n"
            "background-position: center;\n"
            "background-color:#0099CC;")
        self.employee_frame_3.setFrameShape(QFrame.StyledPanel)
        self.employee_frame_3.setFrameShadow(QFrame.Raised)
        self.employee_frame_3.setObjectName("employee_frame_3")
        self.verticalLayout_5 = QVBoxLayout(self.employee_frame_3)
        self.verticalLayout_5.setObjectName("verticalLayout_5")
        spacerItem1 = QSpacerItem(20, 217, QSizePolicy.Minimum,
                                  QSizePolicy.Expanding)
        self.verticalLayout_5.addItem(spacerItem1)
        self.label_11 = QLabel(self.employee_frame_3)
        self.label_11.setStyleSheet("background:transparent;")
        self.label_11.setObjectName("label_11")
        self.verticalLayout_5.addWidget(self.label_11)
        self.gridLayout.addWidget(self.employee_frame_3, 0, 2, 1, 1)
        self.menu_frame_4 = QFrame(self.home_page)
        self.menu_frame_4.setStyleSheet(
            "background-image:url(:/images/menu_frame.png);\n"
            "background-repeat: no-repeat;\n"
            "background-position: center;\n"
            "background-color:#297ACC;")
        self.menu_frame_4.setFrameShape(QFrame.StyledPanel)
        self.menu_frame_4.setFrameShadow(QFrame.Raised)
        self.menu_frame_4.setObjectName("menu_frame_4")
        self.verticalLayout_3 = QVBoxLayout(self.menu_frame_4)
        self.verticalLayout_3.setObjectName("verticalLayout_3")
        spacerItem2 = QSpacerItem(20, 216, QSizePolicy.Minimum,
                                  QSizePolicy.Expanding)
        self.verticalLayout_3.addItem(spacerItem2)
        self.label_12 = QLabel(self.menu_frame_4)
        self.label_12.setStyleSheet("background:transparent;")
        self.label_12.setObjectName("label_12")
        self.verticalLayout_3.addWidget(self.label_12)
        self.gridLayout.addWidget(self.menu_frame_4, 1, 0, 1, 1)
        self.report_frame_5 = QFrame(self.home_page)
        self.report_frame_5.setStyleSheet(
            "background-image:url(:/images/report_frame.png);\n"
            "background-repeat: no-repeat;\n"
            "background-position: center;\n"
            "background-color:#006BB2;")
        self.report_frame_5.setFrameShape(QFrame.StyledPanel)
        self.report_frame_5.setFrameShadow(QFrame.Raised)
        self.report_frame_5.setObjectName("report_frame_5")
        self.verticalLayout_6 = QVBoxLayout(self.report_frame_5)
        self.verticalLayout_6.setObjectName("verticalLayout_6")
        spacerItem3 = QSpacerItem(20, 216, QSizePolicy.Minimum,
                                  QSizePolicy.Expanding)
        self.verticalLayout_6.addItem(spacerItem3)
        self.label_13 = QLabel(self.report_frame_5)
        self.label_13.setStyleSheet("background:transparent;")
        self.label_13.setObjectName("label_13")
        self.verticalLayout_6.addWidget(self.label_13)
        self.gridLayout.addWidget(self.report_frame_5, 1, 1, 1, 1)
        self.waste_frame_6 = QFrame(self.home_page)
        self.waste_frame_6.setStyleSheet(
            "background-image:url(:/images/waste_frame.png);\n"
            "background-repeat: no-repeat;\n"
            "background-position: center;\n"
            "background-color:#003D7A;")
        self.waste_frame_6.setFrameShape(QFrame.StyledPanel)
        self.waste_frame_6.setFrameShadow(QFrame.Raised)
        self.waste_frame_6.setObjectName("waste_frame_6")
        self.verticalLayout_7 = QVBoxLayout(self.waste_frame_6)
        self.verticalLayout_7.setObjectName("verticalLayout_7")
        spacerItem4 = QSpacerItem(20, 216, QSizePolicy.Minimum,
                                  QSizePolicy.Expanding)
        self.verticalLayout_7.addItem(spacerItem4)
        self.label_14 = QLabel(self.waste_frame_6)
        self.label_14.setStyleSheet("background:transparent;")
        self.label_14.setObjectName("label_14")
        self.verticalLayout_7.addWidget(self.label_14)
        self.gridLayout.addWidget(self.waste_frame_6, 1, 2, 1, 1)
        self.inventory_frame_1 = QFrame(self.home_page)
        self.inventory_frame_1.setStyleSheet(
            "background-image:url(:/images/inventory_frame.png);\n"
            "background-repeat: no-repeat;\n"
            "background-position: center;\n"
            "background-color:#ADEBFF;")
        self.inventory_frame_1.setFrameShape(QFrame.StyledPanel)
        self.inventory_frame_1.setFrameShadow(QFrame.Raised)
        self.inventory_frame_1.setObjectName("inventory_frame_1")
        self.verticalLayout_2 = QVBoxLayout(self.inventory_frame_1)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        spacerItem5 = QSpacerItem(20, 217, QSizePolicy.Minimum,
                                  QSizePolicy.Expanding)
        self.verticalLayout_2.addItem(spacerItem5)
        self.label_9 = QLabel(self.inventory_frame_1)
        self.label_9.setStyleSheet("background:transparent;")
        self.label_9.setObjectName("label_9")
        self.verticalLayout_2.addWidget(self.label_9)
        self.gridLayout.addWidget(self.inventory_frame_1, 0, 0, 1, 1)
        self.stackedWidget.addWidget(self.home_page)
        self.detail_page = QWidget()
        self.detail_page.setObjectName("detail_page")
        self.horizontalLayout_2 = QHBoxLayout(self.detail_page)
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.main_tabWidget = QTabWidget(self.detail_page)
        self.main_tabWidget.setAutoFillBackground(False)
        self.main_tabWidget.setStyleSheet("")
        self.main_tabWidget.setTabPosition(QTabWidget.West)
        self.main_tabWidget.setIconSize(QSize(60, 60))
        self.main_tabWidget.setElideMode(Qt.ElideNone)
        self.main_tabWidget.setObjectName("main_tabWidget")
        ##initializes the tabs
        self.add_tabs()
        self.main_tabWidget.setFocusPolicy(Qt.StrongFocus)
        self.main_tabWidget.focusInEvent = self.change_focus
        self.main_tabWidget.currentChanged.connect(self.change_focus)
        self.stackedWidget.currentChanged.connect(self.change_focus)
        ######
        self.horizontalLayout_2.addWidget(self.main_tabWidget)
        self.stackedWidget.addWidget(self.detail_page)
        if ('Admin', True) in self.access:
            self.stackedWidget.addWidget(Admin(self.mainwindow))
        notification = NotificationTab()
        tab = notification.notificationTab_tab_4
        tab.custom_class_object = notification  # class_object is used to access the api through the
        self.stackedWidget.addWidget(tab)
        self.gridLayout_2.addWidget(self.stackedWidget, 0, 0, 1, 1)
        self.mainwindow.setCentralWidget(self.centralWidget)
        self.menuBar = QMenuBar(self.mainwindow)
        self.menuBar.setGeometry(QRect(0, 0, 832, 29))
        self.menuBar.setObjectName("menuBar")
        self.mainwindow.setMenuBar(self.menuBar)
        self.mainToolBar = QToolBar(self.mainwindow)
        self.mainToolBar.setLayoutDirection(Qt.RightToLeft)
        self.mainToolBar.setStyleSheet("")
        self.mainToolBar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        self.mainToolBar.setObjectName("mainToolBar")
        self.mainwindow.addToolBar(Qt.TopToolBarArea, self.mainToolBar)
        self.statusBar = QStatusBar(self.mainwindow)
        self.statusBar.setObjectName("statusBar")
        self.mainwindow.setStatusBar(self.statusBar)
        self.toolBar = QToolBar(self.mainwindow)
        self.toolBar.setLayoutDirection(Qt.RightToLeft)
        self.toolBar.setStyleSheet("")
        self.toolBar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        self.toolBar.setObjectName("toolBar")
        self.mainwindow.addToolBar(Qt.TopToolBarArea, self.toolBar)
        self.actionNotification = QAction(self.mainwindow)
        self.actionNotification.setCheckable(True)
        self.actionNotification.setChecked(False)
        self.actionNotification.setEnabled(True)
        icon6 = QIcon()
        icon6.addPixmap(QPixmap(":/images/notification.png"), QIcon.Normal,
                        QIcon.Off)
        self.actionNotification.setIcon(icon6)
        self.actionNotification.setAutoRepeat(True)
        self.actionNotification.setVisible(True)
        self.actionNotification.setIconVisibleInMenu(False)
        self.actionNotification.setObjectName("actionNotification")
        self.actionNotification
        self.actionAdmin = QAction(self.mainwindow)
        # self.actionAdmin.setCheckable(True)
        icon7 = QIcon()
        icon7.addPixmap(QPixmap(":/images/admin.png"), QIcon.Normal, QIcon.Off)
        self.actionAdmin.setIcon(icon7)
        self.actionAdmin.setObjectName("actionAdmin")
        self.actionRefresh = QAction(self.mainwindow)
        icon8 = QIcon()
        icon8.addPixmap(QPixmap(":/images/refresh.png"), QIcon.Normal,
                        QIcon.Off)
        self.actionRefresh.setIcon(icon8)
        self.actionRefresh.setObjectName("actionRefresh")
        self.actionHome = QAction(self.mainwindow)
        # self.actionHome.setCheckable(True)
        icon9 = QIcon()
        icon9.addPixmap(QPixmap(":/images/home.png"), QIcon.Normal, QIcon.Off)
        self.actionHome.setIcon(icon9)
        self.actionHome.setObjectName("actionHome")
        self.actionSettings = QAction(self.mainwindow)
        icon10 = QIcon()
        icon10.addPixmap(QPixmap(":/images/settings.png"), QIcon.Normal,
                         QIcon.Off)
        self.actionSettings.setIcon(icon10)
        self.actionSettings.setObjectName("actionRefresh")
        self.toolBar.addAction(self.actionNotification)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.actionAdmin)
        if ('Admin', True) in self.access:
            self.toolBar.addSeparator()
        else:
            self.actionAdmin.setVisible(False)
        self.toolBar.addAction(self.actionHome)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.actionRefresh)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.actionSettings)
        ##retranslates
        self.mainwindow.setWindowTitle(
            QApplication.translate("MainWindow", settings.company, None,
                                   QApplication.UnicodeUTF8))
        self.label_10.setText(
            QApplication.translate(
                "MainWindow",
                "<html><head/><body><p align=\"center\">BILLING</p></body></html>",
                None, QApplication.UnicodeUTF8))
        self.label_11.setText(
            QApplication.translate(
                "MainWindow",
                "<html><head/><body><p align=\"center\">EMPLOYEE</p></body></html>",
                None, QApplication.UnicodeUTF8))
        self.label_12.setText(
            QApplication.translate(
                "MainWindow",
                "<html><head/><body><p align=\"center\">MENU</p></body></html>",
                None, QApplication.UnicodeUTF8))
        self.label_13.setText(
            QApplication.translate(
                "MainWindow",
                "<html><head/><body><p align=\"center\">REPORT</p></body></html>",
                None, QApplication.UnicodeUTF8))
        self.label_14.setText(
            QApplication.translate(
                "MainWindow",
                "<html><head/><body><p align=\"center\">WASTE</p></body></html>",
                None, QApplication.UnicodeUTF8))
        self.label_9.setText(
            QApplication.translate(
                "MainWindow",
                "<html><head/><body><p align=\"center\">INVENTORY</p></body></html>",
                None, QApplication.UnicodeUTF8))
        self.inventory_frame_1.setToolTip(
            QApplication.translate("MainWindow", "Go to the Inventory Tab",
                                   None, QApplication.UnicodeUTF8))
        self.billing_frame_2.setToolTip(
            QApplication.translate("MainWindow", "Go to the Billing Tab", None,
                                   QApplication.UnicodeUTF8))
        self.employee_frame_3.setToolTip(
            QApplication.translate("MainWindow", "Go to the Employee Tab",
                                   None, QApplication.UnicodeUTF8))
        self.menu_frame_4.setToolTip(
            QApplication.translate("MainWindow", "Go to the Menu Tab", None,
                                   QApplication.UnicodeUTF8))
        self.report_frame_5.setToolTip(
            QApplication.translate("MainWindow", "Go to the Report Tab", None,
                                   QApplication.UnicodeUTF8))
        self.waste_frame_6.setToolTip(
            QApplication.translate("MainWindow", "Go to the Waste Tab", None,
                                   QApplication.UnicodeUTF8))
        self.toolBar.setWindowTitle(
            QApplication.translate("MainWindow", "toolBar", None,
                                   QApplication.UnicodeUTF8))
        self.actionNotification.setText("&&Notification")
        # QApplication.translate("MainWindow", "&Notification", None, QApplication.UnicodeUTF8))
        self.actionNotification.setToolTip(
            QApplication.translate("MainWindow",
                                   "Click to see new notifications", None,
                                   QApplication.UnicodeUTF8))
        # self.actionNotification.setShortcut(
        # QApplication.translate("MainWindow", "Ctrl+Shift+N", None, QApplication.UnicodeUTF8))
        self.actionAdmin.setText('&&Admin')
        # QApplication.translate("MainWindow", "Admin", None, QApplication.UnicodeUTF8))
        self.actionAdmin.setToolTip(
            QApplication.translate("MainWindow",
                                   "Click to go to admin interface", None,
                                   QApplication.UnicodeUTF8))
        # self.actionAdmin.setShortcut(
        # QApplication.translate("MainWindow", "Ctrl+Shift+A", None, QApplication.UnicodeUTF8))
        self.actionRefresh.setText("&&Refresh")
        # QApplication.translate("MainWindow", "Refresh", None, QApplication.UnicodeUTF8))
        self.actionRefresh.setToolTip(
            QApplication.translate("MainWindow",
                                   "refreshes the data from the server", None,
                                   QApplication.UnicodeUTF8))
        # self.actionRefresh.setShortcut(
        # QApplication.translate("MainWindow", "Ctrl+Shift+R", None, QApplication.UnicodeUTF8))
        self.actionHome.setText('&&Home')
        # QApplication.translate("MainWindow", "Home", None, QApplication.UnicodeUTF8))
        self.actionHome.setToolTip(
            QApplication.translate("MainWindow", "Go back to the home screen",
                                   None, QApplication.UnicodeUTF8))
        self.actionSettings.setText('&&Settings')
        # QApplication.translate("MainWindow", "Settings", None, QApplication.UnicodeUTF8))
        self.actionSettings.setToolTip(
            QApplication.translate("MainWindow", "Go to the settings panel",
                                   None, QApplication.UnicodeUTF8))
        # self.actionHome.setShortcut(
        #     QApplication.translate("MainWindow", "Ctrl+Shift+H", None, QApplication.UnicodeUTF8))
        self.stackedWidget.setCurrentIndex(1)
        self.main_tabWidget.setCurrentIndex(0)

        self.ob = self.main_tabWidget.tabBar()
        # self.add_tool_tip(self.ob) todo avoided due to segmentation fault error, left for future fixes
        self.tb = EventHandlerForTabBar()
        self.ob.installEventFilter(self.tb)

        QMetaObject.connectSlotsByName(self.mainwindow)

    def add_tabs(self):
        """
        adds new tabs
        """
        global logger
        if ('Inventory', True) in self.access:
            logger.info('initiating Inventory')
            icon = QIcon()
            icon.addPixmap(QPixmap(":/images/inventory.png"), QIcon.Normal,
                           QIcon.Off)
            from inventory.inventory import Inventory

            inventory = Inventory()
            # inventory.inventory_tab_1.setToolTip("Inventory Section")
            self.main_tabWidget.addTab(inventory.inventory_tab_1, icon, "")
            inventory.inventory_detail_tabWidget.setCurrentIndex(0)
        else:
            self.inventory_frame_1.setVisible(False)
        self.progress.setLabelText('Inventory Done....')
        self.progress.setValue(2)

        if ('Billing', True) in self.access:
            logger.info('initiating Billing')
            icon1 = QIcon()
            icon1.addPixmap(QPixmap(":/images/billing.png"), QIcon.Normal,
                            QIcon.Off)
            from billing.billing import Billing

            bill = Billing()
            # bill.billing_tab_2.setToolTip("Billing Section")
            self.main_tabWidget.addTab(bill.billing_tab_2, icon1, "")
            bill.billing_detail_tabWidget.setCurrentIndex(0)
        else:
            self.billing_frame_2.setVisible(False)
        self.progress.setLabelText('Billing Done...')
        self.progress.setValue(3)

        if ('Employee', True) in self.access:
            logger.info('initiating Employee')
            icon2 = QIcon()
            icon2.addPixmap(QPixmap(":/images/employee.png"), QIcon.Normal,
                            QIcon.Off)
            from employee.employee import Employee

            employee = Employee()
            # employee.employee_tab_3.setToolTip("Employee Section")
            self.main_tabWidget.addTab(employee.employee_tab_3, icon2, "")
            employee.employee_detail_tabWidget.setCurrentIndex(0)
        else:
            self.employee_frame_3.setVisible(False)
        self.progress.setLabelText('Employee Done...')
        self.progress.setValue(4)

        if ('Menu', True) in self.access:
            logger.info('initiating Menu')
            icon3 = QIcon()
            icon3.addPixmap(QPixmap(":/images/menu.png"), QIcon.Normal,
                            QIcon.Off)
            from menu.menu import Menu

            menu = Menu()
            # menu.menu_tab_4.setToolTip("Menu Section")
            self.main_tabWidget.addTab(menu.menu_tab_4, icon3, "")
            menu.menu_detail_tabWidget.setCurrentIndex(0)
        else:
            self.menu_frame_4.setVisible(False)
        self.progress.setLabelText('Menu Done....')
        self.progress.setValue(5)

        if ('Report', True) in self.access:
            logger.info('initiating Report')
            icon4 = QIcon()
            icon4.addPixmap(QPixmap(":/images/report.png"), QIcon.Normal,
                            QIcon.Off)
            from report.report import Report

            report = Report()
            # report.report_tab_5.setToolTip("Report Section")
            self.main_tabWidget.addTab(report.report_tab_5, icon4, "")
            report.report_detail_tabWidget.setCurrentIndex(0)
        else:
            self.report_frame_5.setVisible(False)
        self.progress.setLabelText('Report Done....')
        self.progress.setValue(6)

        if ('Waste', True) in self.access:
            logger.info('initiating Waste')
            icon5 = QIcon()
            icon5.addPixmap(QPixmap(":/images/waste.png"), QIcon.Normal,
                            QIcon.Off)
            from waste.waste import Waste

            waste = Waste()
            # waste.waste_tab_6.setToolTip("Waste Section")
            self.main_tabWidget.addTab(waste.waste_tab_6, icon5, "")
            waste.waste_detail_tabWidget.setCurrentIndex(0)
        else:
            self.waste_frame_6.setVisible(False)
        self.progress.setLabelText('Waste Done....')
        self.progress.setValue(7)

    def change_focus(self, event=None):
        """
        focus method to set focus to a tab to initialize the corresponding events of the tab
        """
        wid = self.main_tabWidget.currentWidget()
        if wid:
            if wid.isVisible():
                # print wid.objectName()
                # print '1y'
                wid.setFocus()

    def add_tool_tip(
        self, ob
    ):  # todo not working causing segmentation fault, avoided calling this function
        """
        method to add tool tip to the tabs
        :param ob: Tab bar
        """
        obj = ob
        count = obj.count()
        hardcode = {
            0: 'Inventory Section',
            1: "Billing Section",
            2: "Employee Section",
            3: "Menu Section",
            4: "Report Section",
            5: "Waste Section"
        }
        for i in range(count):
            obj.setTabToolTip(i, hardcode[i])
 def go(self):
     global visWindow
     for k in Pedigree.REQUIRED_KEYS.keys():
         t = self.overrides[k].currentText()
         if t == '':
             self.displayError("%s header is required." % k)
             return
         elif not t in self.header:
             self.displayError("%s doesn't exist in the input file." % t)
             return
         Pedigree.REQUIRED_KEYS[k] = t
     for k in Pedigree.RESERVED_KEYS.keys():
         t = self.overrides[k].currentText()
         if self.window.programBox.currentText() == 'vis':
             if t == '':
                 self.displayError("%s header is required." % k)
                 return
             elif not t in self.header:
                 self.displayError("%s doesn't exist in the input file." % t)
                 return
         else:
             if t == '':
                 t = k
         Pedigree.RESERVED_KEYS[k] = t
     
     try:
         if self.window.programBox.currentText() == 'vis':
             fileName = self.window.inputField.text()
             if fileName.lower().endswith('.gexf') or fileName.lower().endswith('.json'):
                 raise Exception('.gexf and .json formats are not supported for the vis program. Use calculateD to create a .dat file.')
             ped = Pedigree(fileName, countAndCalculate=False, zeroMissing=self.window.zeroMissingBox.isChecked())
             from resources.main_app import App
             self.window.hide()
             visWindow = App(ped)
             self.window.close()
         else:
             progress = QProgressDialog(u"Running...", u"Cancel", 0, NUM_TICKS, parent=None)
             progress.setWindowModality(Qt.WindowModal)
             progress.show()
             
             def tick(newMessage=None, increment=1):
                 if progress.wasCanceled():
                     raise cancelException('Cancel clicked.')
                 newValue = min(progress.maximum(),progress.value()+increment)
                 progress.setValue(newValue)
                 if newMessage != None:
                     progress.setLabelText(newMessage)
                 return True
             
             ped = Pedigree(self.window.inputField.text(), countAndCalculate=True, zeroMissing=self.window.zeroMissingBox.isChecked(), tickFunction=tick, numTicks=NUM_TICKS)
             
             progress.setLabelText('Writing File...')
             extension = os.path.splitext(self.window.outputField.text())[1].lower()
             if extension == '.gexf':
                 edgeTypes = Pedigree.defaultEdgeTypes()
                 nodeAttributeTypes = Pedigree.defaultNodeAttributeTypes()
                 nodeAttributeTypes['is_root'] = gexf_node_attribute_mapper('is_root', attrType=gexf_node_attribute_mapper.BOOLEAN, defaultValue=False, validValues=[False,True])
                 ped.write_gexf(self.window.outputField.text(), edgeTypes, nodeAttributeTypes)
             elif extension == '.json':
                 ped.write_json(self.window.outputField.text())
             else:
                 ped.write_egopama(self.window.outputField.text())
             
             progress.close()
             
             self.window.inputField.setText(self.window.outputField.text())
             self.window.outputField.setText("")
             self.window.programBox.setCurrentIndex(1)
     except Exception, e:
         if not isinstance(e, cancelException):
             self.displayError("An unexpected error occurred.",traceback.format_exc())