Esempio n. 1
0
 def get_font(self):
     """ Font is the font used for label. What is stored is the kataja internal font name,
     but what is returned here is the actual QFont.
     :return: QFont instance
     """
     font_id = self._host.forest.settings.get_for_node_type('font_id', g.COMMENT_NODE)
     return qt_prefs.get_font(font_id or g.MAIN_FONT)
Esempio n. 2
0
def color_theme_fragment(panel, layout):
    hlayout = QtWidgets.QHBoxLayout()
    f = qt_prefs.get_font(g.MAIN_FONT)
    panel.selector = SelectionBox(panel)
    panel.selector.setMaximumWidth(120)
    panel.selector_items = ctrl.cm.list_available_themes()
    panel.selector.add_items(panel.selector_items)
    panel.ui_manager.connect_element_to_action(panel.selector, 'set_color_theme')
    hlayout.addWidget(panel.selector)

    panel.randomise = RandomiseButton()
    ctrl.ui.connect_element_to_action(panel.randomise, 'randomise_palette')
    hlayout.addWidget(panel.randomise, 1, QtCore.Qt.AlignRight)

    panel.remove_theme = QtWidgets.QPushButton('Remove')
    #panel.remove_theme.setFixedSize(40, 20)
    ctrl.ui.connect_element_to_action(panel.remove_theme, 'remove_theme')
    panel.remove_theme.hide()
    hlayout.addWidget(panel.remove_theme, 1, QtCore.Qt.AlignRight)

    panel.store_favorite = QtWidgets.QPushButton('★')
    panel.store_favorite.setStyleSheet(
        'font-family: "%s"; font-size: %spx;' % (f.family(), f.pointSize()))
    panel.store_favorite.setFixedSize(26, 20)
    panel.store_favorite.setEnabled(False)
    ctrl.ui.connect_element_to_action(panel.store_favorite, 'remember_palette')
    hlayout.addWidget(panel.store_favorite, 1, QtCore.Qt.AlignRight)
    layout.addLayout(hlayout)
Esempio n. 3
0
 def start_font_dialog(self):
     font = qt_prefs.get_font(self.selected_font)
     if self.font_dialog:
         self.font_dialog.setCurrentFont(font)
     else:
         self.font_dialog = FontDialogForSelector(self, font)
     self.font_dialog.show()
Esempio n. 4
0
    def __init__(self, key, name, parent=None):
        QtWidgets.QFrame.__init__(self, parent)
        self.setBackgroundRole(QtGui.QPalette.AlternateBase)
        self.setAutoFillBackground(True)

        hlayout = QtWidgets.QHBoxLayout()
        hlayout.setContentsMargins(0, 0, 0, 0)
        color_key = ctrl.settings.get_node_setting('color_id', node_type=key)
        font_key = ctrl.settings.get_node_setting('font_id', node_type=key)

        self.key = key
        self.setPalette(ctrl.cm.palette_from_key(color_key))
        f = qt_prefs.get_font(font_key)
        self.setStyleSheet('font-family: "%s"; font-size: %spx;' % (f.family(), f.pointSize()))
        self.add_button = icon_button(ctrl.ui, self, hlayout,
                                      icon=qt_prefs.add_icon,
                                      text='Add ' + name,
                                      action='add_node',
                                      size=24,
                                      color_key=color_key,
                                      tooltip_suffix=name)
        self.add_button.data = key
        self.label = label(self, hlayout, text=name)
        self.label.setBuddy(self.add_button)

        self.conf_button = icon_button(ctrl.ui, self, hlayout,
                                       icon=qt_prefs.settings_pixmap,
                                       text='Modify %s behavior' % name,
                                       size=20,
                                       align=QtCore.Qt.AlignRight)
        self.setLayout(hlayout)
Esempio n. 5
0
 def get_font(self):
     """ Font is the font used for label. What is stored is the kataja internal font name,
     but what is returned here is the actual QFont.
     :return: QFont instance
     """
     font_id = self._host.cached('font_id')
     return qt_prefs.get_font(font_id or g.MAIN_FONT)
Esempio n. 6
0
 def __init__(self, name, default_position='bottom', parent=None, folded=False):
     """
     All of the panel constructors follow the same format so that the construction can be automated.
     :param name: Title of the panel and the key for accessing it
     :param default_position: 'bottom', 'right'...
     :param parent: self.main
     :param ui_manager: pass a dictionary where buttons from this panel will be added
     """
     Panel.__init__(self, name, default_position, parent, folded)
     inner = QtWidgets.QWidget()
     layout = QtWidgets.QVBoxLayout()
     f = qt_prefs.get_font(CONSOLE_FONT)
     self.lextext = QtWidgets.QPlainTextEdit()
     self.setStyleSheet(stylesheet % (f.family(), f.pointSize()))
     self.watchlist = ['forest_changed', 'ui_font_changed']
     layout.addWidget(self.lextext)
     self.sentence_text = QtWidgets.QLineEdit()
     layout.addWidget(self.sentence_text)
     self.semantics_text = QtWidgets.QLineEdit()
     layout.addWidget(self.semantics_text)
     self.info = QtWidgets.QLabel('info text here')
     self.derive_button = text_button(ctrl.ui, layout, text='Derive again',
                                      action='derive_from_lexicon')
     layout.addWidget(self.derive_button)
     layout.addWidget(self.info)
     inner.setLayout(layout)
     self.setWidget(inner)
     self.widget().setAutoFillBackground(True)
     self.prepare_lexicon()
     self.finish_init()
     ctrl.graph_view.activateWindow()
     ctrl.graph_view.setFocus()
Esempio n. 7
0
    def __init__(self,
                 name,
                 default_position='bottom',
                 parent=None,
                 folded=False):
        """
        All of the panel constructors follow the same format so that the construction can be automated.
        :param name: Title of the panel and the key for accessing it
        :param default_position: 'bottom', 'right'...
        :param parent: self.main
        """
        Panel.__init__(self, name, default_position, parent, folded)
        inner = QtWidgets.QTextBrowser()
        layout = QtWidgets.QVBoxLayout()
        inner.setMinimumHeight(48)
        inner.preferred_size = QtCore.QSize(940, 64)
        f = qt_prefs.get_font(g.CONSOLE_FONT)
        inner.setStyleSheet('font-family: "%s"; font-size: %spx;' %
                            (f.family(), f.pointSize()))
        inner.setAutoFillBackground(True)
        inner.sizeHint = self.sizeHint
        inner.setFocusPolicy(QtCore.Qt.NoFocus)
        self.resize_grip = QtWidgets.QSizeGrip(self)
        self.resize_grip.hide()
        self.setAllowedAreas(QtCore.Qt.TopDockWidgetArea
                             | QtCore.Qt.BottomDockWidgetArea)
        self.watchlist = ['ui_font_changed']

        layout.addWidget(self.resize_grip, 0, QtCore.Qt.AlignRight)
        inner.setLayout(layout)

        self.preferred_size = inner.preferred_size
        self.setWidget(inner)
        self.finish_init()
        log.log_handler.set_widget(inner)
Esempio n. 8
0
    def __init__(self, parent, node):
        nname = node.display_name[0].lower()
        UIEmbed.__init__(self, parent, node, 'Edit ' + nname)
        layout = self.vlayout
        ui_p = ctrl.cm.get_qt_palette_for_ui()
        self.setPalette(ui_p)
        ui_s = QtGui.QPalette(ui_p)
        ui_s.setColor(QtGui.QPalette.Text, ctrl.cm.secondary())
        smaller_font = qt_prefs.get_font(g.MAIN_FONT)
        big_font = QtGui.QFont(smaller_font)
        big_font.setPointSize(big_font.pointSize() * 2)
        tt = 'Label used in syntactic computations, plain string. Visible in <i>syntactic mode</i> ' \
             'or if <i>Displayed label</i> is empty.'
        title = 'Syntactic label'
        self.synlabel = KatajaLineEdit(self, tooltip=tt, font=big_font, prefill='label',
                                       on_edit=self.synlabel_edited,
                                       on_finish=self.synlabel_finished,
                                       on_return=self.synlabel_finished)
        make_label(title, self, layout, tt, self.synlabel, ui_s)
        self.synlabel.setPalette(ui_p)
        layout.addWidget(self.synlabel)

        tt = 'Optional index for announcing link between multiple instances.'
        title = 'Index'
        self.index = KatajaLineEdit(self, tooltip=tt, font=big_font, prefill='i',
                                    on_finish=self.index_finished
                                    ).to_layout(layout, with_label=title, label_first=True)
        self.index.setPalette(ui_p)
        self.index.setMaximumWidth(20)

        self.update_embed()
        self.update_position()
        self.hide()
