def configure(self): from mainwindowtabs.itemcreatordialog import ItemCreatorDialog self.searchItemEdit = SearchLineEdit(tabcreator=ItemCreatorDialog, session=self.session, parent=self, function=SqlHandler.searchItem) self.ui.verticalLayout.insertWidget(0, self.searchItemEdit)
def configure(self): self.operationTreeWidget = OperationTreeWidget(parent=self, session=self.session) self.ui.operationMainLayout.insertWidget(0, self.operationTreeWidget) self.ui.operationMainLayout.setStretch(0, 1) self.ui.operationMainLayout.setStretch(1, 2) from models.operation import VisitItem self.visititemTreeWidget = ItemTreeWidget(parent=self, session=self.session, creator=VisitItem) self.ui.itemAddLayout.addWidget(self.visititemTreeWidget) self.animalTreeWidget = VisitAnimalTreeWidget(parent=self, session=self.session) self.ui.animalSelectorLayout.addWidget(self.animalTreeWidget) from models.operation import SurgeryItem self.itemTreeWidget = ItemTreeWidget(parent=self, session=self.session, creator=SurgeryItem) self.ui.itemTreeWidgetLayout.addWidget(self.itemTreeWidget) from mainwindowtabs.ownertab import OwnerTab self.ownerserachline = SearchLineEdit(tabcreator=OwnerTab, session=self.session, parent=self, function=SqlHandler.searchOwner) self.ui.ownerLayout.addWidget(self.ownerserachline)
def __init__(self, parent=None): QWidget.__init__(self, parent) self.resize(280, 150) #Todo: find good values self.serachlineedit = SearchLineEdit(parent=self, function=None) self.setWindowTitle('Operaatiopohja haku') self.makeComboBox() self.makeButtons() self.makeLayout()
class RecipieMedicineDialog(QDialog): def __init__(self, parent=None, item=None): from uipy.ui_recipiemeicineDialog import Ui_RecipieMedicineDialog QDialog.__init__(self, parent=parent) self.ui = Ui_RecipieMedicineDialog() self.ui.setupUi(self) self.item = item self.dialogitem = None self.session = SqlHandler.newSession() self.configure() self.createConnections() self.setBasicInfo() def configure(self): from mainwindowtabs.itemcreatordialog import ItemCreatorDialog self.searchItemEdit = SearchLineEdit(tabcreator=ItemCreatorDialog, session=self.session, parent=self, function=SqlHandler.searchItem) self.ui.verticalLayout.insertWidget(0, self.searchItemEdit) def createConnections(self): self.ui.closeButton.clicked.connect(self.closeDialog) self.ui.saveButton.clicked.connect(self.saveDialog) def saveDialog(self): if self.searchItemEdit.getCurrentItem() != None: if self.item == None: self.item = SqlHandler.RecipieMedicine( self.searchItemEdit.getCurrentItem(), self.ui.spinBox.value()) self.session.add(self.item) else: self.item.update(self.getData()) self.session.commit() self.parent().addAskedItem(self.item) self.closeDialog() def getData(self): data = [] data.append(self.searchItemEdit.getCurrentItem()) data.append(self.ui.spinBox.value()) return data def closeDialog(self): self.session.close() self.setParent(None) self.close() def setBasicInfo(self): if self.item != None: self.ui.spinBox.setValue(self.item.count)
def configure(self): self.billSearchLine = SearchLineEdit(tabcreator=None, session=self.session, parent=self, function=SqlHandler.searchOwner) self.ui.BillInnerLayout.setWidget(0,QtGui.QFormLayout.FieldRole, self.billSearchLine) self.visitOwnerSearchLineEdit = SearchLineEdit(tabcreator=None, session=self.session, parent=self, function=SqlHandler.searchOwner) self.ui.VisitInnerLayout.setWidget(0,QtGui.QFormLayout.FieldRole, self.visitOwnerSearchLineEdit) self.visitAnimalSearchLineEdit = SearchLineEdit(tabcreator=None, session=self.session, parent=self, function=SqlHandler.searchAnimal) self.ui.VisitInnerLayout.setWidget(1,QtGui.QFormLayout.FieldRole, self.visitAnimalSearchLineEdit) self.mainSearchLineEdit = SearchLineEdit(tabcreator=None, session=self.session, parent=self) self.ui.mainSearchLineLayout.insertWidget(0,self.mainSearchLineEdit)
def configure(self): self.billSearchLine = SearchLineEdit(tabcreator=None, session=self.session, parent=self, function=SqlHandler.searchOwner) self.ui.BillInnerLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.billSearchLine) self.visitOwnerSearchLineEdit = SearchLineEdit( tabcreator=None, session=self.session, parent=self, function=SqlHandler.searchOwner) self.ui.VisitInnerLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.visitOwnerSearchLineEdit) self.visitAnimalSearchLineEdit = SearchLineEdit( tabcreator=None, session=self.session, parent=self, function=SqlHandler.searchAnimal) self.ui.VisitInnerLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.visitAnimalSearchLineEdit) self.mainSearchLineEdit = SearchLineEdit(tabcreator=None, session=self.session, parent=self) self.ui.mainSearchLineLayout.insertWidget(0, self.mainSearchLineEdit)
def __init__(self, parent=None, item=None): GenericTab.__init__(self, parent=parent, item=item) self.ui = Ui_ItemCreatorTab() self.ui.setupUi(self) self.session = SqlHandler.newSession() self.itemSearchEdit = SearchLineEdit(tabcreator=ItemCreatorDialog, session=self.session, parent=self, function=SqlHandler.searchItem) self.configure() self.configureConnctions() self.modifyItemCreator()
class RecipieMedicineDialog(QDialog): def __init__(self, parent=None, item=None): from uipy.ui_recipiemeicineDialog import Ui_RecipieMedicineDialog QDialog.__init__(self, parent=parent) self.ui = Ui_RecipieMedicineDialog() self.ui.setupUi(self) self.item = item self.dialogitem = None self.session = SqlHandler.newSession() self.configure() self.createConnections() self.setBasicInfo() def configure(self): from mainwindowtabs.itemcreatordialog import ItemCreatorDialog self.searchItemEdit = SearchLineEdit(tabcreator=ItemCreatorDialog,session=self.session, parent=self, function=SqlHandler.searchItem) self.ui.verticalLayout.insertWidget(0,self.searchItemEdit) def createConnections(self): self.ui.closeButton.clicked.connect(self.closeDialog) self.ui.saveButton.clicked.connect(self.saveDialog) def saveDialog(self): if self.searchItemEdit.getCurrentItem() != None: if self.item == None: self.item = SqlHandler.RecipieMedicine(self.searchItemEdit.getCurrentItem(), self.ui.spinBox.value()) self.session.add(self.item) else: self.item.update(self.getData()) self.session.commit() self.parent().addAskedItem(self.item) self.closeDialog() def getData(self): data = [] data.append(self.searchItemEdit.getCurrentItem()) data.append(self.ui.spinBox.value()) return data def closeDialog(self): self.session.close() self.setParent(None) self.close() def setBasicInfo(self): if self.item != None: self.ui.spinBox.setValue(self.item.count)
def __init__(self, parent=None,item=None): GenericTab.__init__(self, parent=parent, item=None) self.ui = Ui_SummaryTab() self.ui.setupUi(self) self.returnItem = False self.visitanimal = None if type(item) is dict: if 'owner' in item: self.ui.ownerNameLabel.setText(item['owner'].name) else: logERROR(self, "SummaryTab.init: owner not found from dict") if 'visitanimal' in item: self.visitanimal = item['visitanimal'] self.ui.animalNameLabel.setText(item['visitanimal'].animal.name) else: logERROR(self, "SummaryTab.init: owner not found from dict") if 'text' in item: self.addText(item['text']) else: logERROR(self, "SummaryTab.init: text not found from dict") else: logDEBUG(self, "SummaryTab.init: item is not dict it is: "+ item) self.session = SqlHandler.newSession() self.itemSearchEdit = SearchLineEdit(tabcreator=AddNewSummary, session=self.session, parent=self, function=SqlHandler.searchSummary) self.configure() self.configureConnctions()
def configure(self): from mainwindowtabs.animaltab import AnimalTab self.animalsearch = SearchLineEdit(tabcreator=AnimalTab, session=self.session, parent=self, function=SqlHandler.searchAnimal) self.ui.searchLineEditLayout.addWidget(self.animalsearch) self.recipieMedicineTreeWidget = GenericTreeWidget( session=self.session, parent=self) self.recipieMedicineTreeWidget.setTitle('Reseptituotteet') self.recipieMedicineTreeWidget.setHeader( headertexts=['id', 'Nimi', 'Määrä'], hidecolumns=[0]) self.recipieMedicineTreeWidget.setButtons( [ButtonType.add, ButtonType.open, ButtonType.remove]) self.recipieMedicineTreeWidget.setInputMethod( dialog=RecipieMedicineDialog, autoAdd=True) self.ui.verticalLayout.insertWidget(2, self.recipieMedicineTreeWidget)
def __init__(self, parent=None): QWidget.__init__(self,parent) self.resize(280, 150)#Todo: find good values self.serachlineedit = SearchLineEdit(parent=self, function=None) self.setWindowTitle('Operaatiopohja haku') self.makeComboBox() self.makeButtons() self.makeLayout()
def configure(self): from mainwindowtabs.animaltab import AnimalTab self.animalsearch = SearchLineEdit(tabcreator=AnimalTab, session=self.session, parent=self, function=SqlHandler.searchAnimal) self.ui.searchLineEditLayout.addWidget(self.animalsearch) self.recipieMedicineTreeWidget = GenericTreeWidget(session=self.session, parent=self) self.recipieMedicineTreeWidget.setTitle('Reseptituotteet') self.recipieMedicineTreeWidget.setHeader(headertexts=['id', 'Nimi', 'Määrä'], hidecolumns=[0]) self.recipieMedicineTreeWidget.setButtons([ButtonType.add, ButtonType.open, ButtonType.remove]) self.recipieMedicineTreeWidget.setInputMethod(dialog=RecipieMedicineDialog, autoAdd=True) self.ui.verticalLayout.insertWidget(2, self.recipieMedicineTreeWidget)
def setInputMethod(self,dialog=None, item=None,tabcreator=None, autoAdd=False, function=None, searchEnabled=True): if dialog != None: self.ownDialog = dialog if item != None: self.dialogitem = item else: self.tabcreator = tabcreator if searchEnabled: self.searchLineFunction = function self.searchlineedit = SearchLineEdit(tabcreator=self.tabcreator, session=self.session, parent=self, function=self.searchLineFunction) if autoAdd: self.searchlineedit.ui.editor.returnPressed.connect(self.addItem) self.ui.topLayout.insertWidget(2, self.searchlineedit)
def __init__(self, parent=None,item=None): GenericTab.__init__(self, parent=parent, item=item) self.ui = Ui_ItemCreatorTab() self.ui.setupUi(self) self.session = SqlHandler.newSession() self.itemSearchEdit = SearchLineEdit(tabcreator=ItemCreatorDialog, session=self.session, parent=self, function=SqlHandler.searchItem) self.configure() self.configureConnctions() self.modifyItemCreator()
def setInputMethod(self, dialog=None, item=None, tabcreator=None, autoAdd=False, function=None, searchEnabled=True): if dialog != None: self.ownDialog = dialog if item != None: self.dialogitem = item else: self.tabcreator = tabcreator if searchEnabled: self.searchLineFunction = function self.searchlineedit = SearchLineEdit( tabcreator=self.tabcreator, session=self.session, parent=self, function=self.searchLineFunction) if autoAdd: self.searchlineedit.ui.editor.returnPressed.connect( self.addItem) self.ui.topLayout.insertWidget(2, self.searchlineedit)
def __init__(self, parent=None, item=None): QDialog.__init__(self, parent) self.ui = Ui_OperationCreator() self.ui.setupUi(self) self.session = SqlHandler.newSession() if item != None: self.item = SqlHandler.makeCopy(self.session, item) else: self.item = None from models.operation import SurgeryBaseItem self.itemTreeWidget = ItemTreeWidget(session = self.session, parent=self, creator=SurgeryBaseItem) self.itemTreeWidget.setTitle("Leikkauksen tavarat") self.ui.itemPageLayout.addWidget(self.itemTreeWidget) self.itemSearchEdit = SearchLineEdit(tabcreator=ItemCreatorDialog, session=self.session, parent=self, function=SqlHandler.searchItem) self.ui.searchLineEditLayout.insertWidget(0,self.itemSearchEdit) self.configureConnections() self.setBasicInfo()
def configure(self): self.operationTreeWidget = OperationTreeWidget(parent=self, session=self.session) self.ui.operationMainLayout.insertWidget(0, self.operationTreeWidget) self.ui.operationMainLayout.setStretch(0,1) self.ui.operationMainLayout.setStretch(1,2) from models.operation import VisitItem self.visititemTreeWidget = ItemTreeWidget(parent=self, session=self.session, creator=VisitItem) self.ui.itemAddLayout.addWidget(self.visititemTreeWidget) self.animalTreeWidget = VisitAnimalTreeWidget(parent=self, session=self.session) self.ui.animalSelectorLayout.addWidget(self.animalTreeWidget) from models.operation import SurgeryItem self.itemTreeWidget = ItemTreeWidget(parent=self, session=self.session, creator=SurgeryItem) self.ui.itemTreeWidgetLayout.addWidget(self.itemTreeWidget) from mainwindowtabs.ownertab import OwnerTab self.ownerserachline = SearchLineEdit(tabcreator=OwnerTab, session=self.session ,parent=self, function=SqlHandler.searchOwner) self.ui.ownerLayout.addWidget(self.ownerserachline)
class GenericTreeWidget(QWidget): def __init__(self, session, parent, updateFunctio=None): QWidget.__init__(self, parent=parent) self.ui = Ui_GenericTreeWidget() self.ui.setupUi(self) self.configure() self.iconplace = -1 self.session = session self.updateFunctio = updateFunctio self.removecheck = False self.permanentRemove = False self.typecheck = False self.params = None self.tabcreator = None self.item = None self.ownDialog = None self.dialogitem = None self.searchlineedit = None self.searchLineFunction = None def configure(self): self.ui.treeWidget.setRootIsDecorated(False) def setTitle(self, title, hidden=False): if hidden: self.ui.textlabel.hide() else: self.ui.textlabel.setText(title) def setHeader(self,headertexts, iconplace=-1, iconsize=QSize(50,50), hidecolumns=[]): if iconplace >=0: self.ui.treeWidget.setIconSize(iconsize) self.iconplace = iconplace headertexts.insert(self.iconplace,'') self.ui.treeWidget.setHeaderItem(QTreeWidgetItem(headertexts)) for column in hidecolumns: self.ui.treeWidget.hideColumn(column) def setRemoveCheck(self, text='Haluatko varmasti poistaa valitun?', status=True): self.removecheck = status self.removetext = text def setButtons(self, buttons, place=ButtonType.up): if place == ButtonType.up: for button in buttons: self.ui.topLayout.insertWidget(self.ui.topLayout.count(), self.cereateButton(button)) else: for button in buttons: self.ui.bottomLayout.incertWidget(self.ui.bottomLayout.count(), self.cereateButton(button)) def cereateButton(self, button): if button == ButtonType.add: self.addButton = QPushButton(button,parent=self) self.addButton.clicked.connect(self.addItem) return self.addButton elif button == ButtonType.remove: self.removeButton = QPushButton(button,parent=self) self.removeButton.clicked.connect(self.removeSelectedItem) return self.removeButton elif button == ButtonType.open: self.openButton = QPushButton(button, parent=self) self.openButton.clicked.connect(self.openItem) return self.openButton elif button == ButtonType.check: self.checkButton = QPushButton(button, parent=self) self.checkButton.clicked.connect(self.checkItem) return self.checkButton else: print('Error, not valid button type') return None def addItem(self): item = self.getItem() if item != None: self.addItemToTree(item) def getIcon(self, picture_path):#TODO Check if len(picture_path) > 3: return QIcon(picture_path) else: return QIcon('uni.jpg') #TODO: set Default image def setItems(self, itemList): self.ui.treeWidget.clear() for item in itemList: self.addItemToTree(item) #this function will return first selected item #So only one item is returned def getSelectedItem(self): if len(self.ui.treeWidget.selectedItems()) > 0: return self.ui.treeWidget.selectedItems()[0].data(0,0) else: return None def getItemsFromList(self): index=0 itemList = [] while self.ui.treeWidget.topLevelItem(index): item = self.ui.treeWidget.topLevelItem(index).data(0,0) itemList.append(item) index += 1 return itemList def update(self): if self.updateFunctio != None and self.params != None: if len(self.params) == 0: self.setItems(self.updateFunctio(self.session)) elif len(self.params) == 1: self.setItems(self.updateFunctio(self.session, self.params[0])) elif len(self.params) == 2: self.setItems(self.updateFunctio(self.session, self.params[0], self.params[1])) elif len(self.params) == 3: self.setItems(self.updateFunctio(self.session, self.params[0], self.params[1], self.params[2])) elif len(self.params) == 4: self.setItems(self.updateFunctio(self.session, self.params[0], self.params[1], self.params[2], self.params[3])) else: print('GenericTreeWidget.update(): self.updateFunction was None!') def addAskedItem(self, item): if item != None: self.addItemToTree(SqlHandler.makeCopy(self.session, item)) def addAskedItemNoCopy(self, item): if item != None: self.session.add(item) self.addItemToTree(item) '''-----------OVERLOAD ABLE---------------''' def addItemToTree(self, item): if item == None: return if self.itemInList(item) >= 0: self.ui.treeWidget.takeTopLevelItem(self.itemInList(item)) treeItem = self.makeTreeItem(item) self.ui.treeWidget.addTopLevelItem(treeItem) self.ui.treeWidget.setCurrentItem(treeItem) def makeTreeItem(self,item):#Overload if needed textString = item.stringList() #add '' to icon place treeItem = None if self.iconplace >= 0: textString.insert(self.iconplace, '') print('makeTreeItem() textString', textString) treeItem = QTreeWidgetItem(self.ui.treeWidget,textString) treeItem.setIcon(self.iconplace,self.getIcon(item.picurePath())) else: print('makeTreeItem() textString', textString) treeItem = QTreeWidgetItem(self.ui.treeWidget,textString) treeItem.setData(0,0,item) return treeItem def itemInList(self, item):#Overload if needed index = 0 while self.ui.treeWidget.topLevelItem(index): treeItem= self.ui.treeWidget.topLevelItem(index) if treeItem.data(0,0) != None and treeItem.data(0,0).id == item.id: return index index += 1 return -1 def canRemoveItem(self):#Overload if needed if self.removecheck: result = QMessageBox.question(self,'Viesti',self.removetext, QMessageBox.Ok, QMessageBox.Cancel) if result == QMessageBox.Ok: return True else: return False else: return True '''-------------- OVERLOAD ------------''' def setParameters(self, params): self.params = params def setPermanentRemove(self, status=True): self.permanentRemove = status def setInputMethod(self,dialog=None, item=None,tabcreator=None, autoAdd=False, function=None, searchEnabled=True): if dialog != None: self.ownDialog = dialog if item != None: self.dialogitem = item else: self.tabcreator = tabcreator if searchEnabled: self.searchLineFunction = function self.searchlineedit = SearchLineEdit(tabcreator=self.tabcreator, session=self.session, parent=self, function=self.searchLineFunction) if autoAdd: self.searchlineedit.ui.editor.returnPressed.connect(self.addItem) self.ui.topLayout.insertWidget(2, self.searchlineedit) def openItem(self): #TODO: Make this more generic tree_item = self.ui.treeWidget.currentItem() if tree_item != None: item = tree_item.data(0,0) if hasattr(self.tabcreator, "getType"): Tabmanager.openTab(tabCreator=self.tabcreator, newItem=item, returnTab=self) else: if self.ownDialog != None: if self.dialogitem != None: temp = self.ownDialog(parent=self, item=self.dialogitem) else: temp = self.ownDialog(parent=self) temp.show() def getItem(self): if self.searchlineedit == None: if self.ownDialog != None: if self.dialogitem != None: temp = self.ownDialog(parent=self, item=self.dialogitem) else: temp = self.ownDialog(parent=self) temp.show() return None else: return self.searchlineedit.getCurrentItem() def removeSelectedItem(self): if self.canRemoveItem(): removedItem = self.ui.treeWidget.takeTopLevelItem(self.ui.treeWidget.indexOfTopLevelItem(self.ui.treeWidget.currentItem())) if removedItem != None: item = removedItem.data(0,0) if self.permanentRemove and item != None and item.id != None: self.session.delete(item) def clearTreeWidget(self): self.ui.treeWidget.clear()
class ItemCreatorTab(GenericTab): def __init__(self, parent=None,item=None): GenericTab.__init__(self, parent=parent, item=item) self.ui = Ui_ItemCreatorTab() self.ui.setupUi(self) self.session = SqlHandler.newSession() self.itemSearchEdit = SearchLineEdit(tabcreator=ItemCreatorDialog, session=self.session, parent=self, function=SqlHandler.searchItem) self.configure() self.configureConnctions() self.modifyItemCreator() def modifyItemCreator(self): pass def openItem(self, item=None): self.itemCreator = ItemCreatorDialog(parent=self, item=item) #self.ui.itemdialoglayout.addWidget(self.itemCreator) self.itemCreator.show() def openItemFromSearch(self): item = self.itemSearchEdit.getCurrentItem() if item : self.openItem(item) else: logDEBUG(self,"openItemFromSearch: item is None"); def itemCanBeDeleted(self, item): return True def deleteItemFromSearch(self): item = self.itemSearchEdit.getCurrentItem() if item and self.askUser(): if self.itemCanBeDeleted(item): SqlHandler.removeItem(self.session, item) else: pass #error def refresh(self): SqlHandler.commitSession(self.session) def askUser(self): reply = QMessageBox.question(self,'Huomio!','Haluatko varmasti poistaa tuotteen pysyvästi?', QMessageBox.Ok, QMessageBox.Cancel) if reply == QMessageBox.Ok: return True else: return False def openItemNew(self): self.openItem(item = None) def configureConnctions(self): self.ui.newItemButton.clicked.connect(self.openItemNew) self.ui.openItemButton.clicked.connect(self.openItemFromSearch) self.ui.deleteItemButton.clicked.connect(self.deleteItemFromSearch) def configure(self): self.ui.searchlayout.insertWidget(0,self.itemSearchEdit) #self.ui.itemdialoglayout.addWidget(self.itemCreator) # item is returned so we should refresh session def addAskedItem(self, item): self.refresh()
class SummaryTab(GenericTab): def __init__(self, parent=None,item=None): GenericTab.__init__(self, parent=parent, item=None) self.ui = Ui_SummaryTab() self.ui.setupUi(self) self.returnItem = False self.visitanimal = None if type(item) is dict: if 'owner' in item: self.ui.ownerNameLabel.setText(item['owner'].name) else: logERROR(self, "SummaryTab.init: owner not found from dict") if 'visitanimal' in item: self.visitanimal = item['visitanimal'] self.ui.animalNameLabel.setText(item['visitanimal'].animal.name) else: logERROR(self, "SummaryTab.init: owner not found from dict") if 'text' in item: self.addText(item['text']) else: logERROR(self, "SummaryTab.init: text not found from dict") else: logDEBUG(self, "SummaryTab.init: item is not dict it is: "+ item) self.session = SqlHandler.newSession() self.itemSearchEdit = SearchLineEdit(tabcreator=AddNewSummary, session=self.session, parent=self, function=SqlHandler.searchSummary) self.configure() self.configureConnctions() def getItem(self): if self.returnItem: return self.ui.plainTextEdit.toPlainText() else: return None def getDataFromVisitanimal(self): if(self.visitanimal): d = self.visitanimal.getMedicineDict() for key in d.keys(): self.addText(key +':\n') self.addText(d[key] +'\n') def saveChanges(self): self.returnItem = True; self.closeTab() def configureConnctions(self): self.ui.getInfoFromVisitButton.clicked.connect(self.getDataFromVisitanimal) self.ui.canselButton.clicked.connect(self.closeTab) self.ui.closeButton.clicked.connect(self.saveChanges) self.ui.addSearchButton.clicked.connect(self.addFromSearch) def addFromSearch(self): self.addText(self.itemSearchEdit.getCurrentItem().text) def configure(self): self.ui.searchLayout.insertWidget(0,self.itemSearchEdit) def addText(self, text): self.ui.plainTextEdit.appendPlainText(text) def addAskedItem(self, item): try: self.ui.plainTextEdit.appendPlainText(item) except: logERROR(self, "Added item was not string it was : " + str(type(item)))
class GenericTreeWidget(QWidget): def __init__(self, session, parent, updateFunctio=None): QWidget.__init__(self, parent=parent) self.ui = Ui_GenericTreeWidget() self.ui.setupUi(self) self.configure() self.iconplace = -1 self.session = session self.updateFunctio = updateFunctio self.removecheck = False self.permanentRemove = False self.typecheck = False self.params = None self.tabcreator = None self.item = None self.ownDialog = None self.dialogitem = None self.searchlineedit = None self.searchLineFunction = None def configure(self): self.ui.treeWidget.setRootIsDecorated(False) def setTitle(self, title, hidden=False): if hidden: self.ui.textlabel.hide() else: self.ui.textlabel.setText(title) def setHeader(self, headertexts, iconplace=-1, iconsize=QSize(50, 50), hidecolumns=[]): if iconplace >= 0: self.ui.treeWidget.setIconSize(iconsize) self.iconplace = iconplace headertexts.insert(self.iconplace, '') self.ui.treeWidget.setHeaderItem(QTreeWidgetItem(headertexts)) for column in hidecolumns: self.ui.treeWidget.hideColumn(column) def setRemoveCheck(self, text='Haluatko varmasti poistaa valitun?', status=True): self.removecheck = status self.removetext = text def setButtons(self, buttons, place=ButtonType.up): if place == ButtonType.up: for button in buttons: self.ui.topLayout.insertWidget(self.ui.topLayout.count(), self.cereateButton(button)) else: for button in buttons: self.ui.bottomLayout.incertWidget(self.ui.bottomLayout.count(), self.cereateButton(button)) def cereateButton(self, button): if button == ButtonType.add: self.addButton = QPushButton(button, parent=self) self.addButton.clicked.connect(self.addItem) return self.addButton elif button == ButtonType.remove: self.removeButton = QPushButton(button, parent=self) self.removeButton.clicked.connect(self.removeSelectedItem) return self.removeButton elif button == ButtonType.open: self.openButton = QPushButton(button, parent=self) self.openButton.clicked.connect(self.openItem) return self.openButton elif button == ButtonType.check: self.checkButton = QPushButton(button, parent=self) self.checkButton.clicked.connect(self.checkItem) return self.checkButton else: print('Error, not valid button type') return None def addItem(self): item = self.getItem() if item != None: self.addItemToTree(item) def getIcon(self, picture_path): #TODO Check if len(picture_path) > 3: return QIcon(picture_path) else: return QIcon('uni.jpg') #TODO: set Default image def setItems(self, itemList): self.ui.treeWidget.clear() for item in itemList: self.addItemToTree(item) #this function will return first selected item #So only one item is returned def getSelectedItem(self): if len(self.ui.treeWidget.selectedItems()) > 0: return self.ui.treeWidget.selectedItems()[0].data(0, 0) else: return None def getItemsFromList(self): index = 0 itemList = [] while self.ui.treeWidget.topLevelItem(index): item = self.ui.treeWidget.topLevelItem(index).data(0, 0) itemList.append(item) index += 1 return itemList def update(self): if self.updateFunctio != None and self.params != None: if len(self.params) == 0: self.setItems(self.updateFunctio(self.session)) elif len(self.params) == 1: self.setItems(self.updateFunctio(self.session, self.params[0])) elif len(self.params) == 2: self.setItems( self.updateFunctio(self.session, self.params[0], self.params[1])) elif len(self.params) == 3: self.setItems( self.updateFunctio(self.session, self.params[0], self.params[1], self.params[2])) elif len(self.params) == 4: self.setItems( self.updateFunctio(self.session, self.params[0], self.params[1], self.params[2], self.params[3])) else: print('GenericTreeWidget.update(): self.updateFunction was None!') def addAskedItem(self, item): if item != None: self.addItemToTree(SqlHandler.makeCopy(self.session, item)) def addAskedItemNoCopy(self, item): if item != None: self.session.add(item) self.addItemToTree(item) '''-----------OVERLOAD ABLE---------------''' def addItemToTree(self, item): if item == None: return if self.itemInList(item) >= 0: self.ui.treeWidget.takeTopLevelItem(self.itemInList(item)) treeItem = self.makeTreeItem(item) self.ui.treeWidget.addTopLevelItem(treeItem) self.ui.treeWidget.setCurrentItem(treeItem) def makeTreeItem(self, item): #Overload if needed textString = item.stringList() #add '' to icon place treeItem = None if self.iconplace >= 0: textString.insert(self.iconplace, '') print('makeTreeItem() textString', textString) treeItem = QTreeWidgetItem(self.ui.treeWidget, textString) treeItem.setIcon(self.iconplace, self.getIcon(item.picurePath())) else: print('makeTreeItem() textString', textString) treeItem = QTreeWidgetItem(self.ui.treeWidget, textString) treeItem.setData(0, 0, item) return treeItem def itemInList(self, item): #Overload if needed index = 0 while self.ui.treeWidget.topLevelItem(index): treeItem = self.ui.treeWidget.topLevelItem(index) if treeItem.data(0, 0) != None and treeItem.data(0, 0).id == item.id: return index index += 1 return -1 def canRemoveItem(self): #Overload if needed if self.removecheck: result = QMessageBox.question(self, 'Viesti', self.removetext, QMessageBox.Ok, QMessageBox.Cancel) if result == QMessageBox.Ok: return True else: return False else: return True '''-------------- OVERLOAD ------------''' def setParameters(self, params): self.params = params def setPermanentRemove(self, status=True): self.permanentRemove = status def setInputMethod(self, dialog=None, item=None, tabcreator=None, autoAdd=False, function=None, searchEnabled=True): if dialog != None: self.ownDialog = dialog if item != None: self.dialogitem = item else: self.tabcreator = tabcreator if searchEnabled: self.searchLineFunction = function self.searchlineedit = SearchLineEdit( tabcreator=self.tabcreator, session=self.session, parent=self, function=self.searchLineFunction) if autoAdd: self.searchlineedit.ui.editor.returnPressed.connect( self.addItem) self.ui.topLayout.insertWidget(2, self.searchlineedit) def openItem(self): #TODO: Make this more generic tree_item = self.ui.treeWidget.currentItem() if tree_item != None: item = tree_item.data(0, 0) if hasattr(self.tabcreator, "getType"): Tabmanager.openTab(tabCreator=self.tabcreator, newItem=item, returnTab=self) else: if self.ownDialog != None: if self.dialogitem != None: temp = self.ownDialog(parent=self, item=self.dialogitem) else: temp = self.ownDialog(parent=self) temp.show() def getItem(self): if self.searchlineedit == None: if self.ownDialog != None: if self.dialogitem != None: temp = self.ownDialog(parent=self, item=self.dialogitem) else: temp = self.ownDialog(parent=self) temp.show() return None else: return self.searchlineedit.getCurrentItem() def removeSelectedItem(self): if self.canRemoveItem(): removedItem = self.ui.treeWidget.takeTopLevelItem( self.ui.treeWidget.indexOfTopLevelItem( self.ui.treeWidget.currentItem())) if removedItem != None: item = removedItem.data(0, 0) if self.permanentRemove and item != None and item.id != None: self.session.delete(item) def clearTreeWidget(self): self.ui.treeWidget.clear()
class OperationSelectorDialog(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent) self.resize(280, 150) #Todo: find good values self.serachlineedit = SearchLineEdit(parent=self, function=None) self.setWindowTitle('Operaatiopohja haku') self.makeComboBox() self.makeButtons() self.makeLayout() def makeComboBox(self): self.combobox = QComboBox(parent=self) self.combobox.addItem('Lääkintä', SqlHandler.searchAnimal) #MedicationBase self.combobox.addItem('Rokotus', SqlHandler.searchAnimal) #VaccinationBase self.combobox.addItem('Leikkaus', SqlHandler.searchAnimal) #SurgeryBase self.combobox.addItem('Ultraäänitutkimus', SqlHandler.searchAnimal) #UltrasonicBase self.combobox.addItem('Endoskopointi', SqlHandler.searchAnimal) #EndoscopyBase self.combobox.addItem('Ontumatutkimus', SqlHandler.searchAnimal) #LamenessBase self.combobox.addItem('Röntkentutkimus', SqlHandler.searchAnimal) #XrayBase self.combobox.addItem('Hammastutkimus', SqlHandler.searchAnimal) #DentalexaminationBase self.combobox.addItem('Laboratoriotutkimus', SqlHandler.searchAnimal) #OperationBase self.combobox.addItem('muu', SqlHandler.searchAnimal) #OperationBase self.combobox.currentIndexChanged['int'].connect( self.changeSearchLineEditFunction) self.combobox.setCurrentIndex(0) def makeButtons(self): self.cancelButton = QPushButton(parent=self, text='Hylkää') self.cancelButton.clicked.connect(self.close) self.okButton = QPushButton(parent=self, text='Valitse') self.okButton.clicked.connect(self.okPressed) def makeLayout(self): print('makeLayout') buttonslayout = QHBoxLayout() buttonslayout.addStretch() buttonslayout.addWidget(self.cancelButton) buttonslayout.addWidget(self.okButton) searchLayout = QHBoxLayout() searchLayout.addWidget(QLabel(text='Etsi', parent=self)) searchLayout.addWidget(self.serachlineedit) selectorlayout = QVBoxLayout() selectorlayout.addLayout(searchLayout) selectorlayout.addWidget(QLabel(text='Operaation tyyppi', parent=self)) selectorlayout.addWidget(self.combobox) selectorlayout.addStretch() ownmainlayout = QVBoxLayout() ownmainlayout.addLayout(selectorlayout) ownmainlayout.addLayout(buttonslayout) self.setLayout(ownmainlayout) def changeSearchLineEditFunction(self, index): self.serachlineedit.function = self.combobox.itemData(index) def okPressed(self): item = self.serachlineedit.getCurrentItem() if item != None: self.parent().addAskedItem(item) self.close() else: box = QMessageBox() box.setText('Valitse operaatio') box.exec()
class SearchTab(GenericTab): def __init__(self, parent=None, item=None): GenericTab.__init__(self, parent=parent) self.ui = Ui_SearchTab() self.ui.setupUi(self) self.configure() self.configureConnections() self.setBasicInfo() def configure(self): self.billSearchLine = SearchLineEdit(tabcreator=None, session=self.session, parent=self, function=SqlHandler.searchOwner) self.ui.BillInnerLayout.setWidget(0,QtGui.QFormLayout.FieldRole, self.billSearchLine) self.visitOwnerSearchLineEdit = SearchLineEdit(tabcreator=None, session=self.session, parent=self, function=SqlHandler.searchOwner) self.ui.VisitInnerLayout.setWidget(0,QtGui.QFormLayout.FieldRole, self.visitOwnerSearchLineEdit) self.visitAnimalSearchLineEdit = SearchLineEdit(tabcreator=None, session=self.session, parent=self, function=SqlHandler.searchAnimal) self.ui.VisitInnerLayout.setWidget(1,QtGui.QFormLayout.FieldRole, self.visitAnimalSearchLineEdit) self.mainSearchLineEdit = SearchLineEdit(tabcreator=None, session=self.session, parent=self) self.ui.mainSearchLineLayout.insertWidget(0,self.mainSearchLineEdit) def configureConnections(self): self.ui.typeComboBox.currentIndexChanged['int'].connect(self.searchItemChanged) self.ui.specieBox.currentIndexChanged['int'].connect(self.updateSpecieRelated) self.mainSearchLineEdit.ui.editor.textEdited.connect(self.changeSearchFunction) self.ui.openButton.clicked.connect(self.openItem) self.ui.searchButton.clicked.connect(self.searchNow) def searchNow(self): pass def openItem(self): creator = self.ui.typeComboBox.itemData(self.ui.typeComboBox.currentIndex()) currentItem = self.mainSearchLineEdit.getCurrentItem() if currentItem != None: if hasattr(creator, "getType"): Tabmanager.openTab(tabCreator=creator, newItem=currentItem) else: ItemCreatorDialog(parent=self, item=self.mainSearchLineEdit.getCurrentItem()).show() def searchItemChanged(self, index): creator = self.ui.typeComboBox.itemData(index) typeName = creator.getType() if typeName == 'Animal': self.ui.stackedWidget.setCurrentIndex(self.ui.stackedWidget.indexOf(self.ui.AnimalPage)) elif typeName == 'Visit': self.ui.stackedWidget.setCurrentIndex(self.ui.stackedWidget.indexOf(self.ui.VisitPage)) elif typeName == 'Bill': self.ui.stackedWidget.setCurrentIndex(self.ui.stackedWidget.indexOf(self.ui.BillPage)) else: self.ui.stackedWidget.setCurrentIndex(self.ui.stackedWidget.indexOf(self.ui.emptyPage)) def changeSearchFunction(self): creator = self.ui.typeComboBox.itemData(self.ui.typeComboBox.currentIndex()) typeName = creator.getType() self.mainSearchLineEdit.params = None if typeName == 'Animal': self.mainSearchLineEdit.function = self.getAnimalFunction() elif typeName == 'Owner': self.mainSearchLineEdit.function = SqlHandler.searchOwner elif typeName == 'Visit': self.mainSearchLineEdit.function = self.getVisitFunction() elif typeName == 'Bill': self.mainSearchLineEdit.function = self.getBillFunction() elif typeName == 'Item': self.mainSearchLineEdit.function = SqlHandler.searchRealItem elif typeName == 'Medicine': self.mainSearchLineEdit.function = SqlHandler.searchMedicine elif typeName == 'Vaccine': self.mainSearchLineEdit.function = SqlHandler.searchVaccine elif typeName == 'Feed': self.mainSearchLineEdit.function = SqlHandler.searchFeed else: print('SearchTab: SearchItemChanged: typeName is not specified') def getAnimalFunction(self): params_list = [] params_list.append(self.specie()) params_list.append(self.ui.raceBox.itemData(self.ui.raceBox.currentIndex())) params_list.append(self.ui.colorBox.itemData(self.ui.colorBox.currentIndex())) params_list.append(self.ui.sexBox.itemData(self.ui.sexBox.currentIndex())) params_list.append(self.ui.visitStartEdit.date().toPyDate()) params_list.append(self.ui.VisitEndEdit.date().toPyDate()) self.mainSearchLineEdit.params = params_list return SqlHandler.searchLineSearchAnimal def getBillFunction(self): params_list = [] params_list.append(self.billSearchLine.getCurrentItem()) params_list.append(self.ui.billVetBox.itemData(self.ui.billVetBox.currentIndex())) params_list.append(self.ui.billStartEdit.date().toPyDate()) params_list.append(self.ui.billEndEdit.date().toPyDate()) self.mainSearchLineEdit.params = params_list return SqlHandler.searchLineSearchBill def getVisitFunction(self): params_list = [] params_list.append(self.visitOwnerSearchLineEdit.getCurrentItem()) params_list.append(self.visitAnimalSearchLineEdit.getCurrentItem()) params_list.append(self.ui.visitVetBox.itemData(self.ui.visitVetBox.currentIndex()).id if self.ui.visitVetBox.itemData(self.ui.visitVetBox.currentIndex()) != None else None) params_list.append(self.ui.visitStartEdit.date().toPyDate()) params_list.append(self.ui.VisitEndEdit.date().toPyDate()) self.mainSearchLineEdit.params = params_list return SqlHandler.searchLineSearchVisit def setBasicInfo(self): self.ui.VisitEndEdit.setDate(datetime.datetime.today()) self.ui.billEndEdit.setDate(datetime.datetime.today()) self.ui.dateEdit_2.setDate(datetime.datetime.today()) self.setSex() self.setSpecie() self.setTypes() self.setVet() def setTypes(self): from mainwindowtabs.animaltab import AnimalTab from mainwindowtabs.visittab import VisitTab from mainwindowtabs.ownertab import OwnerTab from mainwindowtabs.billTab import BillTab data = [AnimalTab, OwnerTab, VisitTab, BillTab] for item in data: self.ui.typeComboBox.addItem(item.getName(), item) data = SqlHandler.getItemCreators() for item in data: self.ui.typeComboBox.addItem(item.typeName(), item) def updateSpecieRelated(self, index): self.ui.raceBox.clear() self.ui.colorBox.clear() specie = self.ui.specieBox.itemData(index) #check that specie is valid if not not specie: self.setRace() self.setColor() def setVet(self): self.ui.billVetBox.clear() self.ui.visitVetBox.clear() self.ui.visitVetBox.addItem('',None) self.ui.billVetBox.addItem('',None) for vet_temp in SqlHandler.searchVet(self.session): self.ui.visitVetBox.addItem(vet_temp.name, vet_temp) self.ui.billVetBox.addItem(vet_temp.name, vet_temp) def specie(self): return self.ui.specieBox.itemData(self.ui.specieBox.currentIndex()) def setSpecie(self): self.ui.specieBox.clear() self.ui.specieBox.addItem('', None) for specie in SqlHandler.searchSpecie(self.session): self.ui.specieBox.addItem(specie.name, specie) def setSex(self): self.ui.sexBox.clear() self.ui.sexBox.addItem('', None) for sex in SqlHandler.searchSex(self.session): self.ui.sexBox.addItem(sex.name, sex) def setColor(self): self.ui.colorBox.clear() self.ui.colorBox.addItem('', None) specie = self.specie() if specie != None: for color in SqlHandler.searchColor(self.session, specie.id): self.ui.colorBox.addItem(color.name, color) def setRace(self, newName=''): self.ui.raceBox.clear() self.ui.raceBox.addItem('', None) specie = self.specie() if specie != None: for race in SqlHandler.searchRace(self.session, specie.id): self.ui.raceBox.addItem(race.name, race) def isUnique(self=None): return True def createConnections(self): pass def getType(self=None): return 'Search' #------------------Signals-----------------------
class SearchTab(GenericTab): def __init__(self, parent=None, item=None): GenericTab.__init__(self, parent=parent) self.ui = Ui_SearchTab() self.ui.setupUi(self) self.configure() self.configureConnections() self.setBasicInfo() def configure(self): self.billSearchLine = SearchLineEdit(tabcreator=None, session=self.session, parent=self, function=SqlHandler.searchOwner) self.ui.BillInnerLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.billSearchLine) self.visitOwnerSearchLineEdit = SearchLineEdit( tabcreator=None, session=self.session, parent=self, function=SqlHandler.searchOwner) self.ui.VisitInnerLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.visitOwnerSearchLineEdit) self.visitAnimalSearchLineEdit = SearchLineEdit( tabcreator=None, session=self.session, parent=self, function=SqlHandler.searchAnimal) self.ui.VisitInnerLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.visitAnimalSearchLineEdit) self.mainSearchLineEdit = SearchLineEdit(tabcreator=None, session=self.session, parent=self) self.ui.mainSearchLineLayout.insertWidget(0, self.mainSearchLineEdit) def configureConnections(self): self.ui.typeComboBox.currentIndexChanged['int'].connect( self.searchItemChanged) self.ui.specieBox.currentIndexChanged['int'].connect( self.updateSpecieRelated) self.mainSearchLineEdit.ui.editor.textEdited.connect( self.changeSearchFunction) self.ui.openButton.clicked.connect(self.openItem) self.ui.searchButton.clicked.connect(self.searchNow) def searchNow(self): pass def openItem(self): creator = self.ui.typeComboBox.itemData( self.ui.typeComboBox.currentIndex()) currentItem = self.mainSearchLineEdit.getCurrentItem() if currentItem != None: if hasattr(creator, "getType"): Tabmanager.openTab(tabCreator=creator, newItem=currentItem) else: ItemCreatorDialog( parent=self, item=self.mainSearchLineEdit.getCurrentItem()).show() def searchItemChanged(self, index): creator = self.ui.typeComboBox.itemData(index) typeName = creator.getType() if typeName == 'Animal': self.ui.stackedWidget.setCurrentIndex( self.ui.stackedWidget.indexOf(self.ui.AnimalPage)) elif typeName == 'Visit': self.ui.stackedWidget.setCurrentIndex( self.ui.stackedWidget.indexOf(self.ui.VisitPage)) elif typeName == 'Bill': self.ui.stackedWidget.setCurrentIndex( self.ui.stackedWidget.indexOf(self.ui.BillPage)) else: self.ui.stackedWidget.setCurrentIndex( self.ui.stackedWidget.indexOf(self.ui.emptyPage)) def changeSearchFunction(self): creator = self.ui.typeComboBox.itemData( self.ui.typeComboBox.currentIndex()) typeName = creator.getType() self.mainSearchLineEdit.params = None if typeName == 'Animal': self.mainSearchLineEdit.function = self.getAnimalFunction() elif typeName == 'Owner': self.mainSearchLineEdit.function = SqlHandler.searchOwner elif typeName == 'Visit': self.mainSearchLineEdit.function = self.getVisitFunction() elif typeName == 'Bill': self.mainSearchLineEdit.function = self.getBillFunction() elif typeName == 'Item': self.mainSearchLineEdit.function = SqlHandler.searchRealItem elif typeName == 'Medicine': self.mainSearchLineEdit.function = SqlHandler.searchMedicine elif typeName == 'Vaccine': self.mainSearchLineEdit.function = SqlHandler.searchVaccine elif typeName == 'Feed': self.mainSearchLineEdit.function = SqlHandler.searchFeed else: print('SearchTab: SearchItemChanged: typeName is not specified') def getAnimalFunction(self): params_list = [] params_list.append(self.specie()) params_list.append( self.ui.raceBox.itemData(self.ui.raceBox.currentIndex())) params_list.append( self.ui.colorBox.itemData(self.ui.colorBox.currentIndex())) params_list.append( self.ui.sexBox.itemData(self.ui.sexBox.currentIndex())) params_list.append(self.ui.visitStartEdit.date().toPyDate()) params_list.append(self.ui.VisitEndEdit.date().toPyDate()) self.mainSearchLineEdit.params = params_list return SqlHandler.searchLineSearchAnimal def getBillFunction(self): params_list = [] params_list.append(self.billSearchLine.getCurrentItem()) params_list.append( self.ui.billVetBox.itemData(self.ui.billVetBox.currentIndex())) params_list.append(self.ui.billStartEdit.date().toPyDate()) params_list.append(self.ui.billEndEdit.date().toPyDate()) self.mainSearchLineEdit.params = params_list return SqlHandler.searchLineSearchBill def getVisitFunction(self): params_list = [] params_list.append(self.visitOwnerSearchLineEdit.getCurrentItem()) params_list.append(self.visitAnimalSearchLineEdit.getCurrentItem()) params_list.append( self.ui.visitVetBox.itemData(self.ui.visitVetBox.currentIndex() ).id if self.ui.visitVetBox. itemData(self.ui.visitVetBox.currentIndex()) != None else None) params_list.append(self.ui.visitStartEdit.date().toPyDate()) params_list.append(self.ui.VisitEndEdit.date().toPyDate()) self.mainSearchLineEdit.params = params_list return SqlHandler.searchLineSearchVisit def setBasicInfo(self): self.ui.VisitEndEdit.setDate(datetime.datetime.today()) self.ui.billEndEdit.setDate(datetime.datetime.today()) self.ui.dateEdit_2.setDate(datetime.datetime.today()) self.setSex() self.setSpecie() self.setTypes() self.setVet() def setTypes(self): from mainwindowtabs.animaltab import AnimalTab from mainwindowtabs.visittab import VisitTab from mainwindowtabs.ownertab import OwnerTab from mainwindowtabs.billTab import BillTab data = [AnimalTab, OwnerTab, VisitTab, BillTab] for item in data: self.ui.typeComboBox.addItem(item.getName(), item) data = SqlHandler.getItemCreators() for item in data: self.ui.typeComboBox.addItem(item.typeName(), item) def updateSpecieRelated(self, index): self.ui.raceBox.clear() self.ui.colorBox.clear() specie = self.ui.specieBox.itemData(index) #check that specie is valid if not not specie: self.setRace() self.setColor() def setVet(self): self.ui.billVetBox.clear() self.ui.visitVetBox.clear() self.ui.visitVetBox.addItem('', None) self.ui.billVetBox.addItem('', None) for vet_temp in SqlHandler.searchVet(self.session): self.ui.visitVetBox.addItem(vet_temp.name, vet_temp) self.ui.billVetBox.addItem(vet_temp.name, vet_temp) def specie(self): return self.ui.specieBox.itemData(self.ui.specieBox.currentIndex()) def setSpecie(self): self.ui.specieBox.clear() self.ui.specieBox.addItem('', None) for specie in SqlHandler.searchSpecie(self.session): self.ui.specieBox.addItem(specie.name, specie) def setSex(self): self.ui.sexBox.clear() self.ui.sexBox.addItem('', None) for sex in SqlHandler.searchSex(self.session): self.ui.sexBox.addItem(sex.name, sex) def setColor(self): self.ui.colorBox.clear() self.ui.colorBox.addItem('', None) specie = self.specie() if specie != None: for color in SqlHandler.searchColor(self.session, specie.id): self.ui.colorBox.addItem(color.name, color) def setRace(self, newName=''): self.ui.raceBox.clear() self.ui.raceBox.addItem('', None) specie = self.specie() if specie != None: for race in SqlHandler.searchRace(self.session, specie.id): self.ui.raceBox.addItem(race.name, race) def isUnique(self=None): return True def createConnections(self): pass def getType(self=None): return 'Search'
class VisitTab(GenericTab): def __init__(self, parent=None, item=None): owner = None animal = None #check if item is dictionary. So it is called by ownerTab if (item != None and item.__class__.__name__ == 'dict'): if ("owner" in item): owner = item["owner"] if ("animal" in item): animal = item["animal"] item = None GenericTab.__init__(self, parent=parent, item=item) self.ui = Ui_Visit() self.ui.setupUi(self) self.ui.stackedWidget.setCurrentIndex(0) #TODO:remove if needed self.currentVisitAnimal = None self.currentOperation = None self.configure() self.createConnections() self.setBasicInfo() if (owner != None): owner = SqlHandler.makeCopy(self.session, owner) self.ownerserachline.setCurrentItem(owner) if (animal != None): animal = SqlHandler.makeCopy(self.session, animal) self.animalTreeWidget.addAskedItem( animal) #TODO find function to add animal self.disableAnimalTree(False) ''' setup Visit ''' def setBasicInfo(self): self.disableAnimalTree(True) if self.item != None: self.ownerserachline.setCurrentItem(self.item.owner) self.ui.reasonTextEdit.setPlainText(self.item.visit_reason) if self.item.start_time != None: self.ui.startTimeEdit.setDateTime(self.item.start_time) if self.item.end_time: self.ui.endTimeEdit.setDateTime(self.item.end_time) self.setVet(self.item.vet) self.animalTreeWidget.setItems(self.item.visitanimals) self.disableAnimalTree(False) else: self.ui.startTimeEdit.setDateTime(datetime.datetime.now()) self.setVet() def setVet(self, vet=None): self.ui.vetComboBox.clear() for vet_temp in SqlHandler.searchVet(self.session): self.ui.vetComboBox.addItem(vet_temp.name, vet_temp) if vet != None: for index in range(0, self.ui.vetComboBox.count()): if self.ui.vetComboBox.itemData(index).id == vet.id: self.ui.vetComboBox.setCurrentIndex(index) return else: pass #TODO: Select current vet! ConfigServer def configure(self): self.operationTreeWidget = OperationTreeWidget(parent=self, session=self.session) self.ui.operationMainLayout.insertWidget(0, self.operationTreeWidget) self.ui.operationMainLayout.setStretch(0, 1) self.ui.operationMainLayout.setStretch(1, 2) from models.operation import VisitItem self.visititemTreeWidget = ItemTreeWidget(parent=self, session=self.session, creator=VisitItem) self.ui.itemAddLayout.addWidget(self.visititemTreeWidget) self.animalTreeWidget = VisitAnimalTreeWidget(parent=self, session=self.session) self.ui.animalSelectorLayout.addWidget(self.animalTreeWidget) from models.operation import SurgeryItem self.itemTreeWidget = ItemTreeWidget(parent=self, session=self.session, creator=SurgeryItem) self.ui.itemTreeWidgetLayout.addWidget(self.itemTreeWidget) from mainwindowtabs.ownertab import OwnerTab self.ownerserachline = SearchLineEdit(tabcreator=OwnerTab, session=self.session, parent=self, function=SqlHandler.searchOwner) self.ui.ownerLayout.addWidget(self.ownerserachline) def createConnections(self): self.ownerserachline.ui.editor.returnPressed.connect(self.ownerSet) self.animalTreeWidget.ui.treeWidget.currentItemChanged.connect( self.animalChanged) self.operationTreeWidget.ui.treeWidget.currentItemChanged.connect( self.operationChanged) self.ui.saveandcloseButton.clicked.connect(self.saveAndCloseTab) self.ui.saveButton.clicked.connect(self.saveTab) self.ui.billButton.clicked.connect(self.openBill) self.ui.closeButton.clicked.connect(self.closeTab) self.ui.openSummaryButton.clicked.connect(self.openSummary) #item will be string from SummaryTab it item is None do not update def addAskedItem(self, item): if item != None: self.ui.treatmentTextEdit.setPlainText(item) def openSummary(self): from mainwindowtabs.summarytab import SummaryTab Tabmanager.openTab(tabCreator=SummaryTab, newItem={ 'owner': self.ownerserachline.getCurrentItem(), 'visitanimal': self.animalTreeWidget.getSelectedItem(), 'text': self.ui.treatmentTextEdit.toPlainText() }, returnTab=self) def updateOperation(self, line): operation = line.data(0, 0) #get operation string_list = operation.stringList() #get string list for i in operation.getUpdateRange(): line.setText(i, string_list[i]) def operationChanged(self, current, previous): if current != None: '''Enable operation related if those arent enabled''' if not self.ui.operationNameLabel.isEnabled(): self.disableOperationRelated(False) '''Only if real change have happened then update''' if current != previous: if self.currentOperation != None: self.updateCurerentOperation() if previous != None: self.updateOperation(previous) self.currentOperation = current.data(0, 0) self.setOperationData(current.data(0, 0)) else: '''If current is None then treeWidget is empty and all data will be removed''' if self.ui.operationNameLabel.isEnabled(): self.clearOperationRelated() self.disableOperationRelated(True) self.currentOperation = None def clearOperationRelated(self): self.closeOperation() def closeOperation(self): self.ui.operationNameLabel.setText('Nimi') self.ui.retailPriceLabel.setText('0.00') self.itemTreeWidget.clearTreeWidget() self.ui.priceSpinBox.setValue(0) self.ui.countSpinBox.setValue(1) self.ui.descriptionTextEdit.setPlainText('') self.ui.stackedWidget.setCurrentIndex(0) def updateCurerentOperation(self): if self.currentOperation != None: data = {} data["price"] = self.ui.priceSpinBox.value() data["description"] = self.ui.descriptionTextEdit.toPlainText() data["count"] = self.ui.countSpinBox.value() if self.currentOperation.hasList(): data["items"] = self.itemTreeWidget.getItemsFromList() self.currentOperation.update(data) def setOperationData(self, operation=None): self.ui.operationNameLabel.setText(operation.base.name) self.ui.retailPriceLabel.setText(str(operation.base.price)) self.ui.priceSpinBox.setValue(operation.price) self.ui.descriptionTextEdit.setPlainText(operation.description) self.ui.countSpinBox.setValue(operation.count) if self.currentOperation.hasList(): self.ui.stackedWidget.setCurrentIndex(2) self.itemTreeWidget.setItems(self.currentOperation.items) elif self.currentOperation.base.hasItem(): self.ui.stackedWidget.setCurrentIndex(1) self.ui.nameLabel.setText( self.currentOperation.base.item. name if self.currentOperation.base.item != None else '') self.ui.typeLabel.setText(self.currentOperation.base.item.typeName( ) if self.currentOperation.base.item != None else '') self.ui.itemPriceLabel.setText( str(self.currentOperation.base.item.price ) if self.currentOperation.base.item != None else '') else: self.ui.stackedWidget.setCurrentIndex(0) def isEndTimeChanged(self): from models.translationtables import g_visit_end_time_start time = self.qdateToPy(self.ui.endTimeEdit.dateTime()).date() if datetime.datetime.strptime("1.1.2000", "%d.%m.%Y").date() == time: return True else: return False #this function sets end time to current time if it have not been changed yet def setEndTime(self): if self.isEndTimeChanged(): self.ui.endTimeEdit.setDateTime(datetime.datetime.now()) def openBill(self): if self.saveAble(): self.setEndTime() self.saveTab() from mainwindowtabs.billTab import BillTab bill = SqlHandler.getBill(self.session, self.item) if bill != None: Tabmanager.openTab(tabCreator=BillTab, newItem=bill) else: Tabmanager.openTab(tabCreator=BillTab, newItem=self.item) else: self.errorMessage('Omistajaa ei ole asetettu!') def animalChanged(self, current, previous): if current != None: '''Enable animal related if those arent enabled''' if not self.operationTreeWidget.isEnabled(): self.disableAnimalRelated(False) '''Only if real change have happened then update''' if current != previous: if previous != None: self.updateCurrentVisitAnimal() self.currentVisitAnimal = current.data(0, 0) self.setVisitAnimalData(current.data(0, 0)) else: '''If current is None then treeWidget is empty and all data will be removed''' if self.operationTreeWidget.isEnabled(): self.clearAnimalRelated() self.disableAnimalRelated(True) self.currentVisitAnimal = None '''Clears text areas and operation tree''' def clearAnimalRelated(self): #self.ui.animalNameLabel.setText('Ei valittua eläintä') self.ui.amanuensisTextEdit.setPlainText('') self.ui.statusTextEdit.setPlainText('') self.ui.diagnosisTextEdit.setPlainText('') self.ui.treatmentTextEdit.setPlainText('') self.operationTreeWidget.clearTreeWidget() self.visititemTreeWidget.clearTreeWidget() '''Saves current data to self.currentVisitAnimal''' def updateCurrentVisitAnimal(self): print('VisitTab: updateCurrentVisitAnimal') if self.currentVisitAnimal != None: self.currentVisitAnimal.update(self.getVisitAnimalData()) def getVisitAnimalData(self): print('VisitTab: getVisitAnimalData') data = {} data['anamnesis'] = self.ui.amanuensisTextEdit.toPlainText() data['status'] = self.ui.statusTextEdit.toPlainText() data['diagnosis'] = self.ui.diagnosisTextEdit.toPlainText() data['treatment'] = self.ui.treatmentTextEdit.toPlainText() self.updateCurerentOperation() data['operations'] = self.operationTreeWidget.getItemsFromList() data['items'] = self.visititemTreeWidget.getItemsFromList() #self.clearOperationRelated() self.disableOperationRelated(True) return data def setVisitAnimalData(self, visitanimal): #self.ui.animalNameLabel.setText(visitanimal.animal.name) self.ui.amanuensisTextEdit.setPlainText(visitanimal.anamnesis) self.ui.statusTextEdit.setPlainText(visitanimal.status) self.ui.diagnosisTextEdit.setPlainText(visitanimal.diagnosis) self.ui.treatmentTextEdit.setPlainText(visitanimal.treatment) self.operationTreeWidget.setItems(visitanimal.operations) self.visititemTreeWidget.setItems(visitanimal.items) def ownerSet(self): self.disableAnimalTree(False) #if self.item == None: #item_tmp = self.makeItem() #SqlHandler.addItem(self.session, item_tmp) #self.item = item_tmp def disableAnimalTree(self, state): self.animalTreeWidget.setDisabled(state) if state: self.disableAnimalRelated(state) def disableAnimalRelated(self, state): self.ui.amamnesisLabel.setDisabled(state) self.ui.amanuensisTextEdit.setDisabled(state) self.ui.statusLabel.setDisabled(state) self.ui.statusTextEdit.setDisabled(state) self.ui.diagnosisLabel.setDisabled(state) self.ui.diagnosisTextEdit.setDisabled(state) self.ui.threatmentLabel.setDisabled(state) self.ui.treatmentTextEdit.setDisabled(state) self.operationTreeWidget.setDisabled(state) self.visititemTreeWidget.setDisabled(state) self.itemTreeWidget.setDisabled(state) self.ui.openSummaryButton.setDisabled(state) if state: self.disableOperationRelated(state) def disableOperationRelated(self, state): self.ui.operationNameLabel.setDisabled(state) self.ui.priceLabel.setDisabled(state) self.ui.priceSpinBox.setDisabled(state) self.ui.retailPriceLabel.setDisabled(state) self.ui.retailPriceLabel_2.setDisabled(state) self.ui.descriptionLabel.setDisabled(state) self.ui.descriptionTextEdit.setDisabled(state) self.ui.stackedWidget.setDisabled(state) self.ui.countSpinBox.setDisabled(state) self.ui.countLabel.setDisabled(state) '''-------------OVERLOADED FUNCTIONS-----------------''' def getType(self=None): return 'Visit' def getName(self=None): return 'Käynti' def getData(self): data = {} data["start_time"] = self.qdateToPy(self.ui.startTimeEdit.dateTime()) data["owner"] = self.ownerserachline.getCurrentItem() data["vet"] = self.ui.vetComboBox.itemData( self.ui.vetComboBox.currentIndex()) data["visit_reason"] = self.ui.reasonTextEdit.toPlainText() endTime = None if self.isEndTimeChanged(): endTime = self.qdateToPy(self.ui.endTimeEdit.dateTime()) data["end_time"] = endTime #update last animal data before saving all animals self.updateCurrentVisitAnimal() data["visitanimals"] = self.animalTreeWidget.getItemsFromList() return data def makeItem(self): data = self.getData() from models.visit import Visit return Visit(data["start_time"], data["owner"], data["vet"], data["visit_reason"], data["end_time"], data["visitanimals"]) def saveAble(self): if self.ownerserachline.getCurrentItem() != None: return True else: return False ''' If owner is not set then ignore all else changed is True''' def hasChanged(self): if self.ownerserachline.getCurrentItem() != None: return True else: return False def getMessageBoxText(self): return 'Haluatko tallentaa käyntiin tehdyt muutokset?'
class PhoneRecipieDialog(QDialog): def __init__(self, parent=None, item=None, animal=None): from uipy.ui_phonerecipiedialog import Ui_PhoneRecipieDialog QDialog.__init__(self, parent=parent) self.ui = Ui_PhoneRecipieDialog() self.ui.setupUi(self) self.session = SqlHandler.newSession() self.item = item self.animal = None if animal != None: self.animal = SqlHandler.makeCopy(self.session, animal) self.configure() self.createConnections() self.setBasicInfo() def configure(self): from mainwindowtabs.animaltab import AnimalTab self.animalsearch = SearchLineEdit(tabcreator=AnimalTab, session=self.session, parent=self, function=SqlHandler.searchAnimal) self.ui.searchLineEditLayout.addWidget(self.animalsearch) self.recipieMedicineTreeWidget = GenericTreeWidget(session=self.session, parent=self) self.recipieMedicineTreeWidget.setTitle('Reseptituotteet') self.recipieMedicineTreeWidget.setHeader(headertexts=['id', 'Nimi', 'Määrä'], hidecolumns=[0]) self.recipieMedicineTreeWidget.setButtons([ButtonType.add, ButtonType.open, ButtonType.remove]) self.recipieMedicineTreeWidget.setInputMethod(dialog=RecipieMedicineDialog, autoAdd=True) self.ui.verticalLayout.insertWidget(2, self.recipieMedicineTreeWidget) def setBasicInfo(self): if self.item != None: self.animalsearch.setCurrentItem(self.item.animal) self.animalsearch.setDisabled(True) self.ui.madeTimeEdit.setDate(self.item.made_time) if self.item.call_time != None: self.ui.dateTimeEdit.setDate(self.item.call_time) self.recipieMedicineTreeWidget.setItems(self.item.recipiemedicines) else: if self.animal != None: self.animalsearch.setCurrentItem(self.animal) self.animalsearch.setDisabled(True) self.ui.madeTimeEdit.setDateTime(datetime.now()) def createConnections(self): self.ui.canselButton.clicked.connect(self.closeDialog) self.ui.saveButton.clicked.connect(self.saveDialog) self.ui.nowButton.clicked.connect(self.setRingTime) def setRingTime(self): self.ui.dateTimeEdit.setDateTime(datetime.now()) def saveDialog(self): if self.animalsearch.getCurrentItem() != None: if self.item != None: self.item.update() self.parent().update() self.closeDialog() else: self.item = SqlHandler.PhoneRecipie(self.animalsearch.getCurrentItem(), self.recipieMedicineTreeWidget.getItemsFromList()) self.item.update(self.getData()) SqlHandler.addItem(self.session, self.item) self.parent().update() self.closeDialog() def getData(self): data = [] data.append(self.animalsearch.getCurrentItem()) data.append(self.ui.madeTimeEdit.dateTime().toPyDateTime()) data.append(self.ui.dateTimeEdit.datetime().toPyDateTime() if self.ui.dateTimeEdit.dateTime() != datetime(2000,1,1) else None) data.append(self.recipieMedicineTreeWidget.getItemsFromList()) return data def closeDialog(self): self.session.close() self.setParent(None) self.close()
class OperationSelectorDialog(QWidget): def __init__(self, parent=None): QWidget.__init__(self,parent) self.resize(280, 150)#Todo: find good values self.serachlineedit = SearchLineEdit(parent=self, function=None) self.setWindowTitle('Operaatiopohja haku') self.makeComboBox() self.makeButtons() self.makeLayout() def makeComboBox(self): self.combobox = QComboBox(parent=self) self.combobox.addItem('Lääkintä', SqlHandler.searchAnimal)#MedicationBase self.combobox.addItem('Rokotus', SqlHandler.searchAnimal)#VaccinationBase self.combobox.addItem('Leikkaus', SqlHandler.searchAnimal)#SurgeryBase self.combobox.addItem('Ultraäänitutkimus', SqlHandler.searchAnimal)#UltrasonicBase self.combobox.addItem('Endoskopointi', SqlHandler.searchAnimal)#EndoscopyBase self.combobox.addItem('Ontumatutkimus', SqlHandler.searchAnimal)#LamenessBase self.combobox.addItem('Röntkentutkimus', SqlHandler.searchAnimal)#XrayBase self.combobox.addItem('Hammastutkimus', SqlHandler.searchAnimal)#DentalexaminationBase self.combobox.addItem('Laboratoriotutkimus', SqlHandler.searchAnimal)#OperationBase self.combobox.addItem('muu', SqlHandler.searchAnimal)#OperationBase self.combobox.currentIndexChanged['int'].connect(self.changeSearchLineEditFunction) self.combobox.setCurrentIndex(0) def makeButtons(self): self.cancelButton = QPushButton(parent=self, text='Hylkää') self.cancelButton.clicked.connect(self.close) self.okButton = QPushButton(parent=self, text='Valitse') self.okButton.clicked.connect(self.okPressed) def makeLayout(self): print('makeLayout') buttonslayout = QHBoxLayout() buttonslayout.addStretch() buttonslayout.addWidget(self.cancelButton) buttonslayout.addWidget(self.okButton) searchLayout = QHBoxLayout() searchLayout.addWidget(QLabel(text='Etsi', parent=self)) searchLayout.addWidget(self.serachlineedit) selectorlayout = QVBoxLayout() selectorlayout.addLayout(searchLayout) selectorlayout.addWidget(QLabel(text='Operaation tyyppi', parent=self)) selectorlayout.addWidget(self.combobox) selectorlayout.addStretch() ownmainlayout = QVBoxLayout() ownmainlayout.addLayout(selectorlayout) ownmainlayout.addLayout(buttonslayout) self.setLayout(ownmainlayout) def changeSearchLineEditFunction(self, index): self.serachlineedit.function = self.combobox.itemData(index) def okPressed(self): item = self.serachlineedit.getCurrentItem() if item != None: self.parent().addAskedItem(item) self.close() else: box = QMessageBox() box.setText('Valitse operaatio') box.exec()
class OperationBaseCreator(QDialog): def __init__(self, parent=None, item=None): QDialog.__init__(self, parent) self.ui = Ui_OperationCreator() self.ui.setupUi(self) self.session = SqlHandler.newSession() if item != None: self.item = SqlHandler.makeCopy(self.session, item) else: self.item = None from models.operation import SurgeryBaseItem self.itemTreeWidget = ItemTreeWidget(session = self.session, parent=self, creator=SurgeryBaseItem) self.itemTreeWidget.setTitle("Leikkauksen tavarat") self.ui.itemPageLayout.addWidget(self.itemTreeWidget) self.itemSearchEdit = SearchLineEdit(tabcreator=ItemCreatorDialog, session=self.session, parent=self, function=SqlHandler.searchItem) self.ui.searchLineEditLayout.insertWidget(0,self.itemSearchEdit) self.configureConnections() self.setBasicInfo() def getCurrentItemType(self): return self.ui.typeComboBox.currentText() def configureConnections(self): self.ui.typeComboBox.currentIndexChanged['int'].connect(self.setSpecialInfo) self.ui.closeButton.clicked.connect(self.closeCreator) self.ui.saveButton.clicked.connect(self.saveCreator) self.ui.resitCheckBox.stateChanged.connect(self.showHideResistRelative) self.ui.getFromMedicineButton.clicked.connect(self.getMedicineDuration) self.ui.editmedicine.clicked.connect(self.openCurrentMedicine) def openCurrentMedicine(self): current_item = self.itemSearchEdit.getCurrentItem() if current_item != None: creator = ItemCreatorDialog(parent=self.itemSearchEdit,item=current_item) creator.show() else: self.errorMessage('Lääkettä ei ole valittu!') def getMedicineDuration(self): current_item = self.itemSearchEdit.getCurrentItem() if current_item != None: if current_item.getType() == 'Vaccine': self.ui.durationspinBox.setValue(current_item.duration.days if current_item.duration != None else 0) else: self.errorMessage('Valittu tuote ei ole lääke!') else: self.errorMessage('Lääkettä ei ole valittu!') def showHideResistRelative(self, state): self.ui.label_6.setEnabled(True if state>0 else False) self.ui.durationspinBox.setEnabled(True if state>0 else False) self.ui.label_8.setEnabled(True if state>0 else False) self.ui.getFromMedicineButton.setEnabled(True if state>0 else False) def closeCreator(self): self.session.close() self.setParent(None) self.close() def saveCreator(self): if len(self.ui.nameEdit.text()) > 0: self.updateItem() if not self.item is self.session: self.session.add(self.item) self.session.commit() self.parent().addAskedItem(self.item) self.closeCreator() else: self.errorMessage('Operaatiopohjaa ei voida tallentaa sillä sen nimeä ei ole asetettu.') def updateItem(self): functio = self.ui.typeComboBox.itemData(self.ui.typeComboBox.currentIndex()) args = inspect.getargspec(functio.__init__).args name = self.ui.nameEdit.text() price = self.ui.priceSpinBox.value() description = self.ui.descriptionTextEdit.toPlainText() duration = timedelta(self.ui.durationspinBox.value()) need_resit = self.ui.resitCheckBox.isChecked() item = self.itemSearchEdit.getCurrentItem() if self.item == None: if 'need_resit' in args: self.item = functio(name, price, description, duration, need_resit, item) elif 'item' in args: self.item = functio(name, price, description, item) elif 'items' in args: self.item = functio(name, price, description, self.itemTreeWidget.getItemsFromList()) else: self.item = functio(name, price, description) else: tmp_dict = {} if 'need_resit' in args: tmp_dict = {"name":name, "price":price, "description":description, "duration":duration, "need_resit":need_resit, "item":item} elif 'item' in args: tmp_dict = {"name":name, "price":price, "description":description, "item":item} elif 'items' in args: tmp_dict = {"name":name, "price":price, "description":description, "items":self.itemTreeWidget.getItemsFromList()} else: tmp_dict = {"name":name, "price":price, "description":description} self.item.update(tmp_dict) def setBasicInfo(self): self.setTypes() if self.item != None: self.ui.typeComboBox.setCurrentIndex(self.ui.typeComboBox.findText(self.item.getName())) self.ui.typeComboBox.setDisabled(True) self.ui.nameEdit.setText(self.item.name) self.ui.priceSpinBox.setValue(self.item.price) self.ui.descriptionTextEdit.setPlainText(self.item.description) if(self.item.hasItem()): if(self.item.hasDuration()): self.ui.resitCheckBox.setDisabled(False) self.ui.durationspinBox.setDisabled(True) if(self.item.need_resit): self.ui.getFromMedicineButton.setDisabled(False) self.ui.resitCheckBox.setCheckState(2) #Checked self.ui.durationspinBox.setDisabled(False) self.ui.durationspinBox.setValue(self.item.duration.days) self.itemSearchEdit.addAskedItem(self.item.item) if(self.item.hasList()): self.itemTreeWidget.setItems(self.item.items) def setTypes(self): from models.translationtables import g_operationbase_translation_dict from models.operation import OperationBase,VaccinationBase,SurgeryBase,MedicationBase, LabBase,LamenessBase,XrayBase,UltrasonicBase,EndoscopyBase,DentalexaminationBase for item in [OperationBase,VaccinationBase,SurgeryBase,MedicationBase, LabBase,LamenessBase,XrayBase,UltrasonicBase,EndoscopyBase,DentalexaminationBase]: self.ui.typeComboBox.addItem(g_operationbase_translation_dict[item.__name__], item) def setSpecialInfo(self, index): from models.operation import VaccinationBase, MedicationBase, SurgeryBase operationType = self.ui.typeComboBox.itemData(index).__name__ #get baseObject name if operationType is VaccinationBase.__name__: self.ui.stackedWidget.setCurrentIndex(self.ui.stackedWidget.indexOf(self.ui.vaccinePage)) self.ui.resitCheckBox.setDisabled(False) self.ui.durationspinBox.setDisabled(False) elif operationType is MedicationBase.__name__: self.ui.stackedWidget.setCurrentIndex(self.ui.stackedWidget.indexOf(self.ui.vaccinePage)) self.ui.resitCheckBox.setDisabled(True) self.ui.durationspinBox.setDisabled(True) elif operationType is SurgeryBase.__name__: self.ui.stackedWidget.setCurrentIndex(self.ui.stackedWidget.indexOf(self.ui.itemPage)) else: self.ui.stackedWidget.setCurrentIndex(self.ui.stackedWidget.indexOf(self.ui.emptyPage)) def errorMessage(self,msg): box = QMessageBox() box.setText(msg) box.exec()
def configure(self): from mainwindowtabs.itemcreatordialog import ItemCreatorDialog self.searchItemEdit = SearchLineEdit(tabcreator=ItemCreatorDialog,session=self.session, parent=self, function=SqlHandler.searchItem) self.ui.verticalLayout.insertWidget(0,self.searchItemEdit)
class VisitTab(GenericTab): def __init__(self, parent=None, item=None): owner = None animal = None #check if item is dictionary. So it is called by ownerTab if(item != None and item.__class__.__name__ == 'dict'): if("owner" in item): owner = item["owner"] if("animal" in item): animal = item["animal"] item = None GenericTab.__init__(self, parent=parent, item=item) self.ui = Ui_Visit() self.ui.setupUi(self) self.ui.stackedWidget.setCurrentIndex(0) #TODO:remove if needed self.currentVisitAnimal = None self.currentOperation = None self.configure() self.createConnections() self.setBasicInfo() if(owner != None): owner = SqlHandler.makeCopy(self.session,owner) self.ownerserachline.setCurrentItem(owner) if(animal != None): animal = SqlHandler.makeCopy(self.session,animal) self.animalTreeWidget.addAskedItem(animal) #TODO find function to add animal self.disableAnimalTree(False) ''' setup Visit ''' def setBasicInfo(self): self.disableAnimalTree(True) if self.item != None: self.ownerserachline.setCurrentItem(self.item.owner) self.ui.reasonTextEdit.setPlainText(self.item.visit_reason) if self.item.start_time != None: self.ui.startTimeEdit.setDateTime(self.item.start_time) if self.item.end_time: self.ui.endTimeEdit.setDateTime(self.item.end_time) self.setVet(self.item.vet) self.animalTreeWidget.setItems(self.item.visitanimals) self.disableAnimalTree(False) else: self.ui.startTimeEdit.setDateTime(datetime.datetime.now()) self.setVet() def setVet(self, vet=None): self.ui.vetComboBox.clear() for vet_temp in SqlHandler.searchVet(self.session): self.ui.vetComboBox.addItem(vet_temp.name, vet_temp) if vet != None: for index in range(0, self.ui.vetComboBox.count()): if self.ui.vetComboBox.itemData(index).id == vet.id: self.ui.vetComboBox.setCurrentIndex(index) return else: pass #TODO: Select current vet! ConfigServer def configure(self): self.operationTreeWidget = OperationTreeWidget(parent=self, session=self.session) self.ui.operationMainLayout.insertWidget(0, self.operationTreeWidget) self.ui.operationMainLayout.setStretch(0,1) self.ui.operationMainLayout.setStretch(1,2) from models.operation import VisitItem self.visititemTreeWidget = ItemTreeWidget(parent=self, session=self.session, creator=VisitItem) self.ui.itemAddLayout.addWidget(self.visititemTreeWidget) self.animalTreeWidget = VisitAnimalTreeWidget(parent=self, session=self.session) self.ui.animalSelectorLayout.addWidget(self.animalTreeWidget) from models.operation import SurgeryItem self.itemTreeWidget = ItemTreeWidget(parent=self, session=self.session, creator=SurgeryItem) self.ui.itemTreeWidgetLayout.addWidget(self.itemTreeWidget) from mainwindowtabs.ownertab import OwnerTab self.ownerserachline = SearchLineEdit(tabcreator=OwnerTab, session=self.session ,parent=self, function=SqlHandler.searchOwner) self.ui.ownerLayout.addWidget(self.ownerserachline) def createConnections(self): self.ownerserachline.ui.editor.returnPressed.connect(self.ownerSet) self.animalTreeWidget.ui.treeWidget.currentItemChanged.connect(self.animalChanged) self.operationTreeWidget.ui.treeWidget.currentItemChanged.connect(self.operationChanged) self.ui.saveandcloseButton.clicked.connect(self.saveAndCloseTab) self.ui.saveButton.clicked.connect(self.saveTab) self.ui.billButton.clicked.connect(self.openBill) self.ui.closeButton.clicked.connect(self.closeTab) self.ui.openSummaryButton.clicked.connect(self.openSummary) #item will be string from SummaryTab it item is None do not update def addAskedItem(self, item): if item != None: self.ui.treatmentTextEdit.setPlainText(item) def openSummary(self): from mainwindowtabs.summarytab import SummaryTab Tabmanager.openTab(tabCreator=SummaryTab, newItem={'owner' : self.ownerserachline.getCurrentItem(), 'visitanimal' : self.animalTreeWidget.getSelectedItem(), 'text':self.ui.treatmentTextEdit.toPlainText()}, returnTab=self) def updateOperation(self, line): operation = line.data(0,0) #get operation string_list = operation.stringList() #get string list for i in operation.getUpdateRange(): line.setText(i,string_list[i]) def operationChanged(self,current, previous): if current != None: '''Enable operation related if those arent enabled''' if not self.ui.operationNameLabel.isEnabled(): self.disableOperationRelated(False) '''Only if real change have happened then update''' if current != previous: if self.currentOperation != None: self.updateCurerentOperation() if previous != None: self.updateOperation(previous) self.currentOperation = current.data(0,0) self.setOperationData(current.data(0,0)) else: '''If current is None then treeWidget is empty and all data will be removed''' if self.ui.operationNameLabel.isEnabled(): self.clearOperationRelated() self.disableOperationRelated(True) self.currentOperation = None def clearOperationRelated(self): self.closeOperation() def closeOperation(self): self.ui.operationNameLabel.setText('Nimi') self.ui.retailPriceLabel.setText('0.00') self.itemTreeWidget.clearTreeWidget() self.ui.priceSpinBox.setValue(0) self.ui.countSpinBox.setValue(1) self.ui.descriptionTextEdit.setPlainText('') self.ui.stackedWidget.setCurrentIndex(0) def updateCurerentOperation(self): if self.currentOperation != None: data = {} data["price"] = self.ui.priceSpinBox.value() data["description"] = self.ui.descriptionTextEdit.toPlainText() data["count"] = self.ui.countSpinBox.value() if self.currentOperation.hasList(): data["items"] = self.itemTreeWidget.getItemsFromList() self.currentOperation.update(data) def setOperationData(self, operation=None): self.ui.operationNameLabel.setText(operation.base.name) self.ui.retailPriceLabel.setText(str(operation.base.price)) self.ui.priceSpinBox.setValue(operation.price) self.ui.descriptionTextEdit.setPlainText(operation.description) self.ui.countSpinBox.setValue(operation.count) if self.currentOperation.hasList(): self.ui.stackedWidget.setCurrentIndex(2) self.itemTreeWidget.setItems(self.currentOperation.items) elif self.currentOperation.base.hasItem(): self.ui.stackedWidget.setCurrentIndex(1) self.ui.nameLabel.setText(self.currentOperation.base.item.name if self.currentOperation.base.item != None else '') self.ui.typeLabel.setText(self.currentOperation.base.item.typeName() if self.currentOperation.base.item != None else '') self.ui.itemPriceLabel.setText(str(self.currentOperation.base.item.price) if self.currentOperation.base.item != None else '') else: self.ui.stackedWidget.setCurrentIndex(0) def isEndTimeChanged(self): from models.translationtables import g_visit_end_time_start time = self.qdateToPy(self.ui.endTimeEdit.dateTime()).date() if datetime.datetime.strptime("1.1.2000", "%d.%m.%Y").date() == time: return True else: return False #this function sets end time to current time if it have not been changed yet def setEndTime(self): if self.isEndTimeChanged(): self.ui.endTimeEdit.setDateTime(datetime.datetime.now()) def openBill(self): if self.saveAble(): self.setEndTime() self.saveTab() from mainwindowtabs.billTab import BillTab bill = SqlHandler.getBill(self.session, self.item) if bill != None: Tabmanager.openTab(tabCreator=BillTab, newItem=bill) else: Tabmanager.openTab(tabCreator=BillTab, newItem=self.item) else: self.errorMessage('Omistajaa ei ole asetettu!') def animalChanged(self,current, previous): if current != None: '''Enable animal related if those arent enabled''' if not self.operationTreeWidget.isEnabled(): self.disableAnimalRelated(False) '''Only if real change have happened then update''' if current != previous: if previous != None: self.updateCurrentVisitAnimal() self.currentVisitAnimal = current.data(0,0) self.setVisitAnimalData(current.data(0,0)) else: '''If current is None then treeWidget is empty and all data will be removed''' if self.operationTreeWidget.isEnabled(): self.clearAnimalRelated() self.disableAnimalRelated(True) self.currentVisitAnimal = None '''Clears text areas and operation tree''' def clearAnimalRelated(self): #self.ui.animalNameLabel.setText('Ei valittua eläintä') self.ui.amanuensisTextEdit.setPlainText('') self.ui.statusTextEdit.setPlainText('') self.ui.diagnosisTextEdit.setPlainText('') self.ui.treatmentTextEdit.setPlainText('') self.operationTreeWidget.clearTreeWidget() self.visititemTreeWidget.clearTreeWidget() '''Saves current data to self.currentVisitAnimal''' def updateCurrentVisitAnimal(self): print('VisitTab: updateCurrentVisitAnimal') if self.currentVisitAnimal != None: self.currentVisitAnimal.update(self.getVisitAnimalData()) def getVisitAnimalData(self): print('VisitTab: getVisitAnimalData') data = {} data['anamnesis'] = self.ui.amanuensisTextEdit.toPlainText() data['status'] = self.ui.statusTextEdit.toPlainText() data['diagnosis'] = self.ui.diagnosisTextEdit.toPlainText() data['treatment'] = self.ui.treatmentTextEdit.toPlainText() self.updateCurerentOperation() data['operations'] = self.operationTreeWidget.getItemsFromList() data['items'] = self.visititemTreeWidget.getItemsFromList() #self.clearOperationRelated() self.disableOperationRelated(True) return data def setVisitAnimalData(self,visitanimal): #self.ui.animalNameLabel.setText(visitanimal.animal.name) self.ui.amanuensisTextEdit.setPlainText(visitanimal.anamnesis) self.ui.statusTextEdit.setPlainText(visitanimal.status) self.ui.diagnosisTextEdit.setPlainText(visitanimal.diagnosis) self.ui.treatmentTextEdit.setPlainText(visitanimal.treatment) self.operationTreeWidget.setItems(visitanimal.operations) self.visititemTreeWidget.setItems(visitanimal.items) def ownerSet(self): self.disableAnimalTree(False) #if self.item == None: #item_tmp = self.makeItem() #SqlHandler.addItem(self.session, item_tmp) #self.item = item_tmp def disableAnimalTree(self, state): self.animalTreeWidget.setDisabled(state) if state: self.disableAnimalRelated(state) def disableAnimalRelated(self, state): self.ui.amamnesisLabel.setDisabled(state) self.ui.amanuensisTextEdit.setDisabled(state) self.ui.statusLabel.setDisabled(state) self.ui.statusTextEdit.setDisabled(state) self.ui.diagnosisLabel.setDisabled(state) self.ui.diagnosisTextEdit.setDisabled(state) self.ui.threatmentLabel.setDisabled(state) self.ui.treatmentTextEdit.setDisabled(state) self.operationTreeWidget.setDisabled(state) self.visititemTreeWidget.setDisabled(state) self.itemTreeWidget.setDisabled(state) self.ui.openSummaryButton.setDisabled(state) if state: self.disableOperationRelated(state) def disableOperationRelated(self, state): self.ui.operationNameLabel.setDisabled(state) self.ui.priceLabel.setDisabled(state) self.ui.priceSpinBox.setDisabled(state) self.ui.retailPriceLabel.setDisabled(state) self.ui.retailPriceLabel_2.setDisabled(state) self.ui.descriptionLabel.setDisabled(state) self.ui.descriptionTextEdit.setDisabled(state) self.ui.stackedWidget.setDisabled(state) self.ui.countSpinBox.setDisabled(state) self.ui.countLabel.setDisabled(state) '''-------------OVERLOADED FUNCTIONS-----------------''' def getType(self=None): return 'Visit' def getName(self=None): return 'Käynti' def getData(self): data = {} data["start_time"] = self.qdateToPy(self.ui.startTimeEdit.dateTime()) data["owner"] = self.ownerserachline.getCurrentItem() data["vet"] = self.ui.vetComboBox.itemData(self.ui.vetComboBox.currentIndex()) data["visit_reason"] = self.ui.reasonTextEdit.toPlainText() endTime = None if self.isEndTimeChanged(): endTime = self.qdateToPy(self.ui.endTimeEdit.dateTime()) data["end_time"] = endTime #update last animal data before saving all animals self.updateCurrentVisitAnimal() data["visitanimals"] = self.animalTreeWidget.getItemsFromList() return data def makeItem(self): data = self.getData() from models.visit import Visit return Visit(data["start_time"], data["owner"], data["vet"],data["visit_reason"], data["end_time"], data["visitanimals"]) def saveAble(self): if self.ownerserachline.getCurrentItem() != None: return True else: return False ''' If owner is not set then ignore all else changed is True''' def hasChanged(self): if self.ownerserachline.getCurrentItem() != None: return True else: return False def getMessageBoxText(self): return 'Haluatko tallentaa käyntiin tehdyt muutokset?'
class PhoneRecipieDialog(QDialog): def __init__(self, parent=None, item=None, animal=None): from uipy.ui_phonerecipiedialog import Ui_PhoneRecipieDialog QDialog.__init__(self, parent=parent) self.ui = Ui_PhoneRecipieDialog() self.ui.setupUi(self) self.session = SqlHandler.newSession() self.item = item self.animal = None if animal != None: self.animal = SqlHandler.makeCopy(self.session, animal) self.configure() self.createConnections() self.setBasicInfo() def configure(self): from mainwindowtabs.animaltab import AnimalTab self.animalsearch = SearchLineEdit(tabcreator=AnimalTab, session=self.session, parent=self, function=SqlHandler.searchAnimal) self.ui.searchLineEditLayout.addWidget(self.animalsearch) self.recipieMedicineTreeWidget = GenericTreeWidget( session=self.session, parent=self) self.recipieMedicineTreeWidget.setTitle('Reseptituotteet') self.recipieMedicineTreeWidget.setHeader( headertexts=['id', 'Nimi', 'Määrä'], hidecolumns=[0]) self.recipieMedicineTreeWidget.setButtons( [ButtonType.add, ButtonType.open, ButtonType.remove]) self.recipieMedicineTreeWidget.setInputMethod( dialog=RecipieMedicineDialog, autoAdd=True) self.ui.verticalLayout.insertWidget(2, self.recipieMedicineTreeWidget) def setBasicInfo(self): if self.item != None: self.animalsearch.setCurrentItem(self.item.animal) self.animalsearch.setDisabled(True) self.ui.madeTimeEdit.setDate(self.item.made_time) if self.item.call_time != None: self.ui.dateTimeEdit.setDate(self.item.call_time) self.recipieMedicineTreeWidget.setItems(self.item.recipiemedicines) else: if self.animal != None: self.animalsearch.setCurrentItem(self.animal) self.animalsearch.setDisabled(True) self.ui.madeTimeEdit.setDateTime(datetime.now()) def createConnections(self): self.ui.canselButton.clicked.connect(self.closeDialog) self.ui.saveButton.clicked.connect(self.saveDialog) self.ui.nowButton.clicked.connect(self.setRingTime) def setRingTime(self): self.ui.dateTimeEdit.setDateTime(datetime.now()) def saveDialog(self): if self.animalsearch.getCurrentItem() != None: if self.item != None: self.item.update() self.parent().update() self.closeDialog() else: self.item = SqlHandler.PhoneRecipie( self.animalsearch.getCurrentItem(), self.recipieMedicineTreeWidget.getItemsFromList()) self.item.update(self.getData()) SqlHandler.addItem(self.session, self.item) self.parent().update() self.closeDialog() def getData(self): data = [] data.append(self.animalsearch.getCurrentItem()) data.append(self.ui.madeTimeEdit.dateTime().toPyDateTime()) data.append(self.ui.dateTimeEdit.datetime().toPyDateTime( ) if self.ui.dateTimeEdit.dateTime() != datetime(2000, 1, 1) else None) data.append(self.recipieMedicineTreeWidget.getItemsFromList()) return data def closeDialog(self): self.session.close() self.setParent(None) self.close()
class ItemCreatorTab(GenericTab): def __init__(self, parent=None, item=None): GenericTab.__init__(self, parent=parent, item=item) self.ui = Ui_ItemCreatorTab() self.ui.setupUi(self) self.session = SqlHandler.newSession() self.itemSearchEdit = SearchLineEdit(tabcreator=ItemCreatorDialog, session=self.session, parent=self, function=SqlHandler.searchItem) self.configure() self.configureConnctions() self.modifyItemCreator() def modifyItemCreator(self): pass def openItem(self, item=None): self.itemCreator = ItemCreatorDialog(parent=self, item=item) #self.ui.itemdialoglayout.addWidget(self.itemCreator) self.itemCreator.show() def openItemFromSearch(self): item = self.itemSearchEdit.getCurrentItem() if item: self.openItem(item) else: logDEBUG(self, "openItemFromSearch: item is None") def itemCanBeDeleted(self, item): return True def deleteItemFromSearch(self): item = self.itemSearchEdit.getCurrentItem() if item and self.askUser(): if self.itemCanBeDeleted(item): SqlHandler.removeItem(self.session, item) else: pass #error def refresh(self): SqlHandler.commitSession(self.session) def askUser(self): reply = QMessageBox.question( self, 'Huomio!', 'Haluatko varmasti poistaa tuotteen pysyvästi?', QMessageBox.Ok, QMessageBox.Cancel) if reply == QMessageBox.Ok: return True else: return False def openItemNew(self): self.openItem(item=None) def configureConnctions(self): self.ui.newItemButton.clicked.connect(self.openItemNew) self.ui.openItemButton.clicked.connect(self.openItemFromSearch) self.ui.deleteItemButton.clicked.connect(self.deleteItemFromSearch) def configure(self): self.ui.searchlayout.insertWidget(0, self.itemSearchEdit) #self.ui.itemdialoglayout.addWidget(self.itemCreator) # item is returned so we should refresh session def addAskedItem(self, item): self.refresh()