Skip to content

Commit

Permalink
code style updates
Browse files Browse the repository at this point in the history
  • Loading branch information
introkun committed Mar 25, 2024
1 parent 34e7875 commit dcfd96b
Show file tree
Hide file tree
Showing 6 changed files with 534 additions and 451 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ charset = utf-8

# 4 space indentation
[*.py]
indent_style = tab
indent_style = space
indent_size = 4
trim_trailing_whitespace=true
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.8]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Qt
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ indent-after-paren=4

# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
# tab).
indent-string=\t
indent-string=" "

# Maximum number of characters on a single line.
max-line-length=160
Expand Down
162 changes: 94 additions & 68 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,80 +9,106 @@

from qt_range_slider import QtRangeSlider


def _size(size):
print(f'size: {size}')
if size < 0:
print('size is negative, resetting to 0')
size = 0
return humanize.naturalsize(FileSize(size))
print(f"size: {size}")
if size < 0:
print("size is negative, resetting to 0")
size = 0
return humanize.naturalsize(FileSize(size))


# pylint: disable=too-many-arguments
def _render_only_slider(layout, min_value = 0, max_value = 10):
inner_layout = QHBoxLayout()
slider = QtRangeSlider(layout.parent(), min_value, max_value)
slider.setMinimumWidth(500)
inner_layout.addWidget(slider)

layout.addLayout(inner_layout)

def _render_slider_with_labels(layout, min_value = 0, max_value = 10, \
left_thumb_value=0, right_thumb_value=None, size_value=False):
inner_layout = QHBoxLayout()

label_min = QLabel(_size(left_thumb_value) if size_value else str(left_thumb_value))
label_min.setAlignment(Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter)
label_min.setFixedWidth(70)
_right_thumb_value = right_thumb_value if right_thumb_value else max_value
label_max = QLabel(_size(_right_thumb_value) if size_value else str(_right_thumb_value))
label_max.setAlignment(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter)
label_max.setFixedWidth(70)
slider = QtRangeSlider(layout.parent(), min_value, max_value, left_thumb_value, right_thumb_value)
slider.setMinimumWidth(500)
inner_layout.addWidget(label_min)
inner_layout.addWidget(slider)
inner_layout.addWidget(label_max)
layout.addLayout(inner_layout)

# connect signal-slots
if not size_value:
slider.left_thumb_value_changed.connect(label_min.setNum)
slider.right_thumb_value_changed.connect(label_max.setNum)
return slider

slider.left_thumb_value_changed.connect(lambda x: label_min.setText(_size(x)))
slider.right_thumb_value_changed.connect(lambda x: label_max.setText(_size(x)))
return slider
def _render_only_slider(layout, min_value=0, max_value=10):
inner_layout = QHBoxLayout()
slider = QtRangeSlider(layout.parent(), min_value, max_value)
slider.setMinimumWidth(500)
inner_layout.addWidget(slider)

layout.addLayout(inner_layout)


def _render_slider_with_labels(
layout,
min_value=0,
max_value=10,
left_thumb_value=0,
right_thumb_value=None,
size_value=False,
):
inner_layout = QHBoxLayout()

label_min = QLabel(_size(left_thumb_value) if size_value else str(left_thumb_value))
label_min.setAlignment(Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter)
label_min.setFixedWidth(70)
_right_thumb_value = right_thumb_value if right_thumb_value else max_value
label_max = QLabel(
_size(_right_thumb_value) if size_value else str(_right_thumb_value)
)
label_max.setAlignment(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter)
label_max.setFixedWidth(70)
slider = QtRangeSlider(
layout.parent(), min_value, max_value, left_thumb_value, right_thumb_value
)
slider.setMinimumWidth(500)
inner_layout.addWidget(label_min)
inner_layout.addWidget(slider)
inner_layout.addWidget(label_max)
layout.addLayout(inner_layout)

# connect signal-slots
if not size_value:
slider.left_thumb_value_changed.connect(label_min.setNum)
slider.right_thumb_value_changed.connect(label_max.setNum)
return slider

slider.left_thumb_value_changed.connect(lambda x: label_min.setText(_size(x)))
slider.right_thumb_value_changed.connect(lambda x: label_max.setText(_size(x)))
return slider


def main():
app = QApplication(sys.argv)

logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

main_window = QWidget()
main_window.setMinimumSize(640, 480)
layout = QVBoxLayout(main_window)

min_value = 0
max_value = 10
_render_only_slider(layout, min_value, max_value)
_render_slider_with_labels(layout, min_value, max_value)
_render_slider_with_labels(layout, min_value, max_value, min_value + 1, \
max_value - 1)
min_value = 0
max_value = 10*1024*1024*1024
_render_slider_with_labels(layout, min_value, max_value, max_value // 3, \
max_value * 3 // 4, size_value=True)

slider = _render_slider_with_labels(layout, min_value, max_value, max_value // 3, \
max_value * 3 // 4, size_value=True)
slider.setMinimumWidth(500)
slider.set_ticks_count(10)

main_window.show()

sys.exit(app.exec())
app = QApplication(sys.argv)

logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

main_window = QWidget()
main_window.setMinimumSize(640, 480)
layout = QVBoxLayout(main_window)

min_value = 0
max_value = 10
_render_only_slider(layout, min_value, max_value)
_render_slider_with_labels(layout, min_value, max_value)
_render_slider_with_labels(
layout, min_value, max_value, min_value + 1, max_value - 1
)
min_value = 0
max_value = 10 * 1024 * 1024 * 1024
_render_slider_with_labels(
layout,
min_value,
max_value,
max_value // 3,
max_value * 3 // 4,
size_value=True,
)

slider = _render_slider_with_labels(
layout,
min_value,
max_value,
max_value // 3,
max_value * 3 // 4,
size_value=True,
)
slider.setMinimumWidth(500)
slider.set_ticks_count(10)

main_window.show()

sys.exit(app.exec())


if __name__ == "__main__":
main()
main()
Loading

0 comments on commit dcfd96b

Please sign in to comment.