GtkCellRendererText - use "ellipsize" together with "wrap-width" - c

I need to break some generic text into multiple lines using a GtkCellRendererText.
If the text exceeds 3 lines, I would like to ellipsize it.
So here is my attempt, which does not work so well.
...
g_object_set (G_OBJECT (my_text_renderer),
"ellipsize", PANGO_ELLIPSIZE_END,
"single-paragraph-mode", TRUE,
"wrap-mode", PANGO_WRAP_WORD_CHAR,
"wrap-width", 30,
"width-chars", 40,
"xpad", 5,
NULL);
It works fine if I only use "ellipsize", and it works fine if I only use "wrap-width" ... but both together seems to be a problem.
I found this tutorial which suggest to use "gtk_label_set_lines", however I cannot do this, since I dont use a label.

Related

How to distinguish between iTerm2 windows to move / resize only one of them with Hammerspoon?

I have two iTerm2 windows open, and I want to place and resize one via Hammerspoon while leaving the other one as is.
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "Right", function()
local layout = {
{"iTerm2", "/in/my/work/dir", nil, hs.geometry.rect(0.0, 0.40, 0.6, 0.6), nil, nil},
}
hs.layout.apply(layout)
end)
When I run the code as above, nothing happens; Hammerspoon does not find my iTerm2 windows, even though it looks like my window has "/in/my/work/dir" in the title.
When I replace "/in/my/work/dir" with nil, Hammerspoon moves and resizes all my iTerm2 windows. This makes sense, since I just ask for all iTerm2 windows without specifying a title.
When I add debug code to print the list of my iTerm2 windows to the console, I see only one iTerm2 window:
hs.fnutils.each(hs.application.runningApplications(), function(app)
if string.find(app:name(), "iTerm2") then
print("Found " .. app:name() .. " -- " .. app:title())
end
end)
This prints:
Found iTerm2 -- iTerm2
How can I use Hammerspoon to tell my iTerm2 windows apart and move / resize only one of them?
This actually works when you pass the complete title, not only a part of the title. I guess I got misled when the documentation said "string containing a window title". It has to be an exact match.

Menu button in gtk3 not working

I'm using gtk3 in Anjuta with C, with the following cut-out version of my code:
u.wMenuButton = gtk_menu_button_new();
u.weaponMenu = gtk_menu_new();
u.weaponCI = gtk_menu_item_new();
u.weapon = gtk_button_new_with_label("Punch");
gtk_box_pack_start(GTK_BOX(u.horizontal), u.wMenuButton, TRUE, TRUE, 1);
gtk_menu_button_set_popup (GTK_MENU_BUTTON(u.wMenuButton), u.weaponMenu);
gtk_container_add (GTK_CONTAINER(u.weaponCI), u.weapon);
gtk_menu_attach(GTK_MENU(u.weaponMenu), u.weaponCI, 0, 1, 0, 1);
The only difference in my real code is that I used an array of "weaponCI" and "weapon" and formatted each one identical to the above. I've tried NOT using an array, but it didn't work. I've tried different menu_attach column and row combinations, and nothing worked. I've tried using menubars as indicated in tutorials, and it didn't make a difference. I've reviewed the documentation and some tutorials, and I can't figure out what I have wrong.
I've almost completely sure that my headers and everything is fine, and nothing but the menu is working wrong.
However, the menu still pops up as a tiny flat rectangle with nothing in it at the corner of the screen.
Well, did you try to call gtk_widget_show_all on it ?

Using PyMEL to set the "Alpha to Use" attribute in an object of class psdFileTex

I am using Maya to do some procedural work, and I have a lot of textures that I need to load into Maya, and they all have transparencies (alpha channels). I would very much like to be able to automate this process. Using PyMEL, I can create my textures and hook them up to a shader, but the alpha doesn't set properly by default. There is an attribute in the psdFileTex node called "Alpha to Use", and it must be set to "Transparency" in order for my alpha channel to work. My question is this - how do I use PyMEL scripting to set the "Alpha to Use" attribute properly?
Here is the code I am using to set up my textures:
import pymel.core as pm
pm.shadingNode('lambert', asShader=True, name='myShader1')
pm.sets(renderable=True, noSurfaceShader=True, empty=True, name='myShader1SG')
pm.connectAttr('myShader1.outColor', 'myShader1SG.surfaceShader', f=True)
pm.shadingNode('psdFileTex', asTexture=True, name='myShader1PSD')
pm.connectAttr('myShader1PSD.outColor', 'myShader1.color')
pm.connectAttr('myShader1PSD.outTransparency', 'myShader1.transparency')
pm.setAttr('myShader1ColorPSD.fileTextureName', '<pathway>/myShader1_texture.psd', type='string')
If anyone can help me, I would really appreciate it.
Thanks
With any node, you can use listAttr() to get the available editable attributes. Run listAttr('myShaderPSD'), note in it's output, there will be two attributes called 'alpha' and 'alphaList'. Alpha, will return you the current selected alpha channel. AlphaList will return you however many alpha channels you have in your psd.
Example
pm.PyNode('myShader1PSD').alphaList.get()
# Result: [u'Alpha 1', u'Alpha 2'] #
If you know you'll only ever be using just the one alpha, or the first alpha channel, you can simply do this.
psdShader = pm.PyNode('myShader1PSD')
alphaList = psdShader.alphaList.get()
if (len(alphaList) > 0):
psdShader.alpha.set(alphaList[0])
else:
// No alpha channel
pass
Remember that lists start iterating from 0, so our first alpha channel will be located at position 0.
Additionally and unrelated, while you're still using derivative commands of the maya.core converted for Pymel, there's still some commands you can use to help make your code read nicer.
pm.setAttr('myShader1ColorPSD.fileTextureName', '<pathway>/myShader1_texture.psd', type='string')
We can convert this to pymel like so:
pm.PyNode('myShader1ColorPSD').fileTextureName.set('<pathway>/myShader1_texture.psd')
And:
pm.connectAttr('myShader1PSD.outColor', 'myShader1.color')
Can be converted to:
pm.connect('myShader1PSD.outColor', 'myShader1.color')
While they may only be small changes, it reads just the little bit nicer, and it's native PyMel.
Anyway, I hope I have helped you!

