Using a predefined response ID in a GtkDialog in a GtkBuilder XML? - gtk

Is there any way to use a predefined response (e.g., GTK_RESPONSE_OK) in a GtkDialog, without hard-coding the ID? Glade generates XML with "0" there by default, and gives me a numeric entry. While I suppose I could enter -5, that seems to defeat the point of having a constant.
The Glade XML looks like this:
<action-widgets>
<action-widget response="0">cancel-button</action-widget>
<action-widget response="0">connect-button</action-widget>
</action-widgets>
Even the example in the docs:
<action-widgets>
<action-widget response="3">button_ok</action-widget>
<action-widget response="-5">button_cancel</action-widget>
</action-widgets>
(Which is a bit hilarious, given that they're using -5 (GTK_RESPONSE_OK) for "button_cancel"…)

Since GTK 3.12 you can use nck-names for the response.
commit baa471ec130c360a5c4ae314769bc7b858814219
Author: Jasper St. Pierre <jstpierre#mecheye.net>
Date: Mon Oct 28 11:19:43 2013 -0400
gtkdialog: Allow specifying response IDs by nick in <action-widgets>
This makes it a lot more convenient for developers, as they don't
have to look up the numeric value of response IDs.
so you can now do
<action-widgets>
<action-widget response="ok">button_ok</action-widget>
<action-widget response="cancel">button_cancel</action-widget>
</action-widgets>

Related

Google Sheets Auto-Parses Strings To Dates...Sometimes?

I'm using Google Sheets to scrape stock data from the tables on Yahoo Finance. For example, to grab a company's P/E Ratio, it's as simple as:
=INDEX(IMPORTHTML("https://finance.yahoo.com/quote/DELL","table", 2),3,2)
However, I'm running into an odd behavior when grabbing the earnings date. Yahoo Finance lists them in two possible formats: like "Feb 25, 2021" or like "Jan 28, 2021 - Feb 01, 2021"
In the first case, just grab the cell value exactly like above:
=INDEX(IMPORTHTML("https://finance.yahoo.com/quote/DELL","table", 2),5,2)
In the second, grab the cell value then parse out the first bit:
=LEFT(INDEX(IMPORTHTML("https://finance.yahoo.com/quote/KO","table", 2),5,2),12)
Now for the issue: it's inconsistent with how it treats the data. In the first case, it recognizes that the string "looks like" a date, & returns it directly as an actual date - as if the call were wrapped in DATEVALUE(), though obviously it is not. In the latter case, it returns it as a string, so you need to explicitly wrap it in DATEVALUE().
Why does it behave inconsistently, returning the first string as a date but the second string as a string? This makes it difficult to have one formula that handles both cases, as DATEVALUE() will break if you pass it something that's already a date (i.e. as in the first case).
Use your LEFT formula in both cases, add in the end *1 and format both as Date, for a single, consistent formula.
KO example
=LEFT(INDEX(IMPORTHTML("https://finance.yahoo.com/quote/KO","table", 2),5,2),12)*1
DELL example
=LEFT(INDEX(IMPORTHTML("https://finance.yahoo.com/quote/DELL","table", 2),5,2),12)*1

Changing the time format in freemarker

I have the following time format:
Dec 29, 2016 10:57:58 PM
How can I display it in a model of days ago. Like 10days or 20days using Freemarker?
Thank you.
FreeMarker templates don't do calendar calculations, or at least not unless you add a TemplateMethodModelEx for them. But in principle such data should come from the data-model, rather than calculated by the template.
Though, depending on how you define "days ago", something like ((.now?long - someDate?long) / 86400000)?ceiling might works, assuming someDate is a real date-time value and not just a string. But it's ugly.

Changing the Date Format the p-Calendar Transfers

I have a component, p-Calendar.
I had no trouble finding a way to receive the date I selected, and modify it.
<p-calendar
[showIcon]="true"
(onSelect)="onSelectMethod($event)"
[(ngModel)]="myDate"
[dataType]="date"
>
</p-calendar>
So basically when I hit a different date in the calendar, it does catch the date correctly. It will transfer this information:
"Thu Dec 08 2016 00:00:00 GMT-0500 (Eastern Standard Time)"
While I can see that all this detail is useful, I really just want my component to receive:
12/08/16.
Is there any simple way to do this, perhaps some inherent method that comes with the calendar, without manually doing string modifications in my code? I read the documentation and couldn't find the information I am looking for.
The onBlur method seems to be transferring the data in the way I want it to. Unfortunately onBlur only works when you type in the date manually, or when you're one date selection behind. It would be great to somehow call PrimeNG's onBlur method after you made a selection in the calendar drop-down.
I wouldn't particularly recommend this as it's a hacky solution, it is probably better to do transformations of the myDate as appropriate for display or other purposes.
If you really, really want to do this so that the myDate in your component only contains a short date without all that time and location information you can go ahead and separate out the model bindings to make it work like so:
template.html
<p-calendar [ngModel]="myDate"
(onSelect)="onSelectMethod($event)"
[dataType]="date">
</p-calendar>
component.ts
onSelectMethod(event) {
let d = new Date(Date.parse(event));
this.myDate = `${d.getMonth()+1}/${d.getDate()}/${d.getFullYear()}`;
}
Here's a functioning demo: http://plnkr.co/edit/IGRfXjtqIo0TEr2iDC06?p=preview
In case you were wondering about applying a pipe, you would do a straight [(ngModel)]="myDate" bind and, where you want to see the short date in the template do {{myDate | date: 'MM/dd/yy'}}

Drupal - date field language when used for RSS

I have a problem with the following scenario.
I set up a node with a date field with type "Date (ISO format)".
To display that nodes in a RSS feed, i created a view from content and format RSS-feed. In addition i set up a custom date format via "r" (RFC 2822) or (D, d M Y H:i:s O) in Drupal and used it for that field "field_time". That field is used as pubDate.
The date field creates instead of:
Wed, 01 Jul 2015 00:00:00 +0200
the "german" version.
Mi, 01 Jul 2015 00:00:00 +0200
If i do the same with for example the "created" date i get the correct english output.
I have allready tried to set the "field language" of that view to english.
Also i tried to programmatically change the output in the rows tpl (overwhelming my php knowledge).
Its a very similar case like here.
Maybe someone can get me a hint to alter that field, change it in the rows template or something similar.
Thanks in advance!
After some trail and error, i rewrote the output of my field "field_time" via the views templates at field level. I get the raw value from the field, converted it "again" in the RFC 2822 format and it sticks in english.
$rawdate = $row->field_data_field_time_field_time_value;
$unixdate = strtotime($rawdate);
print date('r', $unixdate);
I modified it after that a bit to get other nodes also in the feed which have only e.g. node_created via "rewrite if empty" in the views UI.
if (isset($row->field_data_field_time_field_time_value)) {
$rawdate = $row->field_data_field_time_field_time_value;
$unixdate = strtotime($rawdate);
print date('r', $unixdate);
} else {
print $output;
}
Im not sure, if that is very clean. Suggestions still welcome.

Formatting post's date value in DocPad

Currently if my post has date: 2013-06-16 in my post, and I do #document.date in the post layout I get "Sat Jun 15 2013 19:00:00 GMT-0500 (CDT)".
I would like to get different formats. Like 2013-06-16 for the pubdate HTML5 tag (or something similar).
Or Jun 15, 2013 for the human readable post date, etc.
How can I accomplish this? BTW my layouts are using the .html.coffee file extension. :)
Figured it out! This is my docpad.coffee file:
https://github.com/Greduan/eduantech.docpad/blob/bcc91a247e9741f4ce8aa5883634fac26c9859a5/docpad.coffee#L4-L5
https://github.com/Greduan/eduantech.docpad/blob/bcc91a247e9741f4ce8aa5883634fac26c9859a5/docpad.coffee#L41-L43
And here's my post template:
https://github.com/Greduan/eduantech.docpad/blob/bcc91a247e9741f4ce8aa5883634fac26c9859a5/src/layouts/post.html.coffee#L7-L8
Of course I only linked the relevant parts of the code. Basically I learned and used Moment.js. :)
Although I love Moment.js, if you prefer a solution that does not require an additional plugin and you don't need to do too much with the date, you could use native JavaScript.
For example, if you would like to output your date in this great, human-readable format: Saturday, November 15, 2014, you can use the following native JavaScript method, passing in an optional locale:
date.toLocaleDateString()
And when you need just the year, e.g. 2014, you can use:
date.getFullYear()
Bear in mind, you will need getFullYear and not getYear due to the whole Y2K thing.
With all of the other native JavaScript date methods, you can make your own combinations, though if you're including multiple date formats, you may want to let Moment.js do the heavy lifting.