-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4d17de8
Showing
6 changed files
with
372 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import sys | ||
import os | ||
import random | ||
from PyQt5.QtWidgets import QApplication, QMainWindow | ||
from PyQt5.uic import loadUi | ||
from PyQt5.QtGui import QIntValidator, QIcon | ||
from PyQt5.QtCore import Qt | ||
|
||
|
||
def resource_path(relative_path): | ||
""" Get absolute path to resource, works for dev and for PyInstaller """ | ||
try: | ||
# PyInstaller creates a temp folder and stores path in _MEIPASS | ||
base_path = sys._MEIPASS | ||
except Exception: | ||
base_path = os.path.abspath(".") | ||
return os.path.join(base_path, relative_path) | ||
|
||
|
||
ICON_FILE = resource_path('icon.png') | ||
UI_FILE = resource_path('main.ui') | ||
|
||
|
||
class Main(QMainWindow): | ||
def __init__(self): | ||
super(Main, self).__init__() | ||
loadUi(UI_FILE, self) | ||
self.setWindowTitle("Divide students!") | ||
self.setWindowIcon(QIcon(ICON_FILE)) | ||
self.setFixedWidth(724) | ||
self.setFixedHeight(461) | ||
|
||
# TeamCount | ||
self.teamCount.setValidator(QIntValidator()) | ||
self.teamCount.setMaxLength(2) | ||
self.teamCount.setAlignment(Qt.AlignRight) | ||
self.teamCount.setText("0") | ||
|
||
# MemberCount | ||
self.memberCount.setValidator(QIntValidator()) | ||
self.memberCount.setMaxLength(2) | ||
self.memberCount.setAlignment(Qt.AlignRight) | ||
self.memberCount.setText("2") | ||
self.studentsCount.setText("1") | ||
|
||
self.results.setReadOnly(True) | ||
self.studentsCount.setReadOnly(True) | ||
|
||
self.processButton.clicked.connect(self.DoTheThing) | ||
self.studentsList.textChanged.connect(self.studentsListChanged) | ||
|
||
def studentsListChanged(self): | ||
people = self.studentsList.toPlainText() | ||
people = people.split('\n') | ||
number_people = len(people) | ||
self.studentsCount.setText(str(number_people)) | ||
|
||
def DoTheThing(self): | ||
self.results.clear() | ||
people = self.studentsList.toPlainText() | ||
people = people.split('\n') | ||
number_people = len(people) | ||
number_of_members = int(self.memberCount.text()) | ||
number_of_teams = int(self.teamCount.text()) | ||
if number_of_teams == 0: | ||
number_of_teams = int(number_people/number_of_members) | ||
while number_people > 0 and number_of_members > 0: | ||
if number_people < number_of_members: | ||
team = random.sample(people, number_people) | ||
self.results.appendPlainText( | ||
' - '.join([str(elem) for elem in team])) | ||
for x in team: | ||
people.remove(x) | ||
else: | ||
team = random.sample(people, number_of_members) | ||
self.results.appendPlainText( | ||
' - '.join([str(elem) for elem in team])) | ||
for x in team: | ||
people.remove(x) | ||
number_people -= int(number_of_members) | ||
number_of_teams -= 1 | ||
elif number_of_members == 0: | ||
number_of_members = int(number_people/number_of_teams) | ||
while number_people > 0: | ||
if number_people < number_of_members: | ||
team = random.sample(people, number_people) | ||
self.results.appendPlainText( | ||
' - '.join([str(elem) for elem in team])) | ||
for x in team: | ||
people.remove(x) | ||
else: | ||
team = random.sample(people, number_of_members) | ||
self.results.appendPlainText( | ||
' - '.join([str(elem) for elem in team])) | ||
for x in team: | ||
people.remove(x) | ||
number_people -= int(number_of_members) | ||
number_of_teams -= 1 | ||
else: | ||
while number_people > 0 and number_of_teams > 0: | ||
if number_people < number_of_members: | ||
team = random.sample(people, number_people) | ||
self.results.appendPlainText( | ||
' - '.join([str(elem) for elem in team])) | ||
for x in team: | ||
people.remove(x) | ||
else: | ||
team = random.sample(people, number_of_members) | ||
self.results.appendPlainText( | ||
' - '.join([str(elem) for elem in team])) | ||
for x in team: | ||
people.remove(x) | ||
number_people -= int(number_of_members) | ||
number_of_teams -= 1 | ||
|
||
|
||
app = QApplication(sys.argv) | ||
app.setWindowIcon(QIcon(ICON_FILE)) | ||
mainwidnow = Main() | ||
mainwidnow.show() | ||
sys.exit(app.exec_()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#sudentsDvider |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>MainWindow</class> | ||
<widget class="QMainWindow" name="MainWindow"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>724</width> | ||
<height>460</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>MainWindow</string> | ||
</property> | ||
<widget class="QWidget" name="centralwidget"> | ||
<widget class="QPlainTextEdit" name="studentsList"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>10</x> | ||
<y>30</y> | ||
<width>261</width> | ||
<height>351</height> | ||
</rect> | ||
</property> | ||
<property name="font"> | ||
<font> | ||
<pointsize>18</pointsize> | ||
</font> | ||
</property> | ||
</widget> | ||
<widget class="QLineEdit" name="teamCount"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>320</x> | ||
<y>390</y> | ||
<width>41</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="font"> | ||
<font> | ||
<pointsize>12</pointsize> | ||
<bold>false</bold> | ||
</font> | ||
</property> | ||
<property name="text"> | ||
<string>2</string> | ||
</property> | ||
</widget> | ||
<widget class="QLabel" name="studentsLabel"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>10</x> | ||
<y>10</y> | ||
<width>81</width> | ||
<height>21</height> | ||
</rect> | ||
</property> | ||
<property name="font"> | ||
<font> | ||
<pointsize>16</pointsize> | ||
</font> | ||
</property> | ||
<property name="text"> | ||
<string>Students:</string> | ||
</property> | ||
</widget> | ||
<widget class="QLabel" name="teamcountLabel"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>210</x> | ||
<y>390</y> | ||
<width>101</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="font"> | ||
<font> | ||
<pointsize>16</pointsize> | ||
<italic>false</italic> | ||
</font> | ||
</property> | ||
<property name="text"> | ||
<string>Team count:</string> | ||
</property> | ||
</widget> | ||
<widget class="QLineEdit" name="memberCount"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>520</x> | ||
<y>390</y> | ||
<width>41</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="font"> | ||
<font> | ||
<pointsize>12</pointsize> | ||
</font> | ||
</property> | ||
<property name="text"> | ||
<string>2</string> | ||
</property> | ||
</widget> | ||
<widget class="QPushButton" name="processButton"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>610</x> | ||
<y>390</y> | ||
<width>91</width> | ||
<height>41</height> | ||
</rect> | ||
</property> | ||
<property name="styleSheet"> | ||
<string notr="true">QPushButton { | ||
background-color: #555555; /* Green */ | ||
border: none; | ||
color: white; | ||
text-align: center; | ||
text-decoration: none; | ||
display: inline-block; | ||
font-size: 16px; | ||
} | ||
QPushButton:hover { | ||
background-color: #797979; /* Green */ | ||
color: white; | ||
}</string> | ||
</property> | ||
<property name="text"> | ||
<string>Process!</string> | ||
</property> | ||
</widget> | ||
<widget class="QPlainTextEdit" name="results"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>290</x> | ||
<y>30</y> | ||
<width>411</width> | ||
<height>351</height> | ||
</rect> | ||
</property> | ||
<property name="font"> | ||
<font> | ||
<pointsize>18</pointsize> | ||
</font> | ||
</property> | ||
</widget> | ||
<widget class="QLabel" name="resultsLabel"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>290</x> | ||
<y>10</y> | ||
<width>71</width> | ||
<height>21</height> | ||
</rect> | ||
</property> | ||
<property name="font"> | ||
<font> | ||
<pointsize>16</pointsize> | ||
</font> | ||
</property> | ||
<property name="text"> | ||
<string>Results:</string> | ||
</property> | ||
</widget> | ||
<widget class="QLabel" name="memberCount_2"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>390</x> | ||
<y>390</y> | ||
<width>121</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="font"> | ||
<font> | ||
<pointsize>16</pointsize> | ||
<italic>false</italic> | ||
</font> | ||
</property> | ||
<property name="text"> | ||
<string>Member count:</string> | ||
</property> | ||
</widget> | ||
<widget class="QLabel" name="studentsCountLabel"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>10</x> | ||
<y>390</y> | ||
<width>121</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="font"> | ||
<font> | ||
<pointsize>16</pointsize> | ||
<italic>false</italic> | ||
</font> | ||
</property> | ||
<property name="text"> | ||
<string> Students count:</string> | ||
</property> | ||
</widget> | ||
<widget class="QLineEdit" name="studentsCount"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>140</x> | ||
<y>390</y> | ||
<width>41</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="font"> | ||
<font> | ||
<pointsize>12</pointsize> | ||
<bold>false</bold> | ||
</font> | ||
</property> | ||
<property name="text"> | ||
<string>0</string> | ||
</property> | ||
</widget> | ||
</widget> | ||
<widget class="QStatusBar" name="statusbar"/> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
""" | ||
This is a setup.py script generated by py2applet | ||
Usage: | ||
python setup.py py2app | ||
""" | ||
|
||
from setuptools import setup | ||
|
||
APP = ['DivideStudents.py'] | ||
DATA_FILES = ['icon.png', 'main.ui'] | ||
OPTIONS = { | ||
'iconfile': './icon.icns', | ||
} | ||
|
||
setup( | ||
app=APP, | ||
data_files=DATA_FILES, | ||
options={'py2app': OPTIONS}, | ||
setup_requires=['py2app'], | ||
) |