Visual Relations using Winium automating a WPF app - wpf

Using other automation tools for Windows Apps, such as LeanFT, there is a way to specify a visual relation. For example, if I identified a label, I could then say look for the text box to the right of it.
Is there a way to do this in Winium?
Here is a sample of what the code looks like in LeanFT
var projectButton = baseOR.PlatformWindow.ProjectList.BrowseProjects.Describe<IButton>(new ButtonDescription
{
FullType = "button",
Text = node,
Index = 0
});
return baseOR.PlatformWindow.ProjectList.BrowseProjects.Describe<IButton>(new ButtonDescription
{
FullType = "button",
Vri =
{
new VisualRelation
{
TestObject = projectButton,
HorizontalRelation = HorizontalVisualRelation.LeftAndInline,
}
}
});
As you can see, we are essentially identifying one element, and then using that as the TestObject in the VisualRelation to identify something else.

Related

Command handling in Qooxdoo multi window application

I want to create a Qooxdoo application that consists of a Desktop with multiple Windows. The Desktop (and not each Window) also has a (common) ToolBar.
Now I want to have a command to "save" the document of the active window. This command can be triggered by the keyboard shortcut "Ctrl+S" as well as a button on the toolbar.
To handle the "Ctrl+S" to reach the currently active window the qx.ui.command.GroupManager (as described by https://qooxdoo.org/documentation/v7.5/#/desktop/gui/interaction?id=working-with-commands and https://qooxdoo.org/qxl.demobrowser/#ui~CommandGroupManager.html) is supposed to be the best solution. And I could easily implement that in my code.
But now I'm struggling to make the toolbar save button also call the save command of the currently active window as I don't know how to bind it correctly to the GroupManager.
An example code to get started in the playground https://qooxdoo.org/qxl.playground/:
// NOTE: run this script only once. Before running it again you need to reload
// the page as it seems that the commands are accumulation and not reset.
// I guess that this is a bug in the Playground
const root = this.getRoot();
qx.Class.define('test.Application',
{
extend : qx.application.Standalone,
members: {
main: function() {
const layout = new qx.ui.layout.VBox(5);
const container = new qx.ui.container.Composite(layout);
root.add(container, {edge: 0});
const windowManager = new qx.ui.window.Manager();
const desktop = new qx.ui.window.Desktop(windowManager);
this._manager = new qx.ui.command.GroupManager();
const menuBar = new qx.ui.menubar.MenuBar();
let menu = new qx.ui.menu.Menu();
///////////////////////////
// TODO: Call _doSave() of the active window!
let saveMenuButton = new qx.ui.menu.Button('Save','#MaterialIcons/save/16');
///////////////////////////
menu.add(saveMenuButton);
var fileMenu = new qx.ui.menubar.Button('File', null, menu);
menuBar.add(fileMenu);
const toolBar = new qx.ui.toolbar.ToolBar();
///////////////////////////
// TODO: Call _doSave() of the active window!
let saveToolBarButton = new qx.ui.toolbar.Button('Save','#MaterialIcons/save/16');
///////////////////////////
toolBar.add(saveToolBarButton);
container.add(menuBar,{flex:0});
container.add(toolBar,{flex:0});
container.add(desktop,{flex:1});
this._foo1 = new test.Window('foo1', this);
desktop.add(this._foo1);
this._foo1.open();
this._foo1.moveTo(100,20);
this._foo2 = new test.Window('foo2', this);
desktop.add(this._foo2);
this._foo2.open();
this._foo2.moveTo(200,100);
this._foo3 = new test.Window('foo3', this);
desktop.add(this._foo3);
this._foo3.open();
this._foo3.moveTo(300,180);
},
getGroupManager() {
return this._manager;
}
}
});
qx.Class.define('test.Window', {
extend: qx.ui.window.Window,
construct(windowName, controller) {
this.base(arguments, windowName);
this._name = windowName;
let commandGroup = new qx.ui.command.Group();
const cmd = new qx.ui.command.Command("Ctrl+S");
cmd.addListener('execute', this._doSave, this);
commandGroup.add('save', cmd);
controller.getGroupManager().add(commandGroup);
this.addListener('changeActive', () => {
if (this.isActive()) {
controller.getGroupManager().setActive(commandGroup);
}
}, this);
},
members: {
_doSave() {
alert("save " + this._name);
}
}
});
a = new test.Application();
How should the saveMenuButton.setCommand() and saveToolBarButton.setCommand() should look like to always call the command of the active window?
You can control a current active window via Desktop class:
let saveToolBarButton = new qx.ui.toolbar.Button('Save');
saveToolBarButton.addListener("click", function(){
desktop.getActiveWindow()._doSave();
}, this);
Would be great for your solution imo is to create a separate command and add this command to buttons:
const saveActiveWindowCommand = new qx.ui.command.Command();
saveActiveWindowCommand.addListener("execute", function(){
desktop.getActiveWindow()._doSave();
}, this);
let saveMenuButton = new qx.ui.menu.Button('Save');
saveMenuButton.setCommand(saveActiveWindowCommand);
let saveToolBarButton = new qx.ui.toolbar.Button('Save');
saveToolBarButton.setCommand(saveActiveWindowCommand);
EDIT:
You could set commands dynamically for "Main Panel" menu buttons. Because there is only one instance of command pressing "Ctrl+S" will trigger only one command but maybe you would like that main bar save buttons have extra logic.
You have in application class next method which will be called from window class when changeActive event happens.
setSaveCommand(command){
this.saveMenuButton.setCommand(command);
this.saveToolBarButton.setCommand(command);
},
and in your Window class:
if (this.isActive()) {
controller.setSaveCommand(cmd);
controller.getGroupManager().setActive(commandGroup);
}

Implement custom editor for Quill blot

I'm trying to customize the Quill editor for my needs. I managed to implement and insert custom blots, as described in https://quilljs.com/guides/cloning-medium-with-parchment/ But I need to edit data, which is attached to my blots, like the URL of a link for example. The default implementation of Quill displays a small "inline" edit box for links. I want to implement something like that myself, but just don't get it. I did not find any hints in the docs and guides. Reading the source code of Quill, I was not able to figure out where the editing dialog for links is implemented. Any starting point would be very appreciated.
I've tried something similar. Proper way of doing it should be creating a module. Unfortunately as you already know it is not as easy as it seems.
Let me point you to some useful resources that helped me a lot with understanding how to create extensions for quill.
Quills maintainer is curating Awesome quill list.
I recommend looking especially into
quill-emoji it contains code to display tooltip emoji while writing
quill-form maybe some form extension has some code that will point you in the right direction
Here is my try on to it using custom quill module.
const InlineBlot = Quill.import('blots/inline');
class NamedLinkBlot extends InlineBlot {
static create(value) {
const node = super.create(value);
node.setAttribute('href', value);
node.setAttribute('target', '_blank');
return node;
}
}
NamedLinkBlot.blotName = 'namedlink';
NamedLinkBlot.tagName = 'A';
Quill.register('formats/namedlink', NamedLinkBlot);
const Tooltip = Quill.import('ui/tooltip');
class NamedLinkTooltip extends Tooltip {
show() {
super.show();
this.root.classList.add('ql-editing');
}
}
NamedLinkTooltip.TEMPLATE = [
'<a class="ql-preview" target="_blank" href="about:blank"></a>',
'<input type="text" data-link="https://quilljs.com">',
'Url displayed',
'<input type="text" data-name="Link name">',
'<a class="ql-action"></a>',
'<a class="ql-remove"></a>',
].join('');
const QuillModule = Quill.import('core/module');
class NamedLinkModule extends QuillModule {
constructor(quill, options) {
super(quill, options);
this.tooltip = new NamedLinkTooltip(this.quill, options.bounds);
this.quill.getModule('toolbar').addHandler('namedlink', this.namedLinkHandler.bind(this));
}
namedLinkHandler(value) {
if (value) {
var range = this.quill.getSelection();
if (range == null || range.length === 0) return;
var preview = this.quill.getText(range);
this.tooltip.show();
}
}
}
Quill.register('modules/namedlink', NamedLinkModule);
const quill = new Quill('#editor', {
theme: 'snow',
modules: {
namedlink: {},
toolbar: {
container: [
'bold',
'link',
'namedlink'
]
}
}
});
CodePen Demo
To see the tooltip:
Select any word
Click invisible button on the right of link button, your cursor will turn to hand.
Main issues that need to be addressed:
in order to customize the tooltip you will need to copy majority of the code from SnowTooltip Main pain point is that you cannot easily extend That tooltip.
you need to also adapt the code of event listeners but it should be straightforward
Here's a partial answer. Please see lines 41-64 in file "https://github.com/quilljs/quill/blob/08107187eb039eababf925c8216ee2b7d5166d41/themes/snow.js" (Please note, that the authors have since moved to TypeScript, lines 45-70?, and possibly made other changes.)
I haven't tried implementing something similar but it looks like Quill is watching a "selection-change" event and checks if the selection is on a LinkBlot with a defined link.
The SnowTooltip class includes references to the selectors, 'a.ql-preview', 'ql-editing', 'a.ql-action', and 'a.ql-remove', which we find in the link-editing tooltip.
this.quill.on(
Emitter.events.SELECTION_CHANGE,
(range, oldRange, source) => {
if (range == null) return;
if (range.length === 0 && source === Emitter.sources.USER) {
const [link, offset] = this.quill.scroll.descendant(
LinkBlot,
range.index,
);
if (link != null) {
this.linkRange = new Range(range.index - offset, link.length());
const preview = LinkBlot.formats(link.domNode);
this.preview.textContent = preview;
this.preview.setAttribute('href', preview);
this.show();
this.position(this.quill.getBounds(this.linkRange));
return;
}
} else {
delete this.linkRange;
}
this.hide();
},
);

How to render ChartJs with Kotlin React Frontend

I am experimenting with a simple project based with Kotlin and React and I have some data I would like to visualise with ChartJs.
But I am not sure how exactly to 'connect the dots'.
I am randomly generating some data in background about some dummy 'customers'. It is a continuous stream of data (technically it goes on forever if I don't stop it) and it looks like this:
data:{"name":"John","age": 22,"money":1088.434131568658585820230655372142791748046875}
data:{"name":"Patric","age": 32,"money":9803.739582599226196180097758769989013671875}
data:{"name":"Sven","age": 13,"money":6654.2184028105320976465009152889251708984375}
data:{"name":"Trevor","age": 29,"money":1818.314185601747112741577439010143280029296875}
data:{"name":"John","age": 30,"money":427.240483111973617269541136920452117919921875}
data:{"name":"Mark","age": 15,"money":3065.9830877835693172528408467769622802734375}
data:{"name":"Daniel","age": 18,"money":5860.1371074951812261133454740047454833984375}
data:{"name":"Chris","age": 28,"money":7547.2329861790212817140854895114898681640625}
Here is my Model:
data class CustomerData(var name: String, var age: Int, var money: Int)
and my Chart Component:
interface CustomerChartProps : RProps {
var customerDataList: List<CustomerData>
}
interface CustomerChartState : RState {
var customerDataList: List<CustomerData>
}
class CustomerChart : RComponent<CustomerChartProps, CustomerChartState>() {
override fun CustomerChartState.init(props: CustomerChartProps) {
customerDataList = props.customerDataList
}
override fun RBuilder.render() {
canvas() {
attrs.id = "myChart"
attrs.height = "600"
attrs.width = "600"
key = "chart"
div {
props.customerDataList
}
}
var chart = document.getElementById("myChart")
}
}
fun dummyChartData(data: List<CustomerData>) =
listOf(CustomerData("John", 30, 9999))
fun RBuilder.customerChart(customerDataList: List<CustomerData>) = child(CustomerChart::class) {
attrs.customerDataList = customerDataList
}
What is not clear is how do I tell the RState that my data is constantly changing. I want to be able to update the chart dynamically, while I get new data from my dummy backend. I am not persisting the data in anyway.
What are your suggestions or recommendations?
I cannot seem to find a suitable example/tutorial/documentation either.
I know my question is pretty vague, but I hope at least I am the right direction, or that someone can point out how to get there.

How do I programmatically create a GUI and create it for my windows form?

As above, how do I create buttons or labels programmatically instead of using the drag and drop function?
The following sample is a code for creating a panel.
public Panel createPanel()
{
Panel p = new Panel
{
BorderStyle = BorderStyle.FixedSingle,
Size = new Size(506, 110),
Name = "Panel"
};
Button button = new Button
{
Text = "Clear",
Name = "Button",
Location = new Point(410, 40)
};
p.Controls.Add(button);
return p;
}
Go to YourForm.Designer.cs and see how it's done.
Remember that they're just object members.

Problem with WPF perfomance

I have form which has many tabs. Every tab has many controls textboxes, comboboxes, datagrids and e .t.c. I bind form to one data source in such way
this.DataContext=MyClassInstance
But with this way my form opening very slow. about one minute.
When I comment above code, form opens very quickly. All My controls I bound to the class properties in XAML. Please tell me the way to bind every tab when it's activated, or bind controls in background thread or any other idea which can help me to speed up my form.
Thanks in advance.
I think the problem lies in your class instance you are binding to.
When the xaml is bound to the class, all the getters of the bound properties are fired. If each getter accesses the database to get some data, this can take a while.
I think you should really review your design here, and think about asynchronously fetching your data.
I agree with Gerrie.
I'm suggesting the following:
When you start your application, you automatically open one tab i guess. Load only that tab, don't care about the others. This should start your project much faster.
The thing you do for the other tabs is load them when clicked for the first time. When the user for example is interested in tab 5, the only ones loading will be the initial tab at startup, and tab 5 when clicked by the user. all other tabs will not be loaded, which will decrease startup time.
Hope the idea is clear to you and will help your application.
I found why my form open so slow. I use about 20 XMLDataProvider object in form. and this providers were iteract with xml file. When I comment code below everything working fast. Thank everyone for help
//relatives_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_RelativeList" };
//education_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_EducationList" };
//requalification_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_RequalificationList" };
//jobHistory_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_JobHistoryList" };
//rank_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_RankList" };
//tradeUnion_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_TradeUnionList" };
//election_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_ElectionList" };
//judgeHistory_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_JudgeHistoryList" };
//tempWork_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_TempWorkList" };
//inquire_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_InquireList" };
//bulleten_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_BulletenList" };
//reprimand_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_ReprimandList" };
//certificate_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_CertificateList" };
//course_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_CourceList" };
//incentive_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_IncentiveList" };
//btrip_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_BtripList" };
//vacation_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_VacationList" };
//pass_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_PassList" };
//language_xdp = new XmlDataProvider() { Source = uri, XPath = "Config/ColumnsVisibility/Person_LanguageList" };

Resources