simple c programming gui

I developed the steam table equation solver in C language...but the inputing the values in black screen console is boring.
So I strictly wanted to create simple GUI in C.
I searched for hello world codes, all were pretty long. But this was the only one I understood.
#include <windows.h>
int main()
{
MessageBoxA( NULL, "Hello World!", "Hello", MB_OK );
}
By using a gui builder for C, i got this code, now I was thinking how to scan values from TEXTBOX1 and TEXTBOX2 on Clicking of COMMANDBUTTON1 and display the output in TEXTBOX3?
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include "hello.auto.h"
HWND hwnd_Label1, hwnd_Label2, hwnd_TextBox1, hwnd_TextBox2, hwnd_CommandButton1,
hwnd_TextBox3;
HFONT MSSansSerif_8pt;
void CreateChildWindows(HWND hwndMainWindow, HINSTANCE hInstance)
{
InitCommonControls();
MSSansSerif_8pt = CreateFont(-11,0,0,0,FW_NORMAL,0,0,0,0,0,0,0,0,"MS Sans Serif");
hwnd_Label1 = CreateWindowEx(0, "Static", "Pressure",
WS_CHILD | WS_VISIBLE,
11, 55, 95, 38, hwndMainWindow,
(HMENU)Label1, hInstance, NULL);
SetWindowFont(hwnd_Label1, MSSansSerif_8pt, TRUE);
hwnd_Label2 = CreateWindowEx(0, "Static", "Temperature",
WS_CHILD | WS_VISIBLE,
11, 110, 95, 38, hwndMainWindow,
(HMENU)Label2, hInstance, NULL);
SetWindowFont(hwnd_Label2, MSSansSerif_8pt, TRUE);
hwnd_TextBox1 = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit" , NULL,
WS_CHILD | ES_WANTRETURN | WS_VISIBLE,
187, 55, 83, 35, hwndMainWindow,
(HMENU)TextBox1, hInstance, NULL);
SetWindowFont(hwnd_TextBox1, MSSansSerif_8pt, TRUE);
hwnd_TextBox2 = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit" , NULL,
WS_CHILD | ES_WANTRETURN | WS_VISIBLE,
187, 99, 83, 35, hwndMainWindow,
(HMENU)TextBox2, hInstance, NULL);
SetWindowFont(hwnd_TextBox2, MSSansSerif_8pt, TRUE);
hwnd_CommandButton1 = CreateWindowEx(0, "Button", "CommandButton1",
WS_CHILD | BS_MULTILINE | BS_PUSHBUTTON | WS_VISIBLE,
308, 77, 117, 52, hwndMainWindow,
(HMENU)CommandButton1, hInstance, NULL);
SetWindowFont(hwnd_CommandButton1, MSSansSerif_8pt, TRUE);
hwnd_TextBox3 = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit" , NULL,
WS_CHILD | ES_WANTRETURN | WS_VISIBLE,
66, 220, 385, 35, hwndMainWindow,
(HMENU)TextBox3, hInstance, NULL);
SetWindowFont(hwnd_TextBox3, MSSansSerif_8pt, TRUE);
return;
}
HWND GetItem(int nIDDlgItem)
{
switch(nIDDlgItem)
{
case -1:
return GetParent(hwnd_Label1);
case Label1:
return hwnd_Label1;
case Label2:
return hwnd_Label2;
case TextBox1:
return hwnd_TextBox1;
case TextBox2:
return hwnd_TextBox2;
case CommandButton1:
return hwnd_CommandButton1;
case TextBox3:
return hwnd_TextBox3;
default: return NULL;
}
}
void Form_Unload(HWND hMainWnd)
{
DeleteFont(MSSansSerif_8pt);
return;
}
I tried many times, but failed. Even if you people give me links of good sites, then I will be greatful.
You're looking for a good book on Win32 API programming using C. And you're in luck, there's a great book that pretty much everyone uses to learn it. It's written by Charles Petzold, and it's called (aptly enough) Programming Windows. You want the 5th edition, which is the most recent version that discusses Win32 programming.
There are also various tutorials available online if you search for "Win32 programming". However, a number of them contain some errors and misunderstandings (like the difference between ANSI and Unicode strings), and the good ones are rather short and incomplete. You won't learn everything you need to know to write a non-trivial program from online tutorials, but you should be able to get something really simple up on the screen. This one by theForger is one I've seen recommended many times.
Be warned, though, that writing GUI code (especially at such a low level) tends to be a lot more verbose than simply getting text onto the screen for a console program. You're going to end up writing a bunch of code that is used only to make the GUI work and has nothing to do with the logic of your program. It's much easier if you learn the C language first, and that's best done through simple console-type, text-only programs.
As for your specific question, you've created three textbox controls on the screen, named hwnd_TextBoxX, where X is a number between 1 and 3. As you probably already know, hwnd indicates a handle to a window (wnd), and so those variables hold handles to the textbox windows.
The Win32 API provides a GetWindowText function, which you can use to retrieve the text from a particular window. You pass it a handle to the desired window (hWnd), a pointer to a character buffer, and an integer value indicating the length of your buffer. Already, the ugly nature of the C language crops up—you have to understand how strings work in C in order to call the function correctly.
Once you've retrieved the string displayed in one of the textboxes, you can display it in another textbox window using the similar SetWindowText function, which takes only the window handle (hWnd) and a pointer to the buffer containing the string.
The code would look something like this:
// Get the text displayed in textbox 1
TCHAR szBuffer[100];
GetWindowText(hwnd_TextBox1, szBuffer, 100);
// Display that text in textbox 3
SetWindowText(hwnd_TextBox3, szBuffer);
To do this in response to a click on a button, you'll need to learn about the Win32 equivalent of "events"—window messages. Child windows, like button controls, send notification messages to their parent window (i.e., a dialog) when something potentially interesting happens, like the user clicks on them.
In particular, a button control sends its parent a BN_CLICKED notification through the WM_COMMAND message. By handling the WM_COMMAND message in your main window's window procedure (WndProc) method, you can check that the lParam parameter matches your button control's window handle (hWnd) and that the HIWORD(wParam) matches the BN_CLICKED notification code.
You definitely need a good book that contains step-by-step sample code for that one. It's a bit too difficult to explain thoroughly in a Stack Overflow answer.
Writing a GUI application using just the Win32 API is somewhat fun, but also tedious. It is much easier to use a framework of some sort. This doesn't mean it's impossible though. Here's a quick overview of how you do it.
First, you replace the main routine with WinMain. This routine is the new entry point of your application. It will be responsible for creating the windows and setting up a message dispatch loop.
Notice that I said "windows" and not just a "window". In WinAPI, every "control" you see on the "form" is a "window". The "form" itself is a window also. Every window has a window handle (HWND). You can make an application window using CreateWindow. This gets you a window handle that you can pass to the CreateChildWindows function that the GUI builder made for you. This will add child windows (the controls) to the application window.
Now you need to program all these windows. You do that by processing messages. When you create your application window, you need to supply a window procedure. This procedure will respond to messages as they come in. For example, a button click results in a WM_COMMAND message that you will have to handle. The last thing WinMain does is start a message processing loop that repeatedly calls your WndProc for any incoming message.
This will all start to make sense once you work through the tutorial linked in the other answer. Then you will probably get tired of this and pick up a GUI toolkit :)

