Ejemplo n.º 1
0
 def outputCustomPlatesAll(self):
     """Outputs coloured platesheets in a format given by a dialog."""
     fileName = self.getOutputFileName("results-all")
     if fileName != "":
         results = self.tabs.getAllResultsTable()
         results = ResultsTable(results)
         labels = results.getLabels()
         labels, ok = GetPlateLabels.run(labels)
         if ok:
             pass
Ejemplo n.º 2
0
 def outputForEbrida(self):
     """Outputs an EBrida spreadsheet of results for the active screening tab."""
     fileName = self.getOutputFileName("ebrida")
     if fileName != "":
         results = self.tabs.getScreenResultsTable()
         results = ResultsTable(results)
         results = results.ebridaResults()
         writer = pd.ExcelWriter(fileName + ".xls")
         results.to_excel(writer, "Sheet1", index=False)
         writer.save()
Ejemplo n.º 3
0
 def outputForKeaProcess(self):
     """Outputs a Kea uploadable spreadsheet for the active screening tab."""
     fileName = self.getOutputFileName("process-kea")
     if fileName != "":
         results = self.tabs.getScreenResultsTable()
         results = ResultsTable(results)
         results = results.keaProcessRun()
         writer = pd.ExcelWriter(fileName + ".xls")
         results.to_excel(writer, "Sheet1", index=False)
         writer.save()
Ejemplo n.º 4
0
    def __init__(self):
        super().__init__()

        self.setTitle("Install Packages")
        self.setSubTitle(
            "Specify the packages you want to install into the virtual "
            "environment. Right-click on the item you want to install. "
            "You can install as many packages as you need. When finished "
            "click next.")

        self.console = ConsoleDialog()

        #]===================================================================[#
        #] PAGE CONTENT [#===================================================[#
        #]===================================================================[#

        grid_layout = QGridLayout(self)

        pkg_name_label = QLabel("Package &name:")
        self.pkg_name_line = QLineEdit()
        pkg_name_label.setBuddy(self.pkg_name_line)

        self.search_button = QPushButton("&Search",
                                         clicked=self.pop_results_table)

        # results table
        self.results_table = ResultsTable(
            selectionBehavior=QAbstractItemView.SelectRows,
            editTriggers=QAbstractItemView.NoEditTriggers,
            alternatingRowColors=True,
            sortingEnabled=True,
            doubleClicked=self.install_package,
            context_triggered=self.install_package  # signal
        )

        # adjust vertical headers
        v_header = self.results_table.verticalHeader()
        v_header.setDefaultSectionSize(28)
        v_header.hide()

        # adjust horizontal headers
        h_header = self.results_table.horizontalHeader()
        h_header.setDefaultAlignment(Qt.AlignLeft)
        h_header.setDefaultSectionSize(120)
        h_header.setStretchLastSection(True)
        h_header.setSectionResizeMode(QHeaderView.ResizeToContents)

        # item model
        self.results_model = QStandardItemModel(0, 2, self)
        self.results_table.setModel(self.results_model)

        grid_layout.addWidget(pkg_name_label, 0, 0, 1, 1)
        grid_layout.addWidget(self.pkg_name_line, 0, 1, 1, 1)
        grid_layout.addWidget(self.search_button, 0, 2, 1, 1)
        grid_layout.addWidget(self.results_table, 1, 0, 1, 3)
Ejemplo n.º 5
0
 def outputColouredPlatesAllGeneral(self, suffix, kea):
     """Outputs coloured platesheets for all rounds of screening."""
     fileName = self.getOutputFileName(suffix)
     if fileName != "":
         results = self.tabs.getAllResultsTable()
         results = ResultsTable(results)
         labels = results.getLabels()
         labels, ok = GetPlateLabels.run(labels)
         if ok:
             results.setLabels(labels)
             workBook = Workbook()
             addAllResultsTable(workBook, results, kea, self.markerdata, self.colours)
             addMarkerSheets(
                 workBook,
                 results,
                 kea,
                 self.markerdata,
                 self.markernotes,
                 self.colours,
                 self.var["images"],
                 self.validated,
             )
             addPlateSheets(workBook, results, kea, self.markerdata, self.colours)
             workBook.save(fileName + ".xlsx")
