def test(self): enum1 = EnumFactory('Enum1', ('cst1', 'cst2')) self.assertEqual(enum1.cst1, 0) self.assertEqual(repr(enum1.cst1), 'cst1') self.assertEqual(str(enum1.cst1), 'cst1') self.assertEqual(enum1.cst2, 1) self.assertEqual(repr(enum1.cst2), 'cst2') self.assertEqual(str(enum1.cst2), 'cst2') self.assertEqual(len(enum1), 2) enum2 = ExplicitEnumFactory('Enum2', {'cst1':1, 'cst2':3}) self.assertEqual(enum2.cst1, 1) self.assertEqual(enum2.cst2, 3) self.assertTrue(enum2.cst2 in enum2)
#################################################################################################### import os import platform import sys from PyQt5 import QtCore, QtWidgets #################################################################################################### from CodeReview.Tools.EnumFactory import EnumFactory from CodeReview.Math.Functions import rint #################################################################################################### platform_enum = EnumFactory('PlatformEnum', ('linux', 'windows', 'macosx')) #################################################################################################### class Platform: ############################################## def __init__(self): self.python_version = platform.python_version() self.qt_version = QtCore.QT_VERSION_STR self.pyqt_version = QtCore.PYQT_VERSION_STR self.os = self._get_os()
from CodeReview.PatienceDiff import PatienceSequenceMatcher #################################################################################################### from CodeReview.Tools.EnumFactory import EnumFactory from CodeReview.Tools.Slice import FlatSlice, LineSlice import six #################################################################################################### #: Defines the type of chunks # Fixme: poorly formated by sphinx, name ? # Fixme: header should not be there chunk_type = EnumFactory( 'TwoWayChunkTypes', ('equal', 'insert', 'delete', 'replace', 'equal_block', 'header')) #################################################################################################### class TwoWayChunk: """This class implements a two way chunk. Public attributes: :attr:`chunk1` view for document1 :attr:`chunk2` view for document2
class CommitTableModel(QtCore.QAbstractTableModel): _logger = _module_logger.getChild('CommitTableModel') column_enum = EnumFactory('CommitColumnEnum', ( 'modification', 'old_path', 'new_path', 'similarity', )) __titles__ = ( 'Modification', 'Old Path', 'New Path', 'Similarity', ) __status_to_letter__ = { git.GIT_DELTA_DELETED: 'D', git.GIT_DELTA_MODIFIED: 'M', git.GIT_DELTA_ADDED: 'A', git.GIT_DELTA_RENAMED: 'R', } ############################################## def __init__(self): super(CommitTableModel, self).__init__() self._rows = [] self._number_of_rows = 0 ############################################## def update(self, diff): self._rows = [] self._number_of_rows = 0 for patch in diff: delta = patch.delta if delta.new_file.path != delta.old_file.path: new_file_path = delta.new_file.path similarity = ' {} %'.format(delta.similarity) else: new_file_path = '' similarity = '' status = self.__status_to_letter__[delta.status] row = (status, delta.old_file.path, new_file_path, similarity, patch) self._rows.append(row) self._number_of_rows = len(self._rows) self.modelReset.emit() ############################################## def __iter__(self): for row in self._rows: yield row[-1] ############################################## def __getitem__(self, i): return self._rows[i][-1] ############################################## def data(self, index, role=Qt.DisplayRole): if not index.isValid(): return QtCore.QVariant() column = index.column() row = self._rows[index.row()] if role == Qt.DisplayRole: return QtCore.QVariant(row[column]) elif role == Qt.ForegroundRole and column == self.column_enum.old_path: modification = row[int(self.column_enum.modification)] if modification == 'D': return QtGui.QColor(Qt.red) elif modification == 'M': return QtGui.QColor(Qt.black) elif modification == 'A': return QtGui.QColor(Qt.green) elif modification == 'R': return QtGui.QColor(Qt.black) else: return QtCore.QVariant() return QtCore.QVariant() ############################################## def headerData(self, section, orientation, role=Qt.DisplayRole): if role == Qt.TextAlignmentRole: if orientation == Qt.Horizontal: return QtCore.QVariant(int(Qt.AlignHCenter | Qt.AlignVCenter)) else: return QtCore.QVariant(int(Qt.AlignRight | Qt.AlignVCenter)) if role == Qt.DisplayRole: if orientation == Qt.Horizontal: return QtCore.QVariant(self.__titles__[section]) return QtCore.QVariant() ############################################## def columnCount(self, index=QtCore.QModelIndex()): return len(self.__titles__) ############################################## def rowCount(self, index=QtCore.QModelIndex()): return self._number_of_rows ############################################## def sort(self, column, order): reverse = order == Qt.DescendingOrder self._rows.sort(key=lambda x: x[column], reverse=reverse) self.modelReset.emit()
class LogTableModel(QtCore.QAbstractTableModel): column_enum = EnumFactory('LogColumnEnum', ( 'revision', 'message', 'sha', 'date', 'comitter', )) __titles__ = ( 'Revision', 'Message', 'Id SH1', 'Date', 'Comitter', ) ############################################## def __init__(self, repository): super(LogTableModel, self).__init__() commits = repository.commits() self._number_of_rows = len(commits) self._rows = [('', 'Working directory changes', '', '', None)] self._rows.extend([self._commit_data(i, commit) for i, commit in enumerate(commits)]) ############################################## def _commit_data(self, i, commit): return ( self._number_of_rows - i -1, commit.message, commit.hex, fromtimestamp(commit.commit_time).strftime('%Y-%m-%d %H:%M:%S'), commit.committer.name, # author commit, ) ############################################## def __getitem__(self, i): return self._rows[i][-1] ############################################## def data(self, index, role=Qt.DisplayRole): if not index.isValid(): # or not(0 <= index.row() < self._number_of_rows): return QtCore.QVariant() if role == Qt.DisplayRole: row = self._rows[index.row()] column = index.column() return QtCore.QVariant(row[column]) return QtCore.QVariant() ############################################## def headerData(self, section, orientation, role=Qt.DisplayRole): if role == Qt.TextAlignmentRole: if orientation == Qt.Horizontal: return QtCore.QVariant(int(Qt.AlignHCenter|Qt.AlignVCenter)) else: return QtCore.QVariant(int(Qt.AlignRight|Qt.AlignVCenter)) if role == Qt.DisplayRole: if orientation == Qt.Horizontal: return QtCore.QVariant(self.__titles__[section]) else: return QtCore.QVariant(self._number_of_rows - section) return QtCore.QVariant() ############################################## def columnCount(self, index=QtCore.QModelIndex()): return len(self.__titles__) ############################################## def rowCount(self, index=QtCore.QModelIndex()): return self._number_of_rows
class LogTableModel(QtCore.QAbstractTableModel): COLUMN_ENUM = EnumFactory('LogColumnEnum', ( 'revision', 'message', 'sha', 'date', 'committer', )) _TITLES = ( 'Revision', 'Message', 'Id SH1', 'Date', 'Committer', ) ############################################## def __init__(self, repository): super().__init__() self._tags = repository.tags commits = repository.commits self._number_of_rows = len(commits) self._rows = [('', 'Working directory changes', '', '', None)] for i, commit in enumerate(commits): row = self._commit_data(i, commit) self._rows.append(row) ############################################## def _match_tag(self, commit): for ref in self._tags: ref_commit = ref.peel() if commit.id == ref_commit.id: return ref return None ############################################## def _commit_data(self, i, commit): ref = self._match_tag(commit) if ref is not None: tag_name = ref.name tag_name = tag_name.replace('refs/tags/', '') tag_name = '[{}] '.format(tag_name) else: tag_name = '' author = commit.author committer = commit.committer return ( self._number_of_rows - i - 1, tag_name + commit.message.strip(), str(commit.hex), fromtimestamp(commit.commit_time).strftime('%Y-%m-%d %H:%M:%S'), '{} <{}>'.format(committer.name, committer.email), commit, ) ############################################## def __getitem__(self, i): return self._rows[i][-1] ############################################## def find_commit(self, sha): for i, row in enumerate(self._rows): if row[2] == sha: return self.createIndex(i, 0) return None ############################################## def data(self, index, role=Qt.DisplayRole): if not index.isValid( ): # or not(0 <= index.row() < self._number_of_rows): return QtCore.QVariant() if role == Qt.DisplayRole: row = self._rows[index.row()] column = index.column() return QtCore.QVariant(row[column]) return QtCore.QVariant() ############################################## def headerData(self, section, orientation, role=Qt.DisplayRole): if role == Qt.TextAlignmentRole: if orientation == Qt.Horizontal: return QtCore.QVariant(int(Qt.AlignHCenter | Qt.AlignVCenter)) else: return QtCore.QVariant(int(Qt.AlignRight | Qt.AlignVCenter)) if role == Qt.DisplayRole: if orientation == Qt.Horizontal: return QtCore.QVariant(self._TITLES[section]) else: return QtCore.QVariant(self._number_of_rows - section) return QtCore.QVariant() ############################################## def columnCount(self, index=QtCore.QModelIndex()): return len(self._TITLES) ############################################## def rowCount(self, index=QtCore.QModelIndex()): return self._number_of_rows
#################################################################################################### import os import platform import sys from PyQt5 import QtCore, QtWidgets #################################################################################################### from CodeReview.Tools.EnumFactory import EnumFactory from CodeReview.Math.Functions import rint #################################################################################################### platform_enum = EnumFactory('PlatformEnum', ('linux', 'windows', 'osx', 'unknown')) #################################################################################################### class Platform: ############################################## def __init__(self): self.python_version = platform.python_version() self.qt_version = QtCore.QT_VERSION_STR self.pyqt_version = QtCore.PYQT_VERSION_STR self.os = self._get_os()