예제 #1
0
파일: main.py 프로젝트: rivasfdk/Romano
    def __init__(self):
        super(Main, self).__init__()
        self.ui = Ui_Main()
        self.ui.setupUi(self)
        self.ticketsTableModel = TicketsTableModel([])
        self.ui.ticketsTableView.setModel(self.ticketsTableModel)
        horizontalHeader = self.ui.ticketsTableView.horizontalHeader()
        horizontalHeader.setResizeMode(QtGui.QHeaderView.ResizeToContents)
        config = configparser.ConfigParser()
        settings_path = os.path.abspath(os.path.dirname(__file__))
        config.read(os.path.join(settings_path, 'settings.ini'))

        self.api = API(config.get('Server', 'Host'),
                       config.getint('Server', 'Port'))
        self.ui.actionNewReception.triggered.connect(self.openTicket)
        self.ui.actionNewDispatch.triggered.connect(self.openTicket)
        self.ui.actionLogout.triggered.connect(self.logout)
        self.ui.refreshButton.clicked.connect(self.getTickets)
        self.api.getTicketsFinished.connect(self.getTicketsFinished)
        self.api.createTicketFinished.connect(self.getTickets)
        self.api.closeTicketFinished.connect(self.printTicket)
        self.api.printTicketFinished.connect(self.printTicketFinished)
        self.ui.ticketsTableView.doubleClicked.connect(self.closeTicket)

        self.login()
예제 #2
0
파일: main.py 프로젝트: elshaka/Romano
  def __init__(self):
    super(Main, self).__init__()
    self.ui = Ui_Main()
    self.ui.setupUi(self)
    self.ticketsTableModel = TicketsTableModel([])
    self.ui.ticketsTableView.setModel(self.ticketsTableModel)
    horizontalHeader = self.ui.ticketsTableView.horizontalHeader()
    horizontalHeader.setResizeMode(QtGui.QHeaderView.ResizeToContents)
    config = configparser.ConfigParser()
    settings_path = os.path.abspath(os.path.dirname(__file__))
    config.read(os.path.join(settings_path, 'settings.ini'))

    self.api = API(config.get('Server','Host'), config.getint('Server','Port'))
    self.ui.actionNewReception.triggered.connect(self.openTicket)
    self.ui.actionNewDispatch.triggered.connect(self.openTicket)
    self.ui.actionLogout.triggered.connect(self.logout)
    self.ui.refreshButton.clicked.connect(self.getTickets)
    self.api.getTicketsFinished.connect(self.getTicketsFinished)
    self.api.createTicketFinished.connect(self.getTickets)
    self.api.closeTicketFinished.connect(self.printTicket)
    self.api.printTicketFinished.connect(self.printTicketFinished)
    self.ui.ticketsTableView.doubleClicked.connect(self.closeTicket)

    self.login()
예제 #3
0
파일: main.py 프로젝트: rivasfdk/Romano
class Main(QtGui.QMainWindow):
    def __init__(self):
        super(Main, self).__init__()
        self.ui = Ui_Main()
        self.ui.setupUi(self)
        self.ticketsTableModel = TicketsTableModel([])
        self.ui.ticketsTableView.setModel(self.ticketsTableModel)
        horizontalHeader = self.ui.ticketsTableView.horizontalHeader()
        horizontalHeader.setResizeMode(QtGui.QHeaderView.ResizeToContents)
        config = configparser.ConfigParser()
        settings_path = os.path.abspath(os.path.dirname(__file__))
        config.read(os.path.join(settings_path, 'settings.ini'))

        self.api = API(config.get('Server', 'Host'),
                       config.getint('Server', 'Port'))
        self.ui.actionNewReception.triggered.connect(self.openTicket)
        self.ui.actionNewDispatch.triggered.connect(self.openTicket)
        self.ui.actionLogout.triggered.connect(self.logout)
        self.ui.refreshButton.clicked.connect(self.getTickets)
        self.api.getTicketsFinished.connect(self.getTicketsFinished)
        self.api.createTicketFinished.connect(self.getTickets)
        self.api.closeTicketFinished.connect(self.printTicket)
        self.api.printTicketFinished.connect(self.printTicketFinished)
        self.ui.ticketsTableView.doubleClicked.connect(self.closeTicket)

        self.login()

    def openTicket(self):
        actionSender = self.sender()
        if actionSender == self.ui.actionNewReception:
            newTicketDialog = NewTicket(1, self.user.allow_manual, self)
        elif actionSender == self.ui.actionNewDispatch:
            newTicketDialog = NewTicket(2, self.user.allow_manual, self)

        if newTicketDialog.exec_() == QtGui.QDialog.Accepted:
            self.api.create_ticket(newTicketDialog.ticket)
        newTicketDialog.st.alive = False

    def closeTicket(self, tableIndex):
        ticket_data = {
            'ticket': self.ticketsTableModel.getTicket(tableIndex.row()),
            'weight_captured': False,
            'lots': []
        }

        try:
            fileObject = open("%s.ticket" % ticket_data['ticket'].number, 'rb')
            ticket_data = pickle.load(fileObject)
            print("Se cargo el ticket %s" % ticket_data['ticket'].number)
        except FileNotFoundError:
            print("No se encontró el archivo para el ticket %s" %
                  ticket_data['ticket'].number)

        if not hasattr(ticket_data['ticket'], 'transactions_attributes'):
            ticket_data['ticket'].transactions_attributes = []

        closeTicketDialog = CloseTicket(ticket_data, self.user.allow_manual,
                                        self)
        if closeTicketDialog.exec_() == QtGui.QDialog.Accepted:
            self.api.close_ticket(closeTicketDialog.ticket)
            self.currentTicket = closeTicketDialog.ticket
        closeTicketDialog.st.alive = False

    def printTicket(self):
        self.getTickets()
        self.api.print_ticket(self.currentTicket)

    def printTicketFinished(self, data):
        filename = QtCore.QDir.tempPath(
        ) + "/ticket_%s.pdf" % self.currentTicket.number
        _file = QtCore.QFile(filename)
        _file.open(QtCore.QIODevice.WriteOnly)
        _file.write(data)
        _file.close
        if os.name == "posix":
            os.system("xdg-open %s" % filename)
        elif os.name == "nt":
            os.startfile(filename)

    def login(self):
        loginDialog = Login(self.api, self)
        if loginDialog.exec_() == QtGui.QDialog.Accepted:
            self.user = loginDialog.user
            self.ui.refreshButton.setEnabled(False)
            self.api.get_tickets()

            self.ui.actionUserName.setText(self.user.name)
            self.center()
            self.show()
            self.api.get_document_types()
        else:
            self.close()

    def logout(self):
        self.hide()
        self.login()

    def getTickets(self):
        self.ui.refreshButton.setEnabled(False)
        self.api.get_tickets()

    def getTicketsFinished(self, tickets):
        self.ui.ticketsTableView.model().refreshTickets(tickets)
        self.ui.refreshButton.setEnabled(True)

    def center(self):
        qr = self.frameGeometry()
        cp = QtGui.QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())
