Example #1
0
 def _buffer_context(self, event):
     """Show a context menu when the menu is right clicked."""
     item = self.currentItem()
     if not item:
         return
     menu = QtGui.QMenu()
     label_action = QtGui.QAction(self)
     if item.buf:
         label_action.setText(item.buf.data["full_name"])
     else:
         label_action.setText(str(item.childCount()) + " buffers")
     actions = utils.build_actions(self.actions_def, self)
     for action_name, action_def in self.actions_def.items():
         if len(action_def) > 4 and item.buf:
             checked = item.buf.flag(action_def[4])
             actions[action_name].setChecked(checked)
     menu.addAction(label_action)
     if item.buf:
         menu.addAction(utils.separator(self))
         menu.addActions([actions['beep on message'],
                          actions['blink tray icon'],
                          actions['blink task bar']])
     menu.addActions([utils.separator(self), actions['close']])
     if item.buf and len(self.by_number[item.buf.data["number"]]) > 1:
         menu.addActions([utils.separator(self), actions['unmerge']])
     menu.exec_(self.mapToGlobal(event))
Example #2
0
 def _nicklist_context(self, event):
     """Show a context menu when the nicklist is right clicked."""
     item = self.nicklist.currentItem()
     if not item:
         return
     nick = item.text()
     menu = QtGui.QMenu()
     label_action = QtGui.QAction(nick, self.nicklist)
     actions = utils.build_actions(self.nicklist_actions_def, self.nicklist)
     menu.addActions([label_action, utils.separator(self.nicklist),
                      actions['query'],
                      actions['whois'],
                      actions['ignore']])
     menu.exec_(self.nicklist.mapToGlobal(event))
Example #3
0
 def _context(self, event):
     """Show a context menu when the chat is right clicked."""
     menu = QtGui.QMenu()
     self.actions_def = {
         'copy':       ['edit-copy', False, False,
                        lambda: self.copy()],
         'select all': ['edit-select-all', False, False,
                        lambda: self.selectAll()],
         'clear':      ['edit-clear', False, False,
                        lambda: self.clear()],
     }
     actions = utils.build_actions(self.actions_def, self)
     menu.addActions([
         actions['copy'], actions['select all'], utils.separator(self),
         actions['clear'], utils.separator(self)])
     menu.exec_(self.mapToGlobal(event))
