Esempio n. 1
0
    def __init__(self):
        # Current theme
        self.theme_key = ''
        self.default = 'solarized_lt'
        self.hsv = [0.00, 0.29, 0.35]  # dark rose
        self.theme_contrast = 65
        self.d = OrderedDict()
        self._ui_palette = None
        self._palette = None
        self._accent_palettes = {}
        self.current_hex = ''
        self.gradient = QtGui.QRadialGradient(0, 0, 300)
        self.gradient.setSpread(QtGui.QGradient.PadSpread)
        self.background_lightness = 0.5
        self.custom = False
        # Theme management
        self.default_themes = color_themes
        self.custom_themes = OrderedDict()

        # Create some defaults
        self.activate_color_theme(self.default, try_to_remember=False)

        # Keep an eye on relevant changes
        ctrl.add_watcher(self, 'document_changed')
        ctrl.add_watcher(self, 'color_themes_changed')
Esempio n. 2
0
    def __init__(self):
        # Current theme
        self.theme_key = ''
        self.default = 'solarized_lt'
        self.hsv = [0.00, 0.29, 0.35]  # dark rose
        self.theme_contrast = 65
        self.d = OrderedDict()
        self._ui_palette = None
        self._palette = None
        self._accent_palettes = {}
        self.current_hex = ''
        self.transparent = Qt.transparent
        self.gradient = QtGui.QRadialGradient(0, 0, 300)
        self.gradient.setSpread(QtGui.QGradient.PadSpread)
        self.custom = False
        # Theme management
        self.default_themes = color_themes
        self.custom_themes = OrderedDict()

        # Create some defaults
        self.activate_color_theme(self.default, try_to_remember=False)

        # Keep an eye on relevant changes
        ctrl.add_watcher(self, 'document_changed')
        ctrl.add_watcher(self, 'color_themes_changed')
Esempio n. 3
0
    def showEvent(self, QShowEvent):
        """

        :param QShowEvent:
        """
        if self.isFloating():
            #self.move(self.initial_position())
            pass
        if not self._watched:
            for signal in self.watchlist:
                ctrl.add_watcher(self, signal)
            self._watched = True
        QtWidgets.QDockWidget.showEvent(self, QShowEvent)
Esempio n. 4
0
 def __init__(self, text_options, ui_key, parent=None):
     UIWidget.__init__(self, ui_key=ui_key)
     PanelButton.__init__(self, None, text_options[0], size=24, parent=parent)
     self.setCheckable(True)
     self.text_options = text_options
     font = QtGui.QFont(qt_prefs.fonts[g.UI_FONT])
     font.setPointSize(font.pointSize() * 1.2)
     fm = QtGui.QFontMetrics(font)
     mw = max([fm.width(text) for text in text_options])
     self.setFlat(True)
     self.setMinimumWidth(mw + 12)
     self.setMinimumHeight(24)
     ctrl.add_watcher(self, 'ui_font_changed')
Esempio n. 5
0
    def showEvent(self, QShowEvent):
        """

        :param QShowEvent:
        """
        if self.isFloating():
            #self.move(self.initial_position())
            pass
        if not self._watched:
            for signal in self.watchlist:
                ctrl.add_watcher(self, signal)
            self._watched = True
        QtWidgets.QDockWidget.showEvent(self, QShowEvent)
Esempio n. 6
0
 def finish_init(self):
     """ Do initializations that need to be done after the subclass __init__
     has completed. e.g. hide this from view, which can have odd results
     for measurements for elements and layouts if it is called before
     setting them up. Subclass __init__:s must call finish_init at the end!
     :return:
     """
     if self.isVisible() and not self._watched:
         for signal in self.watchlist:
             ctrl.add_watcher(self, signal)
         self._watched = True
     self.set_folded(self.folded)
     if self.isFloating():
         self.move(self.initial_position())
