Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

import QMessageBox PyQt5

from PyQt5.QtWidgets import QMessageBox
Comment

pyqt5 qmessagebox information example

def open_database(self, filename=''):
    """ This function opens a database and set this on the UI """
 
    # If not filename provide, then open dialog to select
    if self.created:
        QMessageBox.information(self,
                                self.tr("Information"),
                                self.tr("You may only have one database"
                                        " open at time."))
        DEBUG("Ya existe una base de datos abierta")
        return
    if not filename:
        if self.__last_open_folder is None:
            directory = os.path.expanduser("~")
        else:
            directory = self.__last_open_folder
        filter_ = settings.SUPPORTED_FILES.split(';;')[0]
        filename, _ = QFileDialog.getOpenFileName(self,
                                                  self.tr("Open Database"),
                                                  directory,
                                                  filter_)
        # If is canceled, return
        if not filename:
            return
 
        # Remember the folder
        self.__last_open_folder = file_manager.get_path(filename)
 
    DEBUG("Abriendo la base de datos: '{}'".format(filename))
 
    # If filename provide
    try:
        # Read pdb file
        pfile_object = pfile.File(filename)
        db_data = pfile_object.read()
        # Create a dict to manipulate data more easy
        db_data = self.__sanitize_data(db_data)
    except Exception as reason:
        QMessageBox.information(self,
                                self.tr("The file couldn't be open"),
                                str(reason))
        CRITICAL("Error al intentar abrir el archivo: {}".format(reason))
        return
 
    # Create a database container widget
    db_container = database_container.DatabaseContainer()
 
    try:
        db_container.create_database(db_data)
    except Exception as reason:
        QMessageBox.information(self,
                                self.tr("Error"),
                                str(reason))
        CRITICAL("Error al crear la base de datos: {}".format(reason))
        return
 
    # Set the PFile object to the new database
    db_container.pfile = pfile_object
    # Add data base container to stacked
    self.add_widget(db_container)
    # Database name
    db_name = file_manager.get_basename(filename)
    # Update title with the new database name, and enable some actions
    pireal = Pireal.get_service("pireal")
    pireal.change_title(db_name)
    pireal.set_enabled_db_actions(True)
    pireal.set_enabled_relation_actions(True)
    # Add to recent databases
    self.recent_databases = filename
    self.created = True
Comment

PREVIOUS NEXT
Code Example
Python :: python merge two dictionaries 
Python :: how to get RGB value from pixel in screen live python 
Python :: blender python save file 
Python :: add a column while iterating rows pandas 
Python :: keep only duplicates pandas multiple columns 
Python :: find max value index in value count pandas 
Python :: install django rest_framework 
Python :: plotly backend pandas 
Python :: python slice an array 
Python :: autopy in python install 
Python :: round python 
Python :: url in form action django 
Python :: mad scipy 
Python :: install matplotlib pip 
Python :: discord get author slash command 
Python :: tkinter input box 
Python :: shutil copy folder 
Python :: pip fuzzywuzzy 
Python :: dictionary function fromkeys in python 
Python :: pandas datetime.time 
Python :: python candlestick chart 
Python :: AdaBoost in Python 
Python :: latency discord.py 
Python :: rsplit string from last 
Python :: json python no whitespace 
Python :: dataframe rename column 
Python :: sort list in python by substring 
Python :: colab install library 
Python :: multiply all values in column pandas 
Python :: how to create requirements.txt django 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =