parent
39b558204a
commit
946c611a4e
@ -0,0 +1,98 @@ |
|||||||
|
import os |
||||||
|
|
||||||
|
from PyQt5 import uic |
||||||
|
from PyQt5.QtCore import Qt |
||||||
|
from PyQt5.QtWidgets import QDialog , QListWidgetItem |
||||||
|
|
||||||
|
import asl_cards.db as db |
||||||
|
from constants import * |
||||||
|
import globals |
||||||
|
|
||||||
|
# --------------------------------------------------------------------- |
||||||
|
|
||||||
|
class AddCardDialog( QDialog ) : |
||||||
|
"""Allow the user to select an ASL card, based on nationality & card type.""" |
||||||
|
|
||||||
|
def __init__( self , parent ) : |
||||||
|
# initialize |
||||||
|
self.selected_card = None |
||||||
|
super(AddCardDialog,self).__init__( parent=parent ) |
||||||
|
# initialize the dialog |
||||||
|
uic.loadUi( os.path.join(globals.base_dir,"ui/add_card_dialog.ui") , self ) |
||||||
|
self.setMinimumSize( self.size() ) |
||||||
|
self.lb_cards.setSortingEnabled( True ) |
||||||
|
w = self.buttons_widget |
||||||
|
self.xmargin = w.x() |
||||||
|
self.ymargin = self.size().height() - (w.y() + w.height()) |
||||||
|
# load the dialog |
||||||
|
for nationality in globals.cards : |
||||||
|
self.cbo_nationality.addItem( nationality ) |
||||||
|
# connect our handlers |
||||||
|
self.cbo_nationality.currentIndexChanged[str].connect( self.on_nationality_changed ) |
||||||
|
self.ok_button.clicked.connect( self.on_ok ) |
||||||
|
for rb in [self.rb_vehicles,self.rb_ordnance] : |
||||||
|
rb.clicked.connect( self.on_card_type_changed ) |
||||||
|
# select the initial nationality (this will load the rest of the dialog) |
||||||
|
self.cbo_nationality.setCurrentIndex( 0 ) |
||||||
|
self.on_nationality_changed( self.cbo_nationality.itemText(0) ) |
||||||
|
|
||||||
|
def on_ok( self ) : |
||||||
|
# accept the currently selected card |
||||||
|
item = self.lb_cards.currentItem() |
||||||
|
self.selected_card = item.data(Qt.UserRole) if item else None |
||||||
|
self.accept() |
||||||
|
|
||||||
|
def on_nationality_changed( self , val ) : |
||||||
|
"""Update the dialog when the active nationality is changed.""" |
||||||
|
# reload the available cards for the selected nationality |
||||||
|
cards = globals.cards[ val ] |
||||||
|
self.lb_cards.clear() |
||||||
|
# update the vehicle/ordnance radio boxes |
||||||
|
if self.rb_vehicles.isChecked() : |
||||||
|
curr_rb = self.rb_vehicles |
||||||
|
elif self.rb_ordnance.isChecked() : |
||||||
|
curr_rb = self.rb_ordnance |
||||||
|
else : |
||||||
|
curr_rb = None |
||||||
|
self.rb_vehicles.setEnabled( db.TAGTYPE_VEHICLE in cards ) |
||||||
|
self.rb_ordnance.setEnabled( db.TAGTYPE_ORDNANCE in cards ) |
||||||
|
if curr_rb is None or not curr_rb.isEnabled() : |
||||||
|
for rb in [self.rb_vehicles,self.rb_ordnance] : |
||||||
|
if rb.isEnabled() : |
||||||
|
rb.setChecked( True ) |
||||||
|
break |
||||||
|
# reload the cards |
||||||
|
self.on_card_type_changed() |
||||||
|
|
||||||
|
def on_card_type_changed( self ) : |
||||||
|
"""Update the dialog when the active card type is changed.""" |
||||||
|
self.lb_cards.clear() |
||||||
|
# figure out what type of cards to show |
||||||
|
if self.rb_vehicles.isChecked() : |
||||||
|
card_type = db.TAGTYPE_VEHICLE |
||||||
|
elif self.rb_ordnance.isChecked() : |
||||||
|
card_type = db.TAGTYPE_ORDNANCE |
||||||
|
else : |
||||||
|
return |
||||||
|
# reload the available cards |
||||||
|
cards = globals.cards[ self.cbo_nationality.currentText() ] |
||||||
|
cards = cards.get( card_type ) |
||||||
|
if cards is None : |
||||||
|
assert False |
||||||
|
return |
||||||
|
for card in cards : |
||||||
|
item = QListWidgetItem( card.name ) |
||||||
|
item.setData( Qt.UserRole , card ) |
||||||
|
self.lb_cards.addItem( item ) |
||||||
|
self.lb_cards.setCurrentRow( 0 ) |
||||||
|
self.lb_cards.setFocus() |
||||||
|
|
||||||
|
def resizeEvent( self , evt ) : |
||||||
|
# handle the event |
||||||
|
w = self.buttons_widget |
||||||
|
self.buttons_widget.setGeometry( |
||||||
|
self.xmargin , self.size().height() - self.ymargin - w.height() , |
||||||
|
self.size().width() - 2*self.xmargin , w.height() |
||||||
|
) |
||||||
|
w = self.lb_cards |
||||||
|
w.resize( self.size().width() - 2*self.xmargin , self.buttons_widget.y() - w.y() ) |
@ -0,0 +1,176 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<ui version="4.0"> |
||||||
|
<class>MyDialog</class> |
||||||
|
<widget class="QDialog" name="MyDialog"> |
||||||
|
<property name="geometry"> |
||||||
|
<rect> |
||||||
|
<x>0</x> |
||||||
|
<y>0</y> |
||||||
|
<width>380</width> |
||||||
|
<height>336</height> |
||||||
|
</rect> |
||||||
|
</property> |
||||||
|
<widget class="QWidget" name="controls_widget" native="true"> |
||||||
|
<property name="geometry"> |
||||||
|
<rect> |
||||||
|
<x>-1</x> |
||||||
|
<y>9</y> |
||||||
|
<width>301</width> |
||||||
|
<height>55</height> |
||||||
|
</rect> |
||||||
|
</property> |
||||||
|
<property name="sizePolicy"> |
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Ignored"> |
||||||
|
<horstretch>0</horstretch> |
||||||
|
<verstretch>0</verstretch> |
||||||
|
</sizepolicy> |
||||||
|
</property> |
||||||
|
<property name="maximumSize"> |
||||||
|
<size> |
||||||
|
<width>16777215</width> |
||||||
|
<height>55</height> |
||||||
|
</size> |
||||||
|
</property> |
||||||
|
<widget class="QLabel" name="label"> |
||||||
|
<property name="geometry"> |
||||||
|
<rect> |
||||||
|
<x>10</x> |
||||||
|
<y>10</y> |
||||||
|
<width>81</width> |
||||||
|
<height>21</height> |
||||||
|
</rect> |
||||||
|
</property> |
||||||
|
<property name="text"> |
||||||
|
<string>&Nationality:</string> |
||||||
|
</property> |
||||||
|
<property name="buddy"> |
||||||
|
<cstring>cbo_nationality</cstring> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
<widget class="QRadioButton" name="rb_ordnance"> |
||||||
|
<property name="geometry"> |
||||||
|
<rect> |
||||||
|
<x>170</x> |
||||||
|
<y>30</y> |
||||||
|
<width>91</width> |
||||||
|
<height>26</height> |
||||||
|
</rect> |
||||||
|
</property> |
||||||
|
<property name="text"> |
||||||
|
<string>&Ordnance</string> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
<widget class="QComboBox" name="cbo_nationality"> |
||||||
|
<property name="geometry"> |
||||||
|
<rect> |
||||||
|
<x>90</x> |
||||||
|
<y>10</y> |
||||||
|
<width>131</width> |
||||||
|
<height>21</height> |
||||||
|
</rect> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
<widget class="QRadioButton" name="rb_vehicles"> |
||||||
|
<property name="geometry"> |
||||||
|
<rect> |
||||||
|
<x>90</x> |
||||||
|
<y>30</y> |
||||||
|
<width>81</width> |
||||||
|
<height>26</height> |
||||||
|
</rect> |
||||||
|
</property> |
||||||
|
<property name="text"> |
||||||
|
<string>&Vehicles</string> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</widget> |
||||||
|
<widget class="QWidget" name="buttons_widget" native="true"> |
||||||
|
<property name="geometry"> |
||||||
|
<rect> |
||||||
|
<x>10</x> |
||||||
|
<y>280</y> |
||||||
|
<width>361</width> |
||||||
|
<height>46</height> |
||||||
|
</rect> |
||||||
|
</property> |
||||||
|
<property name="sizePolicy"> |
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Fixed"> |
||||||
|
<horstretch>0</horstretch> |
||||||
|
<verstretch>0</verstretch> |
||||||
|
</sizepolicy> |
||||||
|
</property> |
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout"> |
||||||
|
<item> |
||||||
|
<spacer name="horizontalSpacer"> |
||||||
|
<property name="orientation"> |
||||||
|
<enum>Qt::Horizontal</enum> |
||||||
|
</property> |
||||||
|
<property name="sizeHint" stdset="0"> |
||||||
|
<size> |
||||||
|
<width>40</width> |
||||||
|
<height>20</height> |
||||||
|
</size> |
||||||
|
</property> |
||||||
|
</spacer> |
||||||
|
</item> |
||||||
|
<item> |
||||||
|
<widget class="QPushButton" name="ok_button"> |
||||||
|
<property name="text"> |
||||||
|
<string>&OK</string> |
||||||
|
</property> |
||||||
|
<property name="default"> |
||||||
|
<bool>true</bool> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
<item> |
||||||
|
<widget class="QPushButton" name="cancel_button"> |
||||||
|
<property name="text"> |
||||||
|
<string>Cancel</string> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
</layout> |
||||||
|
</widget> |
||||||
|
<widget class="QLabel" name="label_2"> |
||||||
|
<property name="geometry"> |
||||||
|
<rect> |
||||||
|
<x>10</x> |
||||||
|
<y>50</y> |
||||||
|
<width>53</width> |
||||||
|
<height>20</height> |
||||||
|
</rect> |
||||||
|
</property> |
||||||
|
<property name="maximumSize"> |
||||||
|
<size> |
||||||
|
<width>16777215</width> |
||||||
|
<height>20</height> |
||||||
|
</size> |
||||||
|
</property> |
||||||
|
<property name="text"> |
||||||
|
<string>&Cards:</string> |
||||||
|
</property> |
||||||
|
<property name="buddy"> |
||||||
|
<cstring>lb_cards</cstring> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
<widget class="QListWidget" name="lb_cards"> |
||||||
|
<property name="geometry"> |
||||||
|
<rect> |
||||||
|
<x>9</x> |
||||||
|
<y>71</y> |
||||||
|
<width>362</width> |
||||||
|
<height>211</height> |
||||||
|
</rect> |
||||||
|
</property> |
||||||
|
<property name="sizePolicy"> |
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Ignored"> |
||||||
|
<horstretch>0</horstretch> |
||||||
|
<verstretch>0</verstretch> |
||||||
|
</sizepolicy> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</widget> |
||||||
|
<resources/> |
||||||
|
<connections/> |
||||||
|
</ui> |
Loading…
Reference in new issue