update,
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:latest
|
||||
# container_name: db
|
||||
restart: unless-stopped
|
||||
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: root
|
||||
MYSQL_DATABASE: itp4459_asg
|
||||
MYSQL_USER: db_user
|
||||
MYSQL_PASSWORD: db_user_pass
|
||||
ports:
|
||||
- "3306:3306"
|
||||
volumes:
|
||||
- db:/var/lib/mysql
|
||||
|
||||
phpmyadmin:
|
||||
image: phpmyadmin/phpmyadmin
|
||||
# container_name: pma
|
||||
restart: unless-stopped
|
||||
links:
|
||||
- mysql
|
||||
environment:
|
||||
PMA_HOST: mysql
|
||||
PMA_PORT: 3306
|
||||
PMA_ARBITRARY: 1
|
||||
PMA_USER: "root"
|
||||
PMA_PASSWORD: "root"
|
||||
|
||||
ports:
|
||||
- 8081:80
|
||||
|
||||
volumes:
|
||||
db:
|
16
daniel_jo/ITP4459_assignment_2023/src/python/Pipfile
Normal file
16
daniel_jo/ITP4459_assignment_2023/src/python/Pipfile
Normal file
@@ -0,0 +1,16 @@
|
||||
[[source]]
|
||||
url = "https://pypi.org/simple"
|
||||
verify_ssl = true
|
||||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
mysql = "*"
|
||||
mysql-connector-python = "*"
|
||||
mistune = ">=0.7.1"
|
||||
python-docx = ">=0.8.6"
|
||||
sympy = ">=0.7.6.1"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
[requires]
|
||||
python_version = "3.10"
|
214
daniel_jo/ITP4459_assignment_2023/src/python/Pipfile.lock
generated
Normal file
214
daniel_jo/ITP4459_assignment_2023/src/python/Pipfile.lock
generated
Normal file
@@ -0,0 +1,214 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "6fc14ab26679ecb3c73181a5c3e6daa6ec1d2ff80343097b892a649cd17e0574"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_version": "3.10"
|
||||
},
|
||||
"sources": [
|
||||
{
|
||||
"name": "pypi",
|
||||
"url": "https://pypi.org/simple",
|
||||
"verify_ssl": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"default": {
|
||||
"lxml": {
|
||||
"hashes": [
|
||||
"sha256:01d36c05f4afb8f7c20fd9ed5badca32a2029b93b1750f571ccc0b142531caf7",
|
||||
"sha256:04876580c050a8c5341d706dd464ff04fd597095cc8c023252566a8826505726",
|
||||
"sha256:05ca3f6abf5cf78fe053da9b1166e062ade3fa5d4f92b4ed688127ea7d7b1d03",
|
||||
"sha256:090c6543d3696cbe15b4ac6e175e576bcc3f1ccfbba970061b7300b0c15a2140",
|
||||
"sha256:0dc313ef231edf866912e9d8f5a042ddab56c752619e92dfd3a2c277e6a7299a",
|
||||
"sha256:0f2b1e0d79180f344ff9f321327b005ca043a50ece8713de61d1cb383fb8ac05",
|
||||
"sha256:13598ecfbd2e86ea7ae45ec28a2a54fb87ee9b9fdb0f6d343297d8e548392c03",
|
||||
"sha256:16efd54337136e8cd72fb9485c368d91d77a47ee2d42b057564aae201257d419",
|
||||
"sha256:1ab8f1f932e8f82355e75dda5413a57612c6ea448069d4fb2e217e9a4bed13d4",
|
||||
"sha256:223f4232855ade399bd409331e6ca70fb5578efef22cf4069a6090acc0f53c0e",
|
||||
"sha256:2455cfaeb7ac70338b3257f41e21f0724f4b5b0c0e7702da67ee6c3640835b67",
|
||||
"sha256:2899456259589aa38bfb018c364d6ae7b53c5c22d8e27d0ec7609c2a1ff78b50",
|
||||
"sha256:2a29ba94d065945944016b6b74e538bdb1751a1db6ffb80c9d3c2e40d6fa9894",
|
||||
"sha256:2a87fa548561d2f4643c99cd13131acb607ddabb70682dcf1dff5f71f781a4bf",
|
||||
"sha256:2e430cd2824f05f2d4f687701144556646bae8f249fd60aa1e4c768ba7018947",
|
||||
"sha256:36c3c175d34652a35475a73762b545f4527aec044910a651d2bf50de9c3352b1",
|
||||
"sha256:3818b8e2c4b5148567e1b09ce739006acfaa44ce3156f8cbbc11062994b8e8dd",
|
||||
"sha256:3ab9fa9d6dc2a7f29d7affdf3edebf6ece6fb28a6d80b14c3b2fb9d39b9322c3",
|
||||
"sha256:3efea981d956a6f7173b4659849f55081867cf897e719f57383698af6f618a92",
|
||||
"sha256:4c8f293f14abc8fd3e8e01c5bd86e6ed0b6ef71936ded5bf10fe7a5efefbaca3",
|
||||
"sha256:5344a43228767f53a9df6e5b253f8cdca7dfc7b7aeae52551958192f56d98457",
|
||||
"sha256:58bfa3aa19ca4c0f28c5dde0ff56c520fbac6f0daf4fac66ed4c8d2fb7f22e74",
|
||||
"sha256:5b4545b8a40478183ac06c073e81a5ce4cf01bf1734962577cf2bb569a5b3bbf",
|
||||
"sha256:5f50a1c177e2fa3ee0667a5ab79fdc6b23086bc8b589d90b93b4bd17eb0e64d1",
|
||||
"sha256:63da2ccc0857c311d764e7d3d90f429c252e83b52d1f8f1d1fe55be26827d1f4",
|
||||
"sha256:6749649eecd6a9871cae297bffa4ee76f90b4504a2a2ab528d9ebe912b101975",
|
||||
"sha256:6804daeb7ef69e7b36f76caddb85cccd63d0c56dedb47555d2fc969e2af6a1a5",
|
||||
"sha256:689bb688a1db722485e4610a503e3e9210dcc20c520b45ac8f7533c837be76fe",
|
||||
"sha256:699a9af7dffaf67deeae27b2112aa06b41c370d5e7633e0ee0aea2e0b6c211f7",
|
||||
"sha256:6b418afe5df18233fc6b6093deb82a32895b6bb0b1155c2cdb05203f583053f1",
|
||||
"sha256:76cf573e5a365e790396a5cc2b909812633409306c6531a6877c59061e42c4f2",
|
||||
"sha256:7b515674acfdcadb0eb5d00d8a709868173acece5cb0be3dd165950cbfdf5409",
|
||||
"sha256:7b770ed79542ed52c519119473898198761d78beb24b107acf3ad65deae61f1f",
|
||||
"sha256:7d2278d59425777cfcb19735018d897ca8303abe67cc735f9f97177ceff8027f",
|
||||
"sha256:7e91ee82f4199af8c43d8158024cbdff3d931df350252288f0d4ce656df7f3b5",
|
||||
"sha256:821b7f59b99551c69c85a6039c65b75f5683bdc63270fec660f75da67469ca24",
|
||||
"sha256:822068f85e12a6e292803e112ab876bc03ed1f03dddb80154c395f891ca6b31e",
|
||||
"sha256:8340225bd5e7a701c0fa98284c849c9b9fc9238abf53a0ebd90900f25d39a4e4",
|
||||
"sha256:85cabf64adec449132e55616e7ca3e1000ab449d1d0f9d7f83146ed5bdcb6d8a",
|
||||
"sha256:880bbbcbe2fca64e2f4d8e04db47bcdf504936fa2b33933efd945e1b429bea8c",
|
||||
"sha256:8d0b4612b66ff5d62d03bcaa043bb018f74dfea51184e53f067e6fdcba4bd8de",
|
||||
"sha256:8e20cb5a47247e383cf4ff523205060991021233ebd6f924bca927fcf25cf86f",
|
||||
"sha256:925073b2fe14ab9b87e73f9a5fde6ce6392da430f3004d8b72cc86f746f5163b",
|
||||
"sha256:998c7c41910666d2976928c38ea96a70d1aa43be6fe502f21a651e17483a43c5",
|
||||
"sha256:9b22c5c66f67ae00c0199f6055705bc3eb3fcb08d03d2ec4059a2b1b25ed48d7",
|
||||
"sha256:9f102706d0ca011de571de32c3247c6476b55bb6bc65a20f682f000b07a4852a",
|
||||
"sha256:a08cff61517ee26cb56f1e949cca38caabe9ea9fbb4b1e10a805dc39844b7d5c",
|
||||
"sha256:a0a336d6d3e8b234a3aae3c674873d8f0e720b76bc1d9416866c41cd9500ffb9",
|
||||
"sha256:a35f8b7fa99f90dd2f5dc5a9fa12332642f087a7641289ca6c40d6e1a2637d8e",
|
||||
"sha256:a38486985ca49cfa574a507e7a2215c0c780fd1778bb6290c21193b7211702ab",
|
||||
"sha256:a5da296eb617d18e497bcf0a5c528f5d3b18dadb3619fbdadf4ed2356ef8d941",
|
||||
"sha256:a6e441a86553c310258aca15d1c05903aaf4965b23f3bc2d55f200804e005ee5",
|
||||
"sha256:a82d05da00a58b8e4c0008edbc8a4b6ec5a4bc1e2ee0fb6ed157cf634ed7fa45",
|
||||
"sha256:ab323679b8b3030000f2be63e22cdeea5b47ee0abd2d6a1dc0c8103ddaa56cd7",
|
||||
"sha256:b1f42b6921d0e81b1bcb5e395bc091a70f41c4d4e55ba99c6da2b31626c44892",
|
||||
"sha256:b23e19989c355ca854276178a0463951a653309fb8e57ce674497f2d9f208746",
|
||||
"sha256:b264171e3143d842ded311b7dccd46ff9ef34247129ff5bf5066123c55c2431c",
|
||||
"sha256:b26a29f0b7fc6f0897f043ca366142d2b609dc60756ee6e4e90b5f762c6adc53",
|
||||
"sha256:b64d891da92e232c36976c80ed7ebb383e3f148489796d8d31a5b6a677825efe",
|
||||
"sha256:b9cc34af337a97d470040f99ba4282f6e6bac88407d021688a5d585e44a23184",
|
||||
"sha256:bc718cd47b765e790eecb74d044cc8d37d58562f6c314ee9484df26276d36a38",
|
||||
"sha256:be7292c55101e22f2a3d4d8913944cbea71eea90792bf914add27454a13905df",
|
||||
"sha256:c83203addf554215463b59f6399835201999b5e48019dc17f182ed5ad87205c9",
|
||||
"sha256:c9ec3eaf616d67db0764b3bb983962b4f385a1f08304fd30c7283954e6a7869b",
|
||||
"sha256:ca34efc80a29351897e18888c71c6aca4a359247c87e0b1c7ada14f0ab0c0fb2",
|
||||
"sha256:ca989b91cf3a3ba28930a9fc1e9aeafc2a395448641df1f387a2d394638943b0",
|
||||
"sha256:d02a5399126a53492415d4906ab0ad0375a5456cc05c3fc0fc4ca11771745cda",
|
||||
"sha256:d17bc7c2ccf49c478c5bdd447594e82692c74222698cfc9b5daae7ae7e90743b",
|
||||
"sha256:d5bf6545cd27aaa8a13033ce56354ed9e25ab0e4ac3b5392b763d8d04b08e0c5",
|
||||
"sha256:d6b430a9938a5a5d85fc107d852262ddcd48602c120e3dbb02137c83d212b380",
|
||||
"sha256:da248f93f0418a9e9d94b0080d7ebc407a9a5e6d0b57bb30db9b5cc28de1ad33",
|
||||
"sha256:da4dd7c9c50c059aba52b3524f84d7de956f7fef88f0bafcf4ad7dde94a064e8",
|
||||
"sha256:df0623dcf9668ad0445e0558a21211d4e9a149ea8f5666917c8eeec515f0a6d1",
|
||||
"sha256:e5168986b90a8d1f2f9dc1b841467c74221bd752537b99761a93d2d981e04889",
|
||||
"sha256:efa29c2fe6b4fdd32e8ef81c1528506895eca86e1d8c4657fda04c9b3786ddf9",
|
||||
"sha256:f1496ea22ca2c830cbcbd473de8f114a320da308438ae65abad6bab7867fe38f",
|
||||
"sha256:f49e52d174375a7def9915c9f06ec4e569d235ad428f70751765f48d5926678c"
|
||||
],
|
||||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
|
||||
"version": "==4.9.2"
|
||||
},
|
||||
"mistune": {
|
||||
"hashes": [
|
||||
"sha256:0246113cb2492db875c6be56974a7c893333bf26cd92891c85f63151cee09d34",
|
||||
"sha256:bad7f5d431886fcbaf5f758118ecff70d31f75231b34024a1341120340a65ce8"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==2.0.5"
|
||||
},
|
||||
"mpmath": {
|
||||
"hashes": [
|
||||
"sha256:7a28eb2a9774d00c7bc92411c19a89209d5da7c4c9a9e227be8330a23a25b91f",
|
||||
"sha256:a0b2b9fe80bbcd81a6647ff13108738cfb482d481d826cc0e02f5b35e5c88d2c"
|
||||
],
|
||||
"version": "==1.3.0"
|
||||
},
|
||||
"mysql": {
|
||||
"hashes": [
|
||||
"sha256:8893cb143a5ac525c49ef358a23b8a0dc9721a95646f7bab6ca2f384c18a6a9a",
|
||||
"sha256:fd7bae7d7301ce7cd3932e5ff7f77bbc8e34872108252866e08d16d6b8e8de8c"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==0.0.3"
|
||||
},
|
||||
"mysql-connector-python": {
|
||||
"hashes": [
|
||||
"sha256:0004426e964856148e1cde31e9b8be63ae3013715b048ff0f2ede69a6ddd36f7",
|
||||
"sha256:016662c6252f2c5f47805d9168187be1316d0c1d7109f9fe668482c3d6e5711d",
|
||||
"sha256:241483065ad062256985e082e3cbb3e7d1d6d2275cee17c66d22525b09096201",
|
||||
"sha256:34d5c5f6ec7c1e75bf972def40d097138e097dc694e36dec89a5dd604ef7aada",
|
||||
"sha256:37eace5b7eb676a41ff1edc5cf6ce4ae1c28406d1a6fe84941e6aa396d688195",
|
||||
"sha256:3bedf8265fb31698e4144ca54e241e3386802c3a437745b1a536a74cbe7e4fb9",
|
||||
"sha256:41db4452a99ee28494313eab1aa7749475d3e39bed7b24a0868aee45bd0d9c73",
|
||||
"sha256:46ff8a10c13f39996d60f45c30cf2ea15e883bc71d58259ed2fea0a5a6fb93a3",
|
||||
"sha256:4c82fb70f44f2469c0879434c1d8ee3162f56a40cc8f5ca1cc4d97f06c84cd43",
|
||||
"sha256:7266d7b2550f9fe0cdcea1647aa6aade352e14095042b6a3921c9152cf8543e8",
|
||||
"sha256:7318f416b9defe84b2bd025304bab62b68f8d8fcbe479af5593161eff12ef169",
|
||||
"sha256:753d07fb39a67f7f35fe6e6a4fac12008287661de59f9d5c0bf4da3359d83eb8",
|
||||
"sha256:96f7fb0ccfe96e6e478e5f0f034c99bda961b99ffa1c746cee39cfea45b0c04d",
|
||||
"sha256:9775331fa60b5d5a6925781d77eee4384e2b54a12dea694ffdefd1cf1a9c0fdb",
|
||||
"sha256:984f5649e6abee04461d6f52fbc77387d7137b8fd003c54bac66505006f17183",
|
||||
"sha256:9f5eb33e29742c5f8ef23df2d3f0de0e46f4325e4324016e15aba7f8665a68c0",
|
||||
"sha256:a632d7b0e569a46e6d44e6cd3f8db747995a787a081870697dbfd3ae18949339",
|
||||
"sha256:af9feec311d8ea51261e1ef1f959a442708e30f0024d08d0fb537b07a1271634",
|
||||
"sha256:c20a85a69af41d2d7d5cf52106f0b9473775819d189487c6ff3d3f3946931ca2",
|
||||
"sha256:d8167868ebad8d78ba69babd028626e96a51365cab76edf735b2559731759b62",
|
||||
"sha256:db422b19347c5d00e078dd64e281e5b1e5a19a2d972dc2d9733b136d79c34798",
|
||||
"sha256:e853e12c00e3beabc581f4e039222708ee606fef80a3bac6b1f497ed89a31aea",
|
||||
"sha256:ea05590cb972b114efa027c343b4b7110d8e8450493984ebfb9a651e27674636",
|
||||
"sha256:f324233af7ec9fcb19c23096af27662459708c0465886cb017d78ff3f5b78b55",
|
||||
"sha256:f403ff22d3514d08028590fef463d17dc107ac72ea27a49429614949d82fda40"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==8.0.33"
|
||||
},
|
||||
"mysqlclient": {
|
||||
"hashes": [
|
||||
"sha256:0d1cd3a5a4d28c222fa199002810e8146cffd821410b67851af4cc80aeccd97c",
|
||||
"sha256:828757e419fb11dd6c5ed2576ec92c3efaa93a0f7c39e263586d1ee779c3d782",
|
||||
"sha256:996924f3483fd36a34a5812210c69e71dea5a3d5978d01199b78b7f6d485c855",
|
||||
"sha256:b355c8b5a7d58f2e909acdbb050858390ee1b0e13672ae759e5e784110022994",
|
||||
"sha256:c1ed71bd6244993b526113cca3df66428609f90e4652f37eb51c33496d478b37",
|
||||
"sha256:c812b67e90082a840efb82a8978369e6e69fc62ce1bda4ca8f3084a9d862308b",
|
||||
"sha256:dea88c8d3f5a5d9293dfe7f087c16dd350ceb175f2f6631c9cf4caf3e19b7a96"
|
||||
],
|
||||
"markers": "python_version >= '3.5'",
|
||||
"version": "==2.1.1"
|
||||
},
|
||||
"protobuf": {
|
||||
"hashes": [
|
||||
"sha256:03038ac1cfbc41aa21f6afcbcd357281d7521b4157926f30ebecc8d4ea59dcb7",
|
||||
"sha256:28545383d61f55b57cf4df63eebd9827754fd2dc25f80c5253f9184235db242c",
|
||||
"sha256:2e3427429c9cffebf259491be0af70189607f365c2f41c7c3764af6f337105f2",
|
||||
"sha256:398a9e0c3eaceb34ec1aee71894ca3299605fa8e761544934378bbc6c97de23b",
|
||||
"sha256:44246bab5dd4b7fbd3c0c80b6f16686808fab0e4aca819ade6e8d294a29c7050",
|
||||
"sha256:447d43819997825d4e71bf5769d869b968ce96848b6479397e29fc24c4a5dfe9",
|
||||
"sha256:67a3598f0a2dcbc58d02dd1928544e7d88f764b47d4a286202913f0b2801c2e7",
|
||||
"sha256:74480f79a023f90dc6e18febbf7b8bac7508420f2006fabd512013c0c238f454",
|
||||
"sha256:819559cafa1a373b7096a482b504ae8a857c89593cf3a25af743ac9ecbd23480",
|
||||
"sha256:899dc660cd599d7352d6f10d83c95df430a38b410c1b66b407a6b29265d66469",
|
||||
"sha256:8c0c984a1b8fef4086329ff8dd19ac77576b384079247c770f29cc8ce3afa06c",
|
||||
"sha256:9aae4406ea63d825636cc11ffb34ad3379335803216ee3a856787bcf5ccc751e",
|
||||
"sha256:a7ca6d488aa8ff7f329d4c545b2dbad8ac31464f1d8b1c87ad1346717731e4db",
|
||||
"sha256:b6cc7ba72a8850621bfec987cb72623e703b7fe2b9127a161ce61e61558ad905",
|
||||
"sha256:bf01b5720be110540be4286e791db73f84a2b721072a3711efff6c324cdf074b",
|
||||
"sha256:c02ce36ec760252242a33967d51c289fd0e1c0e6e5cc9397e2279177716add86",
|
||||
"sha256:d9e4432ff660d67d775c66ac42a67cf2453c27cb4d738fc22cb53b5d84c135d4",
|
||||
"sha256:daa564862dd0d39c00f8086f88700fdbe8bc717e993a21e90711acfed02f2402",
|
||||
"sha256:de78575669dddf6099a8a0f46a27e82a1783c557ccc38ee620ed8cc96d3be7d7",
|
||||
"sha256:e64857f395505ebf3d2569935506ae0dfc4a15cb80dc25261176c784662cdcc4",
|
||||
"sha256:f4bd856d702e5b0d96a00ec6b307b0f51c1982c2bf9c0052cf9019e9a544ba99",
|
||||
"sha256:f4c42102bc82a51108e449cbb32b19b180022941c727bac0cfd50170341f16ee"
|
||||
],
|
||||
"markers": "python_version >= '3.7'",
|
||||
"version": "==3.20.3"
|
||||
},
|
||||
"python-docx": {
|
||||
"hashes": [
|
||||
"sha256:1105d233a0956dd8dd1e710d20b159e2d72ac3c301041b95f4d4ceb3e0ebebc4"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==0.8.11"
|
||||
},
|
||||
"sympy": {
|
||||
"hashes": [
|
||||
"sha256:938f984ee2b1e8eae8a07b884c8b7a1146010040fccddc6539c54f401c8f6fcf",
|
||||
"sha256:e32380dce63cb7c0108ed525570092fd45168bdae2faa17e528221ef72e88658"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==1.11.1"
|
||||
}
|
||||
},
|
||||
"develop": {}
|
||||
}
|
190
daniel_jo/ITP4459_assignment_2023/src/python/app.py
Normal file
190
daniel_jo/ITP4459_assignment_2023/src/python/app.py
Normal file
@@ -0,0 +1,190 @@
|
||||
import tkinter
|
||||
import tkinter.ttk
|
||||
|
||||
import constants
|
||||
from models import Programme
|
||||
from widgets import ModuleWidget
|
||||
|
||||
from pprint import pprint
|
||||
|
||||
# app.py - Main GUI dialog
|
||||
|
||||
class App(tkinter.Tk):
|
||||
def __init__(self, db):
|
||||
super().__init__()
|
||||
self.__db = db
|
||||
|
||||
self.__programme = None
|
||||
self.__modules = None
|
||||
|
||||
self.refresh_db()
|
||||
self.setup_ui()
|
||||
|
||||
# NOTE: Do not modify this method
|
||||
def report_callback_exception(self, *args):
|
||||
"""When an error is occurred, raise the exception
|
||||
so main_gui.py will handle the display of error.
|
||||
"""
|
||||
raise args[1].with_traceback(args[2])
|
||||
|
||||
def refresh_db(self):
|
||||
# Fetch all program records from database, and store it in __programme as a list
|
||||
self.__programme = Programme.fetchall(self.__db)
|
||||
|
||||
def setup_ui(self):
|
||||
self.title(constants.APP_NAME)
|
||||
self.minsize(640, 480)
|
||||
|
||||
# Set weight of column 0 for auto resizing on X axis
|
||||
self.columnconfigure(0, weight=1)
|
||||
|
||||
# Header
|
||||
frm_top_bar = tkinter.Frame(self)
|
||||
frm_top_bar.grid(row=0, sticky=tkinter.EW)
|
||||
tkinter.Label(
|
||||
frm_top_bar,
|
||||
text = constants.APP_NAME,
|
||||
font = ('bold', 16)
|
||||
).pack(side = tkinter.LEFT, padx=8, pady=8)
|
||||
tkinter.ttk.Separator(self).grid(row=1, sticky=tkinter.EW)
|
||||
|
||||
# Content
|
||||
frm_content = tkinter.Frame(self)
|
||||
frm_content.grid(row=2, sticky=tkinter.NSEW)
|
||||
self.rowconfigure(2, weight=1)
|
||||
|
||||
# Options
|
||||
frm_filter = tkinter.LabelFrame(frm_content, text = "Options")
|
||||
frm_filter.pack(fill=tkinter.X, side=tkinter.TOP, padx=8, pady=(4, 0))
|
||||
frm_filter_container = tkinter.Frame(frm_filter)
|
||||
frm_filter_container.pack(fill=tkinter.BOTH, side=tkinter.TOP, padx=6, pady=(0, 4))
|
||||
|
||||
# Options variables
|
||||
# Option widgets
|
||||
tkinter.Label(frm_filter_container,text = "Programme",).grid(row=0, column=0, padx=(0, 4))
|
||||
list_of_programme=[]
|
||||
for p in self.__programme:
|
||||
list_of_programme.append(p.get_name())
|
||||
|
||||
self.selected_programme = tkinter.StringVar()
|
||||
self.__om_programme_filter = tkinter.ttk.Combobox(frm_filter_container,textvariable=self.selected_programme, width=50)
|
||||
self.__om_programme_filter.set('Please select')
|
||||
self.__om_programme_filter['values'] = list_of_programme
|
||||
self.__om_programme_filter['state'] = 'readonly'
|
||||
self.__om_programme_filter.grid(row=0, column=1, padx=(0, 4), sticky=tkinter.EW)
|
||||
self.__om_programme_filter.bind('<<ComboboxSelected>>', self.on_programme_changed )
|
||||
|
||||
# Semester select
|
||||
tkinter.Label( frm_filter_container, text = "Semester").grid(row=0, column=2, padx=(0, 4))
|
||||
self.selected_semester = tkinter.StringVar()
|
||||
self.__om_semester_filter = tkinter.ttk.Combobox(frm_filter_container, textvariable=self.selected_semester)
|
||||
self.__om_semester_filter.set('Please select')
|
||||
self.__om_semester_filter['state'] = 'disabled'
|
||||
self.__om_semester_filter.grid(row=0, column=3, padx=(4, 4))
|
||||
self.__om_semester_filter.bind('<<ComboboxSelected>>', self.on_semester_changed)
|
||||
|
||||
# Modules
|
||||
frm_modules = tkinter.LabelFrame(frm_content, text = "Modules")
|
||||
frm_modules.pack(fill=tkinter.BOTH, side=tkinter.TOP, expand=1, padx=8, pady=(4, 0))
|
||||
self.__frm_modules_container = tkinter.Frame(frm_modules)
|
||||
self.__frm_modules_container.pack(fill=tkinter.BOTH, side=tkinter.TOP, padx=6, pady=(0, 4))
|
||||
|
||||
self.__module_widgets = list()
|
||||
for _ in range(constants.APP_MAX_MODULES):
|
||||
widget = ModuleWidget(self.__frm_modules_container, self.on_gpa_changed)
|
||||
widget.get_frame().pack(fill=tkinter.X, side=tkinter.TOP, expand=1, pady=8)
|
||||
widget.set_module(None)
|
||||
|
||||
self.__module_widgets.append(widget)
|
||||
|
||||
# Bottom bar
|
||||
frm_bottom_bar = tkinter.Frame(self)
|
||||
frm_bottom_bar.grid(row=3, column=0,padx=(0, 10), pady=(4,4), sticky=tkinter.E)
|
||||
|
||||
# Result Label
|
||||
self.semester_gpa = tkinter.StringVar()
|
||||
self.lbl_stu_list = tkinter.ttk.Label(frm_bottom_bar, text='Semester GPA: %.2f' % 0, font=("bold",11))
|
||||
self.lbl_stu_list.grid(row=0, column=0, sticky=tkinter.E)
|
||||
|
||||
def setup_module_list(self):
|
||||
# Update the ModuleWidget in list __module_widgets to display
|
||||
# modules for the selected programme and semester
|
||||
current_select_idx = self.__om_semester_filter.current()
|
||||
selected_semester = list(sorted(self.__modules.keys()))[current_select_idx]
|
||||
module_in_semester = self.__modules[selected_semester]
|
||||
for widget in self.__frm_modules_container.winfo_children():
|
||||
widget.destroy()
|
||||
|
||||
self.__module_widgets = list()
|
||||
i = 0
|
||||
for _ in range(constants.APP_MAX_MODULES):
|
||||
widget = ModuleWidget(self.__frm_modules_container, self.on_gpa_changed)
|
||||
widget.get_frame().pack(fill=tkinter.X, side=tkinter.TOP, expand=1, pady=8)
|
||||
if (i < len(module_in_semester)):
|
||||
widget.set_module(module_in_semester[i])
|
||||
|
||||
self.__module_widgets.append(widget)
|
||||
i = i + 1
|
||||
|
||||
def on_programme_changed(self, _):
|
||||
# Get selected programme based on option menu index, and update GUI
|
||||
for program in self.__programme:
|
||||
if (self.selected_programme.get() == program.get_name()):
|
||||
self.__om_semester_filter['values'] = sorted(program.get_modules().keys())
|
||||
self.__modules = program.get_modules()
|
||||
break
|
||||
self.__om_semester_filter['state'] = 'readonly'
|
||||
|
||||
self.__om_semester_filter.set('Please select')
|
||||
|
||||
for widget in self.__frm_modules_container.winfo_children():
|
||||
widget.destroy()
|
||||
|
||||
self.__module_widgets = list()
|
||||
for _ in range(constants.APP_MAX_MODULES):
|
||||
widget = ModuleWidget(self.__frm_modules_container, self.on_gpa_changed)
|
||||
widget.get_frame().pack(fill=tkinter.X, side=tkinter.TOP, expand=1, pady=8)
|
||||
widget.set_module(None)
|
||||
self.__module_widgets.append(widget)
|
||||
|
||||
# reset gpa
|
||||
self.lbl_stu_list.configure(text='Semester GPA: %.2f' % (0))
|
||||
|
||||
|
||||
def on_semester_changed(self, _):
|
||||
# Get modules based on option menu value, and update GUI
|
||||
self.setup_module_list()
|
||||
|
||||
# reset gpa
|
||||
self.lbl_stu_list.configure(text='Semester GPA: %.2f' % (0))
|
||||
|
||||
|
||||
def on_gpa_changed(self):
|
||||
# Calcuate semester GPA based on self.__modules
|
||||
|
||||
# 1. For each modules in self.__modules, App class
|
||||
# 2. Obtain the module credit of current module and add it to the total credits
|
||||
# 3. Calculate the module gpa by multiplying the current module gpa and module credit
|
||||
# 4. Add the calculated module gpa to total module gpa
|
||||
# 5. After all module gpa are calculated, divide the total module gpa by total credits
|
||||
|
||||
total = 0
|
||||
current_select_idx = self.__om_semester_filter.current()
|
||||
selected_semester = list(sorted(self.__modules.keys()))[current_select_idx]
|
||||
module_in_semester = self.__modules[selected_semester]
|
||||
number_of_modules = len(module_in_semester)
|
||||
|
||||
should_update = True
|
||||
all_credit = 0
|
||||
for i in range(0, number_of_modules):
|
||||
gpa = self.__module_widgets[i].get_gpa()
|
||||
if (gpa == -1):
|
||||
# not selected
|
||||
should_update = False
|
||||
else:
|
||||
credit =self.__module_widgets[i].get_module().get_credit()
|
||||
all_credit = all_credit + credit
|
||||
total = total + (gpa * credit)
|
||||
|
||||
if should_update:
|
||||
self.lbl_stu_list.configure(text='Semester GPA: %.2f' % (total / all_credit))
|
26
daniel_jo/ITP4459_assignment_2023/src/python/constants.py
Normal file
26
daniel_jo/ITP4459_assignment_2023/src/python/constants.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# Database
|
||||
# NOTE: Modify the username and password if needed
|
||||
DB_HOST = "localhost"
|
||||
DB_NAME = "itp4459_asg"
|
||||
|
||||
DB_USER = "db_user"
|
||||
DB_PASS = "db_user_pass"
|
||||
|
||||
# Tkinter GUI
|
||||
APP_NAME = "GPA Calculator"
|
||||
APP_MAX_MODULES = 7
|
||||
|
||||
# Application logic
|
||||
GPA_MAPPING = {
|
||||
"A": 4,
|
||||
"A-": 3.7,
|
||||
"B+": 3.3,
|
||||
"B": 3,
|
||||
"B-": 2.7,
|
||||
"C+": 2.3,
|
||||
"C": 2,
|
||||
"C-": 1.7,
|
||||
"D+": 1.3,
|
||||
"D": 1,
|
||||
"F": 0
|
||||
}
|
78
daniel_jo/ITP4459_assignment_2023/src/python/db.py
Normal file
78
daniel_jo/ITP4459_assignment_2023/src/python/db.py
Normal file
@@ -0,0 +1,78 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
import mysql.connector
|
||||
|
||||
# db.py - Database related classes
|
||||
# NOTE: You do not need to modify this source file
|
||||
|
||||
__all__ = (
|
||||
'MySQLConnection', 'MySQLObject'
|
||||
)
|
||||
|
||||
class MySQLConnection:
|
||||
"""A class to handle all database related functions for this assingment."""
|
||||
|
||||
def __init__(self, host, user, password, database=None):
|
||||
"""Initialize connection to MySQL server.
|
||||
|
||||
Create database if needed automatically.
|
||||
"""
|
||||
self.db = mysql.connector.connect(
|
||||
host=host,
|
||||
user=user,
|
||||
password=password
|
||||
)
|
||||
if database is not None:
|
||||
with self.db.cursor() as cursor:
|
||||
cursor.execute(f"CREATE DATABASE IF NOT EXISTS {database};")
|
||||
self.db.commit()
|
||||
self.db.database = database
|
||||
|
||||
def close(self):
|
||||
"""Closes the database connection."""
|
||||
self.db.close()
|
||||
|
||||
def cursor(self):
|
||||
"""Returns a database cursor, for executing multiple statments
|
||||
in a single transaction.
|
||||
"""
|
||||
return self.db.cursor()
|
||||
|
||||
def commit(self):
|
||||
"""Commit changes to database."""
|
||||
self.db.commit()
|
||||
|
||||
def execute(self, query):
|
||||
"""Commit: Python -> Database
|
||||
|
||||
e.g. CREATE, INSERT and UPDATE
|
||||
"""
|
||||
with self.db.cursor() as cursor:
|
||||
cursor.execute(query)
|
||||
self.db.commit()
|
||||
|
||||
def fetchone(self, query):
|
||||
"""Fetch: Python <- Database
|
||||
|
||||
e.g. SELECT and SHOW
|
||||
"""
|
||||
with self.db.cursor() as cursor:
|
||||
cursor.execute(query)
|
||||
return cursor.fetchone()
|
||||
|
||||
def fetchall(self, query):
|
||||
"""Fetch: Python <- Database
|
||||
|
||||
e.g. SELECT and SHOW
|
||||
"""
|
||||
with self.db.cursor() as cursor:
|
||||
cursor.execute(query)
|
||||
return cursor.fetchall()
|
||||
|
||||
class MySQLObject(ABC):
|
||||
"""A database managed object."""
|
||||
@staticmethod
|
||||
@abstractmethod
|
||||
def fetchall(db):
|
||||
"""Returns a list of object imported from database."""
|
||||
return NotImplemented
|
99
daniel_jo/ITP4459_assignment_2023/src/python/main_db.py
Normal file
99
daniel_jo/ITP4459_assignment_2023/src/python/main_db.py
Normal file
@@ -0,0 +1,99 @@
|
||||
import constants
|
||||
from db import MySQLConnection
|
||||
|
||||
# main_db.py - Program entry point for Part 1 Database
|
||||
|
||||
tbl_programme = """
|
||||
CREATE TABLE IF NOT EXISTS programmes (
|
||||
programme_id VARCHAR(9) NOT NULL,
|
||||
programme_name VARCHAR(100) NOT NULL,
|
||||
PRIMARY KEY (programme_id)
|
||||
)"""
|
||||
|
||||
tbl_module = """
|
||||
CREATE TABLE IF NOT EXISTS modules (
|
||||
module_id VARCHAR(7) NOT NULL,
|
||||
module_name VARCHAR(100) NOT NULL,
|
||||
module_credit INT,
|
||||
PRIMARY KEY (module_id)
|
||||
)"""
|
||||
|
||||
tbl_mapping = """
|
||||
CREATE TABLE IF NOT EXISTS mappings (
|
||||
mapping_programme_id VARCHAR(9) NOT NULL,
|
||||
mapping_semester INT NOT NULL,
|
||||
mapping_module_id VARCHAR(7) NOT NULL,
|
||||
PRIMARY KEY (mapping_programme_id, mapping_semester, mapping_module_id),
|
||||
FOREIGN KEY (mapping_programme_id) REFERENCES programmes(programme_id),
|
||||
FOREIGN KEY (mapping_module_id) REFERENCES modules(module_id)
|
||||
)"""
|
||||
|
||||
radius = (('circle', 1.0),('circle', 2.0),('circle', 3.0))
|
||||
query = "INSERT INTO circles (name, radius) VALUES (%s, %s)"
|
||||
|
||||
insert_programmes = (
|
||||
('IT114124', "Higher Diploma in AI and Smart Technology"),
|
||||
('IT114122', "Higher Diploma in Cybersecurity")
|
||||
)
|
||||
insert_programme_query = "INSERT INTO programmes (programme_id, programme_name) VALUES (%s, %s)"
|
||||
|
||||
insert_modules = (
|
||||
("LAN3100","English & Communication: Workplace Interaction","6"),
|
||||
("LAN3103","English & Communication: Workplace Correspondance","6"),
|
||||
("LAN4107","English & Communication: Reports","9"),
|
||||
("LAN4108","English & Communication: Persuasive Presentations","9"),
|
||||
("LAN4101","English & Communication: Promotional Materials","10"),
|
||||
("LAN3003","Vocational Chinese Communication: Putonghua Conversation and Reports","6"),
|
||||
("LAN4003","Vocational Chinese Communication: Putonghua Presentations, Administrative and Technical Text Writing","9")
|
||||
)
|
||||
|
||||
insert_modules_query = "INSERT INTO modules (module_id, module_name, module_credit) VALUES (%s, %s, %s)"
|
||||
|
||||
insert_mappings = (
|
||||
("IT114124","1","LAN3100"),
|
||||
("IT114124","1","LAN3103"),
|
||||
("IT114124","1","LAN3003"),
|
||||
("IT114124","2","LAN4107"),
|
||||
("IT114124","2","LAN4003"),
|
||||
("IT114124","4","LAN4108"),
|
||||
("IT114124","5","LAN4101"),
|
||||
("IT114122","1","LAN3100"),
|
||||
("IT114122","1","LAN3103"),
|
||||
("IT114122","1","LAN3003"),
|
||||
("IT114122","2","LAN4107"),
|
||||
("IT114122","2","LAN4003"),
|
||||
("IT114122","4","LAN4108"),
|
||||
("IT114122","5","LAN4101")
|
||||
)
|
||||
|
||||
insert_mappings_query = "INSERT INTO mappings (mapping_programme_id, mapping_semester, mapping_module_id) VALUES (%s, %s, %s)"
|
||||
|
||||
if __name__ == "__main__":
|
||||
db = MySQLConnection(
|
||||
host=constants.DB_HOST,
|
||||
user=constants.DB_USER,
|
||||
password=constants.DB_PASS
|
||||
)
|
||||
|
||||
with db.cursor() as cursor:
|
||||
# Recreate database and select as default
|
||||
cursor.execute(f"DROP DATABASE IF EXISTS {constants.DB_NAME};")
|
||||
cursor.execute(f"CREATE DATABASE {constants.DB_NAME};")
|
||||
cursor.execute(f"USE {constants.DB_NAME};")
|
||||
|
||||
# Tables
|
||||
cursor.execute(tbl_programme)
|
||||
cursor.execute(tbl_module)
|
||||
cursor.execute(tbl_mapping)
|
||||
|
||||
# Records
|
||||
# cursor.executemany(query, radius)
|
||||
cursor.executemany(insert_programme_query, insert_programmes)
|
||||
cursor.executemany(insert_modules_query, insert_modules)
|
||||
cursor.executemany(insert_mappings_query, insert_mappings)
|
||||
|
||||
db.commit()
|
||||
db.close()
|
||||
|
||||
|
||||
|
42
daniel_jo/ITP4459_assignment_2023/src/python/main_gui.py
Normal file
42
daniel_jo/ITP4459_assignment_2023/src/python/main_gui.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from tkinter import messagebox
|
||||
|
||||
import constants
|
||||
import traceback
|
||||
from app import App
|
||||
from db import MySQLConnection
|
||||
|
||||
# main_gui.py - Program entry point for Part 2 GUI
|
||||
# NOTE: You do not need to modify this source file
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = None
|
||||
db = None
|
||||
try:
|
||||
# Create connection to database
|
||||
db = MySQLConnection(
|
||||
host=constants.DB_HOST,
|
||||
user=constants.DB_USER,
|
||||
password=constants.DB_PASS,
|
||||
database=constants.DB_NAME)
|
||||
|
||||
# Create and start app
|
||||
app = App(db)
|
||||
app.mainloop()
|
||||
except Exception as e:
|
||||
# Display error in console
|
||||
traceback.print_exception(e)
|
||||
|
||||
# Display error as message box
|
||||
errorType = f"{type(e).__name__}"
|
||||
messagebox.showerror(errorType, e.__str__())
|
||||
|
||||
# Close the app window
|
||||
if app is App:
|
||||
app.destroy()
|
||||
|
||||
# Raise the error again for debugger
|
||||
raise e
|
||||
finally:
|
||||
# Close database connection
|
||||
if db is MySQLConnection:
|
||||
db.close()
|
143
daniel_jo/ITP4459_assignment_2023/src/python/models.py
Normal file
143
daniel_jo/ITP4459_assignment_2023/src/python/models.py
Normal file
@@ -0,0 +1,143 @@
|
||||
import constants
|
||||
from db import MySQLObject
|
||||
|
||||
# models.py - Python representation of database table records
|
||||
|
||||
class Programme(MySQLObject):
|
||||
def __init__(self, id, name):
|
||||
# initialize the id, name and modules attributes.
|
||||
self.__id = id # a non-public string to store the id of the programme.
|
||||
self.__name = name # a non-public string so store the name of the programme.
|
||||
self.__modules = {} # a non-public dictionary to store Module objects, grouped by semester.
|
||||
|
||||
def __eq__(self, other):
|
||||
# returns true if the id attribute is equal to the other object’s id attribute.
|
||||
return self.__id == other.get_id()
|
||||
|
||||
def get_id(self):
|
||||
# returns the id for this programme.
|
||||
return self.__id
|
||||
|
||||
def get_name(self):
|
||||
# returns the name for this programme.
|
||||
return self.__name
|
||||
|
||||
def get_modules(self):
|
||||
# returns Module dictionary object which contains module list of all semesters
|
||||
return self.__modules
|
||||
|
||||
def add_module(self, semester, module):
|
||||
# append module into list inside modules’ dictionary,
|
||||
# using semester as key.
|
||||
if semester in self.__modules:
|
||||
# module already contain semester, fall to end of function to add module into semester
|
||||
pass
|
||||
else:
|
||||
# If the semester key is not found in the dictionary,
|
||||
# an empty list will be created to store the module object, init an empty semester list literally
|
||||
self.__modules[semester]= []
|
||||
|
||||
# the semester will be available as a key after this line, append module into semester
|
||||
self.__modules[semester].append(module)
|
||||
|
||||
def get_modules_by_semester(self, semester):
|
||||
# returns Module list object from modules dictionary, using semester as key
|
||||
return self.__modules[semester]
|
||||
|
||||
@staticmethod
|
||||
def fetchall(db):
|
||||
# overrides the parent class fetchall abstract static method to
|
||||
# create a list of Programme objects retrieved from database table programme.
|
||||
# For each of the created Programme objects,
|
||||
# The modules belongs to the particular programme
|
||||
|
||||
output = []
|
||||
temp= {}
|
||||
|
||||
with db.cursor() as cursor:
|
||||
cursor.execute(f"USE {constants.DB_NAME};")
|
||||
query = '''
|
||||
SELECT programme_id, mapping_semester, module_id, programme_name, module_name, module_credit
|
||||
FROM programmes
|
||||
INNER JOIN mappings ON programmes.programme_id = mappings.mapping_programme_id
|
||||
INNER JOIN modules ON mappings.mapping_module_id = modules.module_id;
|
||||
'''
|
||||
cursor.execute(query)
|
||||
records = cursor.fetchall()
|
||||
|
||||
# row => module, bloat modules
|
||||
for row in records:
|
||||
programme_id = row[0]
|
||||
mapping_semester = row[1]
|
||||
module_id = row[2]
|
||||
programme_name = row[3]
|
||||
module_name = row[4]
|
||||
module_credit = row[5]
|
||||
new_module = Module(module_id, module_name, module_credit)
|
||||
|
||||
if not(programme_id in temp):
|
||||
temp[programme_id] = {'_name': programme_name}
|
||||
if not(mapping_semester in temp[programme_id] ):
|
||||
temp[programme_id][mapping_semester] = []
|
||||
|
||||
temp[programme_id][mapping_semester].append(new_module)
|
||||
|
||||
for programme_id in temp.keys():
|
||||
new_program = Programme(programme_id, temp[programme_id]['_name'])
|
||||
# semester
|
||||
for semester in temp[programme_id].keys():
|
||||
if (type(semester) == type(1)):
|
||||
modules_in_semester = temp[programme_id][semester]
|
||||
for module in modules_in_semester:
|
||||
new_program.add_module(semester, module)
|
||||
|
||||
output.append(new_program)
|
||||
|
||||
return output
|
||||
|
||||
class Module(MySQLObject):
|
||||
def __init__(self, id, name, credit):
|
||||
# initialize the id, name and credit attributes
|
||||
self.__id = id # a non-public string to store the id of the module
|
||||
self.__name = name # a non-public string to store the name of the module
|
||||
self.__credit = credit # a non-public integer to store the credit of the module
|
||||
|
||||
def __eq__(self, other):
|
||||
# returns true of the id attribute is equal to the other object’s id attribute
|
||||
if (hasattr(other,'get_id')):
|
||||
return self.__id == other.get_id()
|
||||
else:
|
||||
return False
|
||||
|
||||
def get_id(self):
|
||||
# returns the id for this module
|
||||
return self.__id
|
||||
|
||||
def get_name(self):
|
||||
# returns the name for this module
|
||||
return self.__name
|
||||
|
||||
def get_credit(self):
|
||||
# returns the credit for this module
|
||||
return self.__credit
|
||||
|
||||
@staticmethod
|
||||
def fetchall(db):
|
||||
# fetchall overrides the parent class fetchall abstract static method to
|
||||
# return a list of Module objects retrieved from database table module.
|
||||
# Module objects will be created and appended into the
|
||||
# returned list for every records retrieved from database.
|
||||
query = "select module_id, module_name, module_credit from modules"
|
||||
output = []
|
||||
|
||||
with db.cursor() as cursor:
|
||||
cursor.execute(f"USE {constants.DB_NAME};")
|
||||
cursor.execute(query)
|
||||
records = cursor.fetchall()
|
||||
for row in records:
|
||||
module_id = row[0]
|
||||
module_name = row[1]
|
||||
module_credit = row[2]
|
||||
output.append(Module(module_id, module_name, module_credit))
|
||||
|
||||
return output
|
11
daniel_jo/ITP4459_assignment_2023/src/python/readme.md
Normal file
11
daniel_jo/ITP4459_assignment_2023/src/python/readme.md
Normal file
@@ -0,0 +1,11 @@
|
||||
```batch
|
||||
|
||||
# start docker
|
||||
docker compose up -d
|
||||
|
||||
pipenv shell
|
||||
|
||||
# inside shell
|
||||
./run.bat
|
||||
|
||||
```
|
10
daniel_jo/ITP4459_assignment_2023/src/python/run.bat
Normal file
10
daniel_jo/ITP4459_assignment_2023/src/python/run.bat
Normal file
@@ -0,0 +1,10 @@
|
||||
@REM feed
|
||||
@REM python ./main_db.py
|
||||
python "./main_gui.py"
|
||||
|
||||
@REM python ./test_combobox.py
|
||||
|
||||
@REM python .\options_test.py
|
||||
@REM python ".\models.py"
|
||||
|
||||
@REM python ".\test_models.py"
|
92
daniel_jo/ITP4459_assignment_2023/src/python/widgets.py
Normal file
92
daniel_jo/ITP4459_assignment_2023/src/python/widgets.py
Normal file
@@ -0,0 +1,92 @@
|
||||
import tkinter
|
||||
from constants import GPA_MAPPING
|
||||
import tkinter as tk
|
||||
import tkinter.ttk as ttk
|
||||
from pprint import pprint
|
||||
|
||||
# widgets.py - Implements a custom GUI widget 'ModuleWidget'
|
||||
# TODO: Remove all 'pass' statements and complete the implementation based on class description
|
||||
|
||||
class ModuleWidget:
|
||||
"""A supplier class for displaying a module and returning the GPA value.
|
||||
"""
|
||||
def __init__(self, master, command):
|
||||
self.__module = None
|
||||
self.__command = command
|
||||
self.__gpa = -1
|
||||
|
||||
self.setup_ui(master)
|
||||
self.set_module(None)
|
||||
|
||||
def set_module(self, module = None):
|
||||
if (module != None):
|
||||
# TODO: When module is provided:
|
||||
# - Update UI to display module information
|
||||
# - Enable option menu
|
||||
|
||||
self.__var_name.set(module.get_name())
|
||||
self.__var_credit.set(module.get_credit())
|
||||
self.__ent_name['state'] = 'readonly'
|
||||
self.__ent_credit['state'] = 'readonly'
|
||||
self.__om_grade['state'] = 'readonly'
|
||||
|
||||
else:
|
||||
# - Clear entry content
|
||||
# - Disable option menu
|
||||
self.__var_name.set('')
|
||||
self.__var_credit.set('')
|
||||
self.__ent_name['state'] = 'disabled'
|
||||
self.__ent_credit['state'] = 'disabled'
|
||||
self.__om_grade['state'] = 'disabled'
|
||||
|
||||
# Finally, update self.__module
|
||||
self.__module = module
|
||||
|
||||
def get_module(self):
|
||||
return self.__module
|
||||
|
||||
def get_frame(self):
|
||||
return self.__frame
|
||||
|
||||
def get_gpa(self):
|
||||
return self.__gpa
|
||||
|
||||
def setup_ui(self, master):
|
||||
# Variables
|
||||
|
||||
# Contianer
|
||||
self.__frame = tkinter.Frame(master)
|
||||
# pprint(self)
|
||||
|
||||
# Module name
|
||||
tkinter.Label(self.__frame, text = "Module", ).grid(row=0, column=0, padx=(0, 4), sticky=tkinter.W)
|
||||
self.__var_name = tkinter.StringVar(value="")
|
||||
self.__ent_name = ttk.Entry(self.__frame, textvariable=self.__var_name)
|
||||
self.__ent_name.config(width=50)
|
||||
self.__ent_name.grid(row=0, column=1, padx=(4, 4), sticky=tkinter.E+tkinter.W)
|
||||
|
||||
# Module credit
|
||||
tkinter.Label(self.__frame, text = "Credit", ).grid(row=0, column=2, padx=(0, 4), sticky=tkinter.W)
|
||||
self.__var_credit = tkinter.StringVar(value="")
|
||||
self.__ent_credit = ttk.Entry(self.__frame, textvariable=self.__var_credit)
|
||||
self.__ent_credit['state'] = 'disabled'
|
||||
self.__ent_credit.config(width=5)
|
||||
self.__ent_credit.grid(row=0, column=3, padx=(4, 4), sticky=tkinter.E+tkinter.W)
|
||||
|
||||
# Grade
|
||||
tkinter.Label(self.__frame, text = "Grade", ).grid(row=0, column=4, padx=(0, 4), sticky=tkinter.W)
|
||||
self.__var_grade = tk.StringVar()
|
||||
self.__om_grade = ttk.Combobox(self.__frame, textvariable=self.__var_grade)
|
||||
self.__om_grade.set('Please select')
|
||||
self.__om_grade['values'] = [gpa for gpa in GPA_MAPPING.keys()]
|
||||
self.__om_grade['state'] = 'disabled'
|
||||
self.__om_grade.config(width=15)
|
||||
self.__om_grade.grid(row=0, column=5, padx=(0, 4), sticky=tkinter.W)
|
||||
self.__om_grade.bind('<<ComboboxSelected>>', self.on_grade_changed)
|
||||
|
||||
def on_grade_changed(self, _):
|
||||
# Get GPA based on combo box value
|
||||
letter_grade = list(GPA_MAPPING.keys())[self.__om_grade.current()]
|
||||
num_grade = GPA_MAPPING[letter_grade]
|
||||
self.__gpa = num_grade
|
||||
self.__command()
|
16
daniel_jo/ITP4459_assignment_2023/src/readme.md
Normal file
16
daniel_jo/ITP4459_assignment_2023/src/readme.md
Normal file
@@ -0,0 +1,16 @@
|
||||
```bash
|
||||
cd docker
|
||||
docker compose build
|
||||
docker compose up -d
|
||||
cd ..
|
||||
|
||||
# after docker up and running
|
||||
cd python
|
||||
pipenv shell
|
||||
pipenv sync
|
||||
|
||||
# inside pip environment
|
||||
python main_db.py
|
||||
python main_gui.py
|
||||
|
||||
```
|
19
daniel_jo/ITP4459_assignment_2023/src/scripts/dev.ps1
Normal file
19
daniel_jo/ITP4459_assignment_2023/src/scripts/dev.ps1
Normal file
@@ -0,0 +1,19 @@
|
||||
pushd docker
|
||||
|
||||
docker-compose pull
|
||||
|
||||
docker-compose build
|
||||
|
||||
docker-compose kill
|
||||
docker-compose down
|
||||
timeout 1
|
||||
|
||||
rmdir docker\volumes
|
||||
|
||||
docker-compose up -d
|
||||
|
||||
# docker-compose logs -f
|
||||
|
||||
# docker-compose exec -it ubuntu bash
|
||||
|
||||
popd
|
Reference in New Issue
Block a user