def data(self, index, role=Qt.DisplayRole): """score table""" # pylint: disable=R0912,R0914 # pylint too many branches result = QVariant() if role == Qt.TextAlignmentRole: if index.column() == 0: result = QVariant(int(Qt.AlignHCenter | Qt.AlignVCenter)) else: result = QVariant(int(Qt.AlignLeft | Qt.AlignVCenter)) if index.isValid() and (0 <= index.row() < len(self.tables)): table = self.tables[index.row()] if role == Qt.DisplayRole and index.column() in (0, 1): result = QVariant(table.tableid) elif role == Qt.DisplayRole and index.column() == 2: players = [] zipped = zip(table.playerNames, table.playersOnline) for idx, pair in enumerate(zipped): name, online = pair[0], pair[1] if idx < len(zipped) - 1: name += ', ' palette = KApplication.palette() if online: color = palette.color(QPalette.Active, QPalette.WindowText).name() style = 'font-weight:normal;font-style:normal;color:%s' % color else: color = palette.color(QPalette.Disabled, QPalette.WindowText).name() style = 'font-weight:100;font-style:italic;color:%s' % color players.append('<nobr style="%s">' % style + name + '</nobr>') names = ''.join(players) result = QVariant(names) elif role == Qt.DisplayRole and index.column() == 3: status = table.status() if table.suspendedAt: dateVal = ' ' + datetime.datetime.strptime( table.suspendedAt, '%Y-%m-%dT%H:%M:%S').strftime('%c').decode('utf-8') status = 'Suspended' else: dateVal = '' result = QVariant(m18nc('table status', status) + dateVal) elif index.column() == 4: if role == Qt.DisplayRole: result = QVariant( m18n((table.myRuleset if table.myRuleset else table.ruleset).name)) elif role == Qt.ForegroundRole: palette = KApplication.palette() color = palette.windowText() if table.myRuleset else 'red' result = QVariant(QColor(color)) return result
def data(self, index, role=Qt.DisplayRole): """score table""" # pylint: disable=R0912,R0914 # pylint too many branches result = QVariant() if role == Qt.TextAlignmentRole: if index.column() == 0: result = QVariant(int(Qt.AlignHCenter|Qt.AlignVCenter)) else: result = QVariant(int(Qt.AlignLeft|Qt.AlignVCenter)) if index.isValid() and (0 <= index.row() < len(self.tables)): table = self.tables[index.row()] if role == Qt.DisplayRole and index.column() == 1: result = QVariant(table.tableid) elif role == Qt.DisplayRole and index.column() == 0: if not table.status.startswith('Suspended'): result = QVariant(table.tableid) elif role == Qt.DisplayRole and index.column() == 2: players = [] zipped = zip(table.playerNames, table.playersOnline) for idx, pair in enumerate(zipped): name, online = pair[0], pair[1] if idx < len(zipped) - 1: name += ', ' palette = KApplication.palette() if online: color = palette.color(QPalette.Active, QPalette.WindowText).name() style = 'font-weight:normal;font-style:normal;color:%s' % color else: color = palette.color(QPalette.Disabled, QPalette.WindowText).name() style = 'font-weight:100;font-style:italic;color:%s' % color players.append('<nobr style="%s">' % style + name + '</nobr>') names = ''.join(players) result = QVariant(names) elif role == Qt.DisplayRole and index.column() == 3: status = table.status if status.startswith('Suspended'): dateVal = ' ' + datetime.datetime.strptime(status.replace('Suspended', ''), '%Y-%m-%dT%H:%M:%S').strftime('%c').decode('utf-8') status = 'Suspended' else: dateVal = '' result = QVariant(m18nc('table status', status) + dateVal) elif index.column() == 4: if role == Qt.DisplayRole: result = QVariant(m18n(table.ruleset.name)) elif role == Qt.ForegroundRole: palette = KApplication.palette() color = palette.windowText() if table.myRuleset else 'red' result = QVariant(QColor(color)) return result
def data(self, index, role=Qt.DisplayRole): """score table""" result = toQVariant() if role == Qt.TextAlignmentRole: if index.column() == 1: return toQVariant(int(Qt.AlignRight)) else: return toQVariant(int(Qt.AlignLeft)) if index.isValid() and (0 <= index.row() < len(self.chatLines)): chatLine = self.chatLines[index.row()] if role == Qt.DisplayRole and index.column() == 0: local = chatLine.localtimestamp() result = toQVariant('%02d:%02d:%02d' % ( local.hour, local.minute, local.second)) elif role == Qt.DisplayRole and index.column() == 1: result = toQVariant(chatLine.fromUser) elif role == Qt.DisplayRole and index.column() == 2: result = toQVariant(m18n(chatLine.message)) elif role == Qt.ForegroundRole and index.column() == 2: palette = KApplication.palette() # pylint: disable=no-member color = 'blue' if chatLine.isStatusMessage else palette.windowText( ) result = toQVariant(QColor(color)) return result
class ScoreItemDelegate(QStyledItemDelegate): """since setting delegates for a row does not work as wanted with a tree view, we set the same delegate on ALL items.""" # try to use colors that look good with all color schemes. Bright # contrast colors are not optimal as long as our lines have a width of # only one pixel: antialiasing is not sufficient colors = [ KApplication.palette().color(x) for x in [QPalette.Text, QPalette.Link, QPalette.LinkVisited] ] colors.append(QColor('orange')) def __init__(self, parent=None): QStyledItemDelegate.__init__(self, parent) def paint(self, painter, option, index): """where the real work is done...""" item = index.internalPointer() if isinstance(item, ScorePlayerItem) and item.parent.row( ) == 3 and index.column() != 0: for idx, playerItem in enumerate( index.parent().internalPointer().children): chart = index.model().chart(option.rect, index, playerItem) if chart: with Painter(painter): painter.translate(option.rect.topLeft()) painter.setPen(self.colors[idx]) painter.setRenderHint(QPainter.Antialiasing) # if we want to use a pen width > 1, we can no longer directly drawPolyline # separately per cell beause the lines spread vertically over two rows: We would # have to draw the lines into one big pixmap and copy # from the into the cells painter.drawPolyline(*chart) return return QStyledItemDelegate.paint(self, painter, option, index)
def sizeHint(self): """we never want a horizontal scrollbar for player names, we always want to see them in full""" result = QWidget.sizeHint(self) available = KApplication.kApplication().desktop().availableGeometry() height = max(result.height(), available.height() * 2 // 3) width = max(result.width(), available.width() // 2) return QSize(width, height)
def sizeHint(self): """we never want a horizontal scrollbar for player names, we always want to see them in full""" result = QWidget.sizeHint(self) available = KApplication.kApplication().desktop().availableGeometry() height = max(result.height(), available.height() * 2 // 3) width = max(result.width(), available.width() // 2) return QSize(width, height)
def sizeHint(self): """give the main window a sensible default size""" result = KXmlGuiWindow.sizeHint(self) result.setWidth(result.height() * 3 // 2) # we want space to the right for the buttons # the default is too small. Use at least 2/3 of screen height and 1/2 of screen width: available = KApplication.kApplication().desktop().availableGeometry() height = max(result.height(), available.height() * 2 // 3) width = max(result.width(), available.width() // 2) result.setHeight(height) result.setWidth(width) return result
def sizeHint(self): """give the scoring table window a sensible default size""" result = QWidget.sizeHint(self) result.setWidth(result.height() * 3 / 2) # the default is too small. Use at least 2/5 of screen height and 1/4 of screen width: available = KApplication.kApplication().desktop().availableGeometry() height = max(result.height(), available.height() * 2 / 5) width = max(result.width(), available.width() / 4) result.setHeight(height) result.setWidth(width) return result
def sizeHint(self): """give the main window a sensible default size""" result = KXmlGuiWindow.sizeHint(self) result.setWidth(result.height() * 3 // 2) # we want space to the right for the buttons # the default is too small. Use at least 2/3 of screen height and 1/2 of screen width: available = KApplication.kApplication().desktop().availableGeometry() height = max(result.height(), available.height() * 2 // 3) width = max(result.width(), available.width() // 2) result.setHeight(height) result.setWidth(width) return result
def resizeEvent(self, event): """Use this hook to determine if we want to ignore one more resize event happening for maximized / almost maximized windows. this misses a few cases where the window is almost maximized because at this point the window has no border yet: event.size, self.geometry() and self.frameGeometry are all the same. So we cannot check if the bordered window would fit into availableGeometry. """ available = KApplication.kApplication().desktop().availableGeometry() if self.ignoreResizing == 1: # at startup if available.width() <= event.size().width() \ or available.height() <= event.size().height(): self.ignoreResizing += 1 KXmlGuiWindow.resizeEvent(self, event) if self.clientDialog: self.clientDialog.placeInField()
def resizeEvent(self, event): """Use this hook to determine if we want to ignore one more resize event happening for maximized / almost maximized windows. this misses a few cases where the window is almost maximized because at this point the window has no border yet: event.size, self.geometry() and self.frameGeometry are all the same. So we cannot check if the bordered window would fit into availableGeometry. """ available = KApplication.kApplication().desktop().availableGeometry() if self.ignoreResizing == 1: # at startup if available.width() <= event.size().width() \ or available.height() <= event.size().height(): self.ignoreResizing += 1 KXmlGuiWindow.resizeEvent(self, event) if self.clientDialog: self.clientDialog.placeInField()
def data(self, index, role=Qt.DisplayRole): """score table""" result = QVariant() if role == Qt.TextAlignmentRole: if index.column() == 1: return QVariant(int(Qt.AlignRight)) else: return QVariant(int(Qt.AlignLeft)) if index.isValid() and (0 <= index.row() < len(self.chatLines)): chatLine = self.chatLines[index.row()] if role == Qt.DisplayRole and index.column() == 0: local = chatLine.localtimestamp() result = QVariant('%02d:%02d:%02d' % (local.hour, local.minute, local.second)) elif role == Qt.DisplayRole and index.column() == 1: result = QVariant(chatLine.fromUser) elif role == Qt.DisplayRole and index.column() == 2: result = QVariant(m18n(chatLine.message)) elif role == Qt.ForegroundRole and index.column() == 2: palette = KApplication.palette() color = 'blue' if chatLine.isStatusMessage else palette.windowText( ) result = QVariant(QColor(color)) return result
EventData(receiver, event) return QObject.eventFilter(self, receiver, event) from util import gitHead if os.name == 'nt': _ = os.path.dirname(os.path.realpath(__file__)) if _.endswith('.zip'): # cx_freeze os.chdir(os.path.dirname(_)) ABOUT = About() KCmdLineArgs.init(sys.argv, ABOUT.about) KCmdLineArgs.addCmdLineOptions(defineOptions()) APP = KApplication() parseOptions() if hasattr(QGuiApplication, 'setDesktopFileName'): QGuiApplication.setDesktopFileName('org.kde.kajongg') if Debug.neutral: KGlobal.translation = None if Debug.events: EVHANDLER = EvHandler() APP.installEventFilter(EVHANDLER) from config import SetupPreferences SetupPreferences()
def eventFilter(self, receiver, event): """will be called for all events""" from log import EventData EventData(receiver, event) return QObject.eventFilter(self, receiver, event) from util import gitHead ABOUT = About() KCmdLineArgs.init(sys.argv, ABOUT.about) KCmdLineArgs.addCmdLineOptions(defineOptions()) if usingQt4: KApplication.setGraphicsSystem("raster") APP = KApplication() parseOptions() if Debug.neutral: KGlobal.locale().setLanguage("en_US") if Debug.events: EVHANDLER = EvHandler() APP.installEventFilter(EVHANDLER) from config import SetupPreferences SetupPreferences() if Options.csv:
msg = '%s%s->%s' % (name, value, receiver) if hasattr(receiver, 'text'): msg += '(%s)' % receiver.text() elif hasattr(receiver, 'objectName'): msg += '(%s)' % receiver.objectName() logDebug(msg) return QObject.eventFilter(self, receiver, event) if __name__ == "__main__": from util import initLog initLog('kajongg') ABOUT = About() KCmdLineArgs.init (sys.argv, ABOUT.about) KCmdLineArgs.addCmdLineOptions(defineOptions()) KApplication.setGraphicsSystem('raster') APP = KApplication() parseOptions() if Debug.events: EVHANDLER = EvHandler() APP.installEventFilter(EVHANDLER) from config import SetupPreferences SetupPreferences() import qt4reactor qt4reactor.install() from twisted.internet import reactor reactor.runReturn(installSignalHandlers=False) # pylint: disable=E1101 # pylint thinks reactor is missing runReturn
def data(self, index, role=Qt.DisplayRole): """score table""" # pylint: disable=too-many-branches,too-many-locals,redefined-variable-type result = toQVariant() if role == Qt.TextAlignmentRole: if index.column() == 0: result = toQVariant(int(Qt.AlignHCenter | Qt.AlignVCenter)) else: result = toQVariant(int(Qt.AlignLeft | Qt.AlignVCenter)) if index.isValid() and (0 <= index.row() < len(self.tables)): table = self.tables[index.row()] if role == Qt.DisplayRole and index.column() in (0, 1): result = toQVariant(table.tableid) elif role == Qt.DisplayRole and index.column() == 2: players = [] zipped = list(zip(table.playerNames, table.playersOnline)) for idx, pair in enumerate(zipped): name, online = pair[0], pair[1] if idx < len(zipped) - 1: name += ', ' palette = KApplication.palette() if online: color = palette.color( QPalette.Active, QPalette.WindowText).name() style = ('font-weight:normal;' 'font-style:normal;color:%s' % color) else: color = palette.color( QPalette.Disabled, QPalette.WindowText).name() style = ('font-weight:100;font-style:italic;color:%s' % color) players.append( '<nobr style="%s">' % style + name + '</nobr>') names = ''.join(players) result = toQVariant(names) elif role == Qt.DisplayRole and index.column() == 3: status = table.status() if table.suspendedAt: dateVal = u' ' + unicodeString(datetime.datetime.strptime( table.suspendedAt, '%Y-%m-%dT%H:%M:%S').strftime('%c')) status = u'Suspended' else: dateVal = u'' result = toQVariant(m18nc('table status', status) + dateVal) elif index.column() == 4: if role == Qt.DisplayRole: result = toQVariant( m18n(( table.myRuleset if table.myRuleset else table.ruleset).name)) elif role == Qt.ForegroundRole: palette = KApplication.palette() color = palette.windowText() if table.myRuleset else 'red' result = toQVariant(QColor(color)) return result