-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Larch controller independent of Wx GUI + _data in _larch.symtable #411
Comments
Hmm, that is an interesting idea. I'm not opposed, but I have some questions about what LarchController should do.... like, what are its methods? Some of the design of larch.wxxas.xas_controller.XASController is sort of accidental. It does a few things: Not much of it is really wx specific. So, making a generic controller could be possible. It's even reasonable to say that it should do more that is currently scattered throughout XAS_Viewer. For example, "LarchController" could have methods for most of the XAFS processing methods so that one did Is that what you would be looking for? |
I do not have a clear design in mind yet, but I would keep a sort of MVC pattern. As a first step,
I would keep the Larch functions as they are. Would also be fine for you if we store all groups and parameters in a dedicated group of the symbol table called If you are not opposed to this idea, I could start coding something and propose it via a pull request. |
@maurov OK. For "MVC", I understand what "V" is, but am never sure of the difference between "M" and "C" unless "M" is "connection to a database server". For sure, "real functionality" and "GUI code" should be separate, well separate-ish. Or, some things a GUI "does" can be made into functions that can be called in other ways. But in analogy with a database server, "Larch Session (data + functions)" could be "M", and then "C" is pretty close to trivial.
Maybe.... I'm not sure what that solves. |
@newville I wanted to implement a simple feature request from a user (related to the Wx GUI) and I realize that I still do not fully understand how the controller manages things between the Larch interpreter and the Wx GUI.
Yes, to me this is exactly the role of a controller object and I would like to better understand the details. Please, could you comment/reply to the following points, related mainly to "a" and "b" points of your previous reply?
|
@maurov Well, I should restate my view that MVC is one approach to UI. The separation between the 3 objects is often not completely clean. For sure, it is good to keep "real code" out of a GUI. Having the GUI react to input and generate (without loss of generality) some sort of dictionary or another simple mapping of "GUI Component" to "Value" is good. That is, "View" is usually clear.
Well, But Python is not strictly OO, so the GUI code might be able to access the Larch interpreter or its symbol table directly. Does doing that violate "MVC"? Maybe. If so, strict MVC becomes an anti-goal.
I would probably say that the Larch session is the Model. But, all the data and code are in the symbol table.
The
Good point, I agree that "install_group" could be moved to the controller. I'll do that. I'm still in the process of re-doing data importing and working on the Energy Calibration dialog, so this is a fine time to do that.
Yes, that is just
The "LarchWxShell" is a subclass of Larch Interpreter that is the viewable / interactable "Larch Buffer". That is some very old GUI interface and probably needs some attention. Having that use the Jupyter tooling would be interesting and worth investigating. I think that XAS Viewer / Larix will keep some interpreter as the base Model - the model of "GUI generates code that can be run separately or turned into a script" is a feature we want to keep. It could happen that "Larch interpreter" gets replaced by "asteval Interpreter" (especially if Jupyter tooling is used), but that would actually be some work, as the Larch symbol table is sort of hierarchical whereas the asteval one is a flat dict. I am totally willing to say "flat is better", but that would mean touching a lot of Larch code. But, that might be "Larch 1.0" ;). |
@newville thank you very much indeed for the detailed reply. I think I better understand now your design choices. I do not care to strictly follow the MCV paradigm, it was for me just following a scheme to understand the design. No problem with leaving it as it is now. It would be great if you could move I fully agree on the other points. |
@newville thanks for implementing g = Group(groupname="my_new_group_id_abc123", filename="My fancy new group this and that", energy=xarray, mu=yarray, i0=numpy_ones_like(xarray), datatype='xas')
controller.add_group(g) by the way, is |
I will freely admit that the xasgui.install_group does accept either a Group or the name of a group in the Larch symbol table. xas_controller.install_group expects the name of a Group in the Larch symbol table, and doesn't check for whether the first argument is a group or the name of a group.
But we could more completely make "XASController.install_group" and "XASFrame.install_group" be the same -- it was sort of ambiguous how to handle what the dialogs do to create new groups, and especially whether to process and plot the data on installation of a group. Or we could add a separate "add_group()" method that requires the first argument to be a Group that is not already in the Larch symbol table. The downside there is that it probably will not be well documented where that group came from.
No, or it should not be. If the datatype is |
Unfortunately this does not work for me
It think it would be very beneficial to have
Ok, thus this means that when |
Hm, that should work I think.
How should
I don't think so, or at least that is not the intention. I added 'i0' recently mostly so it could be consistently / easily plotted with "mu". None of the downstream processing will really use this. |
Yes, I also do not understand why is not working. Here a specific example of what I am trying to do (not working yet!): master...maurov:xraylarch:add_export_group_from_lcf
Well, to me
I am sorry to come back to the MVC story, but I am not very familiar with GUI development and I find easier reasoning in a MVC way.
I think there are some places in the code where "datatype = 'xas' requires i0 attribute". It is good to know this is not the intention and I will fix it if I will come across it. |
What is the error message ? Like, what line is failing? One thing that can be very useful for debugging here is to look at that command that got executed in the Larch buffer. There, you can check for errors running that command and really see what the outputs are (including, say the group name).
If they do the same thing, why do we need both methods?
Hm, where is that? I would say it is better to have 'i0', but should not be required. |
Looking at the Larch buffer permitted understanding what was the problem, thanks for the help!
Because to add a new group one needs to perform more than simply a call to controller = self.parent.controller
label = f"lcf_fit_{nfit}"
groupname = new_group = f"{dgroup.groupname}_{label}"
filename = f"{dgroup.filename}_{label}"
cmdstr = f"""{new_group} = group(name="{groupname}", groupname="{groupname}", filename="{filename}")"""
controller.larch.eval(cmdstr)
g = controller.symtable.get_group(new_group)
g.energy = g.xdat = xarr
g.mu = g.ydat = g.norm = yfit
g.i0 = i0
g.datatype = 'xas'
controller.install_group(groupname, filename, source="exported from Linear Combo / Fit Results") to me it would be much easier to handle all this behind the scene and simply doing g = Group(...)
controller.install_group(g, source="created from something")
I may be probably wrong. If I find it, I will open a separate issue. |
@newville
In view of having Larch more independent from the Wx GUI, and have the possibility to build more Jupyter friendly examples (or applications) I would propose the following actions:
larch.controller
larch.wxxas.xas_controller.XASController
tolarch.controller.LarchController
XASController
will inherit fromLarchController
_larch.symtable
as model forLarchController
_larch.symtable._data
as the main data container for all data groups created during a sessionLarchController
all the logic for handling data exchange from the model to the view (= GUI)Does this sounds good to you?
The text was updated successfully, but these errors were encountered: