Exemple #1
0
    def addAction(self, act_name_id, act_name_string, is_check=False):
        if TrayEngine == "KDE":
            act_widget = KAction(act_name_string, self.menu)
            act_widget.setCheckable(is_check)
            self.menu.addAction(act_widget)

        elif TrayEngine == "AppIndicator":
            if is_check:
                act_widget = Gtk.CheckMenuItem(act_name_string)
            else:
                act_widget = Gtk.ImageMenuItem(act_name_string)
                act_widget.set_image(None)
            act_widget.show()
            self.menu.append(act_widget)

        elif TrayEngine == "Qt":
            act_widget = QAction(act_name_string, self.menu)
            act_widget.setCheckable(is_check)
            self.menu.addAction(act_widget)

        else:
            act_widget = None

        act_obj = [None, None, None, None]
        act_obj[iActNameId] = act_name_id
        act_obj[iActWidget] = act_widget

        self.act_indexes.append(act_obj)
Exemple #2
0
    def addMenuAction(self, menu_name_id, act_name_id, act_name_string, is_check=False):
        i = self.get_menu_index(menu_name_id)
        if i < 0: return

        menu_widget = self.menu_indexes[i][iMenuWidget]

        if TrayEngine == "KDE":
            act_widget = KAction(act_name_string, menu_widget)
            act_widget.setCheckable(is_check)
            menu_widget.addAction(act_widget)

        elif TrayEngine == "AppIndicator":
            menu_widget = menu_widget.get_submenu()
            if is_check:
                act_widget = Gtk.CheckMenuItem(act_name_string)
            else:
                act_widget = Gtk.ImageMenuItem(act_name_string)
                act_widget.set_image(None)
            act_widget.show()
            menu_widget.append(act_widget)

        elif TrayEngine == "Qt":
            act_widget = QAction(act_name_string, menu_widget)
            act_widget.setCheckable(is_check)
            menu_widget.addAction(act_widget)

        else:
            act_widget = None

        act_obj = [None, None, None, None]
        act_obj[iActNameId] = act_name_id
        act_obj[iActWidget] = act_widget
        act_obj[iActParentMenuId] = menu_name_id

        self.act_indexes.append(act_obj)
Exemple #3
0
def toolbar(name, group=None, callable=None):
    """
    Returns the action with the given name for toolbar use.

    Toolbar use means that there is an icon without text.

    Needed configuration keys:
    icon, action

    Ignored keys:
    text

    Parameters:
      name     -- The name of the action.

      group    -- The QActionGroup to add this action to.
      callable -- The callable to call when the action is triggered.
                  Can be used to override the action in the definition or provide one.
    """
    global toolbar_actions
    action = toolbar_actions.get(name, None)

    if action is None:
        # Create the toolbar action and insert it into the toolbar_actions dict
        global parent
        global action_definitions

        config = action_definitions.get(name, None)
        if config is None:
            return None #Without the config no action can be created

        if group is None:
            action = KAction(parent)
        else:
            action = KAction(group)

        # Will result in a KeyError when the icon is not set in the config.
        # This is slightly wanted behaviour, as the icon is needed for a
        # toolbar action.
        action.setIcon(KIcon(config["icon"]))

        if "checkable" in config:
            action.setCheckable(True)

        # Same exception is wanted here. As an alternative one can specify a callable as a parameter.
        if callable is not None:
            action.triggered.connect(callable)
        else:
            action.triggered.connect(config["action"])

        if "text" in config:
            action.setText(config["text"])

        toolbar_actions["name"] = action

    return action
Exemple #4
0
def kaction(name, actionCollection=None, callable=None):
    # Create the toolbar action and insert it into the toolbar_actions dict
    global parent
    global action_definitions
    global action_groups

    config = action_definitions.get(name, None)

    if config is None:
        print "ERR: No config for action:", name
        return None #Without the config no action can be created

    action = KAction(parent)

    if "group" in config:
        group_name = config["group"]
        if group_name in action_groups:
            group = action_groups[group_name]
        else:
            group = QtGui.QActionGroup(parent)
            action_groups[group_name] = group

        action.setActionGroup(group)

    if "icon" in config:
        action.setIcon(KIcon(config["icon"]))

    if "checkable" in config:
        action.setCheckable(True)

    # Same exception is wanted here. As an alternative one can specify a callable as a parameter.
    if callable is not None:
        action.triggered.connect(callable)
    else:
        action.triggered.connect(config["action"])

    if "text" in config:
        action.setText(config["text"])

    if "tooltip" in config:
        action.setToolTip(config["tooltip"])

    if "whatsthis" in config:
        action.setWhatsThis(config["whatsthis"])

    if actionCollection is not None:
        actionCollection.addAction(name, action)

    return action
Exemple #5
0
def menu(name):
    """
    Returns the action with the given name for menu use.

    Menu use that the action has a text and might have an icon.

    Needed configuration keys:
    text, action

    Optional keys:
    icon

    Parameters:
      name -- The name of the action,
    """
    global menu_actions
    action = menu_actions.get(name, None)

    if action is None:
        # Create the toolbar action and insert it into the toolbar_actions dict
        global parent
        global action_definitions

        config = action_definitions.get(name, None)
        if config is None:
            return None #Without the config no action can be created

        action = KAction(parent)

        if "icon" in config:
            action.setIcon(KIcon(config["icon"]))

        if "checkable" in config:
            action.setCheckable(True)

        # Will result in a KeyError when the text is not set in the config.
        # This is slightly wanted behaviour, as the text is needed for a
        # menu action.
        action.setText(config["text"])

        # Same exception is wanted here.
        action.triggered.connect(config["action"])

        menu_actions["name"] = action

    return action
