def test(): """Local test.""" from trex.utils.qthelpers import qapplication app = qapplication() dlg = ProjectDialog(None) dlg.show() sys.exit(app.exec_())
def test(text): """Test""" from trex.utils.qthelpers import qapplication _app = qapplication() # analysis:ignore dialog = ImportWizard(None, text) if dialog.exec_(): print(dialog.get_data()) # trex: test-skip
def test(): from trex.utils.qthelpers import qapplication app = qapplication() test = ProjectExplorerTest() test.resize(250, 480) test.show() app.exec_()
def test(): """Run breakpoint widget test""" from trex.utils.qthelpers import qapplication app = qapplication() widget = BreakpointWidget(None) widget.show() sys.exit(app.exec_())
def test(): """Run Find in Files widget test""" from trex.utils.qthelpers import qapplication app = qapplication() widget = FindInFilesWidget(None) widget.resize(640, 480) widget.show() sys.exit(app.exec_())
def test(): from trex.utils.qthelpers import qapplication app = qapplication() table = ShortcutsTable() table.show() app.exec_() print([str(s) for s in table.source_model.shortcuts]) # trex: test-skip table.check_shortcuts()
def test(): # pragma: no cover from trex.utils.qthelpers import qapplication app = qapplication() dlg_table = NumpyArrayDialog(None, inline=False) dlg_inline = NumpyArrayDialog(None, inline=True) dlg_table.show() dlg_inline.show() app.exec_()
def test(): """Run web browser""" from trex.utils.qthelpers import qapplication app = qapplication(test_time=8) widget = PydocBrowser(None) widget.show() widget.initialize() sys.exit(app.exec_())
def test(): """Run path manager test""" from trex.utils.qthelpers import qapplication _app = qapplication() # analysis:ignore test = PathManager(None, pathlist=sys.path[:-10], ro_pathlist=sys.path[-10:]) test.exec_() print(test.get_path_list()) # trex: test-skip
def construct_editor(text): app = qapplication() editor = CodeEditor(parent=None) editor.setup_editor(language='Python') editor.set_text(text) cursor = editor.textCursor() cursor.movePosition(QTextCursor.End) editor.setTextCursor(cursor) return editor
def test(): """Run web browser""" from trex.utils.qthelpers import qapplication app = qapplication(test_time=8) widget = WebBrowser() widget.show() widget.set_home_url('http://www.google.com/') widget.go_home() sys.exit(app.exec_())
def test(file_explorer): from trex.utils.qthelpers import qapplication app = qapplication() if file_explorer: test = FileExplorerTest() else: test = ProjectExplorerTest() test.resize(640, 480) test.show() app.exec_()
def main(): """Run Windows environment variable editor""" from trex.utils.qthelpers import qapplication app = qapplication() if os.name == 'nt': dialog = WinUserEnvDialog() else: dialog = EnvDialog() dialog.show() app.exec_()
def test_msgcheckbox(): from trex.utils.qthelpers import qapplication app = qapplication() box = MessageCheckBox() box.setWindowTitle(_("TRex updates")) box.setText("Testing checkbox") box.set_checkbox_text("Check for updates on startup?") box.setStandardButtons(QMessageBox.Ok) box.setDefaultButton(QMessageBox.Ok) box.setIcon(QMessageBox.Information) box.exec_()
def test_edit(data, title="", parent=None): """Test subroutine""" app = qapplication() # analysis:ignore dlg = DataFrameEditor(parent=parent) if dlg.setup_and_check(data, title=title): dlg.exec_() return dlg.get_value() else: import sys sys.exit(1)
def test(): """Text editor demo""" from trex.utils.qthelpers import qapplication _app = qapplication() # analysis:ignore text = """01234567890123456789012345678901234567890123456789012345678901234567890123456789 dedekdh elkd ezd ekjd lekdj elkdfjelfjk e""" dialog = TextEditor(text) dialog.exec_() dlg_text = dialog.get_value() assert text == dlg_text
def test(): """Run layout test widget test""" from trex.utils.qthelpers import qapplication app = qapplication() names = ['test', 'tester', '20', '30', '40'] order = ['test', 'tester', '20', '30', '40'] active = ['test', 'tester'] widget_1 = LayoutSettingsDialog(None, names, order, active) widget_2 = LayoutSaveDialog(None, order) widget_1.show() widget_2.show() sys.exit(app.exec_())
def test(): from qtpy.QtWidgets import QMainWindow from trex.utils.qthelpers import qapplication app = qapplication(test_time=5) win = QMainWindow() win.setWindowTitle("Status widgets test") win.resize(900, 300) statusbar = win.statusBar() swidgets = [] for klass in (ReadWriteStatus, EOLStatus, EncodingStatus, CursorPositionStatus, MemoryStatus, CPUStatus): swidget = klass(win, statusbar) swidgets.append(swidget) win.show() app.exec_()
def test(): """Run dependency widget test""" from trex import dependencies # Test sample dependencies.add("IPython", "Enhanced Python interpreter", ">=0.13") dependencies.add("matplotlib", "Interactive data plotting", ">=1.0") dependencies.add("sympy", "Symbolic Mathematics", ">=10.0") dependencies.add("foo", "Non-existent module", ">=1.0") from trex.utils.qthelpers import qapplication app = qapplication() dlg = DependenciesDialog(None) dlg.set_data(dependencies.DEPENDENCIES) dlg.show() sys.exit(dlg.exec_())
def test(): import os.path as osp from trex.utils.qthelpers import qapplication app = qapplication(test_time=5) shell = ExternalSystemShell(wdir=osp.dirname(__file__), light_background=False) app.aboutToQuit.connect(shell.finish_process) from qtpy.QtGui import QFont font = QFont() font.setPointSize(10) shell.shell.set_font(font) shell.shell.toggle_wrap_mode(True) shell.start_shell(False) shell.show() sys.exit(app.exec_())
def test_get_settings(monkeypatch): def mock_get_option(self, option): if option == 'remote1': return 'remote1val' if option == 'remote2': return 'remote2val' if option == 'dataframe_format': return '3d' monkeypatch.setattr(VariableExplorer, 'CONF_SECTION', 'sect') monkeypatch.setattr('trex.plugins.variableexplorer.REMOTE_SETTINGS', ['remote1', 'remote2']) monkeypatch.setattr(VariableExplorer, 'get_option', mock_get_option) app = qapplication() settings = VariableExplorer(None).get_settings() expected = { 'remote1': 'remote1val', 'remote2': 'remote2val', 'dataframe_format': '%3d' } assert settings == expected
def test(): """Run widget test""" import inspect import tempfile from trex.utils.qthelpers import qapplication primes_sc = inspect.getsource(primes) fd, script = tempfile.mkstemp(suffix='.py') with os.fdopen(fd, 'w') as f: f.write("# -*- coding: utf-8 -*-" + "\n\n") f.write(primes_sc + "\n\n") f.write("primes(100000)") app = qapplication(test_time=5) widget = ProfilerWidget(None) widget.resize(800, 600) widget.show() widget.analyze(script) sys.exit(app.exec_())
def oedit(obj, modal=True, namespace=None): """Edit the object 'obj' in a GUI-based editor and return the edited copy (if Cancel is pressed, return None) The object 'obj' is a container Supported container types: dict, list, tuple, str/unicode or numpy.array (instantiate a new QApplication if necessary, so it can be called directly from the interpreter) """ # Local import from trex.utils.qthelpers import qapplication app = qapplication() if modal: obj_name = '' else: assert is_text_string(obj) obj_name = obj if namespace is None: namespace = globals() keeper.set_namespace(namespace) obj = namespace[obj_name] # keep QApplication reference alive in the Python interpreter: namespace['__qapp__'] = app result = create_dialog(obj, obj_name) if result is None: return dialog, end_func = result if modal: if dialog.exec_(): return end_func(dialog) else: keeper.create_dialog(dialog, obj_name, end_func) import os if os.name == 'nt': app.exec_()
def fedit(data, title="", comment="", icon=None, parent=None, apply=None): """ Create form dialog and return result (if Cancel button is pressed, return None) data: datalist, datagroup title: string comment: string icon: QIcon instance parent: parent QWidget apply: apply callback (function) datalist: list/tuple of (field_name, field_value) datagroup: list/tuple of (datalist *or* datagroup, title, comment) -> one field for each member of a datalist -> one tab for each member of a top-level datagroup -> one page (of a multipage widget, each page can be selected with a combo box) for each member of a datagroup inside a datagroup Supported types for field_value: - int, float, str, unicode, bool - colors: in Qt-compatible text form, i.e. in hex format or name (red,...) (automatically detected from a string) - list/tuple: * the first element will be the selected index (or value) * the other elements can be couples (key, value) or only values """ # Create a QApplication instance if no instance currently exists # (e.g. if the module is used directly from the interpreter) test_travis = os.environ.get('TEST_CI_WIDGETS', None) if test_travis is not None: from trex.utils.qthelpers import qapplication _app = qapplication(test_time=1) elif QApplication.startingUp(): _app = QApplication([]) dialog = FormDialog(data, title, comment, icon, parent, apply) if dialog.exec_(): return dialog.get()
def get_indent_fix(text, indent_chars=" " * 4, tab_stop_width_spaces=4, sol=False, forward=True): """Return text with last line's indentation fixed.""" app = qapplication() editor = CodeEditor(parent=None) editor.setup_editor(language='Python', indent_chars=indent_chars, tab_stop_width_spaces=tab_stop_width_spaces) editor.set_text(text) cursor = editor.textCursor() cursor.movePosition(QTextCursor.End) if sol: lines = text.splitlines(True) repeat = len(lines[-1].lstrip()) cursor.movePosition(QTextCursor.Left, n=repeat) editor.setTextCursor(cursor) editor.fix_indent(forward=forward) return to_text_string(editor.toPlainText())
def test(): from trex.utils.qthelpers import qapplication app = qapplication() from trex.plugins.variableexplorer import VariableExplorer settings = VariableExplorer(None).get_settings() shell = ExternalPythonShell(pythonexecutable=sys.executable, interact=True, stand_alone=settings, wdir=osp.dirname(__file__), mpl_backend=0, light_background=False) from trex.config.gui import get_font font = get_font() shell.shell.set_font(font) shell.shell.toggle_wrap_mode(True) shell.start_shell(False) shell.show() sys.exit(app.exec_())
def main(): # Splash screen # ------------------------------------------------------------------------- # Start Qt Splash to inform the user of the current status app = qapplication() restarter = Restarter() resample = not IS_WINDOWS # Resampling SVG icon only on non-Windows platforms (see Issue 1314): icon = ima.icon('trex', resample=resample) app.setWindowIcon(icon) restarter.set_splash_message(_('Closing TRex')) # Get variables # Note: Variables defined in app/trex.py 'restart()' method trex_args = os.environ.pop('TREX_ARGS', None) pid = os.environ.pop('TREX_PID', None) is_bootstrap = os.environ.pop('TREX_IS_BOOTSTRAP', None) reset = os.environ.pop('TREX_RESET', None) # Get the trex base folder based on this file this_folder = osp.split(osp.dirname(osp.abspath(__file__)))[0] trex_folder = osp.split(this_folder)[0] if not any([trex_args, pid, is_bootstrap, reset]): error = "This script can only be called from within a TRex instance" raise RuntimeError(error) # Variables were stored as string literals in the environment, so to use # them we need to parse them in a safe manner. is_bootstrap = ast.literal_eval(is_bootstrap) pid = ast.literal_eval(pid) args = ast.literal_eval(trex_args) reset = ast.literal_eval(reset) # Enforce the --new-instance flag when running trex if '--new-instance' not in args: if is_bootstrap and '--' not in args: args = args + ['--', '--new-instance'] else: args.append('--new-instance') # Create the arguments needed for reseting if '--' in args: args_reset = ['--', '--reset'] else: args_reset = ['--reset'] # Arrange arguments to be passed to the restarter and reset subprocess args = ' '.join(args) args_reset = ' '.join(args_reset) # Get python excutable running this script python = sys.executable # Build the command if is_bootstrap: trex = osp.join(trex_folder, 'bootstrap.py') else: trexdir = osp.join(trex_folder, 'trex') trex = osp.join(trexdir, 'app', 'start.py') command = '"{0}" "{1}" {2}'.format(python, trex, args) # Adjust the command and/or arguments to subprocess depending on the OS shell = not IS_WINDOWS # Before launching a new TRex instance we need to make sure that the # previous one has closed. We wait for a fixed and "reasonable" amount of # time and check, otherwise an error is launched wait_time = 90 if IS_WINDOWS else 30 # Seconds for counter in range(int(wait_time / SLEEP_TIME)): if not is_pid_running(pid): break time.sleep(SLEEP_TIME) # Throttling control QApplication.processEvents() # Needed to refresh the splash else: # The old trex instance took too long to close and restart aborts restarter.launch_error_message(error_type=CLOSE_ERROR) env = os.environ.copy() # Reset TRex (if required) # ------------------------------------------------------------------------- if reset: restarter.set_splash_message(_('Resetting TRex to defaults')) command_reset = '"{0}" "{1}" {2}'.format(python, trex, args_reset) try: p = subprocess.Popen(command_reset, shell=shell, env=env) except Exception as error: restarter.launch_error_message(error_type=RESET_ERROR, error=error) else: p.communicate() pid_reset = p.pid # Before launching a new TRex instance we need to make sure that the # reset subprocess has closed. We wait for a fixed and "reasonable" # amount of time and check, otherwise an error is launched. wait_time = 20 # Seconds for counter in range(int(wait_time / SLEEP_TIME)): if not is_pid_running(pid_reset): break time.sleep(SLEEP_TIME) # Throttling control QApplication.processEvents() # Needed to refresh the splash else: # The reset subprocess took too long and it is killed try: p.kill() except OSError as error: restarter.launch_error_message(error_type=RESET_ERROR, error=error) else: restarter.launch_error_message(error_type=RESET_ERROR) # Restart # ------------------------------------------------------------------------- restarter.set_splash_message(_('Restarting')) try: subprocess.Popen(command, shell=shell, env=env) except Exception as error: restarter.launch_error_message(error_type=RESTART_ERROR, error=error)
def test(): from trex.utils.qthelpers import qapplication app = qapplication() widget = FindInFiles() widget.show() sys.exit(app.exec_())
choices, 'version_control_system', default='git') vcs_layout = QVBoxLayout() vcs_layout.addWidget(use_version_control) vcs_layout.addWidget(vcs_combo) vcs_group.setLayout(vcs_layout) vlayout = QVBoxLayout() vlayout.addWidget(vcs_group) vlayout.addStretch(1) self.setLayout(vlayout) def apply_settings(self, options): """ """ print('applied') # trex: test-skip #self.main.apply_settings() if __name__ == "__main__": import os.path as osp import tempfile from trex.utils.qthelpers import qapplication app = qapplication() proj_dir = tempfile.mkdtemp() + osp.sep + '.spyproject' proj = EmptyProject(proj_dir) dlg = ProjectPreferences(None, proj) dlg.show() app.exec_()