def _set_defaults(self): """ Set any default values for widgets. Also load settings from the existing campaign if one was specified. """ calendar = self.gobjects['calendar_campaign_expiration'] default_day = datetime.datetime.today() + datetime.timedelta(days=31) gui_utilities.gtk_calendar_set_pydate(calendar, default_day) if self.is_new_campaign: return campaign = self.application.get_graphql_campaign() # set entries self.gobjects['entry_campaign_name'].set_text(campaign['name']) self.gobjects['entry_validation_regex_username'].set_text( campaign['credentialRegexUsername'] or '') self.gobjects['entry_validation_regex_password'].set_text( campaign['credentialRegexPassword'] or '') self.gobjects['entry_validation_regex_mfa_token'].set_text( campaign['credentialRegexMfaToken'] or '') if campaign['description'] is not None: self.gobjects['entry_campaign_description'].set_text( campaign['description']) if campaign['campaignType'] is not None: combobox = self.gobjects['combobox_campaign_type'] model = combobox.get_model() model_iter = gui_utilities.gtk_list_store_search( model, campaign['campaignType']['id'], column=0) if model_iter is not None: combobox.set_active_iter(model_iter) self.gobjects['checkbutton_alert_subscribe'].set_property( 'active', self.application.rpc('campaign/alerts/is_subscribed', self.campaign_id)) self.gobjects['checkbutton_reject_after_credentials'].set_property( 'active', bool(campaign['maxCredentials'])) if campaign['company'] is not None: self.gobjects['radiobutton_company_existing'].set_active(True) combobox = self.gobjects['combobox_company_existing'] model = combobox.get_model() model_iter = gui_utilities.gtk_list_store_search( model, campaign['company']['id'], column=0) if model_iter is not None: combobox.set_active_iter(model_iter) if campaign['expiration'] is not None: expiration = utilities.datetime_utc_to_local( campaign['expiration']) self.gobjects['checkbutton_expire_campaign'].set_active(True) self._expiration_time.time = expiration.time() gui_utilities.gtk_calendar_set_pydate( self.gobjects['calendar_campaign_expiration'], expiration.date())
def _set_defaults(self): """ Set any default values for widgets. Also load settings from the existing campaign if one was specified. """ calendar = self.gobjects['calendar_campaign_expiration'] default_day = datetime.datetime.today() + datetime.timedelta(days=31) gui_utilities.gtk_calendar_set_pydate(calendar, default_day) if self.campaign_id is None: return campaign = self.application.rpc.remote_table_row('campaigns', self.campaign_id, cache=True, refresh=True) self.gobjects['entry_campaign_name'].set_text(campaign.name) if campaign.description is not None: self.gobjects['entry_campaign_description'].set_text( campaign.description) if campaign.campaign_type_id is not None: combobox = self.gobjects['combobox_campaign_type'] model = combobox.get_model() model_iter = gui_utilities.gtk_list_store_search( model, campaign.campaign_type_id, column=0) if model_iter is not None: combobox.set_active_iter(model_iter) self.gobjects['checkbutton_alert_subscribe'].set_property( 'active', self.application.rpc('campaign/alerts/is_subscribed', self.campaign_id)) self.gobjects['checkbutton_reject_after_credentials'].set_property( 'active', campaign.reject_after_credentials) if campaign.company_id is not None: self.gobjects['radiobutton_company_existing'].set_active(True) combobox = self.gobjects['combobox_company_existing'] model = combobox.get_model() model_iter = gui_utilities.gtk_list_store_search( model, campaign.company_id, column=0) if model_iter is not None: combobox.set_active_iter(model_iter) if campaign.expiration is not None: expiration = utilities.datetime_utc_to_local(campaign.expiration) self.gobjects['checkbutton_expire_campaign'].set_active(True) gui_utilities.gtk_calendar_set_pydate( self.gobjects['calendar_campaign_expiration'], expiration) self.gobjects['spinbutton_campaign_expiration_hour'].set_value( expiration.hour) self.gobjects['spinbutton_campaign_expiration_minute'].set_value( expiration.minute)
def test_gtk_calendar_and_pydate(self): gtk_calendar = Gtk.Calendar() year, month, day = 2018, 2, 28 # February 28th, 2018 gtk_calendar.select_month(month - 1, year) # GTK months start at 0 gtk_calendar.select_day(day) date = gui_utilities.gtk_calendar_get_pydate(gtk_calendar) self.assertIsInstance(date, datetime.date) self.assertEquals((date.year, date.month, date.day), (year, month, day)) month, day = 1, 27 # January 27th, 2018 date = date.replace(month=month, day=day) gui_utilities.gtk_calendar_set_pydate(gtk_calendar, date) self.assertEquals(gtk_calendar.get_date(), (year, month - 1, day))
def _set_defaults(self): """ Set any default values for widgets. Also load settings from the existing campaign if one was specified. """ calendar = self.gobjects['calendar_campaign_expiration'] default_day = datetime.datetime.today() + datetime.timedelta(days=31) gui_utilities.gtk_calendar_set_pydate(calendar, default_day) if self.campaign_id is None: return campaign = self.application.get_graphql_campaign() # set entries self.gobjects['entry_campaign_name'].set_text(campaign['name']) self.gobjects['entry_validation_regex_username'].set_text(campaign['credentialRegexUsername'] or '') self.gobjects['entry_validation_regex_password'].set_text(campaign['credentialRegexPassword'] or '') self.gobjects['entry_validation_regex_mfa_token'].set_text(campaign['credentialRegexMfaToken'] or '') if campaign['description'] is not None: self.gobjects['entry_campaign_description'].set_text(campaign['description']) if campaign['campaignType'] is not None: combobox = self.gobjects['combobox_campaign_type'] model = combobox.get_model() model_iter = gui_utilities.gtk_list_store_search(model, campaign['campaignType']['id'], column=0) if model_iter is not None: combobox.set_active_iter(model_iter) self.gobjects['checkbutton_alert_subscribe'].set_property('active', self.application.rpc('campaign/alerts/is_subscribed', self.campaign_id)) self.gobjects['checkbutton_reject_after_credentials'].set_property('active', bool(campaign['maxCredentials'])) if campaign['company'] is not None: self.gobjects['radiobutton_company_existing'].set_active(True) combobox = self.gobjects['combobox_company_existing'] model = combobox.get_model() model_iter = gui_utilities.gtk_list_store_search(model, campaign['company']['id'], column=0) if model_iter is not None: combobox.set_active_iter(model_iter) if campaign['expiration'] is not None: expiration = utilities.datetime_utc_to_local(campaign['expiration']) self.gobjects['checkbutton_expire_campaign'].set_active(True) self._expiration_time.time = expiration.time() gui_utilities.gtk_calendar_set_pydate(self.gobjects['calendar_campaign_expiration'], expiration.date())
def _set_defaults(self): """ Set any default values for widgets. Also load settings from the existing campaign if one was specified. """ calendar = self.gobjects["calendar_campaign_expiration"] default_day = datetime.datetime.today() + datetime.timedelta(days=31) gui_utilities.gtk_calendar_set_pydate(calendar, default_day) if self.campaign_id is None: return campaign = self.application.rpc.remote_table_row("campaigns", self.campaign_id, cache=True, refresh=True) self.gobjects["entry_campaign_name"].set_text(campaign.name) if campaign.description is not None: self.gobjects["entry_campaign_description"].set_text(campaign.description) if campaign.campaign_type_id is not None: combobox = self.gobjects["combobox_campaign_type"] model = combobox.get_model() model_iter = gui_utilities.gtk_list_store_search(model, campaign.campaign_type_id, column=0) if model_iter is not None: combobox.set_active_iter(model_iter) self.gobjects["checkbutton_alert_subscribe"].set_property( "active", self.application.rpc("campaign/alerts/is_subscribed", self.campaign_id) ) self.gobjects["checkbutton_reject_after_credentials"].set_property("active", campaign.reject_after_credentials) if campaign.company_id is not None: self.gobjects["radiobutton_company_existing"].set_active(True) combobox = self.gobjects["combobox_company_existing"] model = combobox.get_model() model_iter = gui_utilities.gtk_list_store_search(model, campaign.company_id, column=0) if model_iter is not None: combobox.set_active_iter(model_iter) if campaign.expiration is not None: expiration = utilities.datetime_utc_to_local(campaign.expiration) self.gobjects["checkbutton_expire_campaign"].set_active(True) gui_utilities.gtk_calendar_set_pydate(self.gobjects["calendar_campaign_expiration"], expiration) self.gobjects["spinbutton_campaign_expiration_hour"].set_value(expiration.hour) self.gobjects["spinbutton_campaign_expiration_minute"].set_value(expiration.minute)
def signal_calendar_prev(self, calendar): today = datetime.date.today() calendar_day = gui_utilities.gtk_calendar_get_pydate(calendar) if calendar_day >= today: return gui_utilities.gtk_calendar_set_pydate(calendar, today)