Showing a popup from a rendered view

As seen in the first picture, I have a view rendered into a column (the one with the clock).
Upon clicking on the clock, it takes calls a view as a popup. This popup view also has a table with a button as a rendered view.
Pressing the button supposedly downloads a file, but I want to use a popup to let the users know that the download has either succeeded or failed.
I have made it to the point where the popup will show, but the error text is not being shown.

I have used some AI to resolve this issue, but they say that there is nothing wrong with the script.
Currently, the button is scripted to call the popup when pressed, and it is passing on parameters directly through the script.
Is there some kind of parameter pathing I am not aware of? Will it not directly handover values to the notification view?

Apologies for it being in a different language, but the script is 98% English, so it shouldn't make a big difference.

Without script or any kind of pictures showing the params of your views, we won't be able to help much.

The popup parameter path is probably the issue. Define an input parameter on the notification view, for example message, then bind the label to view.params.message. When opening it, the dictionary key must match exactly:

system.perspective.openPopup(
    "downloadStatus",
    "Popups/DownloadStatus",
    params={"message": "The file was generated successfully."}
)

(This is a guess. Samuel is right we'll need more details to go further than this)

My fault, here is the script for the download button:

def runAction(self, event):
import sys
import base64
logger = system.util.getLogger("Download btn failDownload")
  def showNotify(message, msgType):
      popup_id = "notification\_%s" % system.date.toMillis(system.date.now())
      logger.info("OPNENING POPUP")
      
      system.perspective.openPopup(
          id = popup_id,
          view = "Screen/Popup/Notification",
          params = {"notifyMsg": str(message), "notifyKind": str(msgType)},
          showCloseIcon = True,
          draggable = True,
          resizable = False,
          modal = True,
          width = 400,
          height = 150
      )
  
  try:
      file_id = self.view.params.value # this is the value stored in the cell of the rendered view
      table_name = "alarm_response"
      database = "PostgreSQL_XXXXXX"
  
      query = "SELECT response_file_name, response_file_data, mime_type from " + table_name + " where event_id = ? "
      result = system.db.runPrepQuery(
          query = query,
          args = \[file_id\],
          database = database
          )
  
      if len(result) == 0:
          logger.warn("No record found for id=%r" % file_id)
          showNotify(u"no data found", "warning")
          return
  
      row = result\[0\]
      file_name = row\["response_file_name"\]
      file_data = row\["response_file_data"\]
      mime_type = row\["mime_type"\]
  
      if file_data is None:
          logger.warn("No file attached for id=%r" % file_id)
          showNotify(u"no file found。", "warning")
          return
  
      if not mime_type:
          ext = file_name.split(".")\[-1\].lower() if "." in file_name else ""
          mimeMap = {"pdf": "application/pdf", "png": "image/png", "jpg": "image/jpeg", "jpeg": "image/jpeg"}
          mime_type = mimeMap.get(ext, "application/octet-stream")
  
      system.perspective.download(
          filename = file_name,
          mimeType= mime_type,
          data = file_data
      )
  except:
      logger.error(str(sys.exc_info()))
      showNotify(u"failed to download。", "error")

Attached is a picture of the parameters set for the notification view.
Please let me know if there are any other scripts you would like to see.

This is basically what I think I have (can't say for sure), but it seems that the strings are not being passed over onto the parameters. :frowning:

Hum, probably irrelevant here (or maybe not ?), but when calling system.perspective.openPopup the height and width parameters do not exist.You need to specify them in the position parameter.

position = {'height': 150, 'width': 400}

Also is there a reason each of your brackets are preceded by \ ?

I'm also assuming you have a binding on the text prop of your label which is similar to
{view.params.notifyMsg} + {view.params.notifyKind} ? Just to be sure ahah

I was thinking the same thing about the properties, I have fixed it but it does seem irrelevant to handing over values.

Regarding the slashes, I don't see them in the original script. (attached)
The text editor must've added it when I pasted it in here maybe?

And yes, I do have the text prop bound to the parameter.
In the attached picture, its an expression, but ultimately, I will be binding it to just the parameter.

Can you add a log after the "OPNENING POPUP" and give us the output in the logger :

logger.info(str(message),str(msgType))

I copied and pasted your code in my app and recreated a view etc and everything works on my end.. although I did have to change some tab formatting ?

Also can you provide us with a screenshot of the beginning of your code ? I feel like the indent might be wrong but it may be due to a copy and paste error...

I have added it in the highlighted area, but then the popup stopped showing up.
Should I add it to a different place?

That's odd, what do the logs in the gateway say ?

I know I'm annoying with that but can you turn on the white spaces in the editor ?

Finally, your screenshot does not show it but I assume there are no red markers in the right hand side of the editor ?

EDIT : Im stupid, it should really be logger.info(message + msgType)

No problem, the script with white spaces and the log is attached.
Changing it the message+msgType allowed the popup to show, but there aren't any logs referring to it.

Regarding the red line that usually appears on the side, no I do not see any.

Actually, I have one last idea. May or may not work.

Since you are using a different language, you have to use unicode, so using the str() function is irrelevant when calling system.perspective.openPopup.

So I would completely remove the str() function calls. You are already using the u'string' notation.

      system.perspective.openPopup(
          id = popup_id,
          view = "Screen/Popup/Notification",
          params = {"notifyMsg": message, "notifyKind": msgType},
          showCloseIcon = True,
          draggable = True,
          resizable = False,
          modal = True,
          position = {'height': 150, 'width': 400}
      )

I have just implemented that, but the log seems to be returning the same thing.

Well, the last thing I can do is provide you with my code in case there are invisible characters or something...

I used random characters for the error messages, apologies for that.

Code

	import sys
	import base64
	logger = system.util.getLogger("Download btn failDownload")
	def showNotify(message, msgType):
		popup_id = "notification\_%s" % system.date.toMillis(system.date.now())
		logger.info("OPNENING POPUP")

		system.perspective.openPopup(
			id = popup_id,
			view = "Screen/Popup/Notification",
			params = {"notifyMsg": message, "notifyKind": msgType},
			showCloseIcon = True,
			draggable = True,
			resizable = False,
			modal = True,
			position= {'height': 150, 'width':400}
		)
	
	try:
		file_id = self.view.params.value # this is the value stored in the cell of the rendered view
		table_name = "alarm_response"
		database = "PostgreSQL_XXXXXX"
	
		query = "SELECT response_file_name, response_file_data, mime_type from " + table_name + " where event_id = ? "
		result = system.db.runPrepQuery(
			query = query,
			args = [file_id],
			database = database
			)
		if len(result) == 0:
			logger.warn("No record found for id=%r" % file_id)
			showNotify(u"今天天气很好,我们去公园散步吧。", "warning")
			return
	
		row = result[0]
		file_name = row["response_file_name"]
		file_data = row["response_file_data"]
		mime_type = row["mime_type"]
	
		if file_data is None:
			logger.warn("No file attached for id=%r" % file_id)
			showNotify(u"今天天气很好,我们去公园散步吧。", "warning")
			return
  
		if not mime_type:
			ext = file_name.split(".")[-1].lower() if "." in file_name else ""
			mimeMap = {"pdf": "application/pdf", "png": "image/png", "jpg": "image/jpeg", "jpeg": "image/jpeg"}
			mime_type = mimeMap.get(ext, "application/octet-stream")
  
		system.perspective.download(
			filename = file_name,
			mimeType= mime_type,
			data = file_data
		)
	except:
		logger.error(str(sys.exc_info()))
		showNotify(u"今天天气很好,我们去公园散步吧。", "error")

Otherwise I'll let the experts try to help you as I am out of ideas for now...

Thank you so much for your time and effort to help me.

I'm not tryna work overtime, so I will be trying this code tomorrow.
I will come back if I need any assistance, so it would be much appreciated if I could get some help then as well.