Skip to content

Commit

Permalink
new options for style and behavior
Browse files Browse the repository at this point in the history
* new setting to color percentage change according to trend
* new setting to add Yahoo Finance hyperlink to symbol/quote
* new setting to use long version for verbose quote name
  • Loading branch information
thegli committed Oct 4, 2020
1 parent 159d263 commit f88b81b
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 22 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ Check out the desklet configuration settings, and choose the data refresh period

## Release Notes

### 0.5.0 - October 4, 2020
Features:
* new setting to color percentage change according to trend. Enabled by default if percentage change is displayed. Courtesy of [plaihonen](https://github.com/plaihonen).
* new setting to add Yahoo Finance hyperlink to symbol/quote. Enabled by default if symbol is displayed. Proposed by [ngaro](https://github.com/ngaro).
* new setting to use long version for verbose quote name. Enabled by default if verbose name is displayed. Courtesy of [ngaro](https://github.com/ngaro).

### 0.4.2 - September 20, 2020
Bugfixes:
* update translation files with new setting
Expand Down
63 changes: 51 additions & 12 deletions files/yfquotes@thegli/desklet.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Yahoo Finance Quotes - 0.4.1
* Yahoo Finance Quotes - 0.5.0
*
* Shows financial market information provided by Yahoo Finance.
* This desklet is based on the work of fthuin's stocks desklet.
Expand Down Expand Up @@ -28,6 +28,7 @@ const Gettext = imports.gettext;
const UUID = "yfquotes@thegli";
const DESKLET_DIR = imports.ui.deskletManager.deskletMeta[UUID].path;
const ABSENT = "N/A";
const YF_PAGE = "https://finance.yahoo.com/quote/";

Gettext.bindtextdomain(UUID, GLib.get_home_dir() + "/.local/share/locale");

Expand Down Expand Up @@ -105,10 +106,10 @@ QuotesTable.prototype = {
cellContents.push(this.createPercentChangeIcon(quote));
}
if (shouldShow.quoteName) {
cellContents.push(this.createQuoteNameLabel(quote, shouldShow.linkQuote));
cellContents.push(this.createQuoteNameLabel(quote, shouldShow.useLongName, shouldShow.linkQuote));
}
if (shouldShow.quoteSymbol) {
cellContents.push(this.createQuoteSymbolLabel(quote));
cellContents.push(this.createQuoteSymbolLabel(quote, shouldShow.linkSymbol));
}
if (shouldShow.marketPrice) {
cellContents.push(this.createMarketPriceLabel(quote, shouldShow.currencySymbol, shouldShow.decimalPlaces));
Expand All @@ -117,7 +118,7 @@ QuotesTable.prototype = {
cellContents.push(this.createAbsoluteChangeLabel(quote, shouldShow.currencySymbol, shouldShow.decimalPlaces));
}
if (shouldShow.percentChange) {
cellContents.push(this.createPercentChangeLabel(quote));
cellContents.push(this.createPercentChangeLabel(quote, shouldShow.colorPercentChange));
}
if (shouldShow.tradeTime) {
cellContents.push(this.createTradeTimeLabel(quote));
Expand All @@ -134,11 +135,22 @@ QuotesTable.prototype = {
existsProperty : function(object, property) {
return object.hasOwnProperty(property) && object[property] !== undefined && object[property] !== null;
},
createQuoteSymbolLabel : function (quote) {
return new St.Label({
createQuoteSymbolLabel : function (quote, addLink) {
const symbolLabel = new St.Label({
text : quote.symbol,
style_class : "quotes-label"
style_class : "quotes-label",
reactive : addLink ? true : false
});
if (addLink) {
const symbolButton = new St.Button();
symbolButton.add_actor(symbolLabel);
symbolButton.connect("clicked", Lang.bind(this, function() {
Gio.app_info_launch_default_for_uri(YF_PAGE + quote.symbol, global.create_app_launch_context());
}));
return symbolButton;
} else {
return symbolLabel;
}
},
createMarketPriceLabel : function (quote, withCurrencySymbol, decimalPlaces) {
let currencySymbol = "";
Expand All @@ -150,17 +162,26 @@ QuotesTable.prototype = {
style_class : "quotes-label"
});
},
createQuoteNameLabel : function (quote, addLink) {
determineQuoteName : function (quote, useLongName) {
if (useLongName && this.existsProperty(quote, "longName")) {
return quote.longName;
} else if (this.existsProperty(quote, "shortName")) {
return quote.shortName;
}

return ABSENT;
},
createQuoteNameLabel : function (quote, useLongName, addLink) {
const nameLabel = new St.Label({
text : this.existsProperty(quote, "shortName") ? quote.shortName : ABSENT,
text : this.determineQuoteName(quote, useLongName),
style_class : "quotes-label",
reactive : addLink ? true : false
});
if (addLink) {
const nameButton = new St.Button();
nameButton.add_actor(nameLabel);
nameButton.connect("clicked", Lang.bind(this, function() {
Gio.app_info_launch_default_for_uri("https://finance.yahoo.com/quote/" + quote.symbol, global.create_app_launch_context());
Gio.app_info_launch_default_for_uri(YF_PAGE + quote.symbol, global.create_app_launch_context());
}));
return nameButton;
} else {
Expand Down Expand Up @@ -207,10 +228,19 @@ QuotesTable.prototype = {
binIcon.set_child(image);
return binIcon;
},
createPercentChangeLabel : function (quote) {
createPercentChangeLabel : function (quote, useTrendColors) {
let trendClassSuffix = "";
if (useTrendColors && this.existsProperty(quote, "regularMarketChangePercent")) {
const percentageChange = parseFloat(quote.regularMarketChangePercent);
if (percentageChange > 0) {
trendClassSuffix = "-up";
} else if (percentageChange < 0) {
trendClassSuffix = "-down";
}
}
return new St.Label({
text : this.existsProperty(quote, "regularMarketChangePercent") ? (this.roundAmount(quote.regularMarketChangePercent, 2) + "%") : ABSENT,
style_class : "quotes-label"
style_class : "quotes-label" + trendClassSuffix
});
},
roundAmount : function (amount, maxDecimals) {
Expand Down Expand Up @@ -291,10 +321,14 @@ StockQuoteDesklet.prototype = {
this.onSettingsChanged, null);
this.settings.bindProperty(Settings.BindingDirection.IN, "showQuoteName", "showQuoteName",
this.onSettingsChanged, null);
this.settings.bindProperty(Settings.BindingDirection.IN, "useLongQuoteName", "useLongQuoteName",
this.onSettingsChanged, null);
this.settings.bindProperty(Settings.BindingDirection.IN, "linkQuoteName", "linkQuoteName",
this.onSettingsChanged, null);
this.settings.bindProperty(Settings.BindingDirection.IN, "showQuoteSymbol", "showQuoteSymbol",
this.onSettingsChanged, null);
this.settings.bindProperty(Settings.BindingDirection.IN, "linkQuoteSymbol", "linkQuoteSymbol",
this.onSettingsChanged, null);
this.settings.bindProperty(Settings.BindingDirection.IN, "showMarketPrice", "showMarketPrice",
this.onSettingsChanged, null);
this.settings.bindProperty(Settings.BindingDirection.IN, "showCurrencyCode", "showCurrencyCode",
Expand All @@ -303,19 +337,24 @@ StockQuoteDesklet.prototype = {
this.onSettingsChanged, null);
this.settings.bindProperty(Settings.BindingDirection.IN, "showPercentChange", "showPercentChange",
this.onSettingsChanged, null);
this.settings.bindProperty(Settings.BindingDirection.IN, "colorPercentChange", "colorPercentChange",
this.onSettingsChanged, null);
this.settings.bindProperty(Settings.BindingDirection.IN, "showTradeTime", "showTradeTime",
this.onSettingsChanged, null);
},
getQuoteDisplaySettings : function () {
return {
"changeIcon" : this.showChangeIcon,
"quoteName" : this.showQuoteName,
"useLongName" : this.useLongQuoteName,
"linkQuote" : this.linkQuoteName,
"quoteSymbol" : this.showQuoteSymbol,
"linkSymbol" : this.linkQuoteSymbol,
"marketPrice" : this.showMarketPrice,
"currencySymbol" : this.showCurrencyCode,
"absoluteChange": this.showAbsoluteChange,
"percentChange" : this.showPercentChange,
"colorPercentChange" : this.colorPercentChange,
"tradeTime" : this.showTradeTime,
"decimalPlaces" : this.roundNumbers ? this.decimalPlaces : -1
};
Expand Down
2 changes: 1 addition & 1 deletion files/yfquotes@thegli/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"name": "Yahoo Finance Quotes",
"prevent-decorations": true,
"max-instances": "10",
"version": "0.4.2",
"version": "0.5.0",
"uuid": "yfquotes@thegli"
}
32 changes: 28 additions & 4 deletions files/yfquotes@thegli/po/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2020-07-17 18:00+0200\n"
"PO-Revision-Date: 2020-09-20 14:00+0200\n"
"PO-Revision-Date: 2020-10-04 18:45+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -168,7 +168,7 @@ msgid "Quote details"
msgstr "Finanzinstrument Details"

#. settings-schema.json->showChangeIcon->description
msgid "Show change icon"
msgid "Show change/trend icon"
msgstr "Änderungssymbol anzeigen"

#. settings-schema.json->showChangeIcon->tooltip
Expand All @@ -183,13 +183,21 @@ msgstr "Name anzeigen"
msgid "Display the quote name (eg. International Business Machines)."
msgstr "Zeigt den Namen des Instruments an (z.B. International Business Machines)."

#. settings-schema.json->useLongQuoteName->description
msgid "Use long version for verbose name"
msgstr "Verwende die längere Version des Namens"

#. settings-schema.json->useLongQuoteName->tooltip
msgid "Use the long version for quote name, if available (eg. International Business Machines Corporation)."
msgstr "Verwende die längere Version des Namens, falls vorhanden (z.B. International Business Machines Corporation)."

#. settings-schema.json->linkQuoteName->description
msgid "Add web link to name"
msgstr "Name mit Web Link hinterlegen"

#. settings-schema.json->linkQuoteName->tooltip
msgid "Click to open quote in browser."
msgstr "Anklicken, um das Instrument im Browser zu öffnen."
msgid "Click name to open quote in browser."
msgstr "Name anklicken, um das Instrument im Browser zu öffnen."

#. settings-schema.json->showQuoteSymbol->description
msgid "Show ticker/symbol"
Expand All @@ -199,6 +207,14 @@ msgstr "Symbol anzeigen"
msgid "Display the quote symbol (eg. IBM)."
msgstr "Zeigt das Symbol des Instruments an (z.B. IBM)."

#. settings-schema.json->linkQuoteSymbol->description
msgid "Add web link to ticker/symbol"
msgstr "Symbol mit Web Link hinterlegen"

#. settings-schema.json->linkQuoteSymbol->tooltip
msgid "Click symbol to open quote in browser."
msgstr "Symbol anklicken, um das Instrument im Browser zu öffnen."

#. settings-schema.json->showMarketPrice->description
msgid "Show price"
msgstr "Marktpreis anzeigen"
Expand Down Expand Up @@ -231,6 +247,14 @@ msgstr "Prozentuale Veränderung anzeigen"
msgid "Display the percent change of the market price (eg. +0.53%)."
msgstr "Zeigt die relative Veränderung des Marktpreises an (z.B. +0.53%)."

#. settings-schema.json->colorPercentChange->description
msgid "Use trend colors for percent change"
msgstr "Verwende Trend-Farben bei prozentualer Veränderung"

#. settings-schema.json->colorPercentChange->tooltip
msgid "Color the percent change to show the trend (green for up, red for down)."
msgstr "Färbt die prozentuale Veränderung gemäss Trend (grün für höher, rot für tiefer)."

#. settings-schema.json->showTradeTime->description
msgid "Show trading time"
msgstr "Handelszeitpunkt anzeigen"
Expand Down
28 changes: 26 additions & 2 deletions files/yfquotes@thegli/po/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2020-07-17 18:00+0200\n"
"PO-Revision-Date: 2020-09-20 14:00+0200\n"
"PO-Revision-Date: 2020-10-04 18:45+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -181,12 +181,20 @@ msgstr ""
msgid "Display the quote name (eg. International Business Machines)."
msgstr ""

#. settings-schema.json->useLongQuoteName->description
msgid "Use long version for verbose name"
msgstr ""

#. settings-schema.json->useLongQuoteName->tooltip
msgid "Use the long version for quote name, if available (eg. International Business Machines Corporation)."
msgstr ""

#. settings-schema.json->linkQuoteName->description
msgid "Add web link to name"
msgstr ""

#. settings-schema.json->linkQuoteName->tooltip
msgid "Click to open quote in browser."
msgid "Click name to open quote in browser."
msgstr ""

#. settings-schema.json->showQuoteSymbol->description
Expand All @@ -197,6 +205,14 @@ msgstr ""
msgid "Display the quote symbol (eg. IBM)."
msgstr ""

#. settings-schema.json->linkQuoteSymbol->description
msgid "Add web link to ticker/symbol"
msgstr ""

#. settings-schema.json->linkQuoteSymbol->tooltip
msgid "Click symbol to open quote in browser."
msgstr ""

#. settings-schema.json->showMarketPrice->description
msgid "Show price"
msgstr ""
Expand Down Expand Up @@ -229,6 +245,14 @@ msgstr ""
msgid "Display the percent change of the market price (eg. +0.53%)."
msgstr ""

#. settings-schema.json->colorPercentChange->description
msgid "Use trend colors for percent change"
msgstr ""

#. settings-schema.json->colorPercentChange->tooltip
msgid "Color the percent change to show the trend (green for up, red for down)."
msgstr ""

#. settings-schema.json->showTradeTime->description
msgid "Show trading time"
msgstr ""
Expand Down
27 changes: 24 additions & 3 deletions files/yfquotes@thegli/settings-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"width": {
"type": "spinbutton",
"default": 480,
"default": 560,
"min": 40,
"max": 4000,
"step": 20,
Expand Down Expand Up @@ -102,7 +102,7 @@
"showChangeIcon": {
"type": "checkbox",
"default": true,
"description": "Show change icon",
"description": "Show change/trend icon",
"tooltip": "Indicates whether the market price moved up, down, or is unchanged."
},
"showQuoteName": {
Expand All @@ -111,11 +111,18 @@
"description": "Show verbose name",
"tooltip": "Display the quote name (eg. International Business Machines)."
},
"useLongQuoteName": {
"type": "checkbox",
"default": true,
"description": "Use long version for verbose name",
"tooltip": "Use the long version for quote name, if available (eg. International Business Machines Corporation).",
"dependency": "showQuoteName"
},
"linkQuoteName": {
"type": "checkbox",
"default": true,
"description": "Add web link to name",
"tooltip": "Click to open quote in browser.",
"tooltip": "Click name to open quote in browser.",
"dependency": "showQuoteName"
},
"showQuoteSymbol": {
Expand All @@ -124,6 +131,13 @@
"description": "Show ticker/symbol",
"tooltip": "Display the quote symbol (eg. IBM)."
},
"linkQuoteSymbol": {
"type": "checkbox",
"default": true,
"description": "Add web link to ticker/symbol",
"tooltip": "Click symbol to open quote in browser.",
"dependency": "showQuoteSymbol"
},
"showMarketPrice": {
"type": "checkbox",
"default": true,
Expand All @@ -149,6 +163,13 @@
"description": "Show percent change",
"tooltip": "Display the percent change of the market price (eg. +0.53%)."
},
"colorPercentChange": {
"type": "checkbox",
"default": true,
"description": "Use trend colors for percent change",
"tooltip": "Color the percent change to show the trend (green for up, red for down).",
"dependency": "showPercentChange"
},
"showTradeTime": {
"type": "checkbox",
"default": true,
Expand Down
10 changes: 10 additions & 0 deletions files/yfquotes@thegli/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
text-align: center;
}

.quotes-label-up {
text-align: center;
color: #00cc55;
}

.quotes-label-down {
text-align: center;
color: #cc0000;
}

.error-label {
text-align: left;
color: #cc0000;
Expand Down
Binary file modified screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f88b81b

Please sign in to comment.