Exemple #1
0
 def focusOutEvent(self, event):
     """Event that fires when the REPL loses focus"""
     self.main_form._key_events_unlock()
     data.print_log("Left REPL")
     #Ignore the event
     event.ignore()
     #Return the focus event
     return data.QLineEdit.focusOutEvent(self, event)
Exemple #2
0
 def plain_add_document(self, document_name):
     """Add a plain scintilla document to self(QTabWidget)"""
     #Create new scintilla object
     new_editor_tab = self.plain_create_document(document_name)
     #Add the scintilla document to the tab widget
     new_editor_tab_index = self.addTab(new_editor_tab, document_name)
     #Make new tab visible
     self.setCurrentIndex(new_editor_tab_index)
     data.print_log("Added new empty tab: " + document_name)
     #Return the reference to the new added scintilla tab widget
     return self.widget(new_editor_tab_index)
Exemple #3
0
 def enterEvent(self, enter_event):
     """Event that fires when the focus shifts to the BasicWidget"""
     cw = self.currentWidget()
     if cw != None:
         #Check if the current widget is a custom editor or a QTextEdit widget
         if isinstance(cw, CustomEditor):
             #Get currently selected tab in the basic widget and display its name and lexer
             self._parent.display.write_to_statusbar(cw.name)
         else:
             #Display only the QTextEdit name
             self._parent.display.write_to_statusbar(cw.name)
     data.print_log("Entered BasicWidget: " + str(self.name))
 def mousePressEvent(self, event):
     """Function connected to the clicked signal of the tree display"""
     super().mousePressEvent(event)
     #Set the focus
     self.setFocus()
     #Set the last focused widget to the parent basic widget
     self.main_form.last_focused_widget = self._parent
     data.print_log("Stored \"{:s}\" as last focused widget".format(
         self._parent.name))
     #Set Save/SaveAs buttons in the menubar
     self._parent._set_save_status()
     # Reset the click&drag context menu action
     components.ActionFilter.clear_action()
Exemple #5
0
 def mousePressEvent(self, event):
     """Overloaded mouse click event"""
     #Execute the superclass mouse click event
     super().mousePressEvent(event)
     #Set focus to the clicked editor
     self.setFocus()
     #Set the last focused widget to the parent basic widget
     self.main_form.last_focused_widget = self._parent
     data.print_log("Stored \"{}\" as last focused widget".format(
         self._parent.name))
     #Hide the function wheel if it is shown
     self.main_form.view.hide_all_overlay_widgets()
     # Reset the click&drag context menu action
     components.ActionFilter.clear_action()
Exemple #6
0
 def mousePressEvent(self, event):
     # Execute the superclass mouse click event
     super().mousePressEvent(event)
     # Reset the main forms last focused widget
     self.main_form.last_focused_widget = None
     data.print_log("Reset last focused widget attribute")
     # Set focus to the clicked helper
     self.setFocus()
     # Hide the function wheel if it is shown
     self.main_form.view.hide_all_overlay_widgets()
     # Need to set focus to self or the repl helper doesn't get focused,
     # don't know why?
     self.setFocus()
     # Reset the click&drag context menu action
     components.ActionFilter.clear_action()
Exemple #7
0
 def focusInEvent(self, event):
     """Event that fires when the REPL gets focus"""
     self.main_form._key_events_lock()
     #Set the focus to the REPL
     self.setFocus()
     #Clear the cursor position from the statusbar
     self.main_form.display.update_cursor_position()
     data.print_log("Entered REPL")
     #Reset the main forms last focused widget
     self.main_form.last_focused_widget = None
     data.print_log("Reset last focused widget attribute")
     #Hide the function wheel if it is shown
     self.main_form.view.hide_all_overlay_widgets()
     #Ignore the event
     event.ignore()
     #Return the focus event
     return data.QLineEdit.focusInEvent(self, event)
Exemple #8
0
    def _signal_editor_tabclose(self, emmited_tab_number, force=False):
        """Event that fires when a tab close"""

        #Nested function for clearing all bookmarks in the document
        def clear_document_bookmarks():
            #Check if bookmarks need to be cleared
            if isinstance(self.widget(emmited_tab_number), CustomEditor):
                self._parent.bookmarks.remove_editor_all(
                    self.widget(emmited_tab_number))

        data.print_log("Closing tab: " + str(self.tabText(emmited_tab_number)))
        # Store the tab reference
        tab = self.widget(emmited_tab_number)
        #Check if the document is modified
        if tab.savable == data.CanSave.YES:
            if tab.save_status == data.FileStatus.MODIFIED and force == False:
                #Close the log window if it is displayed
                self._parent.view.set_log_window(False)
                #Display the close notification
                close_message = "Document '" + self.tabText(emmited_tab_number)
                close_message += "' has been modified!\nClose it anyway?"
                reply = YesNoDialog.question(close_message)
                if reply == data.QMessageBox.Yes:
                    clear_document_bookmarks()
                    #Close tab anyway
                    self.removeTab(emmited_tab_number)
                else:
                    #Cancel tab closing
                    return
            else:
                clear_document_bookmarks()
                #The document is unmodified
                self.removeTab(emmited_tab_number)
        else:
            clear_document_bookmarks()
            #The document cannot be saved, close it
            self.removeTab(emmited_tab_number)
        # Delete the tab from memory
        if hasattr(tab, "clean_up"):
            tab.clean_up()
        # Just in case, decrement the refcount of the tab (that's what del does)
        del tab