Esempio n. 9
0
 def __init__(self, name, default_position='bottom', parent=None, folded=False):
     """
     All of the panel constructors follow the same format so that the construction can be automated.
     :param name: Title of the panel and the key for accessing it
     :param default_position: 'bottom', 'right'...
     :param parent: self.main
     :param ui_manager: pass a dictionary where buttons from this panel will be added
     """
     Panel.__init__(self, name, default_position, parent, folded)
     inner = QtWidgets.QWidget()
     inner.setContentsMargins(4, 4, 4, 4)
     self.setContentsMargins(0, 0, 0, 0)
     layout = QtWidgets.QVBoxLayout()
     self.browser = QtWidgets.QTextBrowser()
     layout.setContentsMargins(0, 0, 0, 0)
     self.browser.setContentsMargins(0, 0, 0, 0)
     f = qt_prefs.get_font(UI_FONT)
     point_size = f.pointSize()
     if point_size < 14:
         point_size = 12
     self.browser.setStyleSheet('font-size: %spx;' % point_size)
     self.browser.setMinimumWidth(200)
     self.browser.setFrameStyle(QtWidgets.QFrame.NoFrame)
     p = self.browser.palette()
     p.setColor(QtGui.QPalette.Base, ctrl.cm.transparent)
     self.browser.setPalette(p)
     layout.addWidget(self.browser)
     inner.setLayout(layout)
     self.setWidget(inner)
     self.watchlist = ['ui_font_changed']
     self.set_text(HelpPanel.default_text)
     self.finish_init()
     ctrl.graph_view.activateWindow()
     ctrl.graph_view.setFocus()
Esempio n. 10
0
 def __init__(self, name, default_position='bottom', parent=None, folded=False):
     """
     All of the panel constructors follow the same format so that the construction can be automated.
     :param name: Title of the panel and the key for accessing it
     :param default_position: 'bottom', 'right'...
     :param parent: self.main
     :param ui_manager: pass a dictionary where buttons from this panel will be added
     """
     Panel.__init__(self, name, default_position, parent, folded)
     inner = QtWidgets.QWidget()
     inner.setContentsMargins(4, 4, 4, 4)
     self.setContentsMargins(0, 0, 0, 0)
     layout = QtWidgets.QVBoxLayout()
     self.browser = QtWidgets.QTextBrowser()
     layout.setContentsMargins(0, 0, 0, 0)
     self.browser.setContentsMargins(0, 0, 0, 0)
     f = qt_prefs.get_font(UI_FONT)
     point_size = f.pointSize()
     if point_size < 14:
         point_size = 12
     self.browser.setStyleSheet('font-size: %spx;' % point_size)
     self.browser.setMinimumWidth(200)
     self.browser.setFrameStyle(QtWidgets.QFrame.NoFrame)
     p = self.browser.palette()
     p.setColor(QtGui.QPalette.Base, QtCore.Qt.transparent)
     self.browser.setPalette(p)
     layout.addWidget(self.browser)
     inner.setLayout(layout)
     self.setWidget(inner)
     self.watchlist = ['ui_font_changed']
     self.set_text(HelpPanel.default_text)
     self.finish_init()
     ctrl.graph_view.activateWindow()
     ctrl.graph_view.setFocus()
Esempio n. 11
0
    def method(self):
        """ Change font key for current node or node type.
        :return: None
        """
        selector = self.sender()
        font_id = selector.currentData() or selector.selected_font
        if font_id.startswith('font_picker::'):
            font_id = font_id.split('::')[1]
            if not selector.font_dialog:
                selector.selected_font = font_id
                selector.start_font_dialog()
        else:
            selector.selected_font = font_id

        if ctrl.ui.scope_is_selection:
            for node in ctrl.selected:
                if isinstance(node, Node):
                    ctrl.settings.set_node_setting('font_id',
                                                   font_id,
                                                   node=node)
                    node.update_label()
        else:
            ctrl.settings.set_node_setting('font_id',
                                           font_id,
                                           node_type=ctrl.ui.active_node_type,
                                           level=FOREST)
            for node in ctrl.forest.nodes.values():
                node.update_label()
        font = qt_prefs.get_font(font_id)
        if selector.font_dialog:
            selector.font_dialog.setCurrentFont(font)
Esempio n. 12
0
    def __init__(self, name, default_position='bottom', parent=None, folded=False):
        """
        All of the panel constructors follow the same format so that the construction can be automated.
        :param name: Title of the panel and the key for accessing it
        :param default_position: 'bottom', 'right'...
        :param parent: self.main
        """
        Panel.__init__(self, name, default_position, parent, folded)
        inner = QtWidgets.QTextBrowser()
        layout = QtWidgets.QVBoxLayout()
        inner.setMinimumHeight(48)
        inner.preferred_size = QtCore.QSize(940, 64)
        f = qt_prefs.get_font(g.CONSOLE_FONT)
        inner.setStyleSheet('font-family: "%s"; font-size: %spx;' % (f.family(), f.pointSize()))
        inner.setAutoFillBackground(True)
        inner.sizeHint = self.sizeHint
        inner.setFocusPolicy(QtCore.Qt.NoFocus)
        self.resize_grip = QtWidgets.QSizeGrip(self)
        self.resize_grip.hide()
        self.setAllowedAreas(QtCore.Qt.TopDockWidgetArea | QtCore.Qt.BottomDockWidgetArea)
        self.watchlist = ['ui_font_changed']

        layout.addWidget(self.resize_grip, 0, QtCore.Qt.AlignRight)
        inner.setLayout(layout)

        self.preferred_size = inner.preferred_size
        self.setWidget(inner)
        self.finish_init()
        log.log_handler.set_widget(inner)
Esempio n. 13
0
    def __init__(self, parent):
        UIEmbed.__init__(self, parent, None, 'Create new node')
        self.marker = None
        self.guess_mode = True
        layout = self.vlayout
        tt = 'Text for new node'
        smaller_font = qt_prefs.get_font(g.MAIN_FONT)
        big_font = QtGui.QFont(smaller_font)
        big_font.setPointSize(big_font.pointSize() * 2)
        self.input_line_edit = ExpandingLineEdit(self, tooltip=tt, big_font=big_font,
                                                 smaller_font=smaller_font, prefill='label',
                                                 on_edit=self.guess_type_for_input)
        layout.addWidget(self.input_line_edit)
        hlayout = box_row(layout)
        self.node_type_selector = SelectionBox(self)
        self.node_type_selector.currentIndexChanged.connect(self.changed_node_type)

        self.node_types = [(g.GUESS_FROM_INPUT, 'Guess from input')]
        for key in classes.node_types_order:
            add_action_name = f'add_{key}_node'
            add_action = add_action_name in ctrl.ui.actions and ctrl.ui.get_action(add_action_name)
            if add_action and add_action.enabler():
                node_class = classes.nodes.get(key, None)
                self.node_types.append((key, 'New %s' % node_class.display_name[0].lower()))
        self.node_type_selector.add_items(self.node_types)
        hlayout.addWidget(self.node_type_selector)
        hlayout.addStretch(0)
        # U+21A9 &#8617;
        self.enter_button = PushButtonBase(parent=self, text="Create ↩",
                                           action='create_new_node_from_text'
                                           ).to_layout(hlayout)
        self.assumed_width = 200
        self.assumed_height = 117
Esempio n. 14
0
 def __init__(self):
     QtWidgets.QPushButton.__init__(self)
     self.reroll()
     f = qt_prefs.get_font(g.MAIN_FONT)
     self.setStyleSheet('font-family: "%s"; font-size: %spx;' % (f.family(), f.pointSize()))
     self.setFixedSize(40, 20)
     self.setEnabled(False)
Esempio n. 15
0
 def get_font(self):
     """ Font is the font used for label. What is stored is the kataja internal font name,
     but what is returned here is the actual QFont.
     :return: QFont instance
     """
     font_id = ctrl.settings.get_node_setting('font_id', node_type=g.COMMENT_NODE)
     return qt_prefs.get_font(font_id or g.MAIN_FONT)
