def _handle_buttons(self, event: wx.CommandEvent) -> None: """ Handle button clicks, run seo check on the new values and display results. Prevent closing if seo failed. :param event: The button event. :return: None """ if event.GetId() == wx.ID_OPEN: new_path, new_name = self._ask_for_image() if not new_path: # No image was selected event.Skip() return else: self._change_image(new_path, new_name) self._ok_button.SetDefault() elif event.GetId() == wx.ID_OK: # Save new information into image and rerun seo test. self._run_spellcheck( ((self._field_item_name, Strings.label_menu_item_name), (self._field_image_link_title, Strings.label_link_title), (self._field_image_alt, Strings.label_alt_description))) self._item_copy.set_article_name(self._field_item_name.GetValue()) self._item_copy.set_link_title( self._field_image_link_title.GetValue()) self._item_copy.set_image_alt(self._field_image_alt.GetValue()) if self._item_copy.test_self(): self._original_item.set_article_name( self._item_copy.get_article_name()[0]) self._original_item.set_link_title( self._item_copy.get_link_title()[0]) self._original_item.set_image_alt( self._item_copy.get_image_alt()[0]) self._original_item.set_href(self._item_copy.get_link_href()) self._original_item.set_image_path( self._item_copy.get_image_path()) self._original_item.set_filename( self._item_copy.get_filename()) self._original_item.test_self() event.Skip() return else: self.display_dialog_contents() elif event.GetId() == wx.ID_ADD: dlg = AddLogoDialog(self, self._work_dir) saved = dlg.ShowModal() if saved == wx.ID_OK: result = wx.MessageBox(Strings.label_use_image, Strings.label_image, wx.YES_NO | wx.ICON_QUESTION) if result == wx.YES: # This function must be used only when the add image dialog is confirmed. # Parameter expansion, expands tuple into the two arguments needed by the function. self._change_image(*dlg.get_logo_location()) dlg.Destroy() else: # Leave the original item as it is. event.Skip()
def OnChar_(self, wxEvent: wx.CommandEvent) -> None: keyCode = wxEvent.GetKeyCode() if keyCode < wx.WXK_SPACE or keyCode == wx.WXK_DELETE or keyCode > 255: wxEvent.Skip() return if chr(keyCode) in string.digits or chr(keyCode) in ('.', '-'): # Allow this character to propagate wxEvent.Skip() return if not wx.Validator.IsSilent(): wx.Bell()
def _handle_buttons(self, event: wx.CommandEvent) -> None: """ Handle button clicks, run seo check on the new values and display results. Prevent closing if seo failed. :param event: The button event :return: None """ if event.GetId() == wx.ID_OPEN: new_path, new_name = self._ask_for_image() if not new_path: # No image was selected event.Skip() return else: self._change_image(new_path, new_name) elif event.GetId() == wx.ID_ADD: dlg = AddImageDialog(self, self._work_dir) saved = dlg.ShowModal() if saved == wx.ID_OK: result = wx.MessageBox(Strings.label_use_image, Strings.label_image, wx.YES_NO | wx.ICON_QUESTION) if result == wx.YES: # This function must be used only when the add image dialog is confirmed. # Parameter expansion, expands tuple into the two arguments needed by the function. self._change_image(*dlg.get_thumbnail_location()) dlg.Destroy() elif event.GetId() == wx.ID_OK: self._run_spellcheck(((self._field_image_link_title, Strings.label_link_title), (self._field_image_alt, Strings.label_alt_description))) # Save new information into the copy of the image and rerun seo test. self._image_copy.set_link_title(self._field_image_link_title.GetValue()) self._image_copy.set_alt(self._field_image_alt.GetValue()) if self._image_copy.test_self(): # If the seo test is good, transfer all information into the original image. self._original_image.set_link_title(self._image_copy.get_link_title()[0]) self._original_image.set_alt(self._image_copy.get_image_alt()[0]) self._original_image.set_original_image_path(self._image_copy.get_original_image_path()) self._original_image.set_thumbnail_image_path(self._image_copy.get_thumbnail_image_path()) self._original_image.set_full_filename(self._image_copy.get_full_filename()) self._original_image.set_thumbnail_filename(self._image_copy.get_thumbnail_filename()) # Reinitialize internal variables after changes, this should never fail as the test was done on the copy self._original_image.test_self() event.Skip() return else: self._display_dialog_contents() else: # Leave the old image as it is and do not do anything. event.Skip()
def OnMenuClick(self, event: CommandEvent): """ Callback for popup menu on class Args: event: """ from org.pyut.general.Mediator import getMediator # avoid circular import pyutObject: PyutClass = self.getPyutObject() eventId: int = event.GetId() if eventId == MENU_TOGGLE_STEREOTYPE: pyutObject.setShowStereotype(not pyutObject.getShowStereotype()) self.autoResize() elif eventId == MENU_TOGGLE_METHODS: pyutObject.showMethods = not pyutObject.showMethods # flip it!! too cute self.autoResize() elif eventId == MENU_TOGGLE_FIELDS: pyutObject.showFields = not pyutObject.showFields # flip it!! too cute self.autoResize() elif eventId == MENU_FIT_FIELDS: self.autoResize() elif eventId == MENU_CUT_SHAPE: ctrl = getMediator() ctrl.deselectAllShapes() self.SetSelected(True) ctrl.cutSelectedShapes() elif eventId == MENU_IMPLEMENT_INTERFACE: ctrl = getMediator() ctrl.requestLollipopLocation(self) else: event.Skip()
def onSnapToGridChanged(self, event: CommandEvent): enabledValue: bool = event.IsChecked() BackgroundPreferences.clsLogger.info( f'onSnapToGridChanged - {enabledValue}') self._prefs.snapToGrid = enabledValue event.Skip(True)
def __OnCmdOk(self, event: CommandEvent): """ """ self._timer.Stop() event.Skip(skip=True) self.SetReturnCode(OK) self.EndModal(OK)
def on_kill_focus(self, event: wx.CommandEvent) -> None: """On EVT_KILL_FOCUS, process the updated value.""" if self._text_dirty: self.Undo() self._text_dirty = False self._selected_dirty = False event.Skip()
def _handle_buttons(self, event: wx.CommandEvent) -> None: """ Handle button clicks, run seo check on the new values and display results. Prevent closing on ok if seo failed. :param event: The button event :return: None """ if event.GetId() == wx.ID_DELETE: # Only OK and Cancel button close the dialog by default. event.Skip() self.EndModal(wx.ID_DELETE) elif event.GetId() == wx.ID_OK: self._run_spellcheck( ((self._field_link_title, Strings.label_link_title), (self._field_link_text, Strings.label_text))) # Save new information into image and rerun seo test. self._link.set_text(self._field_link_text.GetValue()) self._link.set_title(self._field_link_title.GetValue()) self._link.set_url(self._field_url.GetValue()) # Run seo test in thread and show a testing dialog. self._seo_test(return_value=wx.ID_OK) else: # Restore original values self._link.set_url(self._original_url) self._link.set_title(self._original_title) self._link.set_text(self._original_text) self._link.set_modified(False) self._seo_test(return_value=wx.ID_CANCEL)
def checkbox_event(event: wx.CommandEvent): folder = event.GetEventObject().folder for node in folder.children: if hasattr(node, 'checkbox'): if not event.IsChecked(): node.checkbox.SetValue(False) node.checkbox.Enable(event.IsChecked()) event.Skip()
def __onCmdOk(self, event: CommandEvent): """ If Skip(true) is called, the event processing system continues searching for a further handler function for this event, even though it has been processed already in the current handler. """ event.Skip(skip=True) self.SetReturnCode(OK) self.EndModal(OK)
def _handle_buttons(self, event: wx.CommandEvent) -> None: """ Handle button clicks, run seo check on the new values and display results. Prevent closing if seo failed. :param event: The button event :return: None """ if event.GetId() == wx.ID_OK: # Run spellcheck then run seo test, then save if ok. self._run_spellcheck( ((self._field_global_title, Strings.label_global_title), (self._field_author, Strings.label_author), (self._field_meta_keywords, Strings.label_default_keywords), (self._field_meta_description, Strings.label_main_meta_description), (self._field_black_text, Strings.label_main_page_text), (self._field_red_text, Strings.label_main_page_warning))) if self._seo_test(): # In these cases all documents must be re-exported to reflect the change. result = self._config_manager.store_global_title( self._field_global_title.GetValue()) self._save_all = self._save_all or result result = self._config_manager.store_author( self._field_author.GetValue()) self._save_all = self._save_all or result result = self._config_manager.store_script( self._field_script.GetValue()) self._save_all = self._save_all or result # Keywords can be individual for each page. The global value is for new articles. self._config_manager.store_url(self._field_url.GetValue()) self._config_manager.store_global_keywords( self._field_meta_keywords.GetValue()) self._config_manager.store_contact( self._field_contact.GetValue()) self._config_manager.store_main_page_description( self._field_meta_description.GetValue()) self._config_manager.store_black_text( self._field_black_text.GetValue()) self._config_manager.store_red_text( self._field_red_text.GetValue()) self._config_manager.store_number_of_news( self._news_spinner.GetValue()) event.Skip() elif event.GetId() == wx.ID_CANCEL: event.Skip()
def _handle_buttons(self, event: wx.CommandEvent) -> None: """ Handle button clicks, save the file. :param event: The button event :return: None """ event.Skip() if event.GetId() == wx.ID_OK: self._field_text.SaveFile(str(self._file_name))
def _on_menu_click(self, event: wx.CommandEvent) -> None: """ When the image is moved, we add the AsideImage instance into the event so that the containing panel knows which image is being moved. :param event: The CommandEvent from the button. :return: None """ event.SetClientData(self._image) event.Skip()
def OnClearButton(self, event: wx.CommandEvent) -> None: """ Event handler for clear button being pressed :param event: """ self.m_text.Clear() event.Skip()
def OnWindowDestroy_(self, wxEvent: wx.CommandEvent) -> None: if wxEvent.GetId() != self.wxId_: print("WARNING: Received EVT_WINDOW_DESTROY for another window!") return wxEvent.Skip() for tube in self.tubes_: tube.DisconnectAll()
def onGridLineColorSelectionChanged(self, event: CommandEvent): colorValue: str = event.GetString() pyutColorEnum: PyutColorEnum = PyutColorEnum(colorValue) self._prefs.gridLineColor = pyutColorEnum event.Skip(True)
def _handle_image_buttons(self, event: wx.CommandEvent) -> None: """ Handle image button clicks. :param event: The button event, used to distinguish between buttons. :return: None """ event.Skip() if event.GetId() == wx.ID_FILE1: # Create menu item. if not self._menu_item: menu_item: MenuItem = MenuItem( name='', title='', image_alt='', href=self._field_name.GetValue() + Strings.extension_html, disk_path='', img_filename=Strings.label_none) menu_item.test_self() else: menu_item = self._menu_item edit_dialog = EditMenuItemDialog( self, menu_item, self._config_manager.get_working_dir()) # We first need to show the dialog so that the name label can calculate it's size and then switch to modal. edit_dialog.Show() edit_dialog.display_dialog_contents() result = edit_dialog.ShowModal() edit_dialog.Destroy() if result == wx.ID_OK: # Display the image. Disable section and name fields and enable main image button. self._menu_logo_button.SetBitmap( wx.Bitmap(menu_item.get_image())) self._field_name.Disable() self._box_menu.Disable() self._main_image_button.Enable() self._menu_item = menu_item elif event.GetId() == wx.ID_FILE2: # Create article image. if not self._article_image: image = AsideImage(caption='', title='', image_alt='', original_image_path='', thumbnail_path='', full_filename=Strings.label_none, thumbnail_filename=Strings.label_none) image.test_self() else: image = self._article_image edit_dialog = EditAsideImageDialog( self, image, self._config_manager.get_working_dir()) result = edit_dialog.ShowModal() edit_dialog.Destroy() if result == wx.ID_OK: self._main_image_button.SetBitmap(wx.Bitmap(image.get_image())) self._ok_button.Enable() self._article_image = image
def _handle_buttons(self, event: wx.CommandEvent) -> None: """ Handle button clicks, run seo check on the new values and display results. Prevent closing if seo failed. :param event: The button event :return: None """ if event.GetId() == wx.ID_OPEN: self._save_button.Disable() self._image_path, self._image_name = self._ask_for_image() if self._image_path and self._image_name: self._load_image() self._field_image_name.SetFocus() if self._menu_image: self._save_button.Enable() elif event.GetId() == wx.ID_OK: if self._save(): event.Skip() elif event.GetId() == wx.ID_CANCEL: event.Skip()
def onOK(self, event: wx.CommandEvent) -> None: """Writes settings to the configuration when OK is pressed.""" config = self._config config.Write("loggingLevel", self.logging_choice.GetStringSelection()) config.WriteBool("speechEnabled", self.speech_enabled.GetValue()) config.Write("speechVoice", self.speech_voice.GetStringSelection()) config.WriteInt("speechRate", int(self.speech_rate.GetValue())) config.WriteInt("speechVolume", int(self.speech_volume.GetValue())) config.WriteInt("wordCount", int(self.testing_word_count.GetValue())) config.WriteInt("timeLimit", int(self.testing_time_limit.GetValue())) config.Write("databaseFileName", self.database_file.GetPath()) event.Skip()
def _OnObjectiveChanged(self, event: wx.CommandEvent) -> None: objective_name = event.GetString() self.crosshairBoxSize = 512 * wx.GetApp().Objectives.GetPixelSize() self.offset = wx.GetApp().Objectives.GetOffset() self.objectiveSelectedText.SetLabel(objective_name.center(15)) colour = tuple( [int(x * 255) for x in wx.GetApp().Objectives.GetColour()]) self.objectiveSelectedText.SetBackgroundColour(colour) #force a redraw so that the crosshairs are properly sized self.Refresh() event.Skip()
def _handle_buttons(self, event: wx.CommandEvent) -> None: """ Handle button clicks, run seo check on the new values and display results. Prevent closing if seo failed. :param event: The button event :return: None """ if event.GetId() == wx.ID_OK: self._config_manager.store_spelling_language(self._language_list.GetValue()) event.Skip() elif event.GetId() == wx.ID_EDIT: dlg = PlainTextEditDialog(self, self._user_dict) dlg.ShowModal() self._rerun_spellchecks = True dlg.Destroy() elif event.GetId() == wx.ID_IGNORE: dlg = PlainTextEditDialog(self, self._user_exclusion_list) dlg.ShowModal() self._rerun_spellchecks = True dlg.Destroy() elif event.GetId() == wx.ID_CANCEL: event.Skip()
def onEnableBackgroundGridChanged(self, event: CommandEvent): enabledValue: bool = event.IsChecked() BackgroundPreferences.clsLogger.warning( f'onEnableBackgroundGridChanged - {enabledValue}') self._prefs.backgroundGridEnabled = enabledValue if enabledValue is True: self._cbSnapToGrid.Enabled = True else: self._cbSnapToGrid.SetValue(False) self._cbSnapToGrid.Enabled = False self._prefs.snapToGrid = False event.Skip(True)
def _handle_buttons(self, event: wx.CommandEvent) -> None: """ Handle button clicks, run seo check on the new values and display results. Prevent closing if seo failed. :param event: The button event :return: None """ event.Skip() if event.GetId() == wx.ID_OK: self._save() elif event.GetId() == wx.ID_SPELL_CHECK: self._run_spellcheck( ((self._field_page_name, Strings.label_menu_name), (self._field_meta_keywords, Strings.label_menu_meta_keywords), (self._field_meta_description, Strings.label_menu_meta_description)))
def _onOk(self, event: CommandEvent): """ Called when the Ok button is pressed Args: event: """ self._pyutModel.setName(self._txtName.GetValue()) self._pyutModel.methods = self._pyutModelCopy.methods self._pyutModel.description = self._pyutModelCopy.description self._returnAction = OK # This is probably obsolete event.Skip(skip=True) self.SetReturnCode(OK) self.EndModal(OK)
def menuHandler(self, event: wx.CommandEvent) -> None: """Handles menu events. Take action(s) based on the id contained in the event. Passes the event on to the next handler when finished. Args: event (wx.CommandEvent): The event which called this function. """ id = event.GetId() logging.debug(f"Handling menu event {id}") if id == wx.ID_EXIT: self.GetParent().onExit(event) elif id == wx.ID_ABOUT: wx.MessageBox("Typing Test by Thomas Stivers") elif id == wx.ID_CLEAR: pass elif id == self._ADD_SENTENCES_FROM_FILE_ID: directory_name = os.path.abspath(".") file_name = "" with wx.FileDialog(self, "Import sentences from text file.", directory_name, file_name, "*.txt", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as dlg: if dlg.ShowModal() == wx.ID_OK: file_name = dlg.GetFilename() directory_name = dlg.GetDirectory() path = os.path.join(directory_name, file_name) Sentences.fillSentences(filename=path) elif id == self._ADD_SENTENCE_ID: self.GetParent().tests_panel.onAddSentence(None) elif id == wx.ID_DELETE: self.GetParent().results_panel.onRemoveResult(event) elif id == self._EDIT_SENTENCE_ID: self.GetParent().tests_panel.onEditSentence(event) elif id == self._VIEW_RESULTS_ID: self.GetParent().notebook.ChangeSelection(0) elif id == self._VIEW_TESTS_ID: self.GetParent().notebook.ChangeSelection(1) elif id == self._VIEW_USERS_ID: self.GetParent().notebook.ChangeSelection(2) event.Skip()
def onEnter(self, event: wx.CommandEvent = None) -> None: """Handles enter when pressed in typed_text.""" # WHY(self.time = int((datetime.datetime.now()-self.start_time).seconds)) self.typed_list.append(self.typed_text.GetValue().strip()) self.typed_count += len(self.typed_list[-1].split()) self.typed_text.Clear() if self.typed_count <= self.word_count: record = Sentences.randomSentence() while record.id in self.used_sentences: record = Sentences.randomSentence() self.used_sentences.add(record.id) sentence = record.sentence self.given_text.SetLabel(sentence) self.given_list.append(sentence) self.Refresh() if self.speech_enabled: self.speaker.say(sentence) event.Skip() else: self.storeResults(self.calculateResults()) if self.speech_enabled: self.speaker.endLoop() wx.MessageBox("Test completed.", caption="Done") self.end_time = datetime.datetime.now()
def _handle_buttons(self, event: wx.CommandEvent) -> None: """ Handle button clicks, check if target file exists and prevent overwriting it. :param event: The button event, used to distinguish between buttons. :return: None """ event.Skip() if event.GetId() == wx.ID_OK: # Add the new menu item into the correct menu document instance. for menu in self._menus.values(): if menu.get_page_name()[0] == self._box_menu.GetValue(): menu.add_item(self._menu_item) # Create the document once all is set. Add item into menu, let document determine section. self._doc = WhitebearDocumentArticle(self._document_path, self._menus, self._articles, self._css_document) self._doc.set_index_document(self._index) self._doc.determine_menu_section_and_menu_item() self._doc.set_article_image(self._article_image) self._doc.set_date(self._get_current_date()) self._doc.set_keywords( self._config_manager.get_global_keywords().split(', ')) self._doc.test_self(online=False)
def on_text_change(self, event: wx.CommandEvent) -> None: """On EVT_TEXT, set dirty flag true.""" self._text_dirty = True event.Skip()
def on_set_focus(self, event: wx.CommandEvent) -> None: """On EVT_SET_FOCUS, select digits.""" self.SetSelection(0, self.Value.find(' ')) event.Skip()
def on_left_up(self, event: wx.CommandEvent) -> None: """On EVT_LEFT_UP, if not already focused, select digits.""" if not self._selected_dirty: self._selected_dirty = True self.SetSelection(0, self.Value.find(' ')) event.Skip()