Exemple #9
0
 def _signal_editor_tabindex_change(self, change_event):
     """Signal when the tab index changes"""
     # Set Save/SaveAs buttons in the menubar
     self._set_save_status()
     # Check if there is a tab in the tab widget
     current_tab = self.currentWidget()
     if current_tab:
         data.print_log("Selected tab: " + str(self.currentWidget().name))
     # Update the icons of the tabs
     for i in range(self.count()):
         self.update_tab_icon(self.widget(i))
     # Update the corner widgets
     if current_tab != None and hasattr(current_tab, "icon_manipulator"):
         if current_tab.icon_manipulator.update_corner_widget(
                 current_tab) == False:
             # Remove the corner widget if the current widget is of an unknown type
             self.setCornerWidget(None)
     else:
         # Remove the corner widget if there is no current tab active
         self.setCornerWidget(None)
Exemple #10
0
 def mousePressEvent(self, event):
     super().mousePressEvent(event)
     # Set focus to the clicked basic widget
     self.setFocus()
     # Set Save/SaveAs buttons in the menubar
     self._set_save_status()
     # Store the last focused widget to the parent
     self._parent.last_focused_widget = self
     data.print_log("Stored \"{}\" as last focused widget".format(
         self.name))
     # Hide the function wheel if it is shown
     self._parent.view.hide_all_overlay_widgets()
     if (event.button() == data.Qt.RightButton and self.count() == 0):
         # Show the function wheel if right clicked
         self._parent.view.show_function_wheel()
     # Display the tab name in the log window
     if self.currentWidget() != None:
         tab_name = self.currentWidget().name
         data.print_log("Mouse click in: \"" + str(tab_name) + "\"")
     else:
         # Clear the cursor positions in the statusbar
         self._parent.display.update_cursor_position()
         data.print_log("Mouse click in: \"" + self.name + "\"")
     # Reset the click&drag context menu action
     components.ActionFilter.clear_action()
Exemple #11
0
 def dropEvent(self, event):
     """Qt Drop event"""
     if self.drag_dropped_file != None:
         #Displays the file name with path
         data.print_log("Drag&Dropped: " + str(self.drag_dropped_file))
         #Open file in a new scintilla tab
         self._parent.open_file(self.drag_dropped_file, self)
         event.accept()
     elif self.drag_text != None:
         #Drag&drop widget event occured
         try:
             name, str_index = self.drag_text.split()
             index = int(str_index)
             key_modifiers = data.QApplication.keyboardModifiers()
             if (key_modifiers == data.Qt.ControlModifier
                     or key_modifiers == data.Qt.AltModifier):
                 self.copy_editor_in(self.drag_source, index)
                 data.print_log(
                     "Drag&Drop copied tab {:d} from the {} widget".format(
                         index, name))
             else:
                 self.move_editor_in(self.drag_source, index)
                 data.print_log(
                     "Drag&Drop moved tab {:d} from the {} widget".format(
                         index, name))
             event.accept()
         except:
             self._parent.display.repl_display_message(
                 traceback.format_exc(),
                 message_type=data.MessageType.ERROR)
     #Reset the drag&drop data attributes
     self.drag_dropped_file = None
     self.drag_text = None
Exemple #12
0
 def _get_valid_sequence_list(self, string):
     """
     Get the last one or two valid sequence, which will be compared to autocompletion list
     E.G. 1: "print(main.se" returns >> first = "se", second = "main"
     E.G. 2: "print_log(nek" returns >> first = "nek", second = ""
     """
     raw_text = string
     current_sequence = ""
     previous_sequence = ""
     #List the separators as they appear in the raw string
     separator_list = []
     for ch in raw_text:
         if ch in self._comparison_list:
             separator_list.append(ch)
     #Do the standard autocompletion parse
     for i, ch_1 in reversed(list(enumerate(raw_text))):
         #Get the last valid separation character
         if ch_1 in self._comparison_list:
             current_sequence = raw_text[(i + 1):]
             #If the character is a dot, return the previous sequence also
             if ch_1 == ".":
                 #The separator is a dot, get the previous sequence in case it's a class
                 for j, ch_2 in reversed(list(enumerate(raw_text[:i]))):
                     if ch_2 in self._reduced_comparison_list:
                         #Found a character from the reduced comparison list
                         previous_sequence = raw_text[(j + 1):i]
                         break
                     elif j == 0:
                         #Did not find a character from the reduced comparison list and reached the beggining of text
                         previous_sequence = raw_text[j:i]
                         break
             break
     if not [x for x in raw_text if x in self._comparison_list]:
         #None of the separator characters were found in current text
         current_sequence = self.text()
     data.print_log(previous_sequence + "  " + current_sequence)
     return [current_sequence, previous_sequence]