Esempio n. 16
0
    def __init__(self, parent, tooltip='', font=None, prefill='', on_edit=None, label=None,
                 on_focus_out=None, use_parsing_modes=True):
        QtWidgets.QWidget.__init__(self, parent)
        self.raw_text = ''
        self.parsed_latex = ''
        self.parsed_html = ''
        self.parsing_mode = 1
        layout = QtWidgets.QVBoxLayout()
        self.top_row_layout = QtWidgets.QHBoxLayout()
        self.use_parsing_modes = use_parsing_modes
        if use_parsing_modes:
            self.input_parsing_modes = KatajaButtonGroup()
            self.tex_radio = QtWidgets.QRadioButton("TeX", self)
            self.html_radio = QtWidgets.QRadioButton("HTML", self)
            self.input_parsing_modes.addButton(self.tex_radio, 1)
            self.input_parsing_modes.addButton(self.html_radio, 2)
            self.input_parsing_modes.buttonClicked.connect(self.change_text_field_mode)
            host = self.get_host()
            if host:
                self.input_parsing_modes.button(host.text_parse_mode).setChecked(True)

        if label:
            lab = QtWidgets.QLabel(label, self)
            self.top_row_layout.addWidget(lab)
            self.top_row_layout.addStretch(0)
        if use_parsing_modes:
            self.top_row_layout.addWidget(self.tex_radio)
            self.top_row_layout.addWidget(self.html_radio)
            self.top_row_layout.addStretch(0)
        layout.addLayout(self.top_row_layout)
        self.text_area = MyPlainTextEdit(parent, on_focus_out)
        self.text_area.setAutoFillBackground(True)
        self.text_area.setSizeAdjustPolicy(self.text_area.AdjustToContents)
        self.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding,
                           QtWidgets.QSizePolicy.MinimumExpanding)
        if not font:
            font = qt_prefs.get_font(g.CONSOLE_FONT)
        self.text_area.setStyleSheet('font-family: "%s"; font-size: %spx; background-color: %s' % (
            font.family(), font.pointSize(), ctrl.cm.paper().name()))

        self.text_area.setEnabled(True)
        self.cut_point = 24

        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self.text_area)
        self.setLayout(layout)
        self.text_area.setMinimumHeight(40)
        self.text_area.setMinimumWidth(200)
        if tooltip:
            if ctrl.main.use_tooltips:
                self.setToolTip(tooltip)
                self.setToolTipDuration(2000)
        if prefill:
            self.text_area.setPlaceholderText(prefill)
        self.text_area.textChanged.connect(self.text_area_check_for_resize)
        if on_edit:
            self.text_area.textChanged.connect(on_edit)
        self.setAcceptDrops(True)
        self.original_size = None
        self.changed = False
Esempio n. 17
0
 def start_font_dialog(self):
     font = qt_prefs.get_font(self.selected_font)
     if self.font_dialog:
         self.font_dialog.setCurrentFont(font)
     else:
         self.font_dialog = FontDialogForSelector(self, font)
     self.font_dialog.show()
Esempio n. 18
0
    def __init__(self, parent, edge):
        """ EdgeLabelEmbed is for editing edge labels, but it takes Edge as its host,
        because there may be problems if the host item is not subclass of Saved. Use self.label
        to get access to edge.label_item.
        :param parent:
        :param ui_manager:
        :param edge:
        :param ui_key:
        """

        UIEmbed.__init__(self, parent, edge, 'Edit edge text')
        self.marker = None
        self.label = edge.label_item
        layout = QtWidgets.QVBoxLayout()
        layout.addLayout(self.top_row_layout)  # close-button from UIEmbed
        tt = 'Label for arrow'
        f = QtGui.QFont(qt_prefs.get_font(g.MAIN_FONT))
        f.setPointSize(f.pointSize() * 2)
        self.input_line_edit = EmbeddedLineEdit(self, tip=tt, font=f, prefill='label')
        hlayout = QtWidgets.QHBoxLayout()
        hlayout.addWidget(self.input_line_edit)
        self.enter_button = QtWidgets.QPushButton("↩")  # U+21A9 &#8617;
        self.ui_manager.connect_element_to_action(self.enter_button, 'edit_edge_label_enter_text')

        hlayout.addWidget(self.enter_button)
        layout.addLayout(hlayout)
        self.setLayout(layout)
        self.assumed_width = 200
        self.assumed_height = 37
        self.update_position()
Esempio n. 19
0
    def __init__(self, parent, edge):
        """ ArrowLabelEmbed is for editing arrow labels, but it takes Arrow as its host,
        because there may be problems if the host item is not subclass of Saved. Use self.label
        to get access to edge.label_item.
        :param parent:
        :param ui_manager:
        :param edge:
        :param ui_key:
        """

        UIEmbed.__init__(self, parent, edge, 'Edit edge text')
        self.marker = None
        self.label = edge.label_item
        layout = self.vlayout
        tt = 'Label for arrow'
        f = QtGui.QFont(qt_prefs.get_font(g.MAIN_FONT))
        f.setPointSize(f.pointSize() * 2)
        hlayout = box_row(layout)
        self.input_line_edit = KatajaLineEdit(self, tooltip=tt, font=f, prefill='label'
                                              ).to_layout(hlayout)
        # U+21A9 &#8617;
        self.enter_button = PushButtonBase(self, text="↩",
                                           action='edit_edge_label_enter_text'
                                           ).to_layout(hlayout)
        self.assumed_width = 200
        self.assumed_height = 37
        self.update_position()
Esempio n. 20
0
 def update_style_sheet(self):
     c = ctrl.cm.drawing()
     ui = ctrl.cm.ui()
     f = qt_prefs.get_font(g.UI_FONT)
     self.setStyleSheet(stylesheet % {'draw': c.name(), 'lighter': c.lighter().name(),
                                      'paper': ctrl.cm.paper().name(),
                                      'ui': ui.name(), 'ui_lighter': ui.lighter().name(),
                                      'ui_font': f.family(), 'ui_font_size': f.pointSize(),
                                      'ui_font_larger': int(f.pointSize() * 1.2)})
Esempio n. 21
0
    def __init__(self, name, default_position='right', parent=None, folded=False):
        """
        All of the panel constructors follow the same format so that the construction can be
        automated.
        :param name: Title of the panel and the key for accessing it
        :param default_position: 'bottom', 'right'...
        :param parent: self.main
        """
        Panel.__init__(self, name, default_position, parent, folded)
        inner = QtWidgets.QWidget()
        #inner.preferred_size = QtCore.QSize(220, 130)
        inner.setMinimumSize(160, 130)
        inner.setMaximumSize(220, 400)
        inner.setMinimumWidth(160)

        layout = QtWidgets.QVBoxLayout()
        self.selector = SelectionBox(self)
        self.selector.add_items([(table_dict[item], item) for item in table_names])
        self.selector.activated.connect(self.change_symbol_set)
        self.selector.setFocusPolicy(QtCore.Qt.TabFocus)
        layout.addWidget(self.selector)
        self.symlist = QtWidgets.QListWidget()
        self.symlist.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
         QtWidgets.QSizePolicy.Expanding)
        self.symlist.setSpacing(8)
        self.symlist.setMouseTracking(True)
        self.symlist.setFocusPolicy(QtCore.Qt.NoFocus)
        self.symlist.setViewMode(QtWidgets.QListWidget.IconMode)
        f = qt_prefs.get_font(g.MAIN_FONT)
        self.symlist.setStyleSheet('font-family: "%s"; font-size: %spx;' % (
            f.family(), int(f.pointSize() * 1.5)))
        self.symlist.itemEntered.connect(self.item_entered)
        self.symlist.itemClicked.connect(self.item_clicked)
        layout.addWidget(self.symlist)
        hlayout = box_row(layout)
        self.info = QtWidgets.QLabel('')
        hlayout.addWidget(self.info)
        self.resize_grip = QtWidgets.QSizeGrip(self)
        self.resize_grip.hide()
        hlayout.addWidget(self.resize_grip, 0, QtCore.Qt.AlignRight)
        inner.setLayout(layout)
        self.tables = {}
        keys = list(latex_to_unicode.keys())
        for name in table_names:
            self.tables[name] = []
        keys.sort()
        for key in keys:
            char, description, table_key = latex_to_unicode[key]
            self.tables[table_key].append(key)
        self.tables['greek'] = greek_letters
        self.tables['arrows'] = arrows
        self.tables['more arrows'] = more_arrows
        self.tables['common'] = common
        # self.tables['arrows'] = arrows
        self.prepare_symbols('common')
        self.setWidget(inner)
        self.finish_init()
