Django Show models.Model field only when a checkbox is checked - django-models

I want to add a custom in django, (i am using forms from models.Model to create it, already big parts of the code are made), that only pops up when a user selects a particular checkbox. For example a simple code like : Choose what area u want to calculate? Triangle, Rectangle etc. and whenever user Clicks on that particular checkbox (maybe a widget that is working onclick? i dont know how to set it up properly), under it will render options to add angles appear and sides :
first render:
Choose what area u want to calculate
Triangle (unchecked)
Rectangle (unchecked)
Square (unchecked)
etc.
we choose triangle and rectangle:
Triangle (checked):
a =
b =
c =
alpha =
beta =
gamma =
Rectangle (unchecked):
Square (checked):
anybody has any ideas what can I try to use to make it done?
Tried using some widgets, but could not set it up properly. Right now i just have different tabs to calculate some things that i want.

Related

Openlayers React rotate polygon feature

I have a simple react/openlayers here(https://jsfiddle.net/mcneela86/Lx44yc3m/) that I have setup to demonstrate my problem.
I have a simple map which is currently working.
A tool that allows a user to draw a polygon which is currently working.
A tool that allows the user to move the polygon which is currently working.
A tool that allows the user to rotate the polygon, which is not currently working - this is where I need the help and have included the other tools incase they help anyone see how my app is working.
In my sample app if you draw a polygon, select the rotate tool and click on the polygon that you have drawn it will rotate the polygon by 20 degrees - so I know there is a rotate function. I want the user to click and drag or click and display a handle to drag to give them good control over the rotation.
feature.element.getGeometry().rotate(0.349066, c); is currently doing the rotation.
So what I don't know is how do I take the users input, lets say mousedown, detect that they are moving the mouse and use the values in the rotate() function to change the rotation of the polygon?
Any help would be greatly appreciated.
EDIT:
Here is an example of what I mean about the bounding box/handles on the polygon:
The ol-ext project provides a set of cool extensions including an interaction to move/rotate objects.
Have a look at the example: http://viglino.github.io/ol-ext/examples/interaction/map.interaction.transform.html
#+
to display an handle when hovering, detect it with a pointer event:
map.on('pointermove', (evt) => {
if (evt.dragging) {
return;
}
const pixel = this.map.getEventPixel(evt.originalEvent);
const feature = this.map.forEachFeatureAtPixel(
pixel,
someFeature => someFeature, // return first element
{ hitTolerance: 2 }
);
// control an css class somehwere or use style.
map.getTarget().style.cursor = feature ? 'pointer' : '';
});
for the real-live rotation:
user holds the mouse down, triggering mousedown
store the startPosition of the cursor and toggle a "isRotating" flag
in the pointermove event (see above), (if isRotating) use the position to calculate the relative change to the startPosition to update the rotation
(probably optional) when mouseup is triggered, apply the final rotation and toggle the isRotating flag back

Automatically resize form and move controls when new ones are added or a text in a label grows

Beginner in Visual Studio here.
I'm trying to create an C# Windows Form application that simply displays a form to show some information about the local system.
I have created this form with the help of the VS designer:
As you can see, it consists of a simple panel with a PictureBox at the top, a label below it (both centered), three table layouts next to each other, and a button at the bottom. Never mind the label texts.
The rows of all the table layouts are set to absolute, this is because I want to programatically add rows to the end middle and right table layout if there are more than one local IP address in the computer and setting the rows to auto size or percentage would make alignment difficult if more rows are added.
Now, my problem is that I can't figure out how to make the form resize and move the controls (specifically move the 'OK' button down) when more rows are added.
I have tried anchoring the button to the bottom edge of the form as well as the bottom of the middle table, both produce the same result: the button stays where it is and the new rows overlap it, like this
I would also like to know how to have the form resize to fit the contents of the labels. For example, if the text in one of the labels inside the layout is bigger than the column width, I'd like to have the form grow to accommodate it. Likewise, I'd like the form to shrink to fit the largest text.
I realize that this may not be the most efficient or easiest way to create this particular form, but it is what I've come up with, I of course welcome any suggestions in that regard. It is important to maintain alignment between the rows of all table layouts.
Thanks in advance.
Use a data grid and add controls to it if an add button is pressed. You can scroll through the rows so you won't need to adjust the height of the form

How could I interactively create an invoice and preview it on WPF?

I'm creating a trial project wherein my window has two grids, left grid is sort of a table that has labels and textboxes each row and asks for a specific part of the invoice like item, name, address stuff like that and the right grid is to show a preview of the invoice that the left side is creating.
I thought about using a document viewer on the right side but I thought that anything I open there would be static and if I put values on the textboxes on the left grid, it wouldn't matter since I opened a standalone document to view on the right grid.
I thought about just creating a table out of the right grid and have the default values and populate the other ones when a user types something on the textbox and make it function as the preview but then I don't know how would I go about and printing it and also, it has about 45 rows which I couldn't fit in the grid without it being unreadable (because I had to cram 45 rows of data inside that small grid)
So is there a tool in the toolbox that could potentially create a interact-able grid? I tried the grid control but I can't seem to only make it show 4 columns because that's all I need, I don't want it to show E and the rest of the alphabet because I want it to resize accordingly with only 4 columns to make it more readable.
Oh and I also have devexpress installed so you guys could also recommend something I can use from there. Thank You.
I think this is the best solution since it does what I wanted it to do.
I created a scroll view and placed a grid inside it then set the length accordingly to show it in a reasonable size and let the scroll bar do its magic for me to see the rest of the grid without compromises of the content's size.

How to set telerik chart TrackBall position programatically

I have created a custom control which has Telerik RadCartesianChart. This custom control creates any number of charts based on user dropdown selection. The number of charts on screen can vary but all have same x axis. I added a chart track ball line on custom control which is working fine on one chart on mouse movement. I want to add the same track ball line on all of the other chart on window so that movement on one track ball would reflect the same position on the other charts.
How could I implement this behavior programmatically?
I don't know if you can do what you are attempting without adding a ChartTrackBallController to every chart.
What I'd suggest is adding multiple series to the one chart, share the X axis but have multiple Y axes as required. This way the ChartTrackBallController will pick a point on all series in the chart.
// Trackball
ChartTrackballController ctbcMain = new ChartTrackballController();
ctbcMain.TextNeeded += ctbcMain_TextNeeded;
ctbcMain.InnerPointSize = new SizeF(0, 0);
ctbcMain.OuterPointsSize = new SizeF(0, 0);
rcvUPM.Controllers.Add(ctbcMain);
rcvUPM.ShowTrackBall = true;
In the above code snippit, rcvUPM is a radchartview containing all the data series you want to show, and ctbcMain_TextNeeded is used to customise the content of what the hover for the trackball shows.
It seems that by default the hover content will contain multiple points from each series, even after the InnerPointSize and OuterPointsSize was set to zero on advice by Telerik support a LINQ FirstOrDefault was needed on the collection of DataPointInfo objects to limit it to one point per series.

How to show legal moves

I want to make a game where the playing pieces can move around. When I click on a playing piece it shows all available moves were I can go like this:
Red represents legal moves and dark gray represents a wall.
I have created a grid and buttons in it. When I click on a button, I subtract or add the available step count to the button index in the grid. For example if my piece can move 3 places, I subtract 3 from the index of the button and get the available position to the left of the piece. Then I do the same for all other directions. It looks something like this:
For each i as button in grid
Select case grid.indexof(i)
Case grid.getindex(currentPlayingPiece) - 3 'Left
i.background = brushes.red
Case grid.getindex(currentPlayingPiece) + 3 'Right
i.background = brushes.red
Case grid.getindex(currentPlayingPiece) - grid.columndefinitions.count 'Top
i.background = brushes.red
...
Next
Using this method it is very slow and cumbersome to get all available moves and not intuitive to get top and bottom moves. Also if there is a wall in the way and behind there's a available spot it shows that I can move to it. So my question is: is there a better method to accomplish this?
If you prefer not to use an "advanced" algorithm involving graphs or similar solutions, there are a couple of simpler things you might try.
Firstly, creating a variable instead of calling getIndex() a bunch of times might save a few cycles.
Secondly, I would try to use the absolute of each position to evaluate, and so calculate the distance without having to check once for each direction (+ or -); Maybe something like this:
dim currentButtonIndex as Integer = grid.getIndex(currentPlayingPiece)
For each i as button in grid
dim indexToEvaluate as Integer = grid.indexOf(i)
If (Math.Abs(indexToEvaluate - currentButtonIndex) = 3) Then
i.background = brushes.red
End If
Next
You can create a graph from your grid where each cell in your grid will be adjacent to its neighborhood (top-bottom-left-right) then you should specify a value for each vertex (for example 1 if occupied and 0 in not). When the user clicks a particular cell in your grid you find all the possible paths starting from there having a total weight of 0.

Resources