Exemple #13
0
 def wheelEvent(self, wheel_event):
     """Overridden mouse wheel rotate event"""
     key_modifiers = data.QApplication.keyboardModifiers()
     if data.PYQT_MODE == 4:
         delta = wheel_event.delta()
     else:
         delta = wheel_event.angleDelta().y()
     if delta < 0:
         data.print_log("REPL helper mouse rotate down event")
         if key_modifiers == data.Qt.ControlModifier:
             #Zoom out the scintilla tab view
             self.decrease_text_size()
     else:
         data.print_log("REPL helper mouse rotate up event")
         if key_modifiers == data.Qt.ControlModifier:
             #Zoom in the scintilla tab view
             self.increase_text_size()
     #Handle the event
     if key_modifiers == data.Qt.ControlModifier:
         #Accept the event, the event will not be propageted(sent forward) to the parent
         wheel_event.accept()
     else:
         #Propagate(send forward) the wheel event to the parent
         wheel_event.ignore()
Exemple #14
0
 def wheelEvent(self, wheel_event):
     """Overridden mouse wheel rotate event"""
     key_modifiers = data.QApplication.keyboardModifiers()
     if data.PYQT_MODE == 4:
         delta = wheel_event.delta()
     else:
         delta = wheel_event.angleDelta().y()
     if delta < 0:
         data.print_log("REPL helper mouse rotate down event")
         if key_modifiers == data.Qt.ControlModifier:
             #Zoom out the scintilla tab view
             self.zoomOut()
     else:
         data.print_log("REPL helper mouse rotate up event")
         if key_modifiers == data.Qt.ControlModifier:
             #Zoom in the scintilla tab view
             self.zoomIn()
     #Handle the event
     if key_modifiers != data.Qt.ControlModifier:
         #Execute the superclass method
         super().wheelEvent(wheel_event)
     else:
         #Propagate(send forward) the wheel event to the parent
         wheel_event.ignore()
Exemple #15
0
 def _repl_eval(self, external_string=None, display_action=True):
     """Evaluate string entered into the REPL widget"""
     data.print_log("REPL evaluated")
     #Check if an external evaluation string was specified
     if external_string == None:
         #No external evaluation string, evaluate the REPL text
         current_command = self.text()
     else:
         current_command = external_string
     #Display evaluated command if specified
     current_rm_index = None
     if display_action == True:
         repl_messages = self.main_form.display.find_repl_messages_tab()
         if repl_messages != None:
             if repl_messages._parent.count() > 1:
                 current_rm_index = repl_messages._parent.currentIndex()
         #Display the evaluated command (this sets the focus to the REPL messages tab)
         split_command = current_command.split("\n")
         for i, command in enumerate(split_command):
             if i != 0:
                 self.main_form.display.repl_display_message("... " +
                                                             command)
             else:
                 self.main_form.display.repl_display_message(">>> " +
                                                             command)
         if current_rm_index != None:
             #Revert the focus of the TabWidget that hold the REPL messages tab to
             #whichever widget was focused before
             repl_messages._parent.setCurrentIndex(current_rm_index)
     #Evaluate the REPL text and store the result
     eval_return = self.interpreter.eval_command(current_command,
                                                 display_action)
     #Save text into the input buffer
     self._input_buffer_add(self.text())
     #Clear the REPL text
     self.setText("")
     #Check if the REPL focus flag is set
     if self._repl_focus_flag == True:
         #Skip setting focus back to the REPL and reset the skip focus flag
         self._repl_focus_flag = False
     else:
         #Set focus back to the REPL
         self.setFocus()
     #Check evaluation return message and display it in the "REPL Messages" tab
     if eval_return is not None:
         data.print_log(eval_return)
         if display_action == True:
             self.main_form.display.repl_display_message(
                 eval_return, message_type=data.MessageType.ERROR)
         else:
             return eval_return
     else:
         data.print_log("EVALUATION/EXECUTION SUCCESS")
     return None