Esempio n. 22
0
    def __init__(self, parent):
        UIEmbed.__init__(self, parent, None, 'Create new node')
        self.marker = None
        self.guess_mode = True
        layout = QtWidgets.QVBoxLayout()
        layout.addLayout(self.top_row_layout)
        hlayout = box_row(layout)
        ui = self.ui_manager
        self.new_arrow_button = icon_text_button(ui, hlayout, self, '', '',
                                                 " &Arrow", 'new_arrow', size=QtCore.QSize(48, 20),
                                                 draw_method=arrow)
        self.divider_button = icon_text_button(ui, hlayout, self, '', '',
                                               " &Divider", 'new_divider',
                                               size=QtCore.QSize(48, 20), draw_method=divider)
        self.new_arrow_button.setFlat(False)
        self.divider_button.setFlat(False)
        self.new_arrow_button.hide()
        self.divider_button.hide()
        tt = 'Text for new node'
        smaller_font = qt_prefs.get_font(g.MAIN_FONT)
        big_font = QtGui.QFont(smaller_font)
        big_font.setPointSize(big_font.pointSize() * 2)
        self.input_line_edit = ExpandingLineEdit(self,
                                                 tip=tt,
                                                 big_font=big_font,
                                                 smaller_font=smaller_font,
                                                 prefill='label',
                                                 on_edit=self.guess_type_for_input)
        layout.addWidget(self.input_line_edit)
        hlayout = QtWidgets.QHBoxLayout()
        self.node_type_selector = SelectionBox(self)
        self.node_type_selector.currentIndexChanged.connect(self.changed_node_type)

        self.node_types = [('Guess from input', g.GUESS_FROM_INPUT)]
        for key in classes.node_types_order:
            # we have dedicated buttons for arrows and dividers
            #if key not in (g.ARROW, g.DIVIDER):
            node_class = classes.nodes.get(key, None)
            if (not node_class) or node_class.is_syntactic and not ctrl.free_drawing_mode:
                continue
            self.node_types.append(('New %s' % node_class.display_name[0].lower(), key))
        self.node_types.append(('New arrow', g.ARROW))
        #self.node_types.append(('New divider', g.DIVIDER))
        self.node_type_selector.add_items(self.node_types)
        hlayout.addWidget(self.node_type_selector)
        hlayout.addStretch(0)
        self.enter_button = QtWidgets.QPushButton("Create ↩")  # U+21A9 &#8617;
        ui.connect_element_to_action(self.enter_button, 'create_new_node_from_text')

        hlayout.addWidget(self.enter_button)
        layout.addLayout(hlayout)
        self.setLayout(layout)
        self.assumed_width = 200
        self.assumed_height = 117
Esempio n. 23
0
 def __init__(self, sm, label, array_id, color_key, x=0, y=0):
     QtWidgets.QGraphicsSimpleTextItem.__init__(self, label)
     self.label = label
     self.setFont(qt_prefs.get_font(SMALL_FEATURE))
     self.array_id = array_id
     self.color_key = color_key
     self.color_key_tr = color_key if color_key.endswith('tr') else color_key + 'tr'
     self.members = []
     self.setZValue(2)
     self.setPos(x, y)
     if not sm.visible:
         self.hide()
Esempio n. 24
0
 def update_style_sheet(self):
     c = ctrl.cm.drawing()
     ui = ctrl.cm.ui()
     f = qt_prefs.get_font(g.UI_FONT)
     fm = qt_prefs.get_font(g.MAIN_FONT)
     fc = qt_prefs.get_font(g.CONSOLE_FONT)
     self.setStyleSheet(stylesheet % {
         'draw': c.name(),
         'lighter': c.lighter().name(),
         'paper': ctrl.cm.paper().name(),
         'ui': ui.name(),
         'ui_lighter': ui.lighter().name(),
         'ui_font': f.family(),
         'ui_font_size': f.pointSize(),
         'ui_font_larger': int(f.pointSize() * 1.2),
         'ui_darker': ui.darker().name(),
         'main_font': fm.family(),
         'main_font_size': fm.pointSize(),
         'heading_font_size': fm.pointSize() * 2,
         'console_font': fc.family(),
         'console_font_size': fc.pointSize(),
     })
Esempio n. 25
0
 def method(self, font_id: str):
     """ Change font key for current node or node type.
     :param font_id: str
     :return: None
     """
     node_type = self.__class__.node_type
     ctrl.ui.set_active_node_setting('font_id', font_id, node_type)
     for node in ctrl.forest.nodes.values():
         if node.node_type == node_type:
             node.update_label()
     np = ctrl.ui.get_panel_by_node_type(node_type)
     if np:
         np.font_selector.set_dialog_font(qt_prefs.get_font(font_id))
         np.update_title_font(font_id)
Esempio n. 26
0
    def watch_alerted(self, obj, signal, field_name, value):
        """ Receives alerts from signals that this object has chosen to listen. These signals
         are declared in 'self.watchlist'.

         This method will try to sort out the received signals and act accordingly.

        :param obj: the object causing the alarm
        :param signal: identifier for type of the alarm
        :param field_name: name of the field of the object causing the alarm
        :param value: value given to the field
        :return:
        """
        if signal == 'ui_font_changed':
            f = qt_prefs.get_font(g.CONSOLE_FONT)
            self.widget().setStyleSheet('font-family: "%s"; font-size: %spx;' % (f.family(),
                                                                                 f.pointSize()))
Esempio n. 27
0
 def update_style_sheet(self):
     c = ctrl.cm.drawing()
     ui = ctrl.cm.ui()
     f = qt_prefs.get_font(g.UI_FONT)
     self.setStyleSheet(
         stylesheet % {
             'draw': c.name(),
             'lighter': c.lighter().name(),
             'paper': ctrl.cm.paper().name(),
             'ui': ui.name(),
             'ui_lighter': ui.lighter().name(),
             'ui_font': f.family(),
             'ui_font_size': f.pointSize(),
             'ui_font_larger': int(f.pointSize() * 1.2),
             'ui_darker': ui.darker().name()
         })
Esempio n. 28
0
    def watch_alerted(self, obj, signal, field_name, value):
        """ Receives alerts from signals that this object has chosen to listen. These signals
         are declared in 'self.watchlist'.

         This method will try to sort out the received signals and act accordingly.

        :param obj: the object causing the alarm
        :param signal: identifier for type of the alarm
        :param field_name: name of the field of the object causing the alarm
        :param value: value given to the field
        :return:
        """
        if signal == 'ui_font_changed':
            f = qt_prefs.get_font(g.CONSOLE_FONT)
            self.widget().setStyleSheet('font-family: "%s"; font-size: %spx;' %
                                        (f.family(), f.pointSize()))
Esempio n. 29
0
    def __init__(self, parent, tip='', font=None, prefill='', on_edit=None):
        QtWidgets.QWidget.__init__(self, parent)
        self.raw_text = ''
        self.parsed_latex = ''
        self.parsed_html = ''
        self.parsing_mode = 1
        layout = QtWidgets.QVBoxLayout()
        self.top_row_layout = QtWidgets.QHBoxLayout()
        self.input_parsing_modes = QtWidgets.QButtonGroup()
        self.tex_radio = QtWidgets.QRadioButton("TeX", self)
        self.html_radio = QtWidgets.QRadioButton("HTML", self)
        self.input_parsing_modes.buttonClicked.connect(self.change_text_field_mode)
        self.input_parsing_modes.addButton(self.tex_radio, 1)
        self.input_parsing_modes.addButton(self.html_radio, 2)
        self.top_row_layout.addWidget(self.tex_radio)
        self.top_row_layout.addWidget(self.html_radio)
        self.top_row_layout.addStretch(0)
        layout.addLayout(self.top_row_layout)
        self.text_area = QtWidgets.QPlainTextEdit(parent)
        self.text_area.setAutoFillBackground(True)
        self.text_area.setSizeAdjustPolicy(self.text_area.AdjustToContents)
        self.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding,
                           QtWidgets.QSizePolicy.MinimumExpanding)
        self.text_area.setEnabled(True)
        self.cut_point = 24
        self.input_parsing_modes.button(self.get_host().text_parse_mode).setChecked(True)

        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self.text_area)
        self.setLayout(layout)
        self.text_area.setFont(qt_prefs.get_font(g.CONSOLE_FONT))
        self.text_area.setMinimumHeight(40)
        self.text_area.setMinimumWidth(200)
        if tip:
            if ctrl.main.use_tooltips:
                self.setToolTip(tip)
                self.setToolTipDuration(2000)
            self.setStatusTip(tip)
        if prefill:
            self.text_area.setPlaceholderText(prefill)
        self.text_area.textChanged.connect(self.text_area_check_for_resize)
        if on_edit:
            self.text_area.textChanged.connect(on_edit)
        self.setAcceptDrops(True)
        self.original_size = None
        self.changed = False
Esempio n. 30
0
    def select_by_data(self, data):
        """ Override TableModelSelectionBox to include setFont and avoiding selecting font_dialog
        triggers.
        :param data:
        """
        if data.startswith('font_picker::'):
            data = data.split('::')[1]

        item = self.find_list_item(data)
        if item:
            self.setCurrentIndex(item.row())
            self.setModelColumn(item.column())

            self.selected_font = data
            font = qt_prefs.get_font(data)
            self.setFont(font)
            if ctrl.main.use_tooltips:
                self.setToolTip(f"{item.text()}: {font.family()}, {font.pointSize()}pt")
        else:
            print("couldn't find data %s from selector model" % data)