예제 #4
0
파일: main.py 프로젝트: elshaka/Romano
class Main(QtGui.QMainWindow):
  def __init__(self):
    super(Main, self).__init__()
    self.ui = Ui_Main()
    self.ui.setupUi(self)
    self.ticketsTableModel = TicketsTableModel([])
    self.ui.ticketsTableView.setModel(self.ticketsTableModel)
    horizontalHeader = self.ui.ticketsTableView.horizontalHeader()
    horizontalHeader.setResizeMode(QtGui.QHeaderView.ResizeToContents)
    config = configparser.ConfigParser()
    settings_path = os.path.abspath(os.path.dirname(__file__))
    config.read(os.path.join(settings_path, 'settings.ini'))

    self.api = API(config.get('Server','Host'), config.getint('Server','Port'))
    self.ui.actionNewReception.triggered.connect(self.openTicket)
    self.ui.actionNewDispatch.triggered.connect(self.openTicket)
    self.ui.actionLogout.triggered.connect(self.logout)
    self.ui.refreshButton.clicked.connect(self.getTickets)
    self.api.getTicketsFinished.connect(self.getTicketsFinished)
    self.api.createTicketFinished.connect(self.getTickets)
    self.api.closeTicketFinished.connect(self.printTicket)
    self.api.printTicketFinished.connect(self.printTicketFinished)
    self.ui.ticketsTableView.doubleClicked.connect(self.closeTicket)

    self.login()

  def openTicket(self):
    actionSender = self.sender()
    if actionSender == self.ui.actionNewReception:
      newTicketDialog = NewTicket(1, self.user.allow_manual, self)
    elif actionSender == self.ui.actionNewDispatch:
      newTicketDialog = NewTicket(2, self.user.allow_manual, self)

    if newTicketDialog.exec_() == QtGui.QDialog.Accepted:
      self.api.create_ticket(newTicketDialog.ticket)
    newTicketDialog.st.alive = False

  def closeTicket(self, tableIndex):
    ticket_data = {
      'ticket': self.ticketsTableModel.getTicket(tableIndex.row()),
      'weight_captured': False,
      'lots': []
    }

    try:
      fileObject = open("%s.ticket" % ticket_data['ticket'].number, 'rb')
      ticket_data = pickle.load(fileObject)
      print("Se cargo el ticket %s" % ticket_data['ticket'].number)
    except FileNotFoundError:
      print("No se encontró el archivo para el ticket %s" % ticket_data['ticket'].number)

    if not hasattr(ticket_data['ticket'], 'transactions_attributes'):
      ticket_data['ticket'].transactions_attributes = []

    closeTicketDialog = CloseTicket(ticket_data, self.user.allow_manual, self)
    if closeTicketDialog.exec_() == QtGui.QDialog.Accepted:
      self.api.close_ticket(closeTicketDialog.ticket)
      self.currentTicket = closeTicketDialog.ticket
    closeTicketDialog.st.alive = False

  def printTicket(self):
    self.getTickets()
    self.api.print_ticket(self.currentTicket)

  def printTicketFinished(self, data):
    filename = QtCore.QDir.tempPath() + "/ticket_%s.pdf" % self.currentTicket.number
    _file = QtCore.QFile(filename)
    _file.open(QtCore.QIODevice.WriteOnly)
    _file.write(data)
    _file.close
    if os.name == "posix":
      os.system("xdg-open %s" % filename)
    elif os.name == "nt":
      os.startfile(filename)

  def login(self):
    loginDialog = Login(self.api, self)
    if loginDialog.exec_() == QtGui.QDialog.Accepted:
      self.user = loginDialog.user
      self.ui.refreshButton.setEnabled(False)
      self.api.get_tickets()

      self.ui.actionUserName.setText(self.user.name)
      self.center()
      self.show()
      self.api.get_document_types()
    else:
      self.close()
      
  def logout(self):
    self.hide()
    self.login()

  def getTickets(self):
    self.ui.refreshButton.setEnabled(False)
    self.api.get_tickets()

  def getTicketsFinished(self, tickets):
    self.ui.ticketsTableView.model().refreshTickets(tickets)
    self.ui.refreshButton.setEnabled(True)

  def center(self):
    qr = self.frameGeometry()
    cp = QtGui.QDesktopWidget().availableGeometry().center()
    qr.moveCenter(cp)
    self.move(qr.topLeft())