summaryrefslogtreecommitdiff
path: root/raphodo/computerview.py
blob: 87664e8e97e2c2c4875e4ee311b132650167daab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Copyright (C) 2016 Damon Lynch <damonlynch@gmail.com>

# This file is part of Rapid Photo Downloader.
#
# Rapid Photo Downloader is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Rapid Photo Downloader is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Rapid Photo Downloader.  If not,
# see <http://www.gnu.org/licenses/>.

"""
Combines a deviceview and a file system view into one widget
"""

__author__ = 'Damon Lynch'
__copyright__ = "Copyright 2016, Damon Lynch"

from typing import Union
from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QSplitter, QSizePolicy, QFrame)

from raphodo.devicedisplay import DeviceView, EmulatedHeaderRow, device_header_row_height
from raphodo.filebrowse import FileSystemView
from raphodo.destinationdisplay import DestinationDisplay
from raphodo.constants import minFileSystemViewHeight
from raphodo.viewutils import QFramedWidget


class ComputerWidget(QFramedWidget):
    """
    Combines a device view or destination display, and a file system view, into one widget.

    Also contains an empty header row that emulates the look of an actual header row for a
    a device view or destination display -- it's used when a valid destination or source is
    not yet specified.
    """

    def __init__(self, objectName: str,
                 view: Union[DeviceView, DestinationDisplay],
                 fileSystemView: FileSystemView,
                 select_text: str,
                 parent: QWidget=None) -> None:

        super().__init__(parent)
        self.setObjectName(objectName)
        layout = QVBoxLayout()
        border_width = QSplitter().lineWidth()
        layout.setContentsMargins(border_width, border_width, border_width, border_width)
        layout.setSpacing(0)
        self.setLayout(layout)

        self.view = view
        self.view.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)
        self.fileSystemView = fileSystemView
        self.emulatedHeader = EmulatedHeaderRow(select_text)
        self.emulatedHeader.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Maximum)

        layout.addWidget(self.emulatedHeader)
        layout.addWidget(self.view)
        layout.addStretch()
        layout.addWidget(self.fileSystemView, 5)
        self.view.setStyleSheet('QListView {border: none;}')
        self.fileSystemView.setStyleSheet('FileSystemView {border: none;}')

    def setViewVisible(self, visible: bool) -> None:
        self.view.setVisible(visible)
        self.emulatedHeader.setVisible(not visible)
        self.view.updateGeometry()

    def minimumHeight(self) -> int:
        if self.view.isVisible():
            height = self.view.minimumHeight()
        else:
            height = device_header_row_height()
        height += minFileSystemViewHeight()
        return height