Esempio n. 31
0
    def __init__(self, name, default_position='bottom', parent=None, folded=False):
        """
        All of the panel constructors follow the same format so that the construction can be automated.
        :param name: Title of the panel and the key for accessing it
        :param default_position: 'bottom', 'right'...
        :param parent: self.main
        """
        Panel.__init__(self, name, default_position, parent, folded)
        title_widget = self.titleBarWidget()
        tlayout = title_widget.layout()
        levels = [(50, 'CRITICAL'), (40, 'ERROR'), (30, 'WARNING'), (20, 'INFO'), (10, 'DEBUG')]
        tlayout.addStretch(2)

        # self.command_edit = CommandEdit(title_widget)
        # tlayout.addWidget(self.command_edit)
        # tlayout.addStretch(1)
        # self.command_edit.setStyleSheet(ss)

        log_levels = SelectionBox(parent=title_widget, data=levels,
                                  action='set_log_level', mini=True).to_layout(tlayout, with_label='log level:')
        log_levels.setMinimumWidth(72)
        clear_log = PanelButton(parent=title_widget, action='clear_log', pixmap=qt_prefs.trash_icon).to_layout(tlayout)
        clear_log.setFlat(False)
        clear_log.setMaximumHeight(20)
        widget = self.widget()
        self.preferred_floating_size = QtCore.QSize(480, 480)
        self.log_browser = QtWidgets.QTextBrowser(parent=widget)
        self.vlayout.setContentsMargins(0, 0, 0, 0)
        self.vlayout.addWidget(self.log_browser)
        self.preferred_size = QtCore.QSize(940, 160)
        f = qt_prefs.get_font(g.CONSOLE_FONT)
        ss = f'font-family: "{f.family()}"; font-size: {f.pointSize()}px;'
        self.log_browser.setStyleSheet(ss)
        self.log_browser.setAutoFillBackground(True)
        self.log_browser.setFocusPolicy(QtCore.Qt.NoFocus)
        self.resize_grip = QtWidgets.QSizeGrip(widget)
        self.resize_grip.hide()
        self.setAllowedAreas(QtCore.Qt.TopDockWidgetArea | QtCore.Qt.BottomDockWidgetArea)
        self.vlayout.addWidget(self.resize_grip, 0, QtCore.Qt.AlignRight)
        self.finish_init()
        log.log_handler.set_widget(self.log_browser)
Esempio n. 32
0
    def __init__(self, parent, node):
        nname = node.display_name[0].lower()
        UIEmbed.__init__(self, parent, node, 'Edit ' + nname)
        layout = self.vlayout
        ui_p = ctrl.cm.get_qt_palette_for_ui()
        self.setPalette(ui_p)
        ui_s = QtGui.QPalette(ui_p)
        ui_s.setColor(QtGui.QPalette.Text, ctrl.cm.secondary())
        ui_g = QtGui.QPalette(ui_p)
        ui_g.setColor(QtGui.QPalette.Text, ctrl.cm.get('accent5'))
        smaller_font = qt_prefs.get_font(g.MAIN_FONT)
        big_font = QtGui.QFont(smaller_font)
        big_font.setPointSize(big_font.pointSize() * 2)
        tt = 'Label used in syntactic computations, plain string. Visible in <i>syntactic mode</i> ' \
             'or if <i>Displayed label</i> is empty.'
        title = 'Syntactic label'
        self.synlabel = KatajaLineEdit(self, tooltip=tt, font=big_font, prefill='label')
        make_label(title, self, layout, tt, self.synlabel, ui_s)
        self.synlabel.setPalette(ui_p)
        layout.addWidget(self.synlabel)
        self.synlabel.setReadOnly(True)

        tt = 'Index to connect several copies of the same node in a tree.'
        title = 'Index'
        self.index = KatajaLineEdit(self, tooltip=tt, font=big_font, prefill='i'
                                    ).to_layout(layout, with_label=title, label_first=True)
        self.index.setReadOnly(True)
        self.index.setPalette(ui_p)
        self.index.setMaximumWidth(20)

        tt = 'Gloss is syntactically inert translation or explanation for the constituent'
        title = 'Gloss'
        self.gloss_label = KatajaLineEdit(self, tooltip=tt, font=big_font, prefill='gloss',
                                          on_finish=self.gloss_finished)
        self.gloss_label.setPalette(ui_g)
        make_label(title, self, layout, tt, self.gloss_label, ui_s)
        layout.addWidget(self.gloss_label)

        self.update_embed()
        self.update_position()
        self.hide()
Esempio n. 33
0
    def select_by_data(self, data):
        """ Override TableModelSelectionBox to include setFont and avoiding selecting font_dialog
        triggers.
        :param data:
        """
        if data.startswith('font_picker::'):
            data = data.split('::')[1]

        item = self.find_list_item(data)
        if item:
            self.setCurrentIndex(item.row())
            self.setModelColumn(item.column())

            self.selected_font = data
            font = qt_prefs.get_font(data)
            self.setFont(font)
            if ctrl.main.use_tooltips:
                self.setToolTip(
                    f"{item.text()}: {font.family()}, {font.pointSize()}pt")
        else:
            print("couldn't find data %s from selector model" % data)
Esempio n. 34
0
 def __init__(self,
              name,
              default_position='bottom',
              parent=None,
              folded=False):
     """
     All of the panel constructors follow the same format so that the construction can be automated.
     :param name: Title of the panel and the key for accessing it
     :param default_position: 'bottom', 'right'...
     :param parent: self.main
     :param ui_manager: pass a dictionary where buttons from this panel will be added
     """
     Panel.__init__(self, name, default_position, parent, folded)
     inner = QtWidgets.QWidget()
     layout = QtWidgets.QVBoxLayout()
     f = qt_prefs.get_font(CONSOLE_FONT)
     self.lextext = QtWidgets.QPlainTextEdit()
     self.setStyleSheet(stylesheet % (f.family(), f.pointSize()))
     self.watchlist = ['forest_changed', 'ui_font_changed']
     layout.addWidget(self.lextext)
     self.sentence_text = QtWidgets.QLineEdit()
     layout.addWidget(self.sentence_text)
     self.semantics_text = QtWidgets.QLineEdit()
     layout.addWidget(self.semantics_text)
     self.info = QtWidgets.QLabel('info text here')
     self.derive_button = text_button(ctrl.ui,
                                      layout,
                                      text='Derive again',
                                      action='derive_from_lexicon')
     layout.addWidget(self.derive_button)
     layout.addWidget(self.info)
     inner.setLayout(layout)
     self.setWidget(inner)
     self.widget().setAutoFillBackground(True)
     self.prepare_lexicon()
     self.finish_init()
     ctrl.graph_view.activateWindow()
     ctrl.graph_view.setFocus()
Esempio n. 35
0
def color_theme_fragment(panel, inner, layout):
    hlayout = box_row(layout)
    f = qt_prefs.get_font(g.MAIN_FONT)
    panel.selector = SelectionBox(parent=inner, action='set_active_color_theme').to_layout(hlayout)
    panel.selector.setMaximumWidth(120)
    panel.selector_items = ctrl.cm.list_available_themes()
    panel.selector.add_items(panel.selector_items)

    panel.randomise = RandomiseButton(parent=inner, text='', size=(40, 20),
                                      action='randomise_palette'
                                      ).to_layout(hlayout, align=QtCore.Qt.AlignRight)

    panel.remove_theme = TwoColorButton(parent=inner, text='Remove', action='remove_color_theme',
                                        ).to_layout(hlayout, align=QtCore.Qt.AlignRight)
    panel.remove_theme.hide()

    panel.store_favorite = UnicodeIconButton(parent=inner, text='★', size=(26, 20),
                                             action='remember_palette'
                                             ).to_layout(hlayout, align=QtCore.Qt.AlignRight)
    panel.store_favorite.setStyleSheet(
        'font-family: "%s"; font-size: %spx;' % (f.family(), f.pointSize()))
    panel.store_favorite.setEnabled(False)
    panel.store_favorite.setMaximumWidth(26)
Esempio n. 36
0
    def __init__(self, parent, tip='', font=None, prefill='', on_edit=None):
        QtWidgets.QPlainTextEdit.__init__(self, parent)
        if tip:
            if ctrl.main.use_tooltips:
                self.setToolTip(tip)
                self.setToolTipDuration(2000)
            self.setStatusTip(tip)
        if prefill:
            self.setPlaceholderText(prefill)
        self.setAcceptDrops(True)
        self.setSizeAdjustPolicy(QtWidgets.QTextEdit.AdjustToContents)
        self.changed = False
        self.textChanged.connect(self.flag_as_changed)
        if not font:
            font = qt_prefs.get_font(g.CONSOLE_FONT)
        self.setStyleSheet(
            'font-family: "%s"; font-size: %spx; background-color: %s' %
            (font.family(), font.pointSize(), ctrl.cm.paper().name()))

        if on_edit:
            self.textChanged.connect(on_edit)
        #self.setFixedSize(200, 100)
        #self.text_area.textChanged.connect(self.text_area_check_for_resize)
        self.updateGeometry()
Esempio n. 37
0
    def __init__(self, key, name, parent=None):
        QtWidgets.QFrame.__init__(self, parent)
        self.setBackgroundRole(QtGui.QPalette.AlternateBase)
        self.setAutoFillBackground(True)

        hlayout = QtWidgets.QHBoxLayout()
        hlayout.setContentsMargins(0, 0, 0, 0)
        color_key = ctrl.settings.get_node_setting('color_id', node_type=key)
        font_key = ctrl.settings.get_node_setting('font_id', node_type=key)

        self.key = key
        self.setPalette(ctrl.cm.palette_from_key(color_key))
        f = qt_prefs.get_font(font_key)
        self.setStyleSheet('font-family: "%s"; font-size: %spx;' %
                           (f.family(), f.pointSize()))
        self.add_button = icon_button(ctrl.ui,
                                      self,
                                      hlayout,
                                      icon=qt_prefs.add_icon,
                                      text='Add ' + name,
                                      action='add_node',
                                      size=24,
                                      color_key=color_key,
                                      tooltip_suffix=name)
        self.add_button.data = key
        self.label = label(self, hlayout, text=name)
        self.label.setBuddy(self.add_button)

        self.conf_button = icon_button(ctrl.ui,
                                       self,
                                       hlayout,
                                       icon=qt_prefs.settings_pixmap,
                                       text='Modify %s behavior' % name,
                                       size=20,
                                       align=QtCore.Qt.AlignRight)
        self.setLayout(hlayout)
Esempio n. 38
0
    def __init__(self,
                 parent,
                 tip='',
                 font=None,
                 prefill='',
                 on_edit=None,
                 label=None,
                 on_focus_out=None):
        QtWidgets.QWidget.__init__(self, parent)
        self.raw_text = ''
        self.parsed_latex = ''
        self.parsed_html = ''
        self.parsing_mode = 1
        layout = QtWidgets.QVBoxLayout()
        self.top_row_layout = QtWidgets.QHBoxLayout()
        self.input_parsing_modes = QtWidgets.QButtonGroup()
        self.tex_radio = QtWidgets.QRadioButton("TeX", self)
        self.html_radio = QtWidgets.QRadioButton("HTML", self)
        self.input_parsing_modes.addButton(self.tex_radio, 1)
        self.input_parsing_modes.addButton(self.html_radio, 2)
        self.input_parsing_modes.buttonClicked.connect(
            self.change_text_field_mode)
        if label:
            lab = QtWidgets.QLabel(label, self)
            self.top_row_layout.addWidget(lab)
            self.top_row_layout.addStretch(0)
        self.top_row_layout.addWidget(self.tex_radio)
        self.top_row_layout.addWidget(self.html_radio)
        self.top_row_layout.addStretch(0)
        layout.addLayout(self.top_row_layout)
        self.text_area = MyPlainTextEdit(parent, on_focus_out)
        self.text_area.setAutoFillBackground(True)
        self.text_area.setSizeAdjustPolicy(self.text_area.AdjustToContents)
        self.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding,
                           QtWidgets.QSizePolicy.MinimumExpanding)
        if not font:
            font = qt_prefs.get_font(g.CONSOLE_FONT)
        self.text_area.setStyleSheet(
            'font-family: "%s"; font-size: %spx; background-color: %s' %
            (font.family(), font.pointSize(), ctrl.cm.paper().name()))

        self.text_area.setEnabled(True)
        self.cut_point = 24
        self.input_parsing_modes.button(
            self.get_host().text_parse_mode).setChecked(True)

        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self.text_area)
        self.setLayout(layout)
        self.text_area.setMinimumHeight(40)
        self.text_area.setMinimumWidth(200)
        if tip:
            if ctrl.main.use_tooltips:
                self.setToolTip(tip)
                self.setToolTipDuration(2000)
            self.setStatusTip(tip)
        if prefill:
            self.text_area.setPlaceholderText(prefill)
        self.text_area.textChanged.connect(self.text_area_check_for_resize)
        if on_edit:
            self.text_area.textChanged.connect(on_edit)
        self.setAcceptDrops(True)
        self.original_size = None
        self.changed = False
Esempio n. 39
0
    def __init__(self, parent, edge):
        UIEmbed.__init__(self, parent, edge, 'Highlight a group of nodes')
        self.marker = None
        ui = self.ui_manager
        layout = QtWidgets.QVBoxLayout()
        layout.addLayout(self.top_row_layout)  # close-button from UIEmbed
        smaller_font = qt_prefs.get_font(g.ITALIC_FONT)
        big_font = QtGui.QFont(smaller_font)
        big_font.setPointSize(big_font.pointSize() * 2)
        self.input_line_edit = ExpandingLineEdit(self,
                                                 big_font=big_font,
                                                 smaller_font=smaller_font,
                                                 prefill='label')
        hlayout = QtWidgets.QHBoxLayout()
        hlayout.addWidget(self.input_line_edit)
        label = make_label('Name for the group (optional)',
                           parent=self,
                           layout=hlayout,
                           tooltip='Group of nodes can be singled out and named, e.g. as phases',
                           buddy=self.input_line_edit)
        layout.addLayout(hlayout)
        hlayout = QtWidgets.QHBoxLayout()
        self.color_select = ColorSelector(self)
        ui.connect_element_to_action(self.color_select, 'change_group_color')
        hlayout.addWidget(self.color_select, 1, QtCore.Qt.AlignRight)
        label = make_label('Color',
                           parent=self,
                           layout=hlayout,
                           tooltip='Select color for highlight',
                           buddy=self.color_select,
                           align=QtCore.Qt.AlignLeft)
        self.fill_checkbox = QtWidgets.QCheckBox()
        ui.connect_element_to_action(self.fill_checkbox, 'change_group_fill')
        hlayout.addWidget(self.fill_checkbox, 1, QtCore.Qt.AlignRight)
        label = make_label('Fill',
                           parent=self,
                           layout=hlayout,
                           tooltip="Group area is marked with translucent color",
                           buddy=self.fill_checkbox,
                           align=QtCore.Qt.AlignLeft)
        self.outline_checkbox = QtWidgets.QCheckBox()
        ui.connect_element_to_action(self.outline_checkbox, 'change_group_outline')
        hlayout.addWidget(self.outline_checkbox, 1, QtCore.Qt.AlignRight)
        label = make_label('Outline',
                           parent=self,
                           layout=hlayout,
                           tooltip="Group is marked by line drawn around it",
                           buddy=self.outline_checkbox,
                           align=QtCore.Qt.AlignLeft)

        self.include_children_checkbox = QtWidgets.QCheckBox()
        ui.connect_element_to_action(self.include_children_checkbox, 'change_group_children')
        hlayout.addWidget(self.include_children_checkbox, 1, QtCore.Qt.AlignRight)
        label = make_label('Include children',
                           parent=self,
                           layout=hlayout,
                           tooltip="Automatically add child nodes to group's scope",
                           buddy=self.include_children_checkbox,
                           align=QtCore.Qt.AlignLeft)
        self.allow_overlap_checkbox = QtWidgets.QCheckBox()
        ui.connect_element_to_action(self.allow_overlap_checkbox, 'change_group_overlaps')
        hlayout.addWidget(self.allow_overlap_checkbox, 1, QtCore.Qt.AlignRight)
        label = make_label('Allow groups to overlap',
                           parent=self,
                           layout=hlayout,
                           tooltip="Can group include members of other group. If not, lower group "
                                   "has priority",
                           buddy=self.allow_overlap_checkbox,
                           align=QtCore.Qt.AlignLeft)

        layout.addLayout(hlayout)
        hlayout = QtWidgets.QHBoxLayout()
        self.delete_button = QtWidgets.QPushButton("Delete")  # U+21A9 &#8617;
        self.delete_button.setMaximumWidth(60)
        ui.connect_element_to_action(self.delete_button, 'delete_group')

        hlayout.addWidget(self.delete_button)
        self.enter_button = QtWidgets.QPushButton("Keep ↩")  # U+21A9 &#8617;
        self.enter_button.setMaximumWidth(60)
        ui.connect_element_to_action(self.enter_button, 'save_group_changes')
        hlayout.addStretch(0)
        hlayout.addWidget(self.enter_button)
        layout.addLayout(hlayout)
        self.setLayout(layout)
        #self.assumed_width = 200
        #self.assumed_height = 37
        self.update_position()
        self.setEnabled(True)
