Examples

If you downloaded a source archive or cloned pyQode from github, you will find a series of examples in the examples directory, at the root of the archive.

All examples requires pyqode.qt, pyqode.core and pyqode.json to be installed.

Note

All examples are bindings independent so that every user can run them without being required to install an unwanted qt binding.

Pre-configured

Simple example that show you how to use the pre-configured JSONCodeEdit

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
This is a very basic usage example of the JSONCodeEdit.

The interface is minimalist, it will open a test file. You can open other
documents by pressing Ctrl+O
"""
import logging
import os
import random
import sys
from pyqode.qt import QtWidgets
from pyqode.core import api, modes
from pyqode.json.widgets import JSONCodeEdit


class Window(QtWidgets.QMainWindow):
    def __init__(self):
        super(Window, self).__init__()
        self.setMinimumWidth(800)
        self.setMinimumHeight(600)
        self.editor = JSONCodeEdit(self)
        self.setCentralWidget(self.editor)
        self.editor.file.open(
            os.path.abspath(os.path.join(
                '..', 'test', 'files', 'example.json')))

        self.action_open = QtWidgets.QAction('open file', self)
        self.action_open.setShortcut('Ctrl+O')
        self.action_open.triggered.connect(self.open_file)
        self.addAction(self.action_open)

    def open_file(self):
        filename, _ = QtWidgets.QFileDialog.getOpenFileName(
            self, 'Open JSON file')
        if filename:
            self.editor.file.open(filename)


logging.basicConfig(level=logging.INFO)
app = QtWidgets.QApplication(sys.argv)
window = Window()
window.show()
app.exec_()

Table Of Contents

Previous topic

pyqode.json.widgets package