Skip to content

Commit 8bb531f

Browse files
authored
Merge pull request #40 from Lich-Corals/dev
Various improvements for the adaption
2 parents 12267c7 + 7a78319 commit 8bb531f

File tree

2 files changed

+50
-26
lines changed

2 files changed

+50
-26
lines changed

markdown/configuration.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,27 @@ nautilus -q
1010
#start it again, you can also use the normal launcher.
1111
nohup nautilus & disown
1212
```
13-
## 3.1 Automatic updates
13+
## Automatic updates
1414
Automatic updates are only working in the home dictionary. If you've installed the script at the system-wide location, you may turn off automatic updates.
1515
<br/><br/>To <b>turn off automatic updates</b>, open the config file with a text editor and set the `automaticUpdates` variable to 'false'.
1616
To <b>manually trigger a self-update</b>, just open the .py file with a text editor and change the value of the `converterVersion` variable.
1717
To turn off the <b>update pop-up</b>, open the config file with a text editor and set the `showPatchNotes` variable to 'false'.
1818

19-
## 3.2 Shown menu items
20-
To turn off the <b>patch note button</b> in the context menu, open the config file with a text editor and set the `showPatchNoteButton` variable to 'false'.
21-
<br/><br/>To turn off the <b>Configure NFC43 button</b> in the context menu, open the config file with a text editor and set the `showConfigHint` variable to 'false'.
22-
Note: This option is not available in Nemo so far.
19+
## Shown menu items
20+
To turn off the <b>patch note button</b> in the context menu and the <b>version number</b> in the adaption window, open the config file with a text editor and set the `showPatchNoteButton` variable to 'false'.
21+
<br/><br/>To turn off the <b>Configure NFC43 button</b> in the context menu and the <b>config hint</b> in the adaption window, open the config file with a text editor and set the `showConfigHint` variable to 'false'.
2322
<br/><br/>To turn off the '<b>convert to square</b>' option, open the config file with a text editor and set the `convertToSquares` variable to 'false'.
2423
<br/><br/>To turn off the '<b>convert to wallpaper</b>' function, open the config file with a text editor and set the `convertToWallpapers` variable to 'false'.
2524

26-
## 3.3 Other options
25+
## Other options
2726
<br/>To turn off the <b>Double script installation Warning</b>, open the config file with a text editor and set the `checkForDoubleInstallation` variable to 'false'.
2827
Note: This option may be a bit buggy in Nemo, I'll fix it in the future if it appears to be annoying to some users.
2928
<br/>To turn off the __addition of timestamps__ to filenames, open the config file with a text editor and set the `timeInNames` variable to ‘false’.
3029

30+
## Adaption specific options (Nemo)
31+
<br/>To enable the conversion of <b>application/octet-stream</b> files in the adaption version, set the `convertFromOctetStream` option to 'true'. This may allow you to convert files with unmatching mimetypes, which are in a supported- but not as such detected format. This may also allow the context menu option for other un-convertabe files, such a pdf or zip.
32+
<br/>To disable the <b>"-" option</b> in the dropdown-list, set the `showDummyOption` setting to 'false'.
33+
3134
#### All sections
3235
- [Main page](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/README.md)
3336
- __[Configuration](https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/configuration.md)__

nautilus-fileconverter.py

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/python3 -OOt
22

33
# --- Version number ---
4-
converterVersion = "001002009" # Change the number if you want to trigger an update.
4+
converterVersion = "001002010" # Change the number if you want to trigger an update.
55

66
# --- Imports ---
77
import gi
@@ -73,15 +73,17 @@
7373
print(f"WARNING(Nautilus-file-converter)(004): No permission to write configuration file; \"{currentPath}\" is not writeable. View https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/errors-and-warnings.md for more information.")
7474

7575
# --- Set default configs ---
76-
_configPreset = { # These are the pre-defined default settings; edit NFC43-Config.json if the program is installed in your home dictionary.
77-
"automaticUpdates": True, # Replace the "True" with "False" if you don't want automatic updates.
78-
"showPatchNotes": True, # Replace the "True" with "False" if you don't want to see patch notes.
79-
"showPatchNoteButton": True, # Replace the "True" with "False" if you don't want the "View patch notes" button in the converter menu.
80-
"showConfigHint": True, # Replace the "True" with "False" if you don't want to see the config hint.
81-
"convertToSquares": True, # Replace the "True" with "False" if you don't want to convert to square formats.
82-
"convertToWallpapers": True, # Replace the "True" with "False" if you don't want to convert to wallpaper formats.
83-
"checkForDoubleInstallation": True, # Replace the "True" with "False" if you don't the script to check if there is a second installation in another dictionary.
84-
"timeInNames": True # Replace the "True" with "False" if you don't want the script to rename the files to contain a timestamp.
76+
_configPreset = { # These are the pre-defined default settings; edit NFC43-Config.json if the program has permission to write.
77+
"automaticUpdates": True,
78+
"showPatchNotes": True,
79+
"showPatchNoteButton": True,
80+
"showConfigHint": True,
81+
"convertToSquares": True,
82+
"convertToWallpapers": True,
83+
"checkForDoubleInstallation": True,
84+
"timeInNames": True,
85+
"convertFromOctetStream": False,
86+
"showDummyOption": True
8587
}
8688

8789
# --- Load or store configs json ---
@@ -143,7 +145,6 @@
143145
'video/fli',
144146
'image/vnd.fpx',
145147
'image/vnd.net-fpx',
146-
# 'application/octet-stream', <-- Didn't make any problems in nautilus, but Nemo takes all files in it (.zip, .doc, .pdf, etc.) instead of only the image types.
147148
'windows/metafile',
148149
'image/x-xpixmap',
149150
'image/webp')
@@ -185,6 +186,8 @@
185186
'video/x-msvideo',
186187
'video/quicktime')
187188

189+
octetStreamFormats = ('application/octet-stream',)
190+
188191
WRITE_FORMATS_IMAGE = [{'name': 'PNG'},
189192
{'name': 'JPEG'},
190193
{'name': 'BMP'},
@@ -243,6 +246,9 @@
243246
{'name': 'MP3'},
244247
{'name': 'WAV'}]
245248

249+
if _config["convertFromOctetStream"]:
250+
READ_FORMATS_IMAGE = READ_FORMATS_IMAGE + octetStreamFormats
251+
246252
if pillow_heifInstalled:
247253
READ_FORMATS_IMAGE = READ_FORMATS_IMAGE + pyheifReadFormats
248254

@@ -305,14 +311,21 @@ def convert_ffmpeg(menu, format, files):
305311
# --- Nemo adaption ---
306312
class nautilusFileConverterPopup(Gtk.Window):
307313
def __init__(self):
308-
super().__init__(title="Convert file")
314+
super().__init__(title=f"Convert file")
309315
self.set_border_width(15)
310316
self.set_default_size(200, 20)
311317

312318
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
313319

314320
label = Gtk.Label(label="Select a format:")
321+
label.set_justify(Gtk.Justification.CENTER)
315322
vbox.pack_start(label, False, False, 0)
323+
versionInfo = Gtk.Label()
324+
versionInfo.set_markup(f"""<span size="x-small">version {converterVersion}</span>""")
325+
versionInfo.set_justify(Gtk.Justification.CENTER)
326+
configHint = Gtk.Label()
327+
configHint.set_justify(Gtk.Justification.CENTER)
328+
configHint.set_markup(f"""<span size="x-small">View <a href="https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/configuration.md">the config documentation</a>\nto configure the script and hide this text.</span>""")
316329

317330
extensions = Gtk.ListStore(str, str, int)
318331
_allImages = True
@@ -326,6 +339,9 @@ def __init__(self):
326339
if not mime.from_file(_arg) in READ_FORMATS_VIDEO:
327340
_allVideos = False
328341

342+
if _config["showDummyOption"]:
343+
extensions.append(["-", "none", 2])
344+
329345
if _allImages:
330346
for writeFormat in WRITE_FORMATS_IMAGE:
331347
print(writeFormat)
@@ -351,22 +367,27 @@ def __init__(self):
351367
combo.add_attribute(renderer_text, "text", 0)
352368
combo.connect("changed", self._nemoConvert)
353369
vbox.pack_start(combo, False, False, 0)
370+
if _config["showPatchNoteButton"]:
371+
vbox.pack_start(versionInfo, False, False, 0)
372+
if _config["showConfigHint"]:
373+
vbox.pack_start(configHint, True, True, 0)
354374

355375
def _nemoConvert(self, combo):
356-
self.hide()
357376
tree_iter = combo.get_active_iter()
358377
if tree_iter is not None:
359378
model = combo.get_model()
360379
return_name, return_format, return_type = model[tree_iter][:4]
361380
print(return_name, return_format, return_type)
362381
return_format = ast.literal_eval(return_format)
363382
return_paths = []
364-
for retun_path in _nemoArgs:
365-
return_paths.append(Path(retun_path))
366-
if return_type == 0:
367-
convert_image(self, return_format, return_paths)
368-
elif return_type == 1:
369-
convert_ffmpeg(self, return_format, return_paths)
383+
if not return_type == 2:
384+
self.hide()
385+
for retun_path in _nemoArgs:
386+
return_paths.append(Path(retun_path))
387+
if return_type == 0:
388+
convert_image(self, return_format, return_paths)
389+
elif return_type == 1:
390+
convert_ffmpeg(self, return_format, return_paths)
370391

371392

372393
_nemoArgs = sys.argv[1:len(sys.argv)]
@@ -402,7 +423,7 @@ def get_file_items(self, *args) -> List[Nautilus.MenuItem]:
402423
for file in files:
403424
print(file.get_mime_type())
404425
file_mime = file.get_mime_type()
405-
if file_mime in READ_FORMATS_IMAGE:
426+
if file_mime in READ_FORMATS_IMAGE or file_mime == 'application/octet-stream':
406427
return self.__submenu_builder(WRITE_FORMATS_IMAGE,
407428
callback=convert_image,
408429
files=files)

0 commit comments

Comments
 (0)