-
Notifications
You must be signed in to change notification settings - Fork 1
/
RevAssign.py
executable file
·1248 lines (999 loc) · 45.8 KB
/
RevAssign.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
"""
Author: Nicholas Zwart, Jim Pipe
Date: 2011dec19
Summary: User interface for the ISMRM AMPC Reviewer Assignment app.
Specifications:
http://www.ismrm.org/12/7T.pdf
References:
"PyQt by Example"
http://lateral.netmanagers.com.ar/stories/BBS47.html
"""
__authors__ = ["Nick Zwart","Jim Pipe"]
__date__ = "2011dec19"
import os
import sys
import time
# Import Qt modules
from PyQt5 import QtCore,QtGui, QtWidgets
# Import the compiled UI module
from windowUi import Ui_MainWindow
# Import the backend data containers
import backend
# correct the numeric sorting for specified columns of the category list
class cat_TreeWidgetItem(QtWidgets.QTreeWidgetItem):
def __init__(self, parent=None):
QtWidgets.QTreeWidgetItem.__init__(self, parent)
def __lt__(self, otherItem):
column = self.treeWidget().sortColumn()
if column == 2 or column == 3 or column == 4:
return float( self.text(column) ) < float( otherItem.text(column) )
elif column == 0:
cur_s = str(self.text(column))
other_s = str(otherItem.text(column))
cur_l = None # A or B
other_l = None # A or B
# get the underlying number for current
if cur_s.isdigit():
cur = float( cur_s )
else:
cur_l = cur_s[-1] # remove letter
cur = float( cur_s[0:-1] )
# get the underlying number for other
if other_s.isdigit():
other = float( other_s )
else:
other_l = other_s[-1] # remove letter
other = float( other_s[0:-1] )
# compare letters if they have the same base
if cur == other:
return cur_l < other_l
else:
return cur < other
else:
return self.text(column) < otherItem.text(column)
# correct the numeric sorting for specified columns of the reviewer list
class rev_TreeWidgetItem(QtWidgets.QTreeWidgetItem):
def __init__(self, parent=None, parent_obj=None):
QtWidgets.QTreeWidgetItem.__init__(self, parent)
# ref to parent class
self.parent = parent_obj
# if contents passed then decorate for sorting
self.dlist = []
self.dlist.append(int(parent[0])) # member #
for i in range(1,12):
self.dlist.append(str(parent[i]))
for i in range(12,18):
self.dlist.append(int(parent[i]))
self.dlist.append(str(parent[18]))
# color
c1 = 240
c2 = 230
c3 = 220
c4 = 210
c5 = 200
self.hghlghtColor = [QtGui.QColor(255,255,255),QtGui.QColor(c1,c1,c1),QtGui.QColor(c2,c2,c2),QtGui.QColor(c3,c3,c3),QtGui.QColor(c4,c4,c4),QtGui.QColor(c5,c5,c5),QtGui.QColor(128,0,0,alpha=128)]
# set columns to be colorized based on sort
self.totalCol = self.parent.ui.revlist.columnCount()
self.firstcol = 1 # zero column doesn't work for some reason
self.colRange = range(self.firstcol,self.totalCol)
# choice column range
# -choices are in columns 12,13,14,15,16
self.choices = range(12,17)
# current color
# 0:white, 1:light grey, ... 5:dark grey
self.cur_color = 0
self.new_color = 0
# get handle to header and tree widgets
self.tw = self.parent.ui.revlist
self.hdr= self.parent.ui.revlist.header()
self.getZeroColBrush()
self.setAllBrushes()
def getZeroColBrush(self):
self.brush = self.background(0)
def setAllBrushes(self):
'''propagates colors to other items'''
# set all other brushes to the same one
self.brush = self.background(1)
#for col in self.colRange:
for col in range(0,self.totalCol):
self.setBackground(col,self.brush)
def __lt__(self, otherItem):
# faster column refs
# this would be faster if sortCol and sortInd could be known prior to __lt__()
column = self.tw.sortColumn()
sortInd = self.hdr.sortIndicatorOrder()
# if the key exists
if self.parent.cur_catkey and self.parent.rev_sortByChoice:
# regardless of chosen column to sort on, always push common categories to the top
# first check current item
match_cur = False
choice_cur = -1
for i in self.choices:
if float(self.text(i)) == self.parent.cur_catkey_num:
choice_cur = i
self.new_color = i-11
match_cur = True
break # no need to check the rest
# second check other item
match_other = False
choice_other = -1
for i in self.choices:
if float(otherItem.text(i)) == self.parent.cur_catkey_num:
choice_other = i
otherItem.new_color = i-11
match_other = True
break # no need to check the rest
# if they both have matches then sort by choice
if match_cur and match_other:
if choice_other == choice_cur:
# normal sorting
if column == 0 or column == 12 or column == 13 or column == 14 or column == 15 or column == 16 or column == 17:
return float( self.text(column) ) < float( otherItem.text(column) )
else:
return self.text(column) < otherItem.text(column)
else:
# sort on choice prio
if sortInd == 0:
return choice_cur < choice_other
else:
return choice_cur > choice_other
# if one of them matches then it is the priority
if match_cur or match_other:
# always put category sorting on top
if sortInd == 1:
return match_cur < match_other
else:
return match_cur > match_other
# reset to white
self.new_color = 0
otherItem.new_color = 0
# normal sorting
if column == 0 or column == 12 or column == 13 or column == 14 or column == 15 or column == 16 or column == 17:
return float( self.text(column) ) < float( otherItem.text(column) )
else:
return self.text(column) < otherItem.text(column)
# Create a class for our main window
class Main(QtWidgets.QMainWindow):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
# This is always the same
self.ui=Ui_MainWindow()
self.ui.setupUi(self)
# initialize window title
self.setWindowTitle('ISMRM AMPC Reviewer Assignments')
self.status = self.ui.statusbar # get handle
self.progress = QtWidgets.QProgressBar(self.statusBar())
self.status.addPermanentWidget(self.progress)
self.hide_progress_bar()
# init the local data
# instantiate a local copy of the AMPC-chair workbook data
self.chair = backend.AMPCchair_data()
self.rev_items = [] # list of all item refs
self.cat_items = [] # list of all item refs
self.cur_cat_item = None # the cat item currently checked
self.disableRevItemChanged = False
self.disableCatItemChanged = False
self.sessionActive = False
self.cur_catkey = None
self.cur_catkey_num = None # for speeding up sort
self.cur_revkey = None
self.rev_sortByChoice = True
self.rev_colorized = True
self.cur_rev_sortIndicator = 0
self.rev_header = self.ui.revlist.header()
self.rev_abs_warnThresh = 56
self.cat_abs_warnThresh = 5
self.rev_minimum_nr_of_abstracts = 20
self.cat_maximum_nr_of_revs = 8
self.ui.revlist.header().sortIndicatorChanged.connect(self.revlist_header_sortIndicatorChanged)
# default column
self.cur_rev_col = 1
self.cur_cat_col = 1
self.sortMsg = 'sorting items...'
# speedups
#self.ui.catlist.scheduleDelayedItemsLayout()
#self.ui.revlist.scheduleDelayedItemsLayout()
# status
self.update_status('ready')
def setCurCatKey(self,string):
'''set key and numeric equiv'''
# set current dictionary key
self.cur_catkey = string
# change key to digit
if self.cur_catkey.isdigit():
self.cur_catkey_num = int(float(self.cur_catkey))
else:
# strip off A or B suffix
self.cur_catkey_num = int(float(self.cur_catkey[0:-1]))
def loadItems(self):
self.update_status('loading items...')
# don't draw new info to screen
self.disableListUpdates()
# init the list widget for reviewer info
for k in self.chair.reviewers.keys():
# create item from row info based on key
item = self.createRevItem(k)
# init to unchecked, adds an unchecked box to the left of each entry
item.setCheckState(0,QtCore.Qt.Unchecked)
# place item in widget list
self.ui.revlist.addTopLevelItem(item)
# select this one
item.setSelected(1)
# init the list widget for category info
for k in self.chair.categories.keys():
# create item from row info
item = self.createCatItem(k)
# init to unchecked, adds an unchecked box to the left of each entry
item.setCheckState(0,QtCore.Qt.Unchecked)
# place item in widget list
self.ui.catlist.addTopLevelItem(item)
# select this one
item.setSelected(1)
# build list of cat-item references
cur_item = self.ui.catlist.itemAt(0,0)
self.cat_items = [] # clear list before rebuild
self.cat_items.append(cur_item)
while self.ui.catlist.itemBelow(cur_item):
cur_item = self.ui.catlist.itemBelow(cur_item)
self.cat_items.append(cur_item)
# build list of rev-item references
cur_item = self.ui.revlist.itemAt(0,0)
self.rev_items = [] # clear list before rebuild
self.rev_items.append(cur_item)
while self.ui.revlist.itemBelow(cur_item):
cur_item = self.ui.revlist.itemBelow(cur_item)
self.rev_items.append(cur_item)
# do initial sort based on default column
self.update_status(self.sortMsg)
# sort categories first
self.ui.catlist.sortItems(0,0)
# select the first item
cur_item = self.ui.catlist.itemAt(0,0)
self.ui.catlist.setCurrentItem(cur_item)
cur_item.setSelected(self.cur_cat_col)
# set the first item as cat_key
self.setCurCatKey(str(cur_item.text(0)))
self.disableCatItemChanged = True
cur_item.setCheckState(0,QtCore.Qt.Checked)
self.disableCatItemChanged = False
self.cur_cat_item = cur_item #save this item for display updates (refreshDisplay())
# make sure initial checkboxes are set
self.disableRevItemChanged = True
for item in self.rev_items:
key = item.text(0) #reviewer keys from displayed rows
# get associated cat list for current reviewer
assoc = self.chair.reviewers[str(key)][18]
# if the current cat matches any of the associated cat's
# then mark as checked
try:
assoc.index(self.cur_catkey) # if it matches then continue
item.setCheckState(0,QtCore.Qt.Checked)
except:
item.setCheckState(0,QtCore.Qt.Unchecked)
self.disableRevItemChanged = False
# now sort the revlist based on current selected cat_key
self.ui.revlist.sortItems(0,0) # resort based on key
# unselect any selected items
items = self.ui.revlist.selectedItems() # loadItems()
if len(items) > 0:
items[0].setSelected(False) #unselect
# select top item
cur_item = self.ui.revlist.itemAt(0,0)
self.ui.revlist.setCurrentItem(cur_item)
cur_item.setSelected(self.cur_rev_col)
self.cur_revkey = str(cur_item.text(0))
# redraw new info to screen
self.enableListUpdates()
# update item color
self.refreshItemColor_rev()
def deleteAllItems(self):
'''Build lists and then use them to remove all items.'''
# status
self.update_status('clearing memory...')
# this doesn't seem to correctly remove widget items
#self.ui.revlist.clear()
#self.ui.catlist.clear()
self.disableListUpdates()
self.update_status('clearing memory... (categories)')
self.removeItemsFromList(self.ui.catlist,self.listItemsInTree(self.ui.catlist))
self.update_status('clearing memory... (reviewers)')
st = time.time()
self.removeItemsFromList(self.ui.revlist,self.listItemsInTree(self.ui.revlist))
print("revlist removal time: "+str(time.time()-st))
self.enableListUpdates()
def listItemsInTree(self,tree):
# build list of cat-item references
itemlst = []
cur_item = tree.itemAt(0,0)
itemlst.append(cur_item)
while tree.itemBelow(cur_item):
cur_item = tree.itemBelow(cur_item)
itemlst.append(cur_item)
return(itemlst)
def refreshItemColor_rev(self):
'''redraw item colors'''
# stop list updates
self.disableRevItemChanged = True
self.ui.revlist.setDisabled(True)
# status
self.update_status(self.sortMsg)
#cnt = float(self.ui.revlist.topLevelItemCount())
cnt = len(self.rev_items)
# go through all items
# might have to get full list here first,
# then update each item in the list
i = 0
for cur_item in self.rev_items:
if self.rev_colorized:
self.toggleColor(cur_item)
else:
self.setColorToWhite(cur_item)
# status
i += 1
if i % 10 == 0:
self.update_progress(i,cnt)
self.status.clearMessage()
self.hide_progress_bar()
self.disableRevItemChanged = False
self.ui.revlist.setDisabled(False)
def update_progress(self, cur, total):
self.progress.show()
self.progress.setRange(0, total)
self.progress.setValue(cur)
QtWidgets.QApplication.processEvents() # allow gui to update
def update_status(self, mesg):
self.status.showMessage(mesg)
QtWidgets.QApplication.processEvents() # allow gui to update
def hide_progress_bar(self):
self.progress.hide()
QtWidgets.QApplication.processEvents() # allow gui to update
def setHlght_AbsOverload(self,item):
'''change color to light red if reviewer is or will be over the limit
if added to current category
'''
item_key = str(item.text(0))
# if the reviewer alone already has been assigned too many abs, then warn
abs_total = float(self.chair.reviewers[item_key][17])
if abs_total > self.rev_abs_warnThresh:
col = 1
item.setBackground(col,item.hghlghtColor[6])
item.setAllBrushes()
item.cur_color = 6
return
# first check that the item isn't already assigned to the current category
# then warn if the rev's current abs total + current cat abs is too many
try:
self.chair.reviewers[item_key][18].index(self.cur_catkey)
return # don't do anything
except:
abs_total = float(self.chair.reviewers[item_key][17]) + float(self.chair.categories[self.cur_catkey][2])
if abs_total > self.rev_abs_warnThresh:
col = 1
item.setBackground(col,item.hghlghtColor[6])
item.setAllBrushes()
item.cur_color = 6
def setColorToWhite(self,item):
'''change item color based on internal color flags'''
# set to white
item.new_color = 0
# only address if needed
if item.cur_color != item.new_color:
# for each column, change the color
#for col in item.colRange:
col = 1
#for col in item.colRange:
item.setBackground(col,item.hghlghtColor[item.new_color])
#item.brush.setColor(item.hghlghtColor[item.new_color])
item.setAllBrushes()
# set current color
item.cur_color = item.new_color
# check if warning should be set
self.setHlght_AbsOverload(item)
def toggleColor(self,item):
'''change item color based on internal color flags'''
# only address if needed
if item.cur_color != item.new_color:
# for each column, change the color
col = 1
#for col in item.colRange:
item.setBackground(col,item.hghlghtColor[item.new_color])
#item.brush.setColor(item.hghlghtColor[item.new_color])
item.setAllBrushes()
# set current color
item.cur_color = item.new_color
# check if warning should be set
self.setHlght_AbsOverload(item)
def removeItemsFromList(self,tree,inlist):
print('itemcnt:'+str(tree.topLevelItemCount()))
cnt = tree.topLevelItemCount()
tree.clear()
#for i in range(0,cnt):
# tree.takeTopLevelItem(0)
# self.update_progress(i,cnt)
self.hide_progress_bar()
# create a display item
def createCatItem(self, key):
'''write the category info to the QTreeWidgetItem '''
# ensure each item is a string
tmp_list = [ str(item) for item in self.chair.categories[key] ]
# create an item for list in widget
item = cat_TreeWidgetItem(tmp_list)
return(item)
# create a display item
def createRevItem(self, key):
'''write the reviewer info to the QTreeWidgetItem '''
# ensure each item is a string
tmp_list = [ str(item) for item in self.chair.reviewers[key] ]
# create an item for list in widget
item = rev_TreeWidgetItem(tmp_list,self)
return(item)
def on_catlist_itemChanged(self,cur=None,col=None):
''' set current key for category based on row selection '''
if not self.sessionActive: return
if self.disableCatItemChanged: return
# only care if checkbox has changed
if col == 0:
print("catlist changed")
# if it was unchecked, then re-check it
if not cur.checkState(0):
self.disableCatItemChanged = True
cur.setCheckState(0,QtCore.Qt.Checked)
self.disableCatItemChanged = False
return
# if the checkbox is selected
if cur.checkState(0):
# ensure that no other checkboxes are on
# turn off all other non-selected boxes
self.disableCatItemChanged = True
for i in self.cat_items:
if i != cur:
i.setCheckState(0,QtCore.Qt.Unchecked)
self.disableCatItemChanged = False
# save current refs
self.cur_cat_item = cur
self.setCurCatKey(str(cur.text(0)))
# prevent on_revlist_itemChanged() from triggering
# don't update display
self.disableRevItemChanged = True
#self.disableListUpdates()
self.ui.revlist.setDisabled(True)
# whenever the category selection is changed,
# the appropriate reviewers need to be checked.
# So this will go through the items in QTreeWidget(revlist)
# and compare to list in dict(categories), matching keys will
# cause checked boxes and non-matching will cause unchecked boxes
st = time.time()
for item in self.rev_items:
key = item.text(0) #reviewer keys from displayed rows
# get associated cat list for current reviewer
assoc = self.chair.reviewers[str(key)][18]
# if the current cat matches any of the associated cat's
# then mark as checked
try:
assoc.index(self.cur_catkey) # if it matches then continue
item.setCheckState(0,QtCore.Qt.Checked)
except:
item.setCheckState(0,QtCore.Qt.Unchecked)
# initiate sort on current column using current ordering
if self.rev_sortByChoice:
st = time.time()
self.update_status(self.sortMsg)
self.ui.revlist.sortItems(self.ui.revlist.header().sortIndicatorSection(),self.ui.revlist.header().sortIndicatorOrder())
print(" -sort time: "+str(time.time()-st))
# select first item
#cur_item = self.ui.revlist.itemAt(0,0)
#cur_item.setSelected(self.ui.revlist.header().sortIndicatorSection())
#self.ui.revlist.setCurrentItem(cur_item)
# redraw color
st = time.time()
self.refreshItemColor_rev()
print(" -re-color time: "+str(time.time()-st))
# allow update of display
#self.enableListUpdates()
self.ui.revlist.setDisabled(False)
self.disableRevItemChanged = False
# focus on first rev item
# get current selected item
items = self.ui.revlist.selectedItems() # on_catlist_itemChanged()
if len(items) > 0:
items[0].setSelected(False) #unselect
cur_item = self.ui.revlist.itemAt(0,0)
cur_item.setSelected(self.ui.revlist.header().sortIndicatorSection())
self.ui.revlist.setCurrentItem(cur_item)
def on_revlist_itemSelectionChanged(self):
''' set current key for reviewer based on row selection '''
# check sort indicator status and store
#self.cur_rev_sortIndicator = self.ui.revlist.header().sortIndicatorOrder()
#self.cur_rev_col = self.ui.revlist.sortColumn()
if self.sessionActive:
items = self.ui.revlist.selectedItems()
if len(items) > 0:# only one item selectable
self.cur_revkey = str(items[0].text(0))
def revlist_header_sortIndicatorChanged(self):#,section=None,order=None):
print("revlist_header_sortIndicatorChanged triggered")
#print section
#print order
def on_revlist_itemChanged(self,cur=None,col=None):
''' checkbox state change
-item selection always happens first, even if
-checkbox is checked on non-selected item '''
# keep from processing display updates when revlist items are changed
if self.disableRevItemChanged: return
# check sort indicator status and store
#self.cur_rev_sortIndicator = self.ui.revlist.header().sortIndicatorOrder()
#self.cur_rev_col = self.ui.revlist.sortColumn()
# only care if checkbox has changed
if col == 0:
#if True:
# for debugging
if str(cur.text(0)) == self.cur_revkey:
print("spacebar used to select or mouse on highlighted row")
else:
# shouldn't this always be the case?
self.cur_revkey = str(cur.text(0))
print("mouse checked non-highlighted row")
# if it IS checked
if cur.checkState(0):
# test category selection
try:
self.chair.categories[self.cur_catkey]
except:
print("ERROR: please choose a category")
return
# test reviewer selection
try:
self.chair.reviewers[self.cur_revkey]
except:
print("ERROR: please choose a reviewer")
return
print("item checked, col:"+str(col))
self.chair.addRev(self.cur_revkey,self.cur_catkey)
else:
print("item not checked, col:"+str(col))
self.chair.removeRev(self.cur_revkey,self.cur_catkey)
# refresh row data
self.refreshDisplay()
def disableListUpdates(self):
# disable list signals
#self.ui.catlist.setUpdatesEnabled(False)
#self.ui.revlist.setUpdatesEnabled(False)
self.ui.catlist.setDisabled(True)
self.ui.revlist.setDisabled(True)
def enableListUpdates(self):
# enable list signals
#self.ui.catlist.setUpdatesEnabled(True)
#self.ui.revlist.setUpdatesEnabled(True)
self.ui.catlist.setDisabled(False)
self.ui.revlist.setDisabled(False)
def getItemFromRevKey(self,key):
for item in self.rev_items:
if item.text(0) == key:
return item
def getItemFromCatKey(self,key):
for item in self.cat_items:
if item.text(0) == key:
return item
def refreshDisplay(self):
'''update the new tallied items in each list
i.e.:
-number of abstracts
-number of revs in this category
'''
# disable update of display
self.disableRevItemChanged = True
#self.disableListUpdates()
# display cat
#item_r = self.ui.catlist.selectedItems()[0]
item_r = self.cur_cat_item
# set # of assigned reviewers
item_r.setText(3,self.chair.categories[self.cur_catkey][3])
print(item_r.text(3))
# assigned reviewers
item_r.setText(5,str(self.chair.categories[self.cur_catkey][5]))
print(item_r.text(5))
# display rev
#item_c = self.ui.revlist.selectedItems()[0]
item_c = self.getItemFromRevKey(self.cur_revkey)
# set # of assigned reviewers
item_c.setText(17,self.chair.reviewers[self.cur_revkey][17])
item_c.dlist[17] = int(self.chair.reviewers[self.cur_revkey][17])
print(item_c.text(17))
# assigned reviewers
item_c.setText(18,str(self.chair.reviewers[self.cur_revkey][18]))
item_c.dlist[18] = str(self.chair.reviewers[self.cur_revkey][18])
print(item_c.text(18))
# update color after tables have been modified
self.toggleColor(item_c)
# allow update of display
#self.enableListUpdates()
self.disableRevItemChanged = False
def refreshDisplayAllRows(self):
'''update all items in each list
i.e.:
-number of abstracts
-number of revs in this category
'''
# disable update of display
self.disableRevItemChanged = True
# display cat
i = 0
cnt = len(self.chair.categories)
for key, cat in self.chair.categories.items():
self.update_progress(i, cnt)
item_r = self.getItemFromCatKey(key)
# set # of assigned reviewers
item_r.setText(3, cat[3])
# assigned reviewers
item_r.setText(5, str(cat[5]))
i += 1
# display rev
i = 0
cnt = len(self.chair.reviewers)
for key, rev in self.chair.reviewers.items():
self.update_progress(i, cnt)
item_c = self.getItemFromRevKey(key)
# set # of assigned reviewers
item_c.setText(17, rev[17])
item_c.dlist[17] = int(rev[17])
# assigned reviewers
item_c.setText(18,str(rev[18]))
item_c.dlist[18] = str(rev[18])
# update color after tables have been modified
self.toggleColor(item_c)
i += 1
self.hide_progress_bar()
# allow update of display
self.disableRevItemChanged = False
def on_actionAbstractLimit_triggered(self,checked=None):
# this always has to be checked for triggered actions
# to keep from running double actions
if checked is None: return
text, ok = QtWidgets.QInputDialog.getText(self,
'Maximum abstracts per reviewer',
'Maximum abstracts per reviewer (Currently: '+str(int(self.rev_abs_warnThresh))+'):')
if ok:
if str(text).isdigit():
self.ui.revlist.setDisabled(True)
self.rev_abs_warnThresh = float(text)
print("rev_abs_warnThresh set to: "+str(self.rev_abs_warnThresh))
self.refreshItemColor_rev()
self.ui.revlist.setDisabled(False)
def on_actionAbstractLowerLimit_triggered(self,checked=None):
# this always has to be checked for triggered actions
# to keep from running double actions
if checked is None: return
text, ok = QtWidgets.QInputDialog.getText(self,
'Minimum abstracts per reviewer',
'Minimum abstracts per reviewer (Currently: '+str(int(self.rev_minimum_nr_of_abstracts))+'):')
if ok:
if str(text).isdigit():
self.ui.revlist.setDisabled(True)
self.rev_minimum_nr_of_abstracts = float(text)
print("rev_minimum_nr_of_abstracts set to: "+str(self.rev_minimum_nr_of_abstracts))
self.refreshItemColor_rev()
self.ui.revlist.setDisabled(False)
def on_actionReviewerLimit_triggered(self,checked=None):
# this always has to be checked for triggered actions
# to keep from running double actions
if checked is None: return
text, ok = QtWidgets.QInputDialog.getText(self,
'Minimum reviewers per abstract',
'Minimum reviewers per abstract (Currently: '+str(int(self.cat_abs_warnThresh))+'):')
if ok:
if str(text).isdigit():
self.ui.revlist.setDisabled(True)
self.cat_abs_warnThresh = float(text)
print("cat_abs_warnThresh set to: "+str(self.cat_abs_warnThresh))
self.refreshItemColor_rev()
self.ui.revlist.setDisabled(False)
def on_actionReviewerUpperLimit_triggered(self,checked=None):
# this always has to be checked for triggered actions
# to keep from running double actions
if checked is None: return
text, ok = QtWidgets.QInputDialog.getText(self,
'Maximum reviewers per abstract',
'Maximum reviewers per abstract (Currently: '+str(int(self.cat_maximum_nr_of_revs))+'):')
if ok:
if str(text).isdigit():
self.ui.revlist.setDisabled(True)
self.cat_maximum_nr_of_revs = float(text)
print("cat_maximum_nr_of_revs set to: "+str(self.cat_maximum_nr_of_revs))
self.refreshItemColor_rev()
self.ui.revlist.setDisabled(False)
def on_actionReviewerChoice_triggered(self,checked=None):
'''toggle reviewer choice sorting'''
# this always has to be checked for triggered actions
# to keep from running double actions
if checked is None: return
# toggle sorting feature
if checked:
self.rev_sortByChoice = True
else:
self.rev_sortByChoice = False
# update item color
# something is interrupting the conversion back to white
if self.sessionActive:
self.ui.revlist.setDisabled(True)
self.ui.revlist.sortItems(self.ui.revlist.header().sortIndicatorSection(),self.ui.revlist.header().sortIndicatorOrder())
self.refreshItemColor_rev()
self.ui.revlist.setDisabled(False)
def on_actionColorize_triggered(self,checked=None):
'''toggle reviewer choice sorting'''
# this always has to be checked for triggered actions
# to keep from running double actions
if checked is None: return
# toggle sorting feature
if checked:
self.rev_colorized = True
else:
self.rev_colorized = False
# update item color
# something is interrupting the conversion back to white
if self.sessionActive:
self.ui.revlist.setDisabled(True)
self.ui.revlist.sortItems(self.ui.revlist.header().sortIndicatorSection(),self.ui.revlist.header().sortIndicatorOrder())
self.refreshItemColor_rev()
self.ui.revlist.setDisabled(False)
def on_actionSaveSession_triggered(self,checked=None):
# this always has to be checked for triggered actions
# to keep from running double actions
if checked is None: return
# check if session is already active
if not self.sessionActive:
print("ERROR: no active session to save")
return
# open file browser
fname, _ = QtWidgets.QFileDialog.getSaveFileName(self, 'Save Session (*.mpc)', os.path.expanduser('~/'), filter='AMPC Chair Session (*.mpc)')
print(fname)
# check for empty strings, if canceled
if not fname:
return
# save window state
state = []
state.append(self.saveGeometry()) # main window
state.append(self.ui.splitter.saveState()) # splitter
# save session
self.chair.writeSession(fname,state)
def on_actionExport_triggered(self,checked=None):
# this always has to be checked for triggered actions
# to keep from running double actions
if checked is None: return
# check if session is already active
if not self.sessionActive:
print("ERROR: no active session to export")
return
# open file browser
fname, _ = QtWidgets.QFileDialog.getSaveFileName(self, 'Export Session (*.xls)', os.path.expanduser('~/'), filter='AMPC Chair Session (*.xls)')
print(fname)
# check for empty strings, if canceled
if not fname:
return
# save session
self.chair.writeSpreadsheet(fname)
def on_actionOpenSession_triggered(self,checked=None):
# this always has to be checked for triggered actions
# to keep from running double actions
if checked is None: return
# open file browser
fname, _ = QtWidgets.QFileDialog().getOpenFileName(self, 'Open Session (*.mpc)', os.path.expanduser('~/'), filter='AMPC Chair Session (*.mpc)')
print(fname)
# check for empty strings, if canceled
if not fname:
return
# check if session is already active
if self.sessionActive:
self.sessionActive = False
self.deleteAllItems()
self.update_status('clearing memory... (dictionaries)')
self.chair.deleteAll()
# read the file
self.update_status('opening session...')
if self.chair.readSession(fname) != 0:
return
# resize window to saved state
if self.chair.state:
print("restore mainwindow state:")
print(self.restoreGeometry(self.chair.state[0]))
print("restore splitter state:")
print(self.ui.splitter.restoreState(self.chair.state[1]))
# load display
self.loadItems()
# mark a session already in use
self.sessionActive = True