Esempio n. 40
0
    def __init__(self, parent, node):
        nname = node.display_name[0].lower()
        UIEmbed.__init__(self, parent, node, 'Edit ' + nname)
        self.setMinimumWidth(220)
        self.editable = {}
        ui_p = self._palette
        ui_s = QtGui.QPalette(ui_p)
        ui_s.setColor(QtGui.QPalette.Text, ctrl.cm.secondary())
        smaller_font = qt_prefs.get_font(g.MAIN_FONT)
        big_font = QtGui.QFont(smaller_font)
        big_font.setPointSize(big_font.pointSize() * 2)
        self.prepare_template()
        sortable = [(item.get('order', 100), key) for key, item in self.editable.items()]
        sortable.sort()
        field_names = [key for order, key in sortable]
        self.fields = {}
        self.resize_target = None
        hlayout = None

        # Generate edit elements based on data, expand this as necessary
        for field_name in field_names:
            d = self.editable.get(field_name, {})
            # if d.get('hidden', False) or not self.host.check_conditions(d):
            #    continue
            tt = d.get('tooltip', '')
            itype = d.get('input_type', 'text')
            prefill = d.get('prefill', '')
            syntactic = d.get('syntactic', False)
            on_edit = d.get('on_edit', None)
            if on_edit and isinstance(on_edit, str):
                on_edit = getattr(node, on_edit, None)
            field_first = False
            if itype == 'text':
                width = d.get('width', 140)
                field = KatajaLineEdit(self, tooltip=tt, font=big_font, prefill=prefill,
                                       on_edit=on_edit)
                field.setMaximumWidth(width)
            elif itype == 'textarea':
                self._disable_effect = True
                template_width = d.get('width', 0)
                field = KatajaTextarea(self, tooltip=tt, font=smaller_font, prefill=prefill,
                                       on_edit=on_edit)
                max_w = 200
                if node.resizable and node.user_size:
                    w = node.user_size[0]
                elif template_width:
                    w = template_width
                else:
                    w = node.label_object.document().idealWidth()
                field.setFixedWidth(min(w, max_w))
                self.resize_target = field
            elif itype == 'expandingtext':
                field = ExpandingTextArea(self, tip=tt, font=smaller_font, prefill=prefill,
                                          on_edit=on_edit)
                template_width = d.get('width', 0)
                if template_width:
                    field.setFixedWidth(template_width)
                self.resize_target = field
            elif itype == 'checkbox':
                field = QtWidgets.QCheckBox(self)
            elif itype == 'preview':
                field = PreviewLabel(self, tip=tt, font=smaller_font)
            elif itype == 'spinbox':
                field = QtWidgets.QSpinBox(self)
                field.setMinimum(d.get('min', -1))
                field.setMaximum(d.get('max', 4))
            else:
                raise NotImplementedError

            if field:
                action = d.get('select_action')
                if action:
                    self.ui_manager.connect_element_to_action(field, action)
                if syntactic:
                    field.setPalette(ui_s)
                else:
                    field.setPalette(ui_p)

            align = d.get('align', 'newline')
            if align == 'newline':
                # new hlayout means new line, but before starting a new hlayout,
                # end the previous one.
                hlayout = box_row(self.vlayout)
            self.fields[field_name] = field
            if field_first:
                hlayout.addWidget(field)
            ui_name = d.get('name', field_name)
            if ui_name:
                if syntactic:
                    palette = ui_s
                else:
                    palette = ui_p
                make_label(ui_name, self, hlayout, tt, field, palette)
            if not field_first:
                hlayout.addWidget(field)
        hlayout = box_row(self.vlayout)
        hlayout.addStretch(0)
        # U+21A9 &#8617;
        self.enter_button = PushButtonBase(parent=self, text="Keep ↩",
                                           action='finish_editing_node')
        hlayout.addWidget(self.enter_button, 0, QtCore.Qt.AlignRight)
        if self.resize_target:
            self.resize_handle = ResizeHandle(self, self.resize_target)
            hlayout.addWidget(self.resize_handle, 0, QtCore.Qt.AlignRight)
        self.update_embed()
        self.update_position()
        self.hide()
Esempio n. 41
0
    def __init__(self, parent, node):
        nname = node.display_name[0].lower()
        UIEmbed.__init__(self, parent, node, 'Edit ' + nname)
        layout = QtWidgets.QVBoxLayout()
        layout.addLayout(self.top_row_layout)
        layout.addSpacing(4)
        ui_p = self._palette
        ui_s = QtGui.QPalette(ui_p)
        ui_s.setColor(QtGui.QPalette.Text, ctrl.cm.secondary())
        smaller_font = qt_prefs.get_font(g.MAIN_FONT)
        big_font = QtGui.QFont(smaller_font)
        big_font.setPointSize(big_font.pointSize() * 2)
        ed = node.get_editing_template()
        sortable = [(item.get('order', 100), key) for key, item in ed.items()]
        sortable.sort()
        field_names = [key for order, key in sortable]
        self.fields = {}
        self.resize_target = None
        hlayout = None

        # Generate edit elements based on data, expand this as necessary
        for field_name in field_names:
            d = ed.get(field_name, {})
            if d.get('hidden', False) or not self.host.check_conditions(d):
                continue
            tt = d.get('tooltip', '')
            itype = d.get('input_type', 'text')
            prefill = d.get('prefill', '')
            syntactic = d.get('syntactic', False)
            on_edit = d.get('on_edit', None)
            if on_edit and isinstance(on_edit, str):
                on_edit = getattr(node, on_edit, None)
            field_first = False
            field = None
            if itype == 'text':
                width = d.get('width', 140)
                field = EmbeddedLineEdit(self,
                                         tip=tt,
                                         font=big_font,
                                         prefill=prefill,
                                         on_edit=on_edit)
                field.setMaximumWidth(width)
            elif itype == 'textarea':
                self._disable_effect = True
                template_width = d.get('width', 0)
                field = EmbeddedTextarea(self,
                                         tip=tt,
                                         font=smaller_font,
                                         prefill=prefill,
                                         on_edit=on_edit)
                max_w = 200
                if node.user_size:
                    w = node.user_size[0]
                elif template_width:
                    w = template_width
                else:
                    w = node.label_object.document().idealWidth()
                field.setFixedWidth(min(w, max_w))
                self.resize_target = field
            elif itype == 'expandingtext':
                field = ExpandingTextArea(self,
                                          tip=tt,
                                          font=smaller_font,
                                          prefill=prefill,
                                          on_edit=on_edit)
                template_width = d.get('width', 0)
                if template_width:
                    field.setFixedWidth(template_width)
                self.resize_target = field
            elif itype == 'multibutton':
                width = d.get('width', 200)
                op_func = d.get('option_function')
                op_func = getattr(self.host, op_func, None) or getattr(
                    self.syntactic_object, op_func, None)
                field = EmbeddedMultibutton(self, options=op_func())
                field.setMaximumWidth(width)
            elif itype == 'projection_buttons':
                width = d.get('width', 200)
                field = ProjectionButtons(self)
                field.setMaximumWidth(width)
            elif itype == 'checkbox':
                field = QtWidgets.QCheckBox(self)
            elif itype == 'radiobutton':
                width = d.get('width', 200)
                op_func = d.get('option_function')
                op_func = getattr(self.host, op_func, None) or \
                          getattr(self.syntactic_object, op_func, None)
                field = EmbeddedRadiobutton(self, options=op_func())
                field.setMaximumWidth(width)
                field_first = False
            elif itype == 'preview':
                field = PreviewLabel(self, tip=tt, font=smaller_font)
            elif itype == 'spinbox':
                field = QtWidgets.QSpinBox(self)
                field.setMinimum(d.get('min', -1))
                field.setMaximum(d.get('max', 4))
            else:
                raise NotImplementedError

            if field:
                action = d.get('select_action')
                if action:
                    connect_slot = getattr(field, 'connect_slot', None)
                    self.ui_manager.connect_element_to_action(
                        field, action, connect_slot=connect_slot)
                if syntactic:
                    field.setPalette(ui_s)
                else:
                    field.setPalette(ui_p)

            align = d.get('align', 'newline')
            if align == 'newline':
                # new hlayout means new line, but before starting a new hlayout,
                # end the previous one.
                if hlayout:
                    layout.addLayout(hlayout)
                hlayout = QtWidgets.QHBoxLayout()
            self.fields[field_name] = field
            if field_first:
                hlayout.addWidget(field)
            ui_name = d.get('name', field_name)
            if ui_name:
                if syntactic:
                    palette = ui_s
                else:
                    palette = ui_p
                make_label(ui_name, self, hlayout, tt, field, palette)
            if not field_first:
                hlayout.addWidget(field)
        if hlayout:
            layout.addLayout(hlayout)
        hlayout = QtWidgets.QHBoxLayout()
        self.enter_button = QtWidgets.QPushButton("Keep ↩")  # U+21A9 &#8617;
        self.enter_button.setParent(self)
        self.ui_manager.connect_element_to_action(self.enter_button,
                                                  'finish_editing_node')
        hlayout.addStretch(0)
        hlayout.addWidget(self.enter_button, 0, QtCore.Qt.AlignRight)
        if self.resize_target:
            self.resize_handle = ResizeHandle(self, self.resize_target)
            hlayout.addWidget(self.resize_handle, 0, QtCore.Qt.AlignRight)
        layout.addLayout(hlayout)
        self.setLayout(layout)
        self.update_embed()
        self.update_position()
        self.hide()
