def fill_fields(self): """ Fill dates and combo cat_work """ sql = ( "SELECT value FROM " + self.controller.schema_name + ".config_param_user " " WHERE parameter = 'enddate_vdefault' and cur_user = current_user" ) row = self.controller.get_row(sql, log_info=False) if row: enddate = QDate.fromString(row[0], 'yyyy-MM-dd') else: enddate = QDate.currentDate() utils_giswater.setCalendarDate(self.dlg_work_end, "enddate", enddate) sql = ("SELECT id FROM " + self.controller.schema_name + ".cat_work") rows = self.controller.get_rows(sql) utils_giswater.fillComboBox(self.dlg_work_end, self.dlg_work_end.workcat_id_end, rows, allow_nulls=False) utils_giswater.set_autocompleter(self.dlg_work_end.workcat_id_end) sql = ( "SELECT value FROM " + self.controller.schema_name + ".config_param_user " " WHERE parameter = 'workcat_vdefault' and cur_user = current_user" ) row = self.controller.get_row(sql, log_info=False) if row: utils_giswater.setWidgetText(self.dlg_work_end, self.dlg_work_end.workcat_id_end, row[0])
def set_calendars(self, dialog, widget, table_name, value, parameter): """ Executes query and set QDateEdit """ sql = ("SELECT " + value + " FROM " + self.schema_name + "." + table_name + "" " WHERE parameter = '" + parameter + "' AND cur_user = current_user") row = self.controller.get_row(sql) if row: date = QDate.fromString(row[0], 'yyyy-MM-dd') else: date = QDate.currentDate() utils_giswater.setCalendarDate(dialog, widget, date)
def fill_widgets(self, table_object, row): """ Fill input widgets with data int he @row """ if table_object == "doc": utils_giswater.setWidgetText("doc_type", row["doc_type"]) utils_giswater.setWidgetText("observ", row["observ"]) utils_giswater.setWidgetText("path", row["path"]) elif table_object == "element": state = "" if row['state']: sql = ("SELECT name FROM " + self.schema_name + ".value_state" " WHERE id = '" + str(row['state']) + "'") row_aux = self.controller.get_row(sql, commit=self.autocommit) if row_aux: state = row_aux[0] expl_id = "" if row['expl_id']: sql = ("SELECT name FROM " + self.schema_name + ".exploitation" " WHERE expl_id = '" + str(row['expl_id']) + "'") row_aux = self.controller.get_row(sql, commit=self.autocommit) if row_aux: expl_id = row_aux[0] utils_giswater.setWidgetText("state", state) utils_giswater.setWidgetText("expl_id", expl_id) utils_giswater.setWidgetText("elementcat_id", row['elementcat_id']) utils_giswater.setWidgetText("ownercat_id", row['ownercat_id']) utils_giswater.setWidgetText("location_type", row['location_type']) utils_giswater.setWidgetText("buildercat_id", row['buildercat_id']) utils_giswater.setWidgetText("workcat_id", row['workcat_id']) utils_giswater.setWidgetText("workcat_id_end", row['workcat_id_end']) utils_giswater.setWidgetText("comment", row['comment']) utils_giswater.setWidgetText("observ", row['observ']) utils_giswater.setWidgetText("link", row['link']) utils_giswater.setWidgetText("verified", row['verified']) utils_giswater.setWidgetText("rotation", row['rotation']) if str(row['undelete']) == 'True': self.dlg.undelete.setChecked(True) builtdate = QDate.fromString(str(row['builtdate']), 'yyyy-MM-dd') enddate = QDate.fromString(str(row['enddate']), 'yyyy-MM-dd') self.dlg.builtdate.setDate(builtdate) self.dlg.enddate.setDate(enddate)
def fill_widget_with_fields(self, dialog, data_object, field_names): """Fill the Widget with value get from data_object limited to the list of field_names.""" for field_name in field_names: value = getattr(data_object, field_name) if not hasattr(dialog, field_name): continue widget = getattr(dialog, field_name) if type(widget) in [QDateEdit, QDateTimeEdit]: widget.setDateTime(value if value else QDate.currentDate() ) if type(widget) in [QLineEdit, QTextEdit]: if value: widget.setText(value) else: widget.clear() if type(widget) in [QComboBox]: if not value: widget.setCurrentIndex(0) continue # look the value in item text index = widget.findText(str(value)) if index >= 0: widget.setCurrentIndex(index) continue # look the value in itemData index = widget.findData(value) if index >= 0: widget.setCurrentIndex(index) continue
def init_replace_node_form(self): # Create the dialog and signals dlg_nodereplace = Node_replace() utils_giswater.setDialog(dlg_nodereplace) dlg_nodereplace.btn_accept.pressed.connect( partial(self.get_values, dlg_nodereplace)) dlg_nodereplace.btn_cancel.pressed.connect(dlg_nodereplace.close) sql = ("SELECT id FROM " + self.schema_name + ".cat_work ORDER BY id") rows = self.controller.get_rows(sql) if rows: utils_giswater.fillComboBox(dlg_nodereplace.workcat_id_end, rows) utils_giswater.set_autocompleter(dlg_nodereplace.workcat_id_end) sql = 'SELECT value FROM ' + self.schema_name + '.config_param_user' sql += ' WHERE "cur_user" = current_user AND parameter = ' + "'workcat_vdefault'" row = self.controller.get_row(sql) if row: dlg_nodereplace.workcat_id_end.setCurrentIndex( dlg_nodereplace.workcat_id_end.findText(row[0])) sql = 'SELECT value FROM ' + self.schema_name + '.config_param_user' sql += ' WHERE "cur_user" = current_user AND parameter = ' + "'enddate_vdefault'" row = self.controller.get_row(sql) if row: self.enddate_aux = datetime.strptime(row[0], '%Y-%m-%d').date() else: self.enddate_aux = datetime.strptime( QDate.currentDate().toString('yyyy-MM-dd'), '%Y-%m-%d').date() dlg_nodereplace.enddate.setDate(self.enddate_aux) dlg_nodereplace.exec_()
def initGui(self, gui_type): if gui_type == 'full': self.spawnFullGui() self.initTables(self._widget, self.joystick_table_left_edge, self.joystick_table_top_edge) else: self.spawnTabGui() self.initTables(self._widget.gui_tabs.widget(self.raw_data_tab_idx), 20, 20) self._widget.gui_tabs.setCurrentIndex(self.current_tab_idx) self.resetGuiTimer() self.initJoystickGraphics() self.initBumperGraphics() self.initChecklists() self.bindCallbacks() self.refreshMaxSpeed() # Initialize absolute wake time setter to current time datetime_now = QDateTime(QDate.currentDate(), QTime.currentTime()) self._widget.absolute_wake_time_obj.setDateTime(datetime_now) temp_time = self._widget.absolute_wake_time_obj.time() temp_time = QTime(temp_time.hour(), temp_time.minute()) self._widget.absolute_wake_time_obj.setTime(temp_time) # Set connection label text if self.base_connected: self._widget.disconnected_lbl.setVisible(False) else: self._widget.disconnected_lbl.setVisible(True) self._widget.disconnected_lbl.setText('<font color=#FF0000>NOT CONNECTED</font>')
def setCalendarDate(dialog, widget, date, default_current_date=True): if type(widget) is str or type(widget) is unicode: widget = dialog.findChild(QWidget, widget) if not widget: return if type(widget) is QDateEdit or (type(widget) is QgsDateTimeEdit and widget.displayFormat() == 'dd/MM/yyyy') \ or (type(widget) is QgsDateTimeEdit and widget.displayFormat() == 'yyyy/MM/dd'): if date is None: if default_current_date: date = QDate.currentDate() else: date = QDate.fromString('01/01/2000', 'dd/MM/yyyy') widget.setDate(date) elif type(widget) is QDateTimeEdit \ or (type(widget) is QgsDateTimeEdit and widget.displayFormat() == 'dd/MM/yyyy hh:mm:ss'): if date is None: date = QDateTime.currentDateTime() widget.setDateTime(date)
def setCalendarDate(widget, date): if type(widget) is str: widget = _dialog.findChild(QWidget, widget) if not widget: return if type(widget) is QDateEdit: if date is None: date = QDate.currentDate() widget.setDate(date)
def month_selector_row(self, dialog, id_table_left, tableleft, view_name): left_selected_list = dialog.all_rows.selectionModel().selectedRows() if len(left_selected_list) == 0: message = "Cap registre seleccionat" self.controller.show_warning(message) return # Get all selected ids field_list = [] for i in range(0, len(left_selected_list)): row = left_selected_list[i].row() id_ = dialog.all_rows.model().record(row).value(id_table_left) field_list.append(id_) # Get dates plan_month_start = widget_manager.getCalendarDate( dialog, dialog.date_inici) plan_month_end = widget_manager.getCalendarDate(dialog, dialog.date_fi) # Get year from string calendar_year = QDate.fromString(plan_month_start, 'yyyy/MM/dd').year() # if int(calendar_year) < int(self.planned_camp_id): # self.controller.show_details(detail_text="La data d'inici no pot ser anterior a 'Any planificacio'") # return # # if plan_month_start > plan_month_end: # self.controller.show_details(detail_text="La data d'inici no pot ser posterior a la data final") # return # Update values for i in range(0, len(left_selected_list)): row = left_selected_list[i].row() sql = ("UPDATE " + self.schema_name + "." + tableleft + " " " SET plan_code ='" + self.plan_code + "', " " plan_month_start = '" + plan_month_start + "', " " plan_month_end = '" + plan_month_end + "' " " WHERE id='" + str(dialog.all_rows.model().record(row).value('id')) + "'" " AND mu_id ='" + str(dialog.all_rows.model().record(row).value('mu_id')) + "'" " AND campaign_id = '" + self.planned_camp_id + "'") self.controller.execute_sql(sql) # Refresh QTableViews and recalculate price expr = " AND ( plan_code is NULL OR plan_code = '')" self.fill_table_planned_month(dialog.all_rows, dialog.txt_search, view_name, expr) expr = " AND plan_code = '" + self.plan_code + "'" self.fill_table_planned_month(dialog.selected_rows, dialog.txt_selected_filter, view_name, expr) self.calculate_total_price(dialog, self.planned_camp_id)
def basic_new_prices(self, dialog=None): """ Button 03: Price generator """ # Close previous dialog if dialog is not None: self.close_dialog(dialog) self.dlg_new_campaign = NewPrices() self.load_settings(self.dlg_new_campaign) # Set default dates current_year = QDate.currentDate().year() start_date = QDate.fromString( str(int(current_year)) + '/11/01', 'yyyy/MM/dd') self.dlg_new_campaign.start_date.setDate(start_date) end_date = QDate.fromString( str(int(current_year) + 1) + '/10/31', 'yyyy/MM/dd') self.dlg_new_campaign.end_date.setDate(end_date) table_name = 'cat_campaign' field_id = 'id' field_name = 'name' self.dlg_new_campaign.rejected.connect( partial(self.close_dialog, self.dlg_new_campaign)) self.dlg_new_campaign.btn_cancel.clicked.connect( partial(self.close_dialog, self.dlg_new_campaign)) self.dlg_new_campaign.btn_accept.clicked.connect( partial(self.manage_new_price_catalog)) self.populate_cmb_years(table_name, field_id, field_name, self.dlg_new_campaign.cbx_years) self.set_completer_object(table_name, self.dlg_new_campaign.txt_campaign, field_name) if self.rows_cmb_poda_type is None: self.update_cmb_poda_type() self.dlg_new_campaign.exec_()
def __init__(self): QWidget.__init__(self) self.ui = Ui_DateTimeWidget() self.ui.setupUi(self) self.timer = QTimer(self) self.from_time_updater = True self.is_date_changed = False self.current_zone = "" self.tz_dict = {} self.continents = [] self.countries = [] for country, data in yali.localedata.locales.items(): if country == ctx.consts.lang: if data.has_key("timezone"): ctx.installData.timezone = data["timezone"] # Append continents and countries the time zone dictionary self.createTZDictionary() # Sort continent list self.sortContinents() # Append sorted continents to combobox self.loadContinents() # Load current continents country list self.getCountries(self.current_zone["continent"]) # Highlight the current zone self.index = self.ui.continentList.findText(self.current_zone["continent"]) self.ui.continentList.setCurrentIndex(self.index) self.index = self.ui.countryList.findText(self.current_zone["country"]) self.ui.countryList.setCurrentIndex(self.index) # Initialize widget signal and slots self.__initSignals__() self.ui.calendarWidget.setDate(QDate.currentDate()) self.pthread = None self.pds_messagebox = PMessageBox(self) self.pds_messagebox.enableOverlay() self.timer.start(1000)
def showEvent(self, ev): if self.selectedDate().year() == UNDEFINED_DATE.year: self.setSelectedDate(QDate.currentDate())
def setEditorData(self, editor, index): val = index.data(Qt.EditRole).toDate() if is_date_undefined(val): val = QDate(2000, 1, 1) editor.setDate(val)
def edit_config_edit(self): """ Button 98: Open a dialog showing data from table 'config_param_user' """ # Create the dialog and signals self.dlg = ConfigEdit() utils_giswater.setDialog(self.dlg) self.load_settings(self.dlg) self.dlg.btn_accept.pressed.connect(self.edit_config_edit_accept) self.dlg.btn_cancel.pressed.connect(partial(self.close_dialog, self.dlg)) self.dlg.rejected.connect(partial(self.save_settings, self.dlg)) # Set values from widgets of type QComboBox and dates sql = "SELECT DISTINCT(name) FROM " + self.schema_name + ".value_state ORDER BY name" rows = self.controller.get_rows(sql) utils_giswater.fillComboBox("state_vdefault", rows) sql = "SELECT id FROM " + self.schema_name + ".cat_work ORDER BY id" rows = self.controller.get_rows(sql) utils_giswater.fillComboBox("workcat_vdefault", rows) sql = "SELECT id FROM " + self.schema_name + ".value_verified ORDER BY id" rows = self.controller.get_rows(sql) utils_giswater.fillComboBox("verified_vdefault", rows) sql = 'SELECT value FROM ' + self.schema_name + '.config_param_user' sql += ' WHERE "cur_user" = current_user AND parameter = ' + "'builtdate_vdefault'" row = self.controller.get_row(sql) if row is not None: date_value = datetime.strptime(row[0], '%Y-%m-%d') else: date_value = QDate.currentDate() utils_giswater.setCalendarDate("builtdate_vdefault", date_value) sql = 'SELECT value FROM ' + self.schema_name + '.config_param_user' sql += ' WHERE "cur_user" = current_user AND parameter = ' + "'enddate_vdefault'" row = self.controller.get_row(sql) if row is not None: date_value = datetime.strptime(row[0], '%Y-%m-%d') else: date_value = QDate.currentDate() utils_giswater.setCalendarDate("enddate_vdefault", date_value) sql = "SELECT id FROM " + self.schema_name + ".cat_arc ORDER BY id" rows = self.controller.get_rows(sql) utils_giswater.fillComboBox("arccat_vdefault", rows) sql = "SELECT id FROM " + self.schema_name + ".cat_node ORDER BY id" rows = self.controller.get_rows(sql) utils_giswater.fillComboBox("nodecat_vdefault", rows) sql = "SELECT id FROM " + self.schema_name + ".cat_connec ORDER BY id" rows = self.controller.get_rows(sql) utils_giswater.fillComboBox("connecat_vdefault", rows) sql = "SELECT id FROM " + self.schema_name + ".cat_element ORDER BY id" rows = self.controller.get_rows(sql) utils_giswater.fillComboBox("elementcat_vdefault", rows) sql = "SELECT DISTINCT(name) FROM " + self.schema_name + ".exploitation ORDER BY name" rows = self.controller.get_rows(sql) utils_giswater.fillComboBox("exploitation_vdefault", rows) sql = "SELECT DISTINCT(name) FROM " + self.schema_name + ".ext_municipality ORDER BY name" rows = self.controller.get_rows(sql) utils_giswater.fillComboBox("municipality_vdefault", rows) sql = "SELECT DISTINCT(name) FROM " + self.schema_name + ".om_visit_cat ORDER BY name" rows = self.controller.get_rows(sql) utils_giswater.fillComboBox("visitcat_vdefault", rows) # UD sql = "SELECT id FROM " + self.schema_name + ".node_type ORDER BY id" rows = self.controller.get_rows(sql) utils_giswater.fillComboBox("nodetype_vdefault", rows) sql = "SELECT id FROM " + self.schema_name + ".arc_type ORDER BY id" rows = self.controller.get_rows(sql) utils_giswater.fillComboBox("arctype_vdefault", rows) sql = "SELECT id FROM " + self.schema_name + ".connec_type ORDER BY id" rows = self.controller.get_rows(sql) utils_giswater.fillComboBox("connectype_vdefault", rows) # Set current values sql = "SELECT parameter, value FROM " + self.schema_name + ".config_param_user WHERE cur_user = current_user" rows = self.controller.get_rows(sql) for row in rows: utils_giswater.setWidgetText(str(row[0]), str(row[1])) utils_giswater.setChecked("chk_" + str(row[0]), True) # TODO PARAMETRIZAR ESTO!!!!! # Manage parameters 'state_vdefault', 'exploitation_vdefault', 'municipality_vdefault', 'visitcat_vdefault' sql = "SELECT name FROM " + self.schema_name + ".value_state WHERE id::text = " sql += "(SELECT value FROM " + self.schema_name + ".config_param_user WHERE parameter = 'state_vdefault')::text" row = self.controller.get_row(sql) if row: utils_giswater.setWidgetText("state_vdefault", str(row[0])) sql = "SELECT name FROM " + self.schema_name + ".exploitation WHERE expl_id::text = " sql += "(SELECT value FROM " + self.schema_name + ".config_param_user WHERE parameter = 'exploitation_vdefault')::text" row = self.controller.get_row(sql) if row: utils_giswater.setWidgetText("exploitation_vdefault", str(row[0])) sql = "SELECT name FROM " + self.schema_name + ".ext_municipality WHERE muni_id::text = " sql += "(SELECT value FROM " + self.schema_name + ".config_param_user WHERE parameter = 'municipality_vdefault')::text" row = self.controller.get_row(sql) if row: utils_giswater.setWidgetText("municipality_vdefault", str(row[0])) sql = "SELECT name FROM " + self.schema_name + ".om_visit_cat WHERE id::text = " sql += "(SELECT value FROM " + self.schema_name + ".config_param_user WHERE parameter = 'visitcat_vdefault')::text" row = self.controller.get_row(sql) if row: utils_giswater.setWidgetText("visitcat_vdefault", str(row[0])) if self.project_type == 'ws': self.dlg.tab_config.removeTab(1) self.dlg.tab_config.removeTab(1) elif self.project_type == 'ud': self.dlg.tab_config.removeTab(1) self.dlg.exec_()
def setEditorData(self, editor, index): val = index.data(Qt.EditRole).toDate() if val == UNDEFINED_QDATETIME.date(): val = QDate(2000, 1, 1) editor.setDate(val)
def month_selector(self): month_selector = MonthSelector() self.load_settings(month_selector) month_selector.all_rows.setSelectionBehavior( QAbstractItemView.SelectRows) month_selector.selected_rows.setSelectionBehavior( QAbstractItemView.SelectRows) month_selector.setWindowTitle("Planificador mensual") # Set label with selected text from previus dialog month_selector.lbl_plan_code.setText(self.plan_code) month_selector.lbl_year.setText(self.planned_camp_name) sql = ("SELECT start_date, end_date FROM " + self.schema_name + ".cat_campaign " " WHERE id ='" + str(self.planned_camp_id) + "'") row = self.controller.get_row(sql) if row is not None: start_date = QDate.fromString(str(row[0]), 'yyyy-MM-dd') end_date = QDate.fromString(str(row[1]), 'yyyy-MM-dd') else: start_date = QDate.currentDate() end_date = QDate.currentDate().addYears(1) widget_manager.setCalendarDate(month_selector, month_selector.date_inici, start_date) widget_manager.setCalendarDate(month_selector, month_selector.date_fi, end_date) view_name = 'v_plan_mu_year' tableleft = 'planning' id_table_left = 'mu_id' # Left QTableView expr = " AND ( plan_code is NULL OR plan_code = '')" self.fill_table_planned_month(month_selector.all_rows, month_selector.txt_search, view_name, expr) month_selector.txt_search.textChanged.connect( partial(self.fill_table_planned_month, month_selector.all_rows, month_selector.txt_search, view_name, expr, QTableView.NoEditTriggers)) month_selector.btn_select.clicked.connect( partial(self.month_selector_row, month_selector, id_table_left, tableleft, view_name)) self.set_table_columns(month_selector, month_selector.all_rows, view_name, 'basic_month_left') # Right QTableView expr = " AND plan_code = '" + self.plan_code + "'" self.fill_table_planned_month(month_selector.selected_rows, month_selector.txt_selected_filter, view_name, expr) month_selector.txt_selected_filter.textChanged.connect( partial(self.fill_table_planned_month, month_selector.selected_rows, month_selector.txt_selected_filter, view_name, expr, QTableView.NoEditTriggers)) month_selector.btn_unselect.clicked.connect( partial(self.month_unselector_row, month_selector, id_table_left, tableleft, view_name)) self.set_table_columns(month_selector, month_selector.selected_rows, view_name, 'basic_month_right') self.calculate_total_price(month_selector, self.planned_camp_id) month_selector.btn_close.clicked.connect( partial(self.close_dialog, month_selector)) month_selector.rejected.connect( partial(self.close_dialog, month_selector)) month_selector.exec_()