예제 #1
0
 def _icon(self, item):
     try:
         local = item.buf.data['local_variables']
         if local['type'] == "private":
             qicon = utils.qicon_from_theme('im-user')
         elif local['type'] == "channel":
             qicon = utils.qicon_from_theme('view-conversation-balloon')
         elif local['type'] == "server":
             qicon = utils.qicon_from_theme('network-server')
         item.setIcon(0, qicon)
         return qicon
     except:
         pass
     return None
예제 #2
0
    def __init__(self, pane, *args):
        QtGui.QVBoxLayout.__init__(*(self,) + args)
        self.section = "notifications"
        self.config = QtGui.QApplication.instance().config
        self.pane = pane
        self.stack = QtGui.QStackedWidget()

        self.table = QtGui.QTableWidget()
        fg_color = self.table.palette().text().color().name()
        self.action_labels = {
            "sound": "Play a sound",
            "message": "Show a message in a popup",
            "file": "Log to a file",
            "taskbar": "Mark taskbar entry",
            "tray": "Mark systray/indicator",
            "command": "Run a command"}
        self.action_icons = {
            "sound": utils.qicon_from_theme("media-playback-start"),
            "message": utils.qicon_from_theme("dialog-information"),
            "file": utils.qicon_from_theme("document-export"),
            "taskbar": utils.qicon_from_theme("weechat"),
            "tray": utils.qicon_tint("ic_hot", fg_color),
            "command": utils.qicon_from_theme("system-run")}
        self.icon_widget_qss = "padding:0;min-height:10px;min-width:16px;"
        self.table.resizeColumnsToContents()
        self.table.setColumnCount(2)
        self.table.resizeRowsToContents()
        self.table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
        self.table.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
        self.table.setHorizontalHeaderLabels(["State", "Type"])
        self.table.horizontalHeader().setStretchLastSection(True)
        self.table.horizontalHeader().setHighlightSections(False)
        self.table.verticalHeader().setVisible(False)
        self.table.setShowGrid(False)
        self.table.itemSelectionChanged.connect(self._table_row_changed)

        self.buftypes = {}
        for key, value in config.CONFIG_DEFAULT_NOTIFICATION_OPTIONS:
            buftype, optkey = key.split(".")
            if buftype not in self.buftypes:
                self.buftypes[buftype] = {}
            self.buftypes[buftype][optkey] = self.config.get(self.section, key)
        for buftype, optkey in self.buftypes.items():
            self._insert_type(buftype)
        self.update_icons()
        self.resize_table()
        self.addWidget(self.table)
        self.addWidget(self.stack)
        self.table.selectRow(0)
예제 #3
0
 def network_status_set(self, status):
     """Set the network status."""
     pal = self.network_status.palette()
     if status == self.network.status_connected:
         fg_color = QtGui.QColor('green')
     else:
         fg_color = self.menu.palette().windowText().color()
     pal.setColor(QtGui.QPalette.ButtonText, fg_color)
     ssl = ' (SSL)' if status != self.network.status_disconnected \
           and self.network.is_ssl() else ''
     self.network_status.setPalette(pal)
     icon = self.network.status_icon(status)
     if icon:
         qicon = utils.qicon_from_theme(icon)
         self.network_status.setIcon(qicon)
     self.network_status.setText(status.capitalize() + ssl)
     if status == self.network.status_disconnected:
         self.actions['connect'].setEnabled(True)
         self.actions['disconnect'].setEnabled(False)
     else:
         self.actions['connect'].setEnabled(False)
         self.actions['disconnect'].setEnabled(True)
예제 #4
0
    def nicklist_refresh(self):
        """Refresh nicklist."""
        self.widget.nicklist.clear()
        sort = self.config.get("nicks", "sort")
        icons = self.config.get("nicks", "show_icons")
        colors = self.config.get("nicks", "color_nicknames")
        hostnames = self.config.get("nicks", "show_hostnames")
        self.widget.nicklist.confighash = colors + sort + icons + hostnames

        reverse = True if sort[0:3] == "Z-A" else False
        for group in sorted(self.nicklist, reverse=reverse):
            for nick in sorted(self.nicklist[group]['nicks'],
                               key=lambda n: n['name'], reverse=reverse):
                prefix_color = {
                    '': '',
                    ' ': '',
                    '+': 'yellow',
                }
                color = prefix_color.get(nick['prefix'], 'green')
                if color:
                    icon = utils.qicon_from_theme('bullet_%s_8x8' % color)
                else:
                    pixmap = QtGui.QPixmap(8, 8)
                    pixmap.fill()
                    icon = QtGui.QIcon(pixmap)
                label = nick['name']
                if icons != "off":
                    item = QtGui.QListWidgetItem(icon, label)
                else:
                    item = QtGui.QListWidgetItem(label)
                if colors and label in self.widget.chat.prefix_colors:
                    item.setForeground(
                        QtGui.QBrush(self.widget.chat.prefix_colors[label]))
                self.widget.nicklist.addItem(item)
        if not sort[4:]:
            self.widget.nicklist.sortItems(
                Qt.DescendingOrder if reverse else Qt.AscendingOrder)
예제 #5
0
                event.type() == QtCore.QEvent.WindowStateChange and
                self.isMinimized()):
            self.hide()
            self.notifier.tray_icon.show()
            self.notifier.update(event)

    def showEvent(self, event):
        self.notifier.update(event)
        QtGui.QMainWindow.showEvent(self, event)

    def closeEvent(self, event):
        """Called when QWeeChat window is closed."""
        if self.config.getboolean("notifications", "close_to_tray"):
            self.hide()
            self.notifier.tray_icon.show()
            self.notifier.update(event)
            event.ignore()
            return
        self.network.disconnect_weechat()
        if self.debug_dialog:
            self.debug_dialog.close()
        config.write(self.config)
        QtGui.QMainWindow.closeEvent(self, event)


app = QtGui.QApplication(sys.argv)
app.setStyle(QtGui.QStyleFactory.create('Cleanlooks'))
app.setWindowIcon(utils.qicon_from_theme('weechat'))
main = MainWindow()
sys.exit(app.exec_())