Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Get an application instance
self.app = QtWidgets.QApplication.instance()
if self.app:
logger.info("Using existing QApplication instance")
if not self.app:
self.app = QtWidgets.QApplication(sys.argv)
super().__init__()
# https://stackoverflow.com/a/27178019/3620725
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
# Adds DataFrames listed in kwargs to store.
for i, (df_name, df_object) in enumerate(kwargs.items()):
store.data[df_name] = {}
store.data[df_name]["dataframe"] = df_object
# Generates all UI contents
self.setupUI()
# %% Window settings
# Set size
screen = QtWidgets.QDesktopWidget().screenGeometry()
percentage_of_screen = 0.7
size = tuple(
(
pd.np.array([screen.width(), screen.height()]) * percentage_of_screen
).astype(int)
)
self.resize(QtCore.QSize(*size))
# Center window on screen
logger.warning(
f'Automatically converted "{df_name}" from type {type(df_object)}'
" to DataFrame"
)
except:
logger.warning(
f'Could not convert "{df_name}" from type {type(df_object)} to'
" DataFrame"
)
return
# Non-string column indices causes problems when pulling them from a GUI dropdown (which will give str)
if type(df_object.columns) != pd.MultiIndex:
df_object.columns = df_object.columns.astype(str)
store.data[df_name] = {}
store.data[df_name] = {}
store.data[df_name]["dataframe"] = df_object
dfe = DataFrameExplorer(df_object)
self.stacked_widget.addWidget(dfe)
store.data[df_name]["dataframe_explorer"] = dfe
self.add_df_to_nav(df_name)