Esempio n. 7
0
 def finish_init(self):
     """ Do initializations that need to be done after the subclass __init__
     has completed. e.g. hide this from view, which can have odd results
     for measurements for elements and layouts if it is called before
     setting them up. Subclass __init__:s must call finish_init at the end!
     :return:
     """
     if self.isVisible() and not self._watched:
         for signal in self.watchlist:
             ctrl.add_watcher(self, signal)
         self._watched = True
     self.set_folded(self.folded)
     if self.isFloating():
         self.move(self.initial_position())
Esempio n. 8
0
 def __init__(self, text_options, ui_key, parent=None, icon=None):
     UIWidget.__init__(self, ui_key=ui_key)
     self.negated_icon = None
     PanelButton.__init__(self,
                          icon,
                          text_options[0],
                          size=24,
                          parent=parent)
     self.setCheckable(True)
     self.text_options = text_options
     font = QtGui.QFont(qt_prefs.fonts[g.UI_FONT])
     font.setPointSize(font.pointSize() * 1.2)
     fm = QtGui.QFontMetrics(font)
     mw = max([fm.width(text) for text in text_options])
     self.setFlat(True)
     self.setMinimumWidth(mw + 12)
     self.setMinimumHeight(24)
     ctrl.add_watcher(self, 'ui_font_changed')
Esempio n. 9
0
 def prepare_for_drawing(self):
     """ Prepares the forest instance to be displayed in graph scene --
      called when switching forests
     :return: None
     """
     self.in_display = True
     ctrl.disable_undo()
     if not self.is_parsed:
         self.syntax.create_derivation(self)
         self.after_model_update('nodes', 0)
         self.is_parsed = True
     ctrl.add_watcher(self, 'palette_changed')
     ctrl.main.update_colors()
     self.add_all_to_scene()
     self.update_visualization()
     self.scene.keep_updating_visible_area = True
     self.scene.manual_zoom = False
     self.draw()  # do draw once to avoid having the first draw in undo stack.
     ctrl.graph_scene.fit_to_window()
     ctrl.resume_undo()
     ctrl.graph_view.setFocus()
Esempio n. 10
0
 def prepare_for_drawing(self):
     """ Prepares the forest instance to be displayed in graph scene --
      called when switching forests
     :return: None
     """
     self.in_display = True
     ctrl.disable_undo()
     if not self.is_parsed:
         self.syntax.create_derivation(self)
         self.after_model_update('nodes', 0)
         self.is_parsed = True
         self.forest_edited()
     ctrl.add_watcher(self, 'palette_changed')
     ctrl.main.update_colors()
     self.add_all_to_scene()
     self.update_visualization()
     self.scene.keep_updating_visible_area = True
     self.scene.manual_zoom = False
     self.draw()  # do draw once to avoid having the first draw in undo stack.
     ctrl.graph_scene.fit_to_window()
     ctrl.resume_undo()
     ctrl.graph_view.setFocus()
Esempio n. 11
0
 def show(self):
     """ Assign as a watcher if necessary and make visible
     :return: None
     """
     if self.role == g.LABEL_START:
         ctrl.add_watcher(self, 'edge_label')
Esempio n. 12
0
 def showEvent(self, event):
     ctrl.add_watcher(self, 'active_edge_color_changed')
     ctrl.add_watcher(self, 'palette_changed')
     ctrl.add_watcher(self, 'scope_changed')
     super().showEvent(event)
Esempio n. 13
0
 def showEvent(self, event):
     ctrl.add_watcher(self, 'palette_changed')
     super().showEvent(event)
Esempio n. 14
0
 def showEvent(self, event):
     ctrl.add_watcher(self, 'palette_changed')
     super().showEvent(event)
Esempio n. 15
0
 def showEvent(self, event):
     ctrl.add_watcher(self, 'active_edge_color_changed')
     ctrl.add_watcher(self, 'palette_changed')
     ctrl.add_watcher(self, 'scope_changed')
     super().showEvent(event)
