def __init__(self): super(PugdebugMainWindow, self).__init__() self.setObjectName("pugdebug") self.setWindowTitle("pugdebug") if has_setting("window/geometry"): self.restoreGeometry(get_setting("window/geometry")) self.file_browser = PugdebugFileBrowser() self.projects_browser = PugdebugProjectsBrowser() self.settings_window = PugdebugSettingsWindow(self) self.new_project_window = PugdebugNewProjectWindow(self) self.document_viewer = PugdebugDocumentViewer() self.variable_viewer = PugdebugVariableViewer() self.breakpoint_viewer = PugdebugBreakpointViewer() self.stacktrace_viewer = PugdebugStacktraceViewer() self.expression_viewer = PugdebugExpressionViewer() self.file_search_window = PugdebugFileSearchWindow(self) self.setCentralWidget(self.document_viewer) self.setup_gui_elements() if has_setting("window/state"): self.restoreState(get_setting("window/state")) if has_setting("current_project"): self.set_window_title(get_setting("current_project")) self.projects_browser.project_deleted_signal.connect( self.handle_project_deleted)
def __init__(self): super(PugdebugMainWindow, self).__init__() self.setObjectName("pugdebug") self.setWindowTitle("pugdebug") if has_setting("window/geometry"): self.restoreGeometry(get_setting("window/geometry")) self.file_browser = PugdebugFileBrowser() self.projects_browser = PugdebugProjectsBrowser() self.settings_window = PugdebugSettingsWindow(self) self.new_project_window = PugdebugNewProjectWindow(self) self.document_viewer = PugdebugDocumentViewer() self.variable_viewer = PugdebugVariableViewer() self.breakpoint_viewer = PugdebugBreakpointViewer() self.stacktrace_viewer = PugdebugStacktraceViewer() self.expression_viewer = PugdebugExpressionViewer() self.setCentralWidget(self.document_viewer) self.setup_gui_elements() if has_setting("window/state"): self.restoreState(get_setting("window/state")) if has_setting("current_project"): self.set_window_title(get_setting("current_project")) self.projects_browser.project_deleted_signal.connect(self.handle_project_deleted)
def __cut_filename(self, filename): path_map = get_setting('path/path_mapping') if len(path_map) > 0: filename = filename[len(path_map):] else: root = get_setting('path/project_root') filename = filename[len(root):] return "~%s" % filename
def __listen(self, socket_server): """Listen to new incomming connections For every accepted connection, see if it is valid and emit a signal with that new connection. Otherwise silently disregard that connection. """ host = get_setting('debugger/host') port_number = int(get_setting('debugger/port_number')) try: socket_server.bind((host, port_number)) socket_server.listen(5) while self.wait_for_accept: try: sock, address = socket_server.accept() sock.settimeout(None) if sock is not None: connection = PugdebugServerConnection(sock) try: is_valid = connection.init_connection() except OSError as e: # in case the debugged program closes # the connection is_valid = False self.server_error_signal.emit( '%s (during connection initialization)' % e.strerror) if is_valid and self.wait_for_accept: self.new_connection_established_signal.emit( connection) else: connection.disconnect() except socket.timeout: pass except OSError as e: self.server_error_signal.emit(e.strerror) finally: socket_server.close() if not self.wait_for_accept: self.server_stopped_signal.emit()
def start_listening(self): """Start listening to new incomming connections Clear the variable viewer. Clear the stacktrace viewer. Remove all line highlights. Start a debugging session. """ break_at_first_line = int(get_setting('debugger/break_at_first_line')) start_debugging = True if break_at_first_line == 0 and len(self.breakpoints) == 0: messageBox = QMessageBox() messageBox.setText("There are no breakpoints set and the break at" " first line setting is turned off.") messageBox.setInformativeText("Are you sure you want to start" " debugging?") messageBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No) answer = messageBox.exec_() if answer == QMessageBox.No: start_debugging = False if start_debugging: self.variable_viewer.clear() self.stacktrace_viewer.clear() self.document_viewer.remove_line_highlights() self.debugger.start_listening() self.main_window.set_debugging_status(1)
def handle_settings_changed(self, changed_settings): """Handle when settings have changed. Given argument is a set of settings's names which have been changed. """ if has_setting('current_project'): project_name = get_setting('current_project') project = self.projects_browser.load_project_by_name(project_name) if project is not None: project.set_settings(changed_settings) changed_setting_keys = changed_settings.keys() if 'path/project_root' in changed_setting_keys: self.handle_project_root_changed() features = [ 'debugger/max_depth', 'debugger/max_children', 'debugger/max_data' ] if any(True for feature in features if feature in changed_setting_keys): self.handle_debugger_features_changed()
def handle_settings_changed(self, changed_settings): """Handle when settings have changed. Given argument is a set of settings's names which have been changed. """ if has_setting('current_project'): project_name = get_setting('current_project') project = self.projects_browser.load_project_by_name(project_name) if project is not None: project.set_settings(changed_settings) changed_setting_keys = changed_settings.keys() if 'path/project_root' in changed_setting_keys: self.handle_project_root_changed() features = ['debugger/max_depth', 'debugger/max_children', 'debugger/max_data'] if any(True for feature in features if feature in changed_setting_keys): self.handle_debugger_features_changed()
def is_project_current(self): if has_setting('current_project'): current_project = get_setting('current_project') if current_project == self.get_project_name(): return True return False
def __listen(self, socket_server): """Listen to new incomming connections For every accepted connection, see if it is valid and emit a signal with that new connection. Otherwise silently disregard that connection. """ host = get_setting('debugger/host') port_number = int(get_setting('debugger/port_number')) try: socket_server.bind((host, port_number)) socket_server.listen(5) while self.wait_for_accept: try: sock, address = socket_server.accept() sock.settimeout(None) if sock is not None: connection = PugdebugServerConnection(sock) try: is_valid = connection.init_connection() except OSError as e: # in case the debugged program closes the connection is_valid = False self.server_error_signal.emit('%s (during connection initialization)' % e.strerror) if is_valid and self.wait_for_accept: self.new_connection_established_signal.emit( connection ) else: connection.disconnect() except socket.timeout: pass except OSError as e: self.server_error_signal.emit(e.strerror) finally: socket_server.close() if not self.wait_for_accept: self.server_stopped_signal.emit()
def is_project_current(self): if has_setting("current_project"): current_project = get_setting("current_project") if current_project == self.get_project_name(): return True return False
def __set_debugger_features(self): max_depth = int(get_setting('debugger/max_depth')) command = 'feature_set -i %d -n max_depth -v %d' % ( self.__get_transaction_id(), max_depth) self.__send_command(command) max_children = int(get_setting('debugger/max_children')) command = 'feature_set -i %d -n max_children -v %d' % ( self.__get_transaction_id(), max_children) self.__send_command(command) max_data = int(get_setting('debugger/max_data')) command = 'feature_set -i %d -n max_data -v %d' % ( self.__get_transaction_id(), max_data) self.__send_command(command) return True
def restore_state(self): """Load expressions from settings""" expressions = [] if has_setting('expressions_viewer/expressions'): expressions = get_setting('expressions_viewer/expressions') if expressions is not None: for expression in expressions: self.add_expression(expression)
def handle_debugging_post_start(self): """Handle post start debugging If the code should not break at first line, run the debugger. """ break_at_first_line = int(get_setting('debugger/break_at_first_line')) if break_at_first_line == 0: self.run_debug() else: self.step_into()
def handle_project_root_changed(self): """Handle when the project root is changed Update the file browser's model to the new root. """ project_root = get_setting('path/project_root') logging.debug("Project root changed: %s" % project_root) self.file_browser.set_path(project_root)
def handle_project_root_changed(self): """Handle when the project root is changed Update the file browser's model to the new root. """ project_root = get_setting('path/project_root') model = self.file_browser.model() model.set_path(project_root) self.file_browser.setModel(model) self.file_browser.setRootIndex(model.start_index)
def setup_file_browser(self): """Setup the file browser Sets the model on the file browser and hides the not needed columns. """ project_root = get_setting('path/project_root') model = PugdebugFileBrowser(self) self.file_browser.setModel(model) self.file_browser.set_path(project_root)
def __get_path_mapped_to_remote(self, path): """Get a path mapped to remote Turns a path like /home/user/local/path to /var/www """ path_map = get_setting('path/path_mapping') root_path = self.file_browser.model().rootPath() if len(path_map) > 0 and path.find(root_path) == 0: path = path[len(root_path):] path = "%s%s" % (path_map, path) return path
def __set_debugger_features(self): max_depth = int(get_setting('debugger/max_depth')) command = 'feature_set -i %d -n max_depth -v %d' % ( self.__get_transaction_id(), max_depth ) response = self.__send_command(command) max_children = int(get_setting('debugger/max_children')) command = 'feature_set -i %d -n max_children -v %d' % ( self.__get_transaction_id(), max_children ) response = self.__send_command(command) max_data = int(get_setting('debugger/max_data')) command = 'feature_set -i %d -n max_data -v %d' % ( self.__get_transaction_id(), max_data ) response = self.__send_command(command) return True
def setup_file_browser(self): """Setup the file browser Sets the model on the file browser and hides the not needed columns. """ project_root = get_setting('path/project_root') model = PugdebugFileBrowser(self) model.set_path(project_root) self.file_browser.setModel(model) self.file_browser.setRootIndex(model.start_index) self.file_browser.hide_columns()
def handle_debugging_post_start(self): """Handle post start debugging If the code should not break at first line, run the debugger. """ logging.debug("Post start") break_at_first_line = int(get_setting('debugger/break_at_first_line')) logging.debug("Break at first line: %s" % ('Yes' if break_at_first_line != 0 else 'No')) if break_at_first_line == 0: self.run_debug() else: self.step_into()
def __get_path_mapped_to_local(self, path, map_paths=True): """Get a path mapped to local Turns a path like /var/www into /home/user/local/path """ path_map = get_setting('path/path_mapping') if (len(path_map) > 0 and map_paths is True and path.find(path_map) == 0): path_map = path_map.rstrip('/') path = path[len(path_map):] path = "%s%s" % (self.file_browser.model().rootPath(), path) if not os.path.isfile(path): return False return path
def __get_path_mapped_to_local(self, path, map_paths=True): """Get a path mapped to local Turns a path like /var/www into /home/user/local/path """ path_map = get_setting('path/path_mapping') if (len(path_map) > 0 and map_paths is True and path.find(path_map) == 0): path = path[len(path_map):] path = "%s%s" % (self.file_browser.model().rootPath(), path) if not os.path.isfile(path): return False return path
def init_connection(self): """Init a new connection Read in the init message from xdebug and decide based on the idekey should this connection be accepted or not. Do note that it is not needed to call it from a new thread, as it is already called from a thread separate from the main application thread and thus should not block the main thread. """ idekey = get_setting('debugger/idekey') response = self.__receive_message() init_message = self.parser.parse_init_message(response) # See if the init message from xdebug is meant for us if idekey != '' and init_message['idekey'] != idekey: return False self.init_message = init_message return True
def set_font_size(self): font = QFont() font.setPixelSize(int(get_setting('editor/font_size'))) self.setFont(font)
def load_settings(self): """Loads all settings from QSettings into the form""" for name, widget in self.form.widgets.items(): value = get_setting(name) if has_setting(name) \ else get_default_setting(name) self.form.set_widget_value(widget, value)
def exec(self): self.project_root = get_setting('path/project_root') self.file_search = PugdebugFileSearch(self, self.project_root) super(PugdebugFileSearchWindow, self).exec()
def set_editor_features(self): self.setTabStopWidth(int(get_setting('editor/tab_width'))) font = QFont('mono') font.setPixelSize(int(get_setting('editor/font_size'))) self.setFont(font)