Esempio n. 42
0
 def get_font(self):
     """ Font is the font used for label. What is stored is the kataja
     internal font name, but what is returned here is the actual QFont.
     :return: QFont instance
     """
     return qt_prefs.get_font(self.get_label_data('font') or g.MAIN_FONT)
Esempio n. 43
0
 def get_font(self) -> QtGui.QFont:
     """ Helper to get the QFont being used here. It may be local, or set
     for forest, or come from default preferences. You don't need to know.
     :return:
     """
     return qt_prefs.get_font(self.get_font_id())
Esempio n. 44
0
 def if_changed_font(self, value):
     self.label_object.set_font(qt_prefs.get_font(value))
Esempio n. 45
0
 def get_font(self):
     """ Font is the font used for label. What is stored is the kataja
     internal font name, but what is returned here is the actual QFont.
     :return: QFont instance
     """
     return qt_prefs.get_font(self.get_label_data('font') or g.MAIN_FONT)
Esempio n. 46
0
    def __init__(self, parent, node):
        nname = node.display_name[0].lower()
        UIEmbed.__init__(self, parent, node, 'Edit ' + nname)
        layout = QtWidgets.QVBoxLayout()
        layout.addLayout(self.top_row_layout)
        layout.addSpacing(4)
        ui_p = self._palette
        self.setPalette(ui_p)
        ui_s = QtGui.QPalette(ui_p)
        ui_s.setColor(QtGui.QPalette.Text, ctrl.cm.secondary())
        smaller_font = qt_prefs.get_font(g.MAIN_FONT)
        big_font = QtGui.QFont(smaller_font)
        big_font.setPointSize(big_font.pointSize() * 2)
        self.view_buttons = QtWidgets.QButtonGroup(self)
        self.view_buttons.setExclusive(True)

        self.synframebutton = EyeButton(
            'synlabels', 'All nodes show their syntactic labels')
        self.synframebutton.setChecked(True)
        self.ui_manager.connect_element_to_action(self.synframebutton,
                                                  'set_synlabels_visible')
        self.view_buttons.addButton(self.synframebutton)
        hlayout = QtWidgets.QHBoxLayout()
        hlayout.addWidget(self.synframebutton)
        vlayout = QtWidgets.QVBoxLayout()
        hlayout.addLayout(vlayout)
        tt = 'Label used in syntactic computations, plain string. Visible in <i>syntactic mode</i> ' \
             'or if <i>Displayed label</i> is empty.'
        title = 'Syntactic label'
        self.synlabel = EmbeddedLineEdit(self,
                                         tip=tt,
                                         font=big_font,
                                         prefill='label',
                                         on_edit=self.synlabel_edited,
                                         on_finish=self.synlabel_finished,
                                         on_return=self.synlabel_finished)
        make_label(title, self, vlayout, tt, self.synlabel, ui_s)
        self.synlabel.setPalette(ui_p)
        vlayout.addWidget(self.synlabel)
        layout.addLayout(hlayout)

        self.nodeframebutton = EyeButton(
            'nodelabels', 'All nodes show their user-given labels')
        self.view_buttons.addButton(self.nodeframebutton)
        self.ui_manager.connect_element_to_action(self.nodeframebutton,
                                                  'set_node_labels_visible')
        tt = "Freeform label or text for node, has no effect for syntactic computation"
        title = 'User label'
        self.label = ExpandingTextArea(self,
                                       tip=tt,
                                       font=smaller_font,
                                       prefill='label',
                                       on_edit=self.label_edited,
                                       label=title,
                                       on_focus_out=self.label_finished)
        self.label.setPalette(ui_p)
        self.resize_target = self.label
        hlayout = QtWidgets.QHBoxLayout()
        hlayout.addWidget(self.nodeframebutton)
        hlayout.addWidget(self.label)
        layout.addLayout(hlayout)

        self.autoframebutton = EyeButton(
            'autolabels', 'All nodes show their autogenerated x-bar '
            'labels')
        self.ui_manager.connect_element_to_action(self.autoframebutton,
                                                  'set_autolabels_visible')
        self.view_buttons.addButton(self.autoframebutton)
        hlayout = QtWidgets.QHBoxLayout()
        hlayout.addWidget(self.autoframebutton)
        vlayout = QtWidgets.QVBoxLayout()
        hlayout.addLayout(vlayout)
        tt = "These are either XBar or Bare phrase structure labels that are updated " \
             "automatically based on projections."
        title = 'Generated label'
        self.autolabel = EmbeddedLineEdit(self,
                                          tip=tt,
                                          font=big_font,
                                          prefill='autolabel')
        self.autolabel.setReadOnly(True)
        make_label(title, self, vlayout, tt, self.autolabel)
        vlayout.addWidget(self.autolabel)

        vlayout = QtWidgets.QVBoxLayout()
        tt = 'Optional index for announcing link between multiple instances.'
        title = 'Index'
        self.index = EmbeddedLineEdit(self,
                                      tip=tt,
                                      font=big_font,
                                      prefill='i',
                                      on_finish=self.index_finished)
        self.index.setPalette(ui_p)
        self.index.setMaximumWidth(20)
        make_label(title, self, vlayout, tt, self.index)
        vlayout.addWidget(self.index)
        hlayout.addLayout(vlayout)
        layout.addLayout(hlayout)

        hlayout = QtWidgets.QHBoxLayout()
        hlayout.addSpacing(28)
        tt = 'Node can be projection from either or both of its children if those children are ' \
             'heads or projections from their children.'
        title = 'Projects from'
        self.projections = ProjectionButtons(self)
        self.projections.setMaximumWidth(200)

        vlayout = QtWidgets.QVBoxLayout()
        if not self.projections.empty:
            make_label(title, self, vlayout, tt)
        vlayout.addWidget(self.projections)
        hlayout.addLayout(vlayout)
        layout.addLayout(hlayout)
        self.ui_manager.connect_element_to_action(
            self.projections,
            'set_projection_at_embed_ui',
            connect_slot=self.projections.connect_slot)
        if self.resize_target:
            self.resize_handle = ResizeHandle(self, self.resize_target)
            layout.addWidget(self.resize_handle, 0, QtCore.Qt.AlignRight)
        self.setLayout(layout)
        self.update_embed()
        self.update_position()
        self.hide()
Esempio n. 47
0
    def __init__(self,
                 name,
                 default_position='right',
                 parent=None,
                 folded=False):
        """
        All of the panel constructors follow the same format so that the construction can be
        automated.
        :param name: Title of the panel and the key for accessing it
        :param default_position: 'bottom', 'right'...
        :param parent: self.main
        """
        Panel.__init__(self, name, default_position, parent, folded)
        inner = QtWidgets.QWidget()
        #inner.preferred_size = QtCore.QSize(220, 130)
        inner.setMinimumSize(160, 130)
        inner.setMaximumSize(220, 400)
        inner.setMinimumWidth(160)

        layout = QtWidgets.QVBoxLayout()
        self.selector = SelectionBox(self)
        self.selector.add_items([(table_dict[item], item)
                                 for item in table_names])
        self.selector.activated.connect(self.change_symbol_set)
        self.selector.setFocusPolicy(QtCore.Qt.TabFocus)
        layout.addWidget(self.selector)
        self.symlist = QtWidgets.QListWidget()
        self.symlist.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                   QtWidgets.QSizePolicy.Expanding)
        self.symlist.setSpacing(8)
        self.symlist.setMouseTracking(True)
        self.symlist.setFocusPolicy(QtCore.Qt.NoFocus)
        self.symlist.setViewMode(QtWidgets.QListWidget.IconMode)
        f = qt_prefs.get_font(g.MAIN_FONT)
        self.symlist.setStyleSheet('font-family: "%s"; font-size: %spx;' %
                                   (f.family(), int(f.pointSize() * 1.5)))
        self.symlist.itemEntered.connect(self.item_entered)
        self.symlist.itemClicked.connect(self.item_clicked)
        layout.addWidget(self.symlist)
        hlayout = box_row(layout)
        self.info = QtWidgets.QLabel('')
        hlayout.addWidget(self.info)
        self.resize_grip = QtWidgets.QSizeGrip(self)
        self.resize_grip.hide()
        hlayout.addWidget(self.resize_grip, 0, QtCore.Qt.AlignRight)
        inner.setLayout(layout)
        self.tables = {}
        keys = list(latex_to_unicode.keys())
        for name in table_names:
            self.tables[name] = []
        keys.sort()
        for key in keys:
            char, description, table_key = latex_to_unicode[key]
            self.tables[table_key].append(key)
        self.tables['greek'] = greek_letters
        self.tables['arrows'] = arrows
        self.tables['more arrows'] = more_arrows
        self.tables['common'] = common
        # self.tables['arrows'] = arrows
        self.prepare_symbols('common')
        self.setWidget(inner)
        self.finish_init()