This is my .gresource.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/readaratus/decoder">
<file alias="app_icon">icon192.png</file>
</gresource>
</gresources>
I wrote this code to set the icon:
gtk_window_set_icon_from_file(GTK_WINDOW(ui.main_window),
"resource:///org/readaratus/decoder/app_icon",
NULL);
Which fails with the following warning:
Gtk-WARNING **: Error loading icon from file 'resource:///org/readaratus/decoder/app_icon':
Failed to open file 'resource:///org/readaratus/decoder/app_icon': No such file or directory
But if I query the resources bundle, it reports an object with 3631 bytes:
gsize size;
if(g_resources_get_info("/org/readaratus/decoder/app_icon",
G_RESOURCE_LOOKUP_FLAGS_NONE,
&size, NULL, NULL))
{
g_print("app_icon size: %ld\n", size);
}
What is wrong with my code and how do I load an icon from the resource?
GResource is not a file, but a binary resource bundled with your application/library. You should access it only with g_resource_*() methods or special methods which lookup data in resources, like gtk_image_new_from_resource, gtk_builder_new_from_resource, gdk_pixbuf_new_from_resource.
In your case you should have loaded Gdkpixbuf and set it as icon separately.
GdkPixbuf *pixbuf;
pixbuf = gdk_pixbuf_new_from_resource ("/org/readaratus/decoder/app_icon", NULL);
gtk_window_set_icon (window, pixbuf);
Side note: if you have your icon hand-drawn in multiple sizes, use gtk_window_set_icon_list(). Then the best size will be used.
Related
I'm currently working on a WPF application that uses a plotting library called Live Charts for WPF. I want to save a PNG of my graph, which is described on their github page Save Plot Example also discussed at this stackoverflow question here. The problem is adding a reference to the windows base assembly.
`
private void SaveToPng(FrameworkElement visual, string filename)
{
var encoder = new PngBitmapEncoder();
EncodeVisual(visual, filename, encoder);
}
private static void EncodeVisual(FrameworkElement visual, string fileName, BitmapEncoder encoder)
{
var bitmap = new RenderTargetBitmap((int)visual.ActualWidth, (int)visual.ActualHeight, 96, 96, PixelFormats.Pbgra32);
//bitmap.Render();
bitmap.Render(visual);
var frame = BitmapFrame.Create(bitmap);
encoder.Frames.Add(frame);
using (var stream = File.Create(fileName)) encoder.Save(stream);
}
`
I have tried to add this dll as a reference which is located at C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0, but when I do this it does not work. It is actually implicitly included in the project, so that may be why I can add it explicitly like I did with the PresentationCore.dll and PresentationFramework.dll which were also required and solved a few errors. The error states: the type 'System.Windows.Freezable' is defined in an assembly that is not referenced. You must add a reference to assembly 'WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. This is shown by hovering over the call to bitmap.Render(visual), and when hovering over encoder.Save(stream) as shown in the picture and in the above code. I believe resolving this dependency would fix the problem, but I cannot figure out how. Thank you.
Picture of Project
Discovered what I believe is the answer to the problem. I was creating the SaveToPNG and EncodeVisual methods inside of a class library which would be used in the WPF project. The class library is unable to accept WindowsBase as an explicit reference, but the WPF project itself can. It will take some restructuring of the code to implement this in the WPF project itself, but it seems to be the way to resolve this problem.
I am using .NET 6. Here is the contents of my csproj file in my class library:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<ItemGroup>
<Compile Update="Core Library\Port.cs">
<SubType>Component</SubType>
</Compile>
</ItemGroup>
</Project>
I did not see the attributes that you spoke of, and autocomplete could not reference them in this file. Inside of the IDE (Rider) I was able to target net6.0-windows in the properties menu of the project. I then reinserted the code into the class library, but the same error still occurred. I agree with you that it shouldn't be necessary to reference WindowsBase, which isn't necessary when placing the code in the wpf project itself, but in the class library I also had to reference PresentationCore and PresentationFramework, which did take care of multiple errors.
I am trying to show a static pdf in React app. I have tried a lot of packages:
react-pdf
react-pdf-js
react-pdf-js-infinite
simple-react-pdf
pdfjs-dist
react-pdf-pages
They often say that we can use the URL, or pdf file for the props for the PDF component easily, but I cannot use either.
I had two main errors.
As I want to use myPDF for the props for the component, I write this:
import myPDF from 'path/to/pdf_file';
then, render_some_component pdf:{myPDF}
Here is the error:
ModuleParseError in
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
(Source code omitted for this binary file)
(When I comment that line, this kind of error disappears)
I used the file-loader in webpack config, I have tried many different ways but failed.
I use the pdf file directly for the props like this:
render_some_component pdf:{'path/to/pdf_file'}
In the Console:
Warning: Setting up fake worker.
11:23:55.962 pdf.worker.js:349 Warning: Ignoring invalid character "33" in hex string
11:23:55.963 pdf.worker.js:349 Warning: Ignoring invalid character "79" in hex string
...
There are a lot of 'Ignoring invalid character' like that and it always ends with:
localhost/:1 Uncaught (in promise) InvalidPDFException {name: "InvalidPDFException", message: "Invalid PDF structure"}
In the Network, Headers, I see:
Request URL:http://localhost:3000/myPdfFile.pdf
Request Method:GET
Status Code:200 OK
Remote Address:127.0.0.1:3000
but In the Network, Response, I see just the HTML layout.
I think the pdf file is loaded correctly but the package cannot recognize its PDF structure.
Except that two main errors, I had another error related to the Worker used in the packages but I don't know how to fix it:
Uncaught DOMException: Failed to construct 'Worker'
(This is something relates to Chrome as people say Chrome does not allow Worker in the local server)
Any help is highly appreciated as I am stuck in this in 4 days already.
Can you pleas clarify what you main task is?
If I understood it right you want to display a PDF file that already exists in a part of your application? You don't want to create a new PDF with JavaScript.
If you want to just show a PDF have you tried to use iframe?
Something like this:
<iframe
title="file"
style={{ width: '100%', height: '100%' }}
src={downloadURL}
/>
You ca use here also relative paths to the file from the location where your Component is or use full URLs to the file.
I'm getting a dozen "Invalid Resx file. ResX input is not valid. Cannot find valid "resheader" tags for the ResX reader and writer type names." err msgs on trying to compile.
I had this problem before, as can be seen here.
This time, though, it manifests itself a little differently.
First, here is what I did: I selected the context menu item "Undo Pending Changes" on several files in a project. For each of them, their related *.resx file apparently got corrupted.
2-clicking the first err msg in the Error List takes me here in the .resx file:
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
2-clicking the next err takes me here in the .resx file:
<resheader name="resmimetype">text/microsoft-resx</resheader>
This is a commented out explanatory section; in a little bit of context:
<!--
Microsoft ResX Schema
Version 1.3
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
</data>
. . .
All 10 other 2-clickings takes me right to the first line in the .resx file, namely:
<?xml version="1.0" encoding="utf-8"?>
Hans Passant's answer to the same question by a different cat here indicates superfluous white space needs to be removed; I see no such extra white space in my .resx files, though...
What need I do to fix these mangled .resx files?
UPDATE
It may be that those first two locations where the err msg seems to point are bogus/misleading; they may be simply places in the files where I had previously put my cursor (odd that the err msg would go there instead of to the supposed location of the problem, though...)
UPDATE 2
According to the err msg, the failing *.resx files are missing valid resheader reader/writer tags. Yet those tags/declarations do exist there in the failing *.resx files. These look like this:
<resheader name="reader">
<value>System.Windows.Forms.Design.CFResXResourceReader, System.CF.Design,
Version=7.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</resheader>
<resheader name="writer">
<value>System.Windows.Forms.Design.CFResXResourceWriter, System.CF.Design,
Version=7.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</resheader>
....but, interestingly enough (if you're an uebergeek, anyway) those do differ from the RESX readers and writer declarations in other (compiling) forms, which look like this:
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0,
Culture=neutral,PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0,
Culture=neutral,PublicKeyToken=b77a5c561934e089</value>
</resheader>
If I replace the RESX reader/writer declarations in the non-compiling forms with the other format (IOW I replace "System.Windows.Forms.Design.CFResXResourceReader, System.CF.Design, Version=7.0.5000.0" with "System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0" (and use the differing public key tokens), it compiles!
BUT (and this is a big but[t] (think Bertha)), the machine on which this project is being compiled is a PC (of course), but the target machine on which the .exe will run is a Compact Framework (handheld) device. So, will replacing the "CF" with the more generic RESX verbiage prove problematic once the .exe is moved from point PC to point Handheld Windows CE device?
I am trying to recompile a gtk application and instead of launching the g:help browser, I want to launch the default browser and html file on my file system.
I modified the source code to:
#define APP_HELP "file://usr/local/share/doc/APP/APP.html"
/*ret = gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (parent)),
link,
GDK_CURRENT_TIME,
&error);*/
ret = gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (parent)),
APP_HELP,
GDK_CURRENT_TIME,
&error);
But when I launch the help I see the following error:
What happened to /usr ? How can I fix it?
Closing the question after the useful remark from Kwariz:
because the URI should begin with file:///usr/....
I have a problem while loading my jar file at run time.
My hotel.jar is loaded and a method of it (makeReservation) is invoked using the following code:
File file = new File("c:/ComponentFiles/hotel.jar");
URL jarfile = new URL("jar", "", "file:" + file.getAbsolutePath() + "!/");
URLClassLoader cl = URLClassLoader.newInstance(new URL[]{jarfile});
Class componentClass = cl.loadClass("HotelPackage.HotelMgt");
Object componentObject = componentClass.newInstance();
Method setMethod = componentClass.getDeclaredMethod("makeReservation", null);
setMethod.invoke(componentObject, null);
The problem is in the class HotelPackage.HotelMgt of my jar file , I have a class variable of another class (HotelPackage.Hotel) which is in another jar file.
I tried to open and load the other jar file with the same code as above but I receive the exception that cannot find the class def.:
Exception in thread "main" java.lang.NoClassDefFoundError: BeanPackage/Hotel
what is the solution?
You can specify dependencies between JARs by defining the Class-Path property in the JARs' manifest files. Then the JVM will load the dependency JARs automatically as needed.
More information is here: http://java.sun.com/docs/books/tutorial/deployment/jar/downman.html
Thanks, but I found another solution that really works. Since I know whole the component series that are going to work with each other, I load them all with one class loader instance (array of URLs). then the classloader itself manages the dependencies.