[83eb5208] | 1 | # Convert all .ui files in all subdirectories of the current script |
---|
| 2 | import os |
---|
[2e27cdb6] | 3 | import sys |
---|
[83eb5208] | 4 | |
---|
| 5 | def pyrrc(in_file, out_file): |
---|
| 6 | """ Run the pyrcc4 script""" |
---|
[4992ff2] | 7 | execute = 'pyrcc5 %s -o %s' % (in_file, out_file) |
---|
[83eb5208] | 8 | os.system(execute) |
---|
| 9 | |
---|
| 10 | def pyuic(in_file, out_file): |
---|
[b3e8629] | 11 | """ Run the pyuic5 script""" |
---|
[4992ff2] | 12 | execute = 'pyuic5 -o %s %s' % (out_file, in_file) |
---|
[83eb5208] | 13 | os.system(execute) |
---|
| 14 | |
---|
[67642f7] | 15 | def file_in_newer(file_in, file_out): |
---|
| 16 | """ |
---|
| 17 | Check whether file_in is newer than file_out, if file_out exists. |
---|
| 18 | |
---|
| 19 | Returns True if file_in is newer, or if file_out doesn't exist; False |
---|
| 20 | otherwise. |
---|
| 21 | """ |
---|
| 22 | try: |
---|
| 23 | out_stat = os.stat(file_out) |
---|
| 24 | except OSError: |
---|
| 25 | # file_out does not exist |
---|
| 26 | return True |
---|
| 27 | |
---|
| 28 | in_stat = os.stat(file_in) |
---|
| 29 | |
---|
| 30 | # simple comparison of modification time |
---|
| 31 | return in_stat.st_mtime >= out_stat.st_mtime |
---|
| 32 | |
---|
[83eb5208] | 33 | # look for .ui files |
---|
| 34 | for root, dirs, files in os.walk("."): |
---|
| 35 | for file in files: |
---|
| 36 | if file.endswith(".ui"): |
---|
| 37 | file_in = os.path.join(root, file) |
---|
| 38 | file_out = os.path.splitext(file_in)[0]+'.py' |
---|
[67642f7] | 39 | if file_in_newer(file_in, file_out): |
---|
| 40 | print("Generating " + file_out + " ...") |
---|
| 41 | pyuic(file_in, file_out) |
---|
[83eb5208] | 42 | |
---|
| 43 | # RC file in UI directory |
---|
[2e27cdb6] | 44 | execute_root = os.path.split(sys.modules[__name__].__file__)[0] |
---|
| 45 | ui_root = os.path.join(execute_root, 'UI') |
---|
[83eb5208] | 46 | rc_file = 'main_resources.qrc' |
---|
| 47 | out_file = 'main_resources_rc.py' |
---|
[2e27cdb6] | 48 | |
---|
[67642f7] | 49 | in_file = os.path.join(ui_root, rc_file) |
---|
| 50 | out_file = os.path.join(ui_root, out_file) |
---|
| 51 | |
---|
| 52 | if file_in_newer(in_file, out_file): |
---|
| 53 | print("Generating " + out_file + " ...") |
---|
| 54 | pyrrc(in_file, out_file) |
---|
[83eb5208] | 55 | |
---|
| 56 | # Images |
---|
[2e27cdb6] | 57 | images_root = os.path.join(execute_root, 'images') |
---|
[c03692f] | 58 | out_root = os.path.join(execute_root, 'UI') |
---|
[83eb5208] | 59 | rc_file = 'images.qrc' |
---|
| 60 | out_file = 'images_rc.py' |
---|
[67642f7] | 61 | |
---|
| 62 | in_file = os.path.join(images_root, rc_file) |
---|
| 63 | out_file = os.path.join(ui_root, out_file) |
---|
| 64 | |
---|
| 65 | if file_in_newer(in_file, out_file): |
---|
| 66 | print("Generating " + out_file + " ...") |
---|
| 67 | pyrrc(in_file, out_file) |
---|
| 68 | |
---|