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