Exemple #6
0
class KateReload(QObject):
  def __init__(self):
    QObject.__init__(self)
    
    self.window = kate.mainInterfaceWindow().window()
    
    kate.configuration.root.clear()
    
    self.act = KAction(KIcon("reload"), i18n("Auto Reload"), self)
    self.act.setObjectName("auto reload")
        
    self.window.actionCollection().addAction(self.act.objectName(), self.act)    
    self.window.findChild(QMenu, 'view').addAction(self.act)

    if not self.act.objectName() in kate.configuration:
        kate.configuration[self.act.objectName()] = "alt+r"
    self.act.setShortcut(kate.configuration[self.act.objectName()])

    self.act.setCheckable(True)
    self.act.setChecked(False)

    
    self.act.changed.connect(self.onActionChange)
    self.act.toggled.connect(self.toggle)
    
    kate.mainInterfaceWindow().viewChanged.connect(self.onViewChanged)
        
  def onViewChanged(self):
      try:
        doc = sip.cast(kate.activeDocument(), KateDocument)
      except kate.api.NoActiveView:
        return
    
      self.act.blockSignals(True)
      if doc.property('AutoReload'):
          self.act.setChecked(True)
      else:
          self.act.setChecked(False)
      self.act.blockSignals(False)
      

  def onActionChange(self):
      kate.configuration[self.sender().objectName()] = self.sender().shortcut().toString()
      kate.configuration.save()
  
  def toggle(self, state):
      doc = sip.cast(kate.activeDocument(), KateDocument)
      if state == True:
        self.enable(doc)
      else:
        self.disable(doc)
  
  def enable(self, doc):
      if doc.url() == '':
        self.act.blockSignals(True)
        showError(i18n('Can\'t auto-reload unsaved file'))
        self.act.setChecked(False)
        self.act.blockSignals(False)
        return

      doc.setModifiedOnDiskWarning(False)
      doc.modifiedOnDisk.connect(doc.documentReload)
      doc.setProperty('AutoReload', True)
      
      showOk(i18n('Auto-Reload enabled'))
      
  def disable(self, doc):
      if doc.property('AutoReload'):
        doc.setModifiedOnDiskWarning(True)
        doc.modifiedOnDisk.disconnect(doc.documentReload)
        doc.setProperty('AutoReload', False)
        showOk(i18n('Auto-Reload disabled'))
      else:
        print('Error disabled called on something with no auto-reload')
Exemple #7
0
class KateReload(QObject):
    def __init__(self):
        QObject.__init__(self)

        self.window = kate.mainInterfaceWindow().window()

        kate.configuration.root.clear()

        self.act = KAction(KIcon("reload"), i18n("Auto Reload"), self)
        self.act.setObjectName("auto reload")

        self.window.actionCollection().addAction(self.act.objectName(),
                                                 self.act)
        self.window.findChild(QMenu, 'view').addAction(self.act)

        if not self.act.objectName() in kate.configuration:
            kate.configuration[self.act.objectName()] = "alt+r"
        self.act.setShortcut(kate.configuration[self.act.objectName()])

        self.act.setCheckable(True)
        self.act.setChecked(False)

        self.act.changed.connect(self.onActionChange)
        self.act.toggled.connect(self.toggle)

        kate.mainInterfaceWindow().viewChanged.connect(self.onViewChanged)

    def onViewChanged(self):
        try:
            doc = sip.cast(kate.activeDocument(), KateDocument)
        except kate.api.NoActiveView:
            return

        self.act.blockSignals(True)
        if doc.property('AutoReload'):
            self.act.setChecked(True)
        else:
            self.act.setChecked(False)
        self.act.blockSignals(False)

    def onActionChange(self):
        kate.configuration[
            self.sender().objectName()] = self.sender().shortcut().toString()
        kate.configuration.save()

    def toggle(self, state):
        doc = sip.cast(kate.activeDocument(), KateDocument)
        if state == True:
            self.enable(doc)
        else:
            self.disable(doc)

    def enable(self, doc):
        if doc.url() == '':
            self.act.blockSignals(True)
            showError(i18n('Can\'t auto-reload unsaved file'))
            self.act.setChecked(False)
            self.act.blockSignals(False)
            return

        doc.setModifiedOnDiskWarning(False)
        doc.modifiedOnDisk.connect(doc.documentReload)
        doc.setProperty('AutoReload', True)

        showOk(i18n('Auto-Reload enabled'))

    def disable(self, doc):
        if doc.property('AutoReload'):
            doc.setModifiedOnDiskWarning(True)
            doc.modifiedOnDisk.disconnect(doc.documentReload)
            doc.setProperty('AutoReload', False)
            showOk(i18n('Auto-Reload disabled'))
        else:
            print('Error disabled called on something with no auto-reload')