Ejemplo n.º 6
0
def results(request):
    #region GET
    if request.method == 'GET':
        queryset = ResultModel.objects.all()

        if not queryset.exists():
            request.session.update(
                dict(error_message='No Results Available Yet'))
            return redirect('home')
    #endregion
    #region POST
    if request.method == 'POST':
        query = request.POST.get('search')

        queryset = ResultModel.objects.filter(winning_address=query) | ResultModel.objects.filter(winning_deposit=query)\
                  | ResultModel.objects.filter(losing_address=query) | ResultModel.objects.filter(losing_deposit=query)\
                  | ResultModel.objects.filter(txid=query)
    #endregion
    #region RETURN
    if queryset.exists():
        queryset = queryset.order_by('-id')
        data_source = ModelDataSource(
            queryset[:100], fields=['id', 'winning_deposit', 'losing_deposit'])
        chart = flot.LineChart(data_source)

        form = ResultsSearchForm()
        table = ResultsTable(queryset)
        RequestConfig(request, paginate=dict(per_page=100)).configure(table)

        html_dtc = dict(table=table, form=form, chart=chart)

        error_message = request.session.get('error_message', False)
        if error_message:
            html_dtc.update(dict(error_message=error_message))
            del request.session['error_message']

        html_dtc.update(csrf(request))

        return render(request, 'chikun/results.html', html_dtc)

    request.session.update(dict(error_message='No Result Found'))
    return redirect('results')