Exemple #16
0
 def editor_add_document(self,
                         document_name,
                         type=None,
                         bypass_check=False):
     """Check tab type and add a document to self(QTabWidget)"""
     if type == "file":
         ## New tab is a file on disk
         file_type = "unknown"
         if bypass_check == False:
             file_type = functions.get_file_type(document_name)
         if file_type != "unknown" or bypass_check == True:
             # Test if file can be read
             if functions.test_text_file(document_name) == None:
                 self._parent.display.repl_display_message(
                     "Testing for TEXT file failed!",
                     message_type=data.MessageType.ERROR)
                 # File cannot be read
                 return None
             # Create new scintilla document
             new_editor_tab = self.editor_create_document(document_name)
             # Set the lexer that colour codes the document
             new_editor_tab.choose_lexer(file_type)
             # Add the scintilla document to the tab widget
             new_editor_tab_index = self.addTab(
                 new_editor_tab, os.path.basename(document_name))
             # Make the new tab visible
             self.setCurrentIndex(new_editor_tab_index)
             data.print_log("Added file: " + document_name)
             # Return the reference to the new added scintilla tab widget
             return self.widget(new_editor_tab_index)
         else:
             data.print_log(
                 "!! Document is not a text file or has an unsupported format"
             )
             self._parent.display.write_to_statusbar(
                 "Document is not a text file, doesn't exist or has an unsupported format!",
                 1500)
             return None
     else:
         ## New tab is an empty tab
         # Create new scintilla object
         new_editor_tab = self.editor_create_document(document_name)
         # Add the scintilla document to the tab widget
         new_editor_tab_index = self.addTab(new_editor_tab, document_name)
         # Make new tab visible
         self.setCurrentIndex(new_editor_tab_index)
         data.print_log("Added new empty tab: " + document_name)
         # Return the reference to the new added scintilla tab widget
         return self.widget(new_editor_tab_index)
Exemple #17
0
 def eval_command(self, command, display_action=True):
     """
     This EVAL function executes the command by the interactive interpreter.
     (inputted by the REPL ReplLineEdit and pressing enter)
     """
     try:
         #Reset the error message
         self.eval_error = None
         #Replace certain strings with methods
         filtered_command = self.replace_references(self.dict_re_references,
                                                    command)
         filtered_command = self.replace_keywords(self.dict_keywords,
                                                  filtered_command)
         #Remove the literal sequences from the command
         filtered_command = filtered_command.replace(
             self.re_escape_sequence, "")
         data.print_log("------------------")
         data.print_log(">>> " + command)
         data.print_log(">> " + filtered_command)
         #Execute the filtered command string with the custom InteractiveInterpreter
         #First try to evaluate the command string, to see if it's an expression
         try:
             #Try to EVALUATE the command
             data.print_log("Trying to EVALUATE the command.")
             eval_return = eval(filtered_command, self.locals)
             if display_action == True:
                 self.repl_print(eval_return)
             data.print_log(eval_return)
             data.print_log("Evaluation succeeded!")
             return None
         except:
             #EXECUTE
             self.eval_error = None
             data.print_log("Evaluation failed! EXECUTING the command.")
             #Execute and return the error message
             return self._custom_runcode(filtered_command)
     except Exception as ex:
         data.print_log("!! Cannot run code: \"" + str(command) + "\"")
         data.print_log(str(ex))
         return "REPL evaluation error!"
Exemple #18
0
 def eval_command(self, command, display_action=True):
     """
     This EVAL function executes the command by the interactive interpreter.
     (inputted by the REPL ReplLineEdit and pressing enter)
     """
     try:
         #Reset the error message
         self.eval_error = None
         #Replace certain strings with methods
         filtered_command = self.replace_references(self.dict_re_references, command)
         filtered_command = self.replace_keywords(self.dict_keywords, filtered_command)
         #Remove the literal sequences from the command
         filtered_command = filtered_command.replace(self.re_escape_sequence, "")
         data.print_log("------------------")
         data.print_log(">>> " + command)
         data.print_log(">> " + filtered_command)
         #Execute the filtered command string with the custom InteractiveInterpreter
         #First try to evaluate the command string, to see if it's an expression
         try:
             #Try to EVALUATE the command
             data.print_log("Trying to EVALUATE the command.")
             eval_return = eval(filtered_command, self.locals)
             if display_action == True:
                 self.repl_print(eval_return)
             data.print_log(eval_return)
             data.print_log("Evaluation succeeded!")
             return None
         except:
             #EXECUTE
             self.eval_error = None
             data.print_log("Evaluation failed! EXECUTING the command.")
             #Execute and return the error message
             return self._custom_runcode(filtered_command)
     except Exception as ex:
         data.print_log("!! Cannot run code: \"" + str(command) + "\"")
         data.print_log(str(ex))
         return "REPL evaluation error!"