-
Notifications
You must be signed in to change notification settings - Fork 13
/
rgb
executable file
·95 lines (78 loc) · 3.29 KB
/
rgb
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
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
import argparse
import os
import sys
import librgb
from librgb.qt_shims import QtWidgets
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, params):
super(MainWindow, self).__init__()
adapter = librgb.GenericWindowAdapter(params)
shortcut_manager = librgb.ShortcutManager(adapter, params)
for shortcut, func in shortcut_manager.shortcuts.items():
adapter.define_shortcut(shortcut, self, func)
adapter.define_shortcut('Q', self, self.close)
layout = adapter.create_layout()
central_widget = QtWidgets.QWidget(self)
central_widget.setLayout(layout)
self.setCentralWidget(central_widget)
adapter.draw()
def parse_args():
class CustomHelpFormatter(argparse.HelpFormatter):
def __init__(self, prog):
super().__init__(prog, max_help_position=40, width=80)
def _format_action_invocation(self, action):
if not action.option_strings:
return super()._format_action_invocation(action)
default = self._get_default_metavar_for_optional(action)
values = self._format_args(action, default)
opts = action.option_strings
short = [arg for arg in opts if not arg.startswith('--')]
long = [arg for arg in opts if arg.startswith('--')]
return '%*s%s%s %s' % (
3, ', '.join(short), ', ' if short else ' ', ', '.join(long),
values)
class HexAction(argparse.Action):
def __call__(self, parser, ns, values, option_string=None):
setattr(ns, self.dest, int(values, 16))
fmt = lambda prog: CustomHelpFormatter(prog)
parser = argparse.ArgumentParser(
description='Preview given file as raw pixels.', formatter_class=fmt)
parser.add_argument(
'files', metavar='FILE', nargs='+', default=[], help='file to view')
parser.add_argument(
'--flip', default=False, action='store_true',
help='flip the preview vertically')
parser.add_argument(
'--brightness', metavar='MULTIPLIER', default=50.0, type=float,
help='sets brightness adjustment')
parser.add_argument(
'-f', '--format', metavar='FORMAT',
choices=librgb.PixelFormats.get_short_names().values(), default='G8',
help='set the pixel format of the preview')
parser.add_argument(
'--width', metavar='NUM', type=int, default=800,
help='set the preview width')
parser.add_argument(
'--height', metavar='NUM', type=int, default=600,
help='set the preview height')
parser.add_argument(
'-a', '--address', metavar='HEXNUM', action=HexAction, default=0,
help='set the position within the file to start preview at')
return parser.parse_args()
def main():
args = parse_args()
params = librgb.RendererParams()
params.readers = [librgb.FileReader(file) for file in args.files]
params.format = librgb.PixelFormats.from_short_name(args.format)
params.width = args.width
params.height = args.height
params.address = args.address
params.flip = args.flip
params.brightness = args.brightness
app = QtWidgets.QApplication(sys.argv)
win = MainWindow(params)
win.show()
app.exec_()
if __name__ == '__main__':
main()