lunduniversity / introprog-scalalib Goto Github PK
View Code? Open in Web Editor NEWScala library with simple-to-use utilites for students of introductory programming. http://cs.lth.se/pgk/api
License: BSD 2-Clause "Simplified" License
Scala library with simple-to-use utilites for students of introductory programming. http://cs.lth.se/pgk/api
License: BSD 2-Clause "Simplified" License
After reading though lunduniversity/introprog#782 I think that some of the issues associated with Bank's saving and loading could be addressed by introducing a method that lets the user easily append to text files (since it might feel natural to do so in doEvent.)
I propose that a method be added for appending lines.
Add more tests here: https://github.com/lunduniversity/introprog-scalalib/tree/master/src/test/scala
The goal is to have at least one test per method for non-gui-related stuff. Currently, only the IO api is non-gui-related, so this issue means adding more tests on IO.
We use munit which wraps JUnit in a nice scala api.
Swing has this cool look-and-feel, esp Dark theme etc.:
https://www.formdev.com/flatlaf/
Investigate how to use this and check that it works on WSL, Windows 10, Windows 11, macos, Ubuntu...
Impacts the Swing.scala file.
The latest Kojo release use it, so in that code-base there should be inspiration to make it platform-independent.
During the SnakeLab there's some confusion regarding how drawBlock() in BlockWindow works.
This is partly due to the fact that if you instantiate a BlockWindow class in REPL (which students repeatedly are told to play around in) and then use the drawBlock() function, nothing happens.
A solution would be to perhaps have a very primitive code that shows the functionality in a working state, where students can play around as REPL doesn't provide that functionality and still not give away too much, so there's still learning potential.
For example the code found here could possibly help; https://github.com/dixine55/BlockWindow-functionality
Another solution would be to inside of the introprog Documentation mention that drawBlock only works inside of a gameLoop, and specify what that is and how to initiate one.
It might be better if we instead used composition for the BlockWindow instance in order to just provide the API and not the rest of the BlockWindow code during the SnakeLab.
This would also follow the "Composition over inheritance"-mentality and make it a bit more straightforward for the people working with the code.
Running the library on WSL currently throws an exception due to wrong look and feel being used (javax.swing.UnsupportedLookAndFeelException
). GTK+ is incorrectly chosen, when it should be the same as for Windows. A check should be added to determine this for WSL.
See also PR #27
y coordinate checks less than width
but should be height
https://github.com/lunduniversity/introprog-scalalib/pull/5/files#diff-f9c222247a5c88c3452c22542c23d92cR204
@jos-rosenqvist-3812 I'll fix this today; will abstract over checks by isInside and requireInside
Instructions can be copied from main readme
exception should happen in calling thread
Sbt idomatic build should include settings inside of lazy val ... (project in file(".")).settings(...
.
Add SemVer into the build to enable check for binary compatibility etc. More info here:
For more info on sbt tricks in the migration guide:
https://docs.scala-lang.org/scala3/guides/migration/compatibility-classpath.html
Key event handling is not cross-platform compatible as noted in lunduniversity/introprog#491. See also #1 which is related.
I have a working fix for above issues tested on macOS and Linux, see comment lunduniversity/introprog#491 (comment). Could use help with testing on Windows.
Another issue persists which is that TAB
key strokes are not recognized by introprog. From what I can gather this seems related to the Focus Subsystem of Swing, where TAB
and Shift-TAB
will cycle the focus forward or backwards. This would need to be disabled for the event handler to recognize the key strokes.
The example where the repl is shown in chapter 7 part 1 subpart 36 needs some fixing
As it is now this is how it looks:
scala> type Pt = (Int, Int)
scala> def distToOrigo(pt: Pt): Int = math.hypot(pt._1, pt._2)
scala> type Pts = Vector[Pt]
scala> def firstPt(pts: Pts): Pt = pts.head
scala> val xs: Pde3,3))
scala> firstPt(xde
res0: Pt = (1,1)de
Last three lines needs some fixing
see e.g. https://stackoverflow.com/a/24982850
@fritjof-b If you like, you are very welcome to add github actions with build badge here. use sbt compile
as we have no tests yet...
This PR #27 includes a hopefully feasible way to detect OS and set the right look and feel so that window stuff does not crash on WSL + GWSL, and we should test that in as many setups as possible including Windows 11.
However, the code could be refactored to be more elegant and easier to read and also more effective:
We should use java's File stuff instead -- it's unnecessarily heavy to fire up a whole new OS process just to check what's in a file. I did not question the tip on how to detect WSL. So before we make an ordinary release to Maven central 1.3.1 we should fix this. And the isInProc is an implementation detail that should not be visible outside, and actually a part of isOS so that method should use a private isInProc. If so, the code would feel more "natural".
I am requesting the setTitle method to be implemented and accessible from introprog.PixelWindow. I noticed that JFrame has a method for renaming the frame title, and I am missing this feature in PixelWindow, it could be useful
in current file dialog there is no file selected, and button says Ok
add some test to check non-gui-stuff, to be executed with sbt testOnly or scala-cli test or something similar
There is no documentation for the method gameLoop(stopWhen: => Boolean): Unit on the api site. This makes the code hard to read for students when they work because the code calls on a method that they don't know what it does.
If we want the ImageProcessing project to use introprog.PixewlWindow this is a must-have.
and when some tests have been added, use sbt test
in github actions CI. depends on #19
Currently info on how to use is lost when moving to scala3doc:
https://cs.lth.se/pgk/api/
See what to migrate from old scaladoc here:
https://github.com/lunduniversity/introprog-scalalib/blob/master/src/rootdoc.txt
It is a hassle to cross-publish and we want to use the new cool stuff in Scala 3...
Delete key is now a special utf charcter displayed as � or \utf(007F). Make lastKey be "Delete"
The documentation in the file introprog.IO
for the parameter fileName
is a bit ambiguous. After trying to use this library myself and after reading in the course forum in the channel frågor-och-svar
, I’ve come to the conclusion that it probably should be renamed to path or add documentation to explain that it’s the path of the file and not just the file name.
In exercise 7 chap 4 we're to look at the source code for TestPixelWindow however there is no link to the source code at https://fileadmin.cs.lth.se/pgk/api/api/introprog/examples/TestPixelWindow$.html
Nor are there links for any other source code. Björn noted that this is likely to be due to the new scaladoc for Scala 3
and thinks a new option is needed, see link: https://docs.scala-lang.org/scala3/guides/scaladoc/settings.html
http://cs.lth.se/pgk/lib is currently old 2.13
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.