Example #1
0
 def get_icon_string(self, nid: int, app_icon, icon):
     if app_icon and not os.path.isabs(app_icon):
         #safe to use
         return app_icon
     if icon and icon[0] == b"png":
         icon_data = icon[3]
         from xpra.platform.paths import get_xpra_tmp_dir
         tmp = osexpand(get_xpra_tmp_dir())
         d = tmp
         missing = []
         while d and not os.path.exists(d):
             missing.append(d)
             d = os.path.dirname(d)
         for d in reversed(missing):
             os.mkdir(d, 0o700)
         temp = tempfile.NamedTemporaryFile(
             mode='w+b',
             suffix='.png',
             prefix='xpra-notification-icon-',
             dir=tmp,
             delete=False)
         temp.write(icon_data)
         temp.close()
         self.temp_files[nid] = temp.name
         return temp.name
     return ""
Example #2
0
 def set_icon_from_data(self,
                        pixels,
                        has_alpha,
                        w,
                        h,
                        rowstride,
                        _options=None):
     self.clean_last_tmp_icon()
     #use a temporary file (yuk)
     from xpra.gtk_common.gtk_util import pixbuf_save_to_memory, get_pixbuf_from_data
     tray_icon = get_pixbuf_from_data(pixels, has_alpha, w, h, rowstride)
     png_data = pixbuf_save_to_memory(tray_icon)
     tmp_dir = osexpand(get_xpra_tmp_dir())
     if not os.path.exists(tmp_dir):
         os.mkdir(tmp_dir, 0o755)
     fd = None
     try:
         fd, self.tmp_filename = tempfile.mkstemp(prefix="tray",
                                                  suffix=".png",
                                                  dir=tmp_dir)
         log("set_icon_from_data%s using temporary file %s",
             ("%s pixels" % len(pixels), has_alpha, w, h, rowstride),
             self.tmp_filename)
         os.write(fd, png_data)
     except OSError as e:
         log("error saving temporary file", exc_info=True)
         log.error("Error saving icon data to temporary file")
         log.error(" %s", e)
         return
     finally:
         if fd:
             os.fchmod(fd, 0o644)
             os.close(fd)
     self.do_set_icon_from_file(self.tmp_filename)
Example #3
0
 def set_icon_from_data(self, pixels, has_alpha, w, h, rowstride, _options=None):
     self.clean_last_tmp_icon()
     #use a temporary file (yuk)
     from xpra.gtk_common.gtk_util import COLORSPACE_RGB, pixbuf_new_from_data, pixbuf_save_to_memory
     import tempfile
     tmp_dir = osexpand(get_xpra_tmp_dir())
     if not os.path.exists(tmp_dir):
         os.mkdir(tmp_dir, 0o755)
     self.tmp_filename = tempfile.mkstemp(prefix="tray", suffix=".png", dir=tmp_dir)[1]
     log("set_icon_from_data%s using temporary file %s",
         ("%s pixels" % len(pixels), has_alpha, w, h, rowstride), self.tmp_filename)
     tray_icon = pixbuf_new_from_data(pixels, COLORSPACE_RGB, has_alpha, 8, w, h, rowstride)
     png_data = pixbuf_save_to_memory(tray_icon)
     with open(self.tmp_filename, "wb") as f:
         f.write(png_data)
     self.do_set_icon_from_file(self.tmp_filename)
Example #4
0
 def get_icon_string(self, nid, app_icon, icon):
     if app_icon and not os.path.isabs(app_icon):
         #safe to use
         return app_icon
     elif icon and icon[0] == b"png":
         icon_data = icon[3]
         from xpra.platform.paths import get_xpra_tmp_dir
         tmp = osexpand(get_xpra_tmp_dir())
         if not os.path.exists(tmp):
             os.mkdir(tmp, 0o700)
         temp = tempfile.NamedTemporaryFile(mode='w+b',
                                            suffix='png',
                                            prefix='xpra-notification',
                                            dir=tmp,
                                            delete=False)
         temp.write(icon_data)
         temp.close()
         self.temp_files[nid] = temp.name
         return temp.name
     return ""