Ejemplo n.º 7
0
class InstallPackages(QWizardPage):
    """
    Install packages via Pip into the created virtual environment.
    """
    def __init__(self):
        super().__init__()

        self.setTitle("Install Packages")
        self.setSubTitle(
            "Specify the packages you want to install into the virtual "
            "environment. Right-click on the item you want to install. "
            "You can install as many packages as you need. When finished "
            "click next.")

        self.console = ConsoleDialog()

        #]===================================================================[#
        #] PAGE CONTENT [#===================================================[#
        #]===================================================================[#

        grid_layout = QGridLayout(self)

        pkg_name_label = QLabel("Package &name:")
        self.pkg_name_line = QLineEdit()
        pkg_name_label.setBuddy(self.pkg_name_line)

        self.search_button = QPushButton("&Search",
                                         clicked=self.pop_results_table)

        # results table
        self.results_table = ResultsTable(
            selectionBehavior=QAbstractItemView.SelectRows,
            editTriggers=QAbstractItemView.NoEditTriggers,
            alternatingRowColors=True,
            sortingEnabled=True,
            doubleClicked=self.install_package,
            context_triggered=self.install_package  # signal
        )

        # adjust vertical headers
        v_header = self.results_table.verticalHeader()
        v_header.setDefaultSectionSize(28)
        v_header.hide()

        # adjust horizontal headers
        h_header = self.results_table.horizontalHeader()
        h_header.setDefaultAlignment(Qt.AlignLeft)
        h_header.setDefaultSectionSize(120)
        h_header.setStretchLastSection(True)
        h_header.setSectionResizeMode(QHeaderView.ResizeToContents)

        # item model
        self.results_model = QStandardItemModel(0, 2, self)
        self.results_table.setModel(self.results_model)

        grid_layout.addWidget(pkg_name_label, 0, 0, 1, 1)
        grid_layout.addWidget(self.pkg_name_line, 0, 1, 1, 1)
        grid_layout.addWidget(self.search_button, 0, 2, 1, 1)
        grid_layout.addWidget(self.results_table, 1, 0, 1, 3)

    def initializePage(self):
        self.python_version = self.field("python_version")
        self.python_path = self.field("python_path")
        self.venv_name = self.field("venv_name")
        self.venv_location = self.field("venv_location")
        self.requirements = self.field("requirements")

        # clear all inputs and contents
        self.results_model.clear()
        self.pkg_name_line.clear()
        self.pkg_name_line.setFocus(True)

        # set text in column headers
        self.results_model.setHorizontalHeaderLabels(
            ["Name", "Version", "Description"])

        # remove focus from 'next' button
        QTimer.singleShot(0, lambda: self.next_button.setDefault(False))

        # set focus on 'search' button
        QTimer.singleShot(0, lambda: self.search_button.setDefault(True))

        # disable 'back' button
        back_button = self.wizard().button(QWizard.BackButton)
        QTimer.singleShot(0, lambda: back_button.setEnabled(False))

        if self.wizard().basic_settings.with_pip_check_box.isChecked():
            # connect 'next' button to self.save_requirements()
            self.next_button = self.wizard().button(QWizard.NextButton)
            self.next_button.disconnect()
            self.next_button.clicked.connect(self.save_requirements)

        # run the installer if self.requirements holds a str
        if len(self.requirements) > 0:
            try:
                creator.fix_requirements(self.requirements)
            except FileNotFoundError:
                pass  # the gui will show an error message
            self.install_requirements()

    def install_requirements(self):
        """Install the packages from the specified requirements file.
        """
        self.setEnabled(False)

        self.console.setWindowTitle("Creating environment")
        logger.info("Creating environment...")

        # open the console when recieving signal from manager
        self.manager = PipManager(self.venv_location, f"'{self.venv_name}'")
        self.manager.started.connect(self.console.exec_)

        # start installing packages from requirements file
        #print(f"[PROCESS]: Installing packages from '{self.requirements}'")
        self.manager.run_pip(creator.cmds[0],
                             [creator.opts[1], f"'{self.requirements}'"])

        # display the updated output
        self.manager.textChanged.connect(self.console.update_status)

        # show info dialog
        self.manager.failed.connect(self.console.finish_fail)
        self.manager.failed.connect(self.console.close)

        # clear the contents when closing console
        if self.console.close:
            self.console.console_window.clear()

        self.setEnabled(True)

    def pop_results_table(self):
        """Refresh the results table.
        """
        search_item = self.pkg_name_line.text()

        self.results_model.setRowCount(0)

        for info in get_data.get_package_infos(search_item):
            self.results_model.insertRow(0)

            for i, text in enumerate(
                (info.pkg_name, info.pkg_version, info.pkg_summary)):
                self.results_model.setItem(0, i, QStandardItem(text))

        if not get_data.get_package_infos(search_item):
            logger.debug(f"No matches for '{search_item}'")
            QMessageBox.information(self, "No result",
                                    f"No result matching '{search_item}'.\n")

    def install_package(self):
        """
        Get the name of the selected item from the results table. Ask user
        for confirmation before installing. If user confirmes, install the
        selected package into the created virtual environment, else abort.
        """
        indexes = self.results_table.selectionModel().selectedRows()
        for index in sorted(indexes):
            self.pkg = index.data()

        msg_box_question = QMessageBox.question(
            self, "Confirm", f"Are you sure you want to install '{self.pkg}'?",
            QMessageBox.Yes | QMessageBox.Cancel)

        if msg_box_question == QMessageBox.Yes:
            self.console.setWindowTitle(f"Installing {self.pkg}")

            self.manager = PipManager(self.venv_location,
                                      f"'{self.venv_name}'")
            # open the console when recieving signal from manager
            self.manager.started.connect(self.console.exec_)

            # start installing the selected package
            logger.info(f"Installing '{self.pkg}'...")
            self.manager.run_pip(creator.cmds[0], [creator.opts[0], self.pkg])

            # display the updated output
            self.manager.textChanged.connect(self.console.update_status)

            # clear the content when closing console
            if self.console.close:
                self.console.console_window.clear()

                # clear search input line
                self.pkg_name_line.clear()
                self.pkg_name_line.setFocus(True)

    def save_requirements(self):
        """
        Ask if they want to save the requirements of the
        created virtual environment.
        """
        self.setEnabled(False)

        msg_box_question = QMessageBox.question(
            self, "Save requirements",
            "Do you want to generate a requirements?",
            QMessageBox.Yes | QMessageBox.No)

        if msg_box_question == QMessageBox.Yes:
            venv_dir = os.path.join(self.venv_location, self.venv_name)
            save_file = QFileDialog.getSaveFileName(
                self,
                "Save requirements",
                directory=f"{venv_dir}/requirements.txt")
            save_path = save_file[0]

            if save_path != "":
                self.manager = PipManager(self.venv_location, self.venv_name)
                self.manager.run_pip(creator.cmds[2], [">", save_path])

                msg_txt = (f"Saved requirements in: \n{save_path}")
                QMessageBox.information(self, "Saved", msg_txt)
                logger.info(f"Saved '{save_path}'...")
                self.wizard().next()
        else:
            self.wizard().next()

        self.setEnabled(True)