Example #1
0
    def __init__(self, main_window):
        """
        Initialize treeView object from Main Window.

        Args:
            main_window (QtWidgets.QMainWindow): [description]
        """
        self.main_window = main_window
        self.treeView = self.main_window.treeView
        self.cache_files = {}
        tree = self.treeView
        # https://doc.qt.io/archives/qt-4.8/qabstractitemview.html
        tree.selectionMode = QAbstractItemView.ExtendedSelection
        tree.setEditTriggers(QAbstractItemView.NoEditTriggers)
        tree.clicked.connect(self.tree_clicked)
        tree.doubleClicked.connect(self.tree_dblclicked)
        tree.expanded.connect(self.on_expanded)

        tree.setContextMenuPolicy(Qt.CustomContextMenu)
        tree.customContextMenuRequested.connect(self.open_menu)
        self.source_model = QtGui.QStandardItemModel()
        tree.setModel(self.source_model)
        self.selection_model = QItemSelectionModel(self.source_model)
        tree.setSelectionModel(self.selection_model)
        tree.selectionModel().selectionChanged.connect(
            self.on_selection_changed)
Example #2
0
    def __init__(self, parent=None):
        super(Games, self).__init__(parent)
        self.selectedGame = None
        self.onlyPending = True
        decorateWindow(self, i18nc('kajongg', 'Games'))
        self.setObjectName('Games')
        self.resize(700, 400)
        self.model = GamesModel()
        if Debug.modelTest:
            self.modelTest = ModelTest(self.model, self)

        self.view = MJTableView(self)
        self.view.setModel(self.model)
        self.selection = QItemSelectionModel(self.model, self.view)
        self.view.setSelectionModel(self.selection)
        self.view.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.view.setSelectionMode(QAbstractItemView.SingleSelection)

        self.buttonBox = QDialogButtonBox(self)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel)
        self.newButton = self.buttonBox.addButton(
            i18nc('start a new game', "&New"), QDialogButtonBox.ActionRole)
        self.newButton.setIcon(KIcon("document-new"))
        self.newButton.clicked.connect(self.accept)
        self.loadButton = self.buttonBox.addButton(
            i18n("&Load"), QDialogButtonBox.AcceptRole)
        self.loadButton.clicked.connect(self.loadGame)
        self.loadButton.setIcon(KIcon("document-open"))
        self.deleteButton = self.buttonBox.addButton(
            i18n("&Delete"), QDialogButtonBox.ActionRole)
        self.deleteButton.setIcon(KIcon("edit-delete"))
        self.deleteButton.clicked.connect(self.delete)

        chkPending = QCheckBox(i18n("Show only pending games"), self)
        chkPending.setChecked(True)
        cmdLayout = QHBoxLayout()
        cmdLayout.addWidget(chkPending)
        cmdLayout.addWidget(self.buttonBox)

        layout = QVBoxLayout()
        layout.addWidget(self.view)
        layout.addLayout(cmdLayout)
        self.setLayout(layout)
        StateSaver(self)

        self.selection.selectionChanged.connect(self.selectionChanged)
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)
        self.view.doubleClicked.connect(self.loadGame)
        chkPending.stateChanged.connect(self.pendingOrNot)
Example #3
0
 def loadTables(self, tables):
     """build and use a model around the tables.
     Show all new tables (no gameid given yet) and all suspended
     tables that also exist locally. In theory all suspended games should
     exist locally but there might have been bugs or somebody might
     have removed the local database like when reinstalling linux"""
     if not Internal.scene:
         return
     if Debug.table:
         for table in tables:
             if table.gameid and not table.gameExistsLocally():
                 logDebug('Table %s does not exist locally' % table)
     tables = [x for x in tables if not x.gameid or x.gameExistsLocally()]
     tables.sort(key=lambda x: x.tableid)
     preselectTableId = self.__preselectTableId(tables)
     self.__keepChatWindows(tables)
     model = TablesModel(tables)
     self.view.setModel(model)
     if Debug.modelTest:
         self.debugModelTest = ModelTest(model, self.view)
     selection = QItemSelectionModel(model, self.view)
     self.view.initView()
     self.view.setSelectionModel(selection)
     self.view.setSelectionBehavior(QAbstractItemView.SelectRows)
     self.view.setSelectionMode(QAbstractItemView.SingleSelection)
     selection.selectionChanged.connect(self.selectionChanged)
     if len(tables) == 1:
         self.selectTable(0)
         self.startButton.setFocus()
     elif not tables:
         self.newButton.setFocus()
     else:
         _ = [x for x in tables if x.tableid >= preselectTableId]
         self.selectTable(tables.index(_[0]) if _ else 0)
     self.updateButtonsForTable(self.selectedTable())
     self.view.setFocus()