Esempio n. 16
0
    def __init__(self, kataja_app, no_prefs=False, reset_prefs=False):
        """ KatajaMain initializes all its children and connects itself to
        be the main window of the given application. Receives launch arguments:
        :param no_prefs: bool, don't load or save preferences
        :param reset_prefs: bool, don't attempt to load preferences, use defaults instead

        """
        QtWidgets.QMainWindow.__init__(self)
        kataja_app.processEvents()
        SavedObject.__init__(self)
        self.use_tooltips = True
        self.available_plugins = {}
        self.setDockOptions(QtWidgets.QMainWindow.AnimatedDocks)
        self.setCorner(QtCore.Qt.TopLeftCorner, QtCore.Qt.LeftDockWidgetArea)
        self.setCorner(QtCore.Qt.TopRightCorner, QtCore.Qt.RightDockWidgetArea)
        self.setCorner(QtCore.Qt.BottomLeftCorner, QtCore.Qt.LeftDockWidgetArea)
        self.setCorner(QtCore.Qt.BottomRightCorner,
                       QtCore.Qt.RightDockWidgetArea)
        x, y, w, h = (50, 50, 1152, 720)
        self.setMinimumSize(w, h)
        self.app = kataja_app
        self.save_prefs = not no_prefs
        self.forest = None
        self.fontdb = QtGui.QFontDatabase()
        self.color_manager = PaletteManager()
        self.settings_manager = Settings()
        self.forest_keepers = []
        self.forest_keeper = None
        ctrl.late_init(self)
        classes.late_init()
        prefs.import_node_classes(classes)
        self.syntax = SyntaxConnection()
        prefs.load_preferences(disable=reset_prefs or no_prefs)
        qt_prefs.late_init(running_environment, prefs, self.fontdb, log)
        self.settings_manager.set_prefs(prefs)
        self.color_manager.update_custom_colors()
        self.find_plugins(prefs.plugins_path or running_environment.plugins_path)
        self.setWindowIcon(qt_prefs.kataja_icon)
        self.graph_scene = GraphScene(main=self, graph_view=None)
        self.graph_view = GraphView(main=self, graph_scene=self.graph_scene)
        self.graph_scene.graph_view = self.graph_view
        ctrl.add_watcher(self, 'ui_font_changed')
        self.ui_manager = UIManager(self)
        self.settings_manager.set_ui_manager(self.ui_manager)
        self.ui_manager.populate_ui_elements()
        # make empty forest and forest keeper so initialisations don't fail because of their absence
        self.visualizations = VISUALIZATIONS
        self.init_forest_keepers()
        self.settings_manager.set_document(self.forest_keeper)
        kataja_app.setPalette(self.color_manager.get_qt_palette())
        self.forest = Forest()
        self.settings_manager.set_forest(self.forest)
        self.change_color_theme(prefs.color_theme, force=True)
        self.update_style_sheet()
        self.graph_scene.late_init()
        self.setCentralWidget(self.graph_view)
        self.setGeometry(x, y, w, h)
        self.setWindowTitle(self.tr("Kataja"))
        self.print_started = False
        self.show()
        self.raise_()
        kataja_app.processEvents()
        self.activateWindow()
        self.status_bar = self.statusBar()
        self.install_plugins()
        self.load_initial_treeset()
        log.info('Welcome to Kataja! (h) for help')
        #ctrl.call_watchers(self.forest_keeper, 'forest_changed')
        # toolbar = QtWidgets.QToolBar()
        # toolbar.setFixedSize(480, 40)
        # self.addToolBar(toolbar)
        gestures = [QtCore.Qt.TapGesture, QtCore.Qt.TapAndHoldGesture, QtCore.Qt.PanGesture,
                    QtCore.Qt.PinchGesture, QtCore.Qt.SwipeGesture, QtCore.Qt.CustomGesture]
        #for gesture in gestures:
        #    self.grabGesture(gesture)
        self.action_finished(undoable=False)
        self.forest.undo_manager.flush_pile()
Esempio n. 17
0
 def show(self):
     """ Assign as a watcher if necessary and make visible
     :return: None
     """
     if self.role == g.LABEL_START:
         ctrl.add_watcher(self, 'edge_label')