-
Notifications
You must be signed in to change notification settings - Fork 1
/
graphical_dice_roll.py
731 lines (623 loc) · 27.6 KB
/
graphical_dice_roll.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
#
# Graphical Dice Roll 0.6.0 Beta for Windows 11
# Written for Python 3.11.6
#
##############################################################
"""
Graphical Dice Roll 0.6.0 Beta for Windows 11
--------------------------------------------------------
This program makes various dice rolls and calculates their graphs if needed.
"""
import pyttsx3
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from mainwindow import Ui_MainWindow
from aboutdialog import Ui_aboutDialog
from alertdialog import Ui_alertDialog
from rpg_tools.pydice import roll
import sys
import time
import os
import numpy as np
from matplotlib import font_manager
import logging
__author__ = 'Shawn Driscoll <shawndriscoll@hotmail.com>\nshawndriscoll.blogspot.com'
__app__ = 'Graphical Dice Roll 0.6.0 Beta'
__version__ = '0.6.0b'
__py_version_req__ = (3,11,6)
__expired_tag__ = False
engine = pyttsx3.init()
voice_list = engine.getProperty('voices')
voices = ['Mute Voice']
voice = {}
rate = -50
volume = 1.0
# Look for installed TTS voices
for i in voice_list:
rec = {}
name_found = i.name[i.name.find(' ')+1:]
name_found = name_found[:name_found.find(' ')]
voices.append(name_found)
rec['Name'] = i.id
rec['Rate'] = rate
rec['Volume'] = volume
voice[name_found] = rec
rate = engine.getProperty('rate')
volume = engine.getProperty('volume')
die_types = ['D4', 'D6', 'D8', 'D10', 'D12', 'D20', 'D30', 'D66', 'D100']
roll_accuracies = ['50', '100', '500', '1000', '5000', '10000', '50000', '100000', '500000', '1000000', '5000000']
class aboutDialog(QDialog, Ui_aboutDialog):
def __init__(self):
'''
Open the About dialog window
'''
super().__init__()
log.info('PyQt5 aboutDialog initializing...')
self.setWindowFlags(Qt.Drawer | Qt.WindowStaysOnTopHint)
self.setupUi(self)
self.aboutOKButton.clicked.connect(self.acceptOKButtonClicked)
log.info('PyQt5 aboutDialog initialized.')
def acceptOKButtonClicked(self):
'''
Close the About dialog window
'''
log.info('PyQt5 aboutDialog closing...')
self.close()
class alertDialog(QDialog, Ui_alertDialog):
def __init__(self):
'''
Open the Alert dialog window
'''
super().__init__()
log.info('PyQt5 alertDialog initializing...')
self.setWindowFlags(Qt.Drawer | Qt.WindowStaysOnTopHint)
self.setupUi(self)
self.aboutOKButton.clicked.connect(self.acceptOKButtonClicked)
log.info('PyQt5 alertDialog initialized.')
def acceptOKButtonClicked(self):
'''
Close the Alert dialog window
'''
log.info('PyQt5 alertDialog closing...')
self.close()
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self):
'''
Display the Main window.
Connect all the buttons to their functions.
Initialize their value ranges.
'''
super().__init__()
log.info('PyQt5 MainWindow initializing...')
self.setupUi(self)
self.diceCount.valueChanged.connect(self.diceCount_changed)
for i in range(len(die_types)):
self.diceType.addItem(die_types[i])
self.dice_type = 'D6'
self.diceType.setCurrentIndex(1)
self.diceType.currentIndexChanged.connect(self.diceType_changed)
for i in range(len(roll_accuracies)):
self.rollaccuracyType.addItem(roll_accuracies[i])
self.roll_accuracy = 5000
self.rollaccuracyType.setCurrentIndex(3)
self.rollaccuracyType.currentIndexChanged.connect(self.rollaccuracyType_changed)
self.diceDM.valueChanged.connect(self.diceDM_changed)
self.rollButton.clicked.connect(self.rollButton_clicked)
self.actionRoll_Dice.triggered.connect(self.rollButton_clicked)
self.clear_graphButton.clicked.connect(self.clear_graphButton_clicked)
self.actionClear_Graph.triggered.connect(self.clear_graphButton_clicked)
self.clearButton.clicked.connect(self.clearButton_clicked)
self.actionClear_All.triggered.connect(self.clearButton_clicked)
self.actionAbout_Graphical_Dice_Roll.triggered.connect(self.actionAbout_triggered)
# Set the About menu item
self.popAboutDialog=aboutDialog()
# Set the Alert menu item
self.popAlertDialog=alertDialog()
self.quitButton.clicked.connect(self.quitButton_clicked)
self.actionQuit.triggered.connect(self.quitButton_clicked)
self.rollInput.returnPressed.connect(self.manual_roll)
for i in voices:
self.voiceBox.addItem(i)
self.voiceBox.setCurrentIndex(0)
self.voiceBox.currentIndexChanged.connect(self.voiceBox_changed)
self.dice_to_roll = ''
self.clear_graph = False
self.rolled_manually = False
self.ms_voice_muted = True
log.info('PyQt5 MainWindow initialized.')
if __expired_tag__ == True:
'''
Beta for this app has expired!
'''
log.warning(__app__ + ' expiration detected...')
self.alert_window()
'''
Display alert message and disable all the things
'''
self.diceCount.setDisabled(True)
self.diceType.setDisabled(True)
self.rollaccuracyType.setDisabled(True)
self.voiceBox.setDisabled(True)
self.diceDM.setDisabled(True)
self.rollButton.setDisabled(True)
self.clear_graphButton.setDisabled(True)
self.clearButton.setDisabled(True)
self.rollInput.setDisabled(True)
self.rollBrowser.setDisabled(True)
self.sampleBrowser.setDisabled(True)
self.actionAbout_Graphical_Dice_Roll.setDisabled(True)
self.actionRoll_Dice.setDisabled(True)
self.actionClear_Graph.setDisabled(True)
self.actionClear_All.setDisabled(True)
def diceCount_changed(self):
'''
Clear die modifier and last roll result
'''
self.diceDM.setValue(0)
self.diceRoll.setText('')
self.rollInput.clear()
def diceType_changed(self):
'''
Enable/disable the dice count and die modifier fields
depending on the dice type chosen.
And clear fields as needed.
'''
self.dice_type = die_types[self.diceType.currentIndex()]
if self.diceType.currentIndex() <= 6:
self.countLabel.setEnabled(1)
self.diceCount.setEnabled(1)
self.dmLabel.setEnabled(1)
self.diceDM.setEnabled(1)
if self.diceType.currentIndex() == 8:
self.diceCount.setValue(1)
self.countLabel.setEnabled(0)
self.diceCount.setEnabled(0)
self.dmLabel.setEnabled(1)
self.diceDM.setEnabled(1)
if self.diceType.currentIndex() == 7:
self.diceCount.setValue(1)
self.countLabel.setEnabled(0)
self.diceCount.setEnabled(0)
self.dmLabel.setEnabled(0)
self.diceDM.setEnabled(0)
self.diceDM.setValue(0)
self.diceRoll.setText('')
self.rollInput.clear()
def rollaccuracyType_changed(self):
'''
Choose the accuracy of the roll chart
'''
self.roll_accuracy = int(roll_accuracies[self.rollaccuracyType.currentIndex()])
def diceDM_changed(self):
'''
Clear last roll result if die modifier is changed
'''
self.diceRoll.setText('')
self.rollInput.clear()
def rollButton_clicked(self):
'''
Roll button was clicked.
Construct the string argument needed for roll().
'''
if self.diceDM.value() >= 0:
math_op = '+'
else:
math_op = ''
if self.diceType.currentIndex() > 6:
self.dice_to_roll = ''
else:
self.dice_to_roll = str(self.diceCount.value())
self.dice_to_roll += self.dice_type
if self.diceType.currentIndex() != 7:
self.dice_to_roll += math_op + str(self.diceDM.value())
self.roll_result = roll(self.dice_to_roll)
self.diceRoll.setText(str(self.roll_result))
self.rollBrowser.append(self.dice_to_roll + ' = ' + self.diceRoll.text())
sample = '[ '
for x in range(10):
sample += str(roll(self.dice_to_roll)) + ' '
sample += ']'
self.sampleBrowser.clear()
self.sampleBrowser.append(sample)
self.rollInput.clear()
if not self.ms_voice_muted:
engine.say('Calculating roll')
engine.runAndWait()
self.draw_graph()
if not self.ms_voice_muted:
engine.say(str(self.roll_result))
engine.runAndWait()
def manual_roll(self):
'''
A roll was inputed manually
'''
dice_entered = self.rollInput.text()
dice_entered = dice_entered.upper()
self.manual_dice_entered = dice_entered
if dice_entered == 'INFO' or dice_entered == 'TEST' or dice_entered == 'MINMAXAVG' or dice_entered == 'HEX' or dice_entered == 'EHEX':
roll_returned = roll(dice_entered)
else:
log.debug('Rolling manually.')
roll_returned = roll(dice_entered)
# Was the roll a valid one?
if roll_returned == -9999:
returned_line = dice_entered + ' = ' + '<span style=" color:#ff0000;">' + str(roll_returned) + '</span>'
else:
returned_line = dice_entered + ' = ' + str(roll_returned)
# Display the roll result inside the text browser
self.rollBrowser.append(returned_line)
if roll_returned != -9999:
sample = '[ '
for x in range(10):
sample += str(roll(dice_entered)) + ' '
sample += ']'
else:
sample = ''
self.sampleBrowser.clear()
self.sampleBrowser.append(sample)
log.info('Sample for die type: ' + sample)
self.roll_result = roll_returned
self.diceRoll.setText('')
self.rolled_manually = True
if self.roll_result != -9999:
if not self.ms_voice_muted:
engine.say('Calculating ' + dice_entered)
engine.runAndWait()
self.draw_graph()
if not self.ms_voice_muted:
engine.say(str(self.roll_result))
engine.runAndWait()
else:
if not self.ms_voice_muted:
engine.say('invalid input')
engine.runAndWait()
self.clear_graph = True
self.draw_graph()
def clear_graphButton_clicked(self):
'''
Clear the graph
'''
self.clear_graph = True
self.draw_graph()
def clearButton_clicked(self):
'''
Clear/reset all fields
'''
self.diceCount.setValue(1)
self.diceDM.setValue(0)
self.diceRoll.setText('')
self.rollInput.clear()
self.rollBrowser.clear()
self.sampleBrowser.clear()
self.clear_graph = True
self.draw_graph()
def actionAbout_triggered(self):
'''
Display the About window
'''
self.popAboutDialog.show()
def alert_window(self):
'''
open the Alert window
'''
log.warning(__app__ + ' show Beta expired PyQt5 alertDialog...')
self.popAlertDialog.show()
def draw_graph(self):
'''
Graph button was clicked.
Construct the string argument needed for graphing (if a valid roll type).
'''
if self.clear_graph:
#print('clear graph')
xper_range = ''
yper_range = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
percent = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
bar_height = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
die_range = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
max_percent = len(yper_range)
self.mpl.canvas.ax.clear()
self.mpl.canvas.ax.bar(np.arange(len(die_range)), percent, width=0.6, alpha=.3, color='b')
self.mpl.canvas.ax.set_xlim(xmin=-0.25, xmax=len(die_range)-0.75)
self.mpl.canvas.ax.set_xticks(range(len(die_range)))
self.mpl.canvas.ax.set_xticklabels(die_range)
ticks_font = font_manager.FontProperties(style='normal', size=6, weight='normal', stretch='normal')
for label in self.mpl.canvas.ax.get_xticklabels():
label.set_fontproperties(ticks_font)
title_font = font_manager.FontProperties(style='normal', size=10, weight='normal', stretch='normal')
label = self.mpl.canvas.ax.set_title(xper_range)
label.set_fontproperties(title_font)
self.mpl.canvas.ax.set_yticks(range(0, max_percent, 1))
self.mpl.canvas.ax.set_yticklabels(yper_range)
ticks_font = font_manager.FontProperties(style='normal', size=6, weight='normal', stretch='normal')
for label in self.mpl.canvas.ax.get_yticklabels():
label.set_fontproperties(ticks_font)
ylabel_font = font_manager.FontProperties(style='normal', size=10, weight='normal', stretch='normal')
#self.mpl.canvas.ax.set_ylabel('Percentages')
label = self.mpl.canvas.ax.set_ylabel('Percentages')
label.set_fontproperties(ylabel_font)
#self.mpl.canvas.ax.get_xaxis().grid(True)
self.mpl.canvas.ax.get_yaxis().grid(True)
self.mpl.canvas.draw()
log.debug('Graph Cleared')
self.clear_graph = False
self.rolled_manually = False
else:
if self.rolled_manually:
self.dice_to_roll = self.manual_dice_entered
self.rolled_manually = False
print('dice_to_roll:', self.dice_to_roll)
die_range = []
percent = []
bar_height = []
min_die_roll = 99999
max_die_roll = -99999
# calculate the range of the die rolls (using a smaple of 10000 rolls)
for i in range(self.roll_accuracy):
rolled_value = roll(self.dice_to_roll)
if min_die_roll > rolled_value:
min_die_roll = rolled_value
if max_die_roll < rolled_value:
max_die_roll = rolled_value
print(min_die_roll, '-', max_die_roll)
for i in range(min_die_roll, max_die_roll + 1):
die_range.append(i)
percent.append(0)
bar_height.append(0)
if self.dice_to_roll == 'D44' or self.dice_to_roll == 'D66' or self.dice_to_roll == 'D88' or self.dice_to_roll.find('S6') != -1 \
or self.dice_to_roll.find('S10') != -1:
print('No die_range')
print('No mean_avg')
else:
# calculate the mean average for die_range
print('die_range:', die_range)
j = 0
for i in range(len(die_range)):
j += die_range[i]
print('mean_avg:', j / len(die_range))
n = self.roll_accuracy
num_errors = 0
# calculate the percentage for each die roll (using a sample of n=10000 rolls)
for i in range(n):
roll_not_in_range = True
while roll_not_in_range:
temp = roll(self.dice_to_roll)
if temp >= min_die_roll and temp <= max_die_roll:
percent[temp - min_die_roll] += 1
roll_not_in_range = False
else:
# we just rolled ouside of our calculated die roll range, so don't count that one
print("Index error:", temp)
num_errors += 1
print('num_errors:', num_errors)
max_percent = 0
for i in range(len(die_range)):
percent[i] = percent[i] * 100. / (n - num_errors)
if percent[i] > max_percent:
max_percent = int(percent[i]) + 3
yper_range = range(0, max_percent)
print('yper_range:', list(yper_range))
print('percent:', percent)
log.debug('Generate ' + self.dice_to_roll + ' graph')
xper_range = self.dice_to_roll + ' Roll'
for i in range(len(percent)):
if i + min_die_roll == self.roll_result:
bar_height[i] = percent[i]
print('bar_height:',bar_height)
print()
self.mpl.canvas.ax.clear()
self.mpl.canvas.ax.bar(np.arange(len(die_range)), percent, width=0.6, alpha=.3, color='b')
self.mpl.canvas.ax.set_xlim(xmin=-0.25, xmax=len(die_range)-0.75)
self.mpl.canvas.ax.set_xticks(range(len(die_range)))
self.mpl.canvas.ax.set_xticklabels(die_range)
ticks_font = font_manager.FontProperties(style='normal', size=6, weight='normal', stretch='normal')
for label in self.mpl.canvas.ax.get_xticklabels():
label.set_fontproperties(ticks_font)
title_font = font_manager.FontProperties(style='normal', size=10, weight='normal', stretch='normal')
label = self.mpl.canvas.ax.set_title(xper_range)
label.set_fontproperties(title_font)
self.mpl.canvas.ax.set_yticks(range(0, max_percent, 1))
self.mpl.canvas.ax.set_yticklabels(yper_range)
ticks_font = font_manager.FontProperties(style='normal', size=6, weight='normal', stretch='normal')
for label in self.mpl.canvas.ax.get_yticklabels():
label.set_fontproperties(ticks_font)
ylabel_font = font_manager.FontProperties(style='normal', size=10, weight='normal', stretch='normal')
#self.mpl.canvas.ax.set_ylabel('Percentages')
label = self.mpl.canvas.ax.set_ylabel('Percentages')
label.set_fontproperties(ylabel_font)
#self.mpl.canvas.ax.get_xaxis().grid(True)
self.mpl.canvas.ax.get_yaxis().grid(True)
self.mpl.canvas.ax.bar(np.arange(len(die_range)), bar_height, width=0.6, alpha=1.0, color='r')
self.mpl.canvas.ax.set_xlim(xmin=-0.25, xmax=len(die_range)-0.75)
self.mpl.canvas.ax.set_xticks(range(len(die_range)))
self.mpl.canvas.ax.set_xticklabels(die_range)
ticks_font = font_manager.FontProperties(style='normal', size=6, weight='normal', stretch='normal')
for label in self.mpl.canvas.ax.get_xticklabels():
label.set_fontproperties(ticks_font)
title_font = font_manager.FontProperties(style='normal', size=10, weight='normal', stretch='normal')
label = self.mpl.canvas.ax.set_title(xper_range)
label.set_fontproperties(title_font)
self.mpl.canvas.ax.set_yticks(range(0, max_percent, 1))
self.mpl.canvas.ax.set_yticklabels(yper_range)
ticks_font = font_manager.FontProperties(style='normal', size=6, weight='normal', stretch='normal')
for label in self.mpl.canvas.ax.get_yticklabels():
label.set_fontproperties(ticks_font)
ylabel_font = font_manager.FontProperties(style='normal', size=10, weight='normal', stretch='normal')
#self.mpl.canvas.ax.set_ylabel('Percentages')
label = self.mpl.canvas.ax.set_ylabel('Percentages')
label.set_fontproperties(ylabel_font)
#self.mpl.canvas.ax.get_xaxis().grid(True)
self.mpl.canvas.ax.get_yaxis().grid(True)
self.mpl.canvas.draw()
def voiceBox_changed(self):
'''
Was a text-to-speech voice selected?
'''
speaker = voices[self.voiceBox.currentIndex()]
if speaker == 'Mute Voice':
self.ms_voice_muted = True
else:
self.ms_voice_muted = False
engine.setProperty('rate', rate + voice[speaker]['Rate'])
engine.setProperty('volume', volume + voice[speaker]['Volume'])
engine.setProperty('voice', voice[speaker]['Name'])
def quitButton_clicked(self):
'''
Exit this app (using task tray icon)
'''
self.close()
def activate(self, reason):
'''
Toggle showing/hiding the app when clicking the system tray icon
'''
if reason == QSystemTrayIcon.Trigger: # systray icon clicked.
if self.isVisible():
self.hide()
else:
self.show()
def display_app(self, reason):
'''
Use task tray icon menu to display app
'''
self.show()
def hide_app(self, reason):
'''
Use task tray icon menu to hide app
'''
self.hide()
if __name__ == '__main__':
'''
Technically, this program starts right here when run.
If this program is imported instead of run, none of the code below is executed.
'''
# logging.basicConfig(filename = 'graphical_dice_roll.log',
# level = logging.DEBUG,
# format = '%(asctime)s %(levelname)s %(name)s - %(message)s',
# datefmt='%a, %d %b %Y %H:%M:%S',
# filemode = 'w')
log = logging.getLogger('graphical_dice_roll')
log.setLevel(logging.INFO)
#log.setLevel(logging.DEBUG)
#log.setLevel(logging.WARNING)
if not os.path.exists('Logs'):
os.mkdir('Logs')
fh = logging.FileHandler('Logs/graphical_dice_roll.log', 'w')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(name)s - %(message)s', datefmt = '%a, %d %b %Y %H:%M:%S')
fh.setFormatter(formatter)
log.addHandler(fh)
log.info('Logging started.')
log.info(__app__ + ' starting...')
trange = time.localtime()
log.info(__app__ + ' started, and running...')
if len(sys.argv) < 2:
if trange[0] > 2024 or trange[1] > 12:
__expired_tag__ = True
__app__ += ' [EXPIRED]'
app = QApplication(sys.argv)
app.setQuitOnLastWindowClosed(True)
#print(QStyleFactory.keys()) #use to find a setStyle you like, instead of 'Fusion'
#app.setStyle('Fusion')
# darkPalette = QPalette()
# darkPalette.setColor(QPalette.Window, QColor(53, 53, 53))
# darkPalette.setColor(QPalette.WindowText, Qt.white)
# darkPalette.setColor(QPalette.Disabled, QPalette.WindowText, QColor(127, 127, 127))
# darkPalette.setColor(QPalette.Base, QColor(42, 42, 42))
# darkPalette.setColor(QPalette.AlternateBase, QColor(66, 66, 66))
# darkPalette.setColor(QPalette.ToolTipBase, Qt.white)
# darkPalette.setColor(QPalette.ToolTipText, Qt.white)
# darkPalette.setColor(QPalette.Text, Qt.white)
# darkPalette.setColor(QPalette.Disabled, QPalette.Text, QColor(127, 127, 127))
# darkPalette.setColor(QPalette.Dark, QColor(35, 35, 35))
# darkPalette.setColor(QPalette.Shadow, QColor(20, 20, 20))
# darkPalette.setColor(QPalette.Button, QColor(53, 53, 53))
# darkPalette.setColor(QPalette.ButtonText, Qt.white)
# darkPalette.setColor(QPalette.Disabled, QPalette.ButtonText, QColor(127, 127, 127))
# darkPalette.setColor(QPalette.BrightText, Qt.red)
# darkPalette.setColor(QPalette.Link, QColor(42, 130, 218))
# darkPalette.setColor(QPalette.Highlight, QColor(42, 130, 218))
# darkPalette.setColor(QPalette.Disabled, QPalette.Highlight, QColor(80, 80, 80))
# darkPalette.setColor(QPalette.HighlightedText, Qt.white)
# darkPalette.setColor(QPalette.Disabled, QPalette.HighlightedText, QColor(127, 127, 127))
MainApp = MainWindow()
MainApp.show()
#app.setPalette(darkPalette)
# Create the systray icon
icon = QIcon(":/icons/die_icon.ico")
# Create the systray
tray = QSystemTrayIcon()
tray.setIcon(icon)
tray.setVisible(True)
# Create the systray menu
menu = QMenu()
showApp = QAction("Show App")
showApp.triggered.connect(MainApp.display_app)
menu.addAction(showApp)
hideApp = QAction("Hide App")
hideApp.triggered.connect(MainApp.hide_app)
menu.addAction(hideApp)
quit = QAction("Exit")
quit.triggered.connect(app.quit)
menu.addAction(quit)
tray.setToolTip("Graphical Dice Roll")
# Add the menu to the tray
tray.setContextMenu(menu)
tray.activated.connect(MainApp.activate)
app.exec_()
elif trange[0] > 2024 or trange[1] > 12:
__app__ += ' [EXPIRED]'
'''
Beta for this app has expired!
'''
log.warning(__app__)
print()
print(__app__)
elif sys.argv[1] in ['-h', '/h', '--help', '-?', '/?']:
log.info('Graphical Dice Roll was run from the CMD prompt. Help will be sent if needed.')
print()
print(' Using the CMD prompt to make dice rolls:')
print(" C:\>graphical_dice_roll.py roll('2d6')")
print()
print(' Or just:')
print(' C:\>graphical_dice_roll.py 2d6')
elif sys.argv[1] in ['-v', '/v', '--version']:
print()
print(' Graphical Dice Roll, release version ' + __version__ + ' for Python ' + str(__py_version_req__))
log.info('Reporting: Graphical Dice Roll release version: %s' % __version__)
else:
print()
dice = ''
if len(sys.argv) > 2:
for i in range(len(sys.argv)):
if i > 0:
dice += sys.argv[i]
else:
dice = sys.argv[1]
if "roll('" in dice:
num = dice.find("')")
if num != -1:
dice = dice[6:num]
dice = str(dice).upper().strip()
if dice == '':
dice = '2D6'
log.debug('Default roll was made')
num = roll(dice)
if dice != 'TEST' and dice != 'INFO' and dice != 'MINMAXAVG':
print("Your '%s' roll is %s." % (dice, num))
log.info("The direct call to Graphical Dice Roll with '%s' resulted in %s." % (dice, num))
elif dice == 'INFO':
print('Graphical Dice Roll, release version ' + __version__ + ' for Python ' + str(__py_version_req__))
log.info('Reporting: Graphical Dice Roll release version: %s' % __version__)
else:
print('Typo of some sort --> ' + dice)
else:
dice = str(dice).upper().strip()
if dice == 'ROLL()':
dice = '2D6'
log.debug('Default roll was made')
num = roll(dice)
if dice != 'TEST' and dice != 'INFO' and dice != 'MINMAXAVG':
print("Your '%s' roll is %s." % (dice, num))
log.info("The direct call to Graphical Dice Roll with '%s' resulted in %s." % (dice, num))
elif dice == 'INFO':
print('Graphical Dice Roll, release version ' + __version__ + ' for Python ' + str(__py_version_req__))
log.info('Reporting: Graphical Dice Roll release version: %s' % __version__)