Change filename which is shown in state widget

Hi,

I would like to change the filename that's displayed in the "state" widget when a print is ongoing. So e.g instead of displaying "myfile.gcode" I would like to show something different. I've already tried several things, but somehow I can't figure out how I can accomplish that. I think I have to use the "printerStateViewModel" somehow, but I can't figure out how to do that.

Any help would be greatly appreciated!

Thanks for your time,
Bernhard

hmm..well you can overwrite the filename like this:

self.printerStateViewModel.filedisplay("new-filename.something")

But it will be overwriten from "time to time". Yes of course you can make a subscription an that field and everytime the value is changed you can "rechange" it with your value....but this is really dirty.

self.printerStateViewModel.filedisplay.subscribe(function(newValue){
 // do whatever you link...try to prevent endless-loops ;-)
});

Maybe you can give us more inside about your activity?
Adding a new filed below the origin-field is maybe easier, because then you have full control over it.

Many thanks for your reply - very much appreciated!

Maybe you can give us more inside about your activity?

Well, that takes a bit of explaining. For several releases now, I am experiencing some problems with stuttering when printing something via OctoPrint. I've tried all bunch of things to fix the problem (replaced cables, replaced the SD card, monitored the load of the system, monitored the log files for any indications what could cause the problems, etc), but couldn't fix the problem. As the stuttering only occurred sporadically, it was really hard to debug and at some point I didn't want to invest any more time into it. I know that there are some Anti-Stutter plugins and some firmware fixes to mitigate that issue, but I didn't want to go that route.

As I do not use any fancy OctoPrint plugins and I mainly use OctoPrint for organizing my gcode files, I decided to fix the problem with hardware. So, I created a custom PCB which makes the SD card available via WiFi. When I now press the Print button in OctoPrint, the gcode will first be sent to the SD card and then the print is started directly from the SD card. As there's a filename length limitation on the SD card I cannot use the original name when writing the gcode file to the SD card, but have to shorten the name to a 8.3 filename.

e.g: I select the file my super cool file.gcode for printing and press the print button. The file is then sent to the SD card via WiFi and stored on the SD card with the name mscf.gco. So, in the OctoPrint state widget, it shows up as: File: mscf.gco (SD). I would like to change that to my super cool file.gcode

There's already a PR that's been merged that allows for renaming filenames, not sure that will work with cards stored on SD though.

Edit: I take that back, that's a different thing, you want a virtual name mapping to sd card filename. If you're overwriting the same file every time on the SD then it would always overwrite the same file, which basically would just be an internal mapping in a plugin.

I guess the question would be is it kind of depends on how you're sending the file to sd, I assume that's the same plugin that you are attempting these changes. I agree with Ollis, subscribing to the state panel and checking against something to avoid memory loops would be a way to go. Another approach would be replacing the elelement in the state panel viewmodel prior to binding, and then bind your own internal observable to it possibly. It's kind of similar to what I do for thumbnails in the state panel.

And to be honest, you could create your own state view model that is a duplicate of the original with your own replacement with get_template_configs using replaces.

Thanks also to you @jneilliii

When the print is started I already store the original filename in the settings (I got inspired by your StatefulSidebar plugin here ;)), but I couldn't figure out how to overwrite the value in the UI.

It's already a bit late here, but I'll definitely give the solution @OllisGit proposed a try tomorrow. In case it doesn't work as expected, I'll have a look at the get_template_configs approach.

Thanks a lot to you both @OllisGit and @jneilliii - you already helped me a lot here!

Add a dependency in your view model to the stateViewModel and add to the top as parameters[#], as appropriate.

dependencies: ['settingsViewModel', 'filesViewModel', 'printerStateViewModel'],
self.printerStateViewModel = parameters[2];

In onBeforeBinding of your viewmodel add this...

self.onBeforeBinding = function() {
	self.printerStateViewModel.custom_filedisplay = ko.observable();
	$('#state > div > strong:eq(1)').replaceWith('<strong data-bind="text: custom_filedisplay, attr: {title: filepath}"></strong>');

In your file send code function change update the self.printerStateViewModel.custom_filedisplay observable by calling it like a function with the value as string.

self.printerStateViewModel.custom_filedisplay('real_filename');

Thanks a lot for your help!

Unfortunately, I couldn't make it work with the observable, as suggested in your last post. But with the "dirty hack" (i.e subscribing to the field and manually changing the value back) it works. Not sure if there are any long term issues with "the hacky solution", that makes it worth investigating a bit more time getting the 'observables approach' to work, but if not, I could also totally live with the hacky solution :smiley: