def check_db_then_call(self, func, *parameters): if not echo_sql_db(): self.on_sql() if echo_sql_db(): func(*parameters) else: wx.MessageBox( 'Connection to SQL database could not be established.', 'Connection Error', wx.OK | wx.OK_DEFAULT | wx.ICON_WARNING)
def check_db_then_call(self, func, window_type, *parameters): if not echo_sql_db(): self.on_sql() if echo_sql_db(): if self.tool_bar_windows[window_type]: self.tool_bar_windows[window_type].Raise() else: self.tool_bar_windows[window_type] = func(*parameters) else: wx.MessageBox('Connection to SQL database could not be established.', 'Connection Error', wx.OK | wx.OK_DEFAULT | wx.ICON_WARNING)
def __catch_failed_sql_connection_on_app_launch(self): if self.options.DB_TYPE == 'pgsql': if not echo_sql_db(): wx.MessageBox('Invalid credentials!', 'Echo SQL Database', wx.OK | wx.ICON_WARNING) self.on_sql() else: # if using sqlite initialize_db()
def get_uncategorized_variations(physician, ignored_variations=False): if echo_sql_db(): with DVH_SQL() as cnx: physician = clean_name(physician).upper() condition = "physician_roi = '%s'" % [ 'uncategorized', 'ignored' ][ignored_variations] cursor_rtn = cnx.query('dvhs', 'roi_name, study_instance_uid', condition) new_variations = {} for row in cursor_rtn: variation = str(row[0]) study_instance_uid = str(row[1]) physician_db = cnx.get_unique_values( 'Plans', 'physician', "study_instance_uid = '%s'" % study_instance_uid) if physician_db and physician_db[0] == physician: if variation not in list(new_variations): new_variations[variation] = { 'roi_name': variation, 'study_instance_uid': [study_instance_uid] } else: new_variations[variation][ 'study_instance_uid'].append( study_instance_uid) return new_variations
def valid_sql_settings(self): config = { key: self.input[key].GetValue() for key in self.keys if self.input[key].GetValue() } if self.selected_db_type == 'pgsql': config['dbname'] = self.input['dbname'].GetValue() return echo_sql_db(config, db_type=self.selected_db_type)
def run(self): res = self.ShowModal() if res == wx.ID_OK: new_config = {key: self.input[key].GetValue() for key in self.keys if self.input[key].GetValue()} if echo_sql_db(new_config, db_type=self.selected_db_type): self.write_successful_cnf() with DVH_SQL(group=self.group) as cnx: cnx.initialize_database() else: dlg = wx.MessageDialog(self, 'Connection to database could not be established.', 'ERROR!', wx.OK | wx.ICON_ERROR) dlg.ShowModal() self.Destroy()
def on_sql(self, *args): SQLSettingsDialog(self.options) [self.__disable_add_filter_buttons, self.__enable_add_filter_buttons][echo_sql_db()]()
def __init__(self, *args, **kwds): kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) self.layout_set = False self.sizer_dvhs = wx.BoxSizer(wx.VERTICAL) set_msw_background_color( self) # If windows, change the background color self.options = Options() # Initial DVH object and data self.dvh = None self.data = {key: None for key in ['Plans', 'Beams', 'Rxs']} self.stats_data = None self.save_data = {} self.toolbar_keys = [ 'Open', 'Close', 'Save', 'Export', 'Import', 'Database', 'ROI Map', 'Settings' ] self.toolbar_ids = { key: i + 1000 for i, key in enumerate(self.toolbar_keys) } # sql_columns.py contains dictionaries of all queryable variables along with their # SQL columns and tables. Numerical categories include their units as well. self.categorical_columns = sql_columns.categorical self.numerical_columns = sql_columns.numerical # Keep track of currently selected row in the query tables self.selected_index_categorical = None self.selected_index_numerical = None # Load ROI Map now and pass to other objects for continuity # TODO: Need a method to address multiple users editing roi_map at the same time self.roi_map = DatabaseROIs() self.__add_menubar() self.__add_tool_bar() self.__add_layout_objects() self.__bind_layout_objects() self.__set_properties() self.__set_tooltips() self.__add_notebook_frames() self.__do_layout() self.disable_query_buttons('categorical') self.disable_query_buttons('numerical') self.button_query_execute.Disable() self.__disable_notebook_tabs() columns = { 'categorical': ['category_1', 'category_2', 'Filter Type'], 'numerical': ['category', 'min', 'max', 'Filter Type'] } self.data_table_categorical = DataTable(self.table_categorical, columns=columns['categorical']) self.data_table_numerical = DataTable(self.table_numerical, columns=columns['numerical']) if not echo_sql_db(): self.__disable_add_filter_buttons()
def valid_sql_settings(self): config = { key: self.input[key].GetValue() for key in self.keys if self.input[key].GetValue() } return echo_sql_db(config)
def valid_sql_settings(self): return echo_sql_db(self.config, db_type=self.selected_db_type)