|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2010 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a widget to stack url bars. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtWidgets import QStackedWidget, QSizePolicy |
|
11 |
|
12 |
|
13 class StackedUrlBar(QStackedWidget): |
|
14 """ |
|
15 Class implementing a widget to stack URL bars. |
|
16 """ |
|
17 def __init__(self, parent=None): |
|
18 """ |
|
19 Constructor |
|
20 |
|
21 @param parent reference to the parent widget (QWidget) |
|
22 """ |
|
23 super().__init__(parent) |
|
24 |
|
25 sizePolicy = QSizePolicy(QSizePolicy.Policy.Expanding, |
|
26 QSizePolicy.Policy.Preferred) |
|
27 sizePolicy.setHorizontalStretch(6) |
|
28 sizePolicy.setVerticalStretch(0) |
|
29 self.setSizePolicy(sizePolicy) |
|
30 self.setMinimumSize(200, 22) |
|
31 |
|
32 def currentUrlBar(self): |
|
33 """ |
|
34 Public method to get a reference to the current URL bar. |
|
35 |
|
36 @return reference to the current URL bar (UrlBar) |
|
37 """ |
|
38 return self.urlBar(self.currentIndex()) |
|
39 |
|
40 def urlBar(self, index): |
|
41 """ |
|
42 Public method to get a reference to the URL bar for a given index. |
|
43 |
|
44 @param index index of the url bar (integer) |
|
45 @return reference to the URL bar for the given index (UrlBar) |
|
46 """ |
|
47 return self.widget(index) |
|
48 |
|
49 def moveBar(self, from_, to_): |
|
50 """ |
|
51 Public slot to move an URL bar. |
|
52 |
|
53 @param from_ index of URL bar to be moved (integer) |
|
54 @param to_ index to move the URL bar to (integer) |
|
55 """ |
|
56 fromBar = self.widget(from_) |
|
57 self.removeWidget(fromBar) |
|
58 self.insertWidget(to_, fromBar) |
|
59 |
|
60 def urlBars(self): |
|
61 """ |
|
62 Public method to get a list of references to all URL bars. |
|
63 |
|
64 @return list of references to URL bars (list of UrlBar) |
|
65 """ |
|
66 urlBars = [] |
|
67 for index in range(self.count()): |
|
68 urlBars.append(self.widget(index)) |
|
69 return urlBars |