Change text color of label in GTK in C

I am using Gtk 2.0.
I am trying to change the text color/font color of the label.
How difficult can it get? I am just trying things like gtk_widget_modify_text etc to no avail. I want to go the "android" or "Qt" way by say adding a simple resource file with all the styles. Where and as what(.rc?) should I add this file? How to parse this file?
I already wrote my App with a lot of widgets and I do not want to change/redo them all. Can somebody show me a simple example?
I even tried a Pango example from the web but the problem is the text in my label keeps changing and therefore I could not follow this.
Please help. Here is what I have tried so far and without success.
GtkWidget *label1;
label1= gtk_label_new(" ");
gtk_box_pack_start (GTK_BOX(box1), label1,TRUE,TRUE, 0);
GdkColor color;
gdk_color_parse ("white", &color);
gtk_widget_modify_text ( GTK_WIDGET(label1), GTK_STATE_NORMAL, &color);
gchar *stringMarkupText = "<span foreground=\"white\"> <b>Bold</b></span>"; //white color and bold--> the length of this text is fixed by number of spaces. I need to call a function that would set this text on a g_signal_connect so do not want to fix spaces!!
gchar *stringPlainText;
PangoAttrList *attrList;
pango_parse_markup(stringMarkupText, -1, 0, &attrList, &stringPlainText, NULL, NULL);
gtk_label_set_attributes(GTK_LABEL(label1), attrList);
From my point of view, you may use GTK resource file(rc file) in this case.
You can use the gtk_rc_parse function to load your rc file.
void gtk_rc_parse(const gchar *filename);

Resources