Example #4
0
    def __init__(self, *args):
        QtGui.QMainWindow.__init__(*(self,) + args)
        app = QtGui.QApplication.instance()
        self.config = config.read()
        app.config = self.config

        self.resize(1000, 600)
        self.setWindowTitle(NAME)

        self.debug_dialog = None
        self.debug_lines = []

        self.about_dialog = None
        self.connection_dialog = None
        self.preferences_dialog = None

        # network
        self.network = Network()
        self.network.statusChanged.connect(self._network_status_changed)
        self.network.messageFromWeechat.connect(self._network_weechat_msg)
        self._last_msgid = None

        # list of buffers
        self.switch_buffers = BufferSwitchWidget()
        self.switch_buffers.currentItemChanged.connect(self._buffer_switch)
        self._hotlist = []

        # default buffer
        self.buffers = [Buffer()]
        self.stacked_buffers = QtGui.QStackedWidget()
        self.stacked_buffers.addWidget(self.buffers[0].widget)

        # splitter with buffers + chat/input
        self.splitter = QtGui.QSplitter()
        self.splitter.addWidget(self.switch_buffers)
        self.splitter.addWidget(self.stacked_buffers)

        self.setCentralWidget(self.splitter)

        # notification manager:
        self.notifier = NotificationManager(self)

        # actions for menu and toolbar
        actions_def = {
            'connect': [
                'network-connect', 'Connect to WeeChat',
                'Ctrl+O', self.open_connection_dialog],
            'disconnect': [
                'network-disconnect', 'Disconnect from WeeChat',
                'Ctrl+D', self.network.disconnect_weechat],
            'debug': [
                'edit-find', 'Debug console window',
                'Ctrl+Shift+B', self.open_debug_dialog],
            'view source': [
                None, 'View buffer chat source',
                'Ctrl+Shift+U', self.open_chat_source],
            '_reconnect': [
                None, 'Test Reconnect',
                None, self.network._reconnect_weechat],
            'preferences': [
                'preferences-other', 'Preferences',
                'Ctrl+P', self.open_preferences_dialog],
            'about': [
                'help-about', 'About',
                'Ctrl+H', self.open_about_dialog],
            'save connection': [
                'document-save', 'Save connection configuration',
                'Ctrl+S', self.save_connection],
            'quit': [
                'application-exit', 'Quit application',
                'Ctrl+Q', self.close],
        }
        # toggleable actions
        self.toggles_def = {
            'show menubar': [
                False, 'Show Menubar', 'Ctrl+M',
                lambda: self.config_toggle('look', 'menubar'),
                'look.menubar'],
            'show toolbar': [
                False, 'Show Toolbar',
                False, lambda: self.config_toggle('look', 'toolbar'),
                'look.toolbar'],
            'show status bar': [
                False, 'Show Status Bar',
                False, lambda: self.config_toggle('look', 'statusbar'),
                'look.statusbar'],
            'show title': [
                False, 'Show Topic',
                False, lambda: self.config_toggle('look', 'title'),
                'look.title'],
            'show nick list': [
                False, 'Show Nick List',
                'Ctrl+F7', lambda: self.config_toggle('look', 'nicklist'),
                'look.nicklist'],
            'fullscreen': [
                False, 'Fullscreen',
                'F11', self.toggle_fullscreen],
        }
        self.actions = utils.build_actions(actions_def, self)
        self.actions.update(utils.build_actions(self.toggles_def, self))

        # menu
        self.menu = self.menuBar()
        menu_file = self.menu.addMenu('&File')
        menu_file.addActions([self.actions['connect'],
                              self.actions['disconnect'],
                              self.actions['preferences'],
                              self.actions['save connection'],
                              self.actions['quit']])
        menu_view = self.menu.addMenu('&View')
        menu_view.addActions([self.actions['show menubar'],
                              self.actions['show toolbar'],
                              self.actions['show status bar'],
                              utils.separator(self),
                              self.actions['show title'],
                              self.actions['show nick list'],
                              utils.separator(self),
                              self.actions['fullscreen']])
        menu_window = self.menu.addMenu('&Window')
        menu_window.addAction(self.actions['debug'])
        menu_window.addAction(self.actions['view source'])
        menu_window.addAction(self.actions['_reconnect'])
        menu_help = self.menu.addMenu('&Help')
        menu_help.addAction(self.actions['about'])

        # network status indicator
        self.network_status = QtGui.QPushButton()
        self.network_status.setContentsMargins(0, 0, 10, 0)
        self.network_status.setFlat(True)
        self.network_status.setFocusPolicy(QtCore.Qt.NoFocus)
        self.network_status.setStyleSheet("""text-align:right;padding:0;
            background-color: transparent;min-width:216px;min-height:20px""")
        if hasattr(self.menu, 'setCornerWidget'):
            self.menu.setCornerWidget(self.network_status,
                                      QtCore.Qt.TopRightCorner)

        # toolbar
        toolbar = self.addToolBar('toolBar')
        toolbar.setMovable(False)
        toolbar.addActions([self.actions['connect'],
                            self.actions['disconnect'],
                            self.actions['debug'],
                            self.actions['preferences'],
                            self.actions['about'],
                            self.actions['quit']])
        self.toolbar = toolbar

        # Override context menu for both -- default is a simple menubar toggle.
        self.menu.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.toolbar.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.menu.customContextMenuRequested.connect(self._menu_context)
        self.toolbar.customContextMenuRequested.connect(self._toolbar_context)

        self.buffers[0].widget.input.setFocus()

        # requested buffers for focus:
        self.requested_buffer_names = set()

        # open debug dialog
        if self.config.getboolean('look', 'debug'):
            self.open_debug_dialog()

        self.apply_preferences()
        self.network_status_set(self.network.status_disconnected)

        # auto-connect to relay
        if self.config.getboolean('relay', 'autoconnect'):
            self.network.connect_weechat(self.config.get('relay', 'server'),
                                         self.config.get('relay', 'port'),
                                         self.config.getboolean('relay',
                                                                'ssl'),
                                         self.config.get('relay', 'password'),
                                         self.config.get('relay', 'lines'),
                                         self.config.get('relay', 'ping'))

        self.show()