Example #1
0
class NoteBook( QFrame ):

    # =======================================================================
    def __init__(self, parent=None):

        # -------------------------------------------------------------------
        QFrame.__init__(self, parent);

        # -------------------------------------------------------------------
        self.PARENT                                 = parent;
        self.DEBUG                                  = False;
        self.LOG_TAG                                = str(self.__class__.__name__).upper();

        self.setGeometry( 4, 34, 1012, 606 );
        self.setStyleSheet( "QFrame{ font: 12px 'monospace'; color: #fff; background-color: rbga(0,0,0, 190); border-style: solid; border-width: 5px; border-color: #FFF; }" );

        # -------------------------------------------------------------------
        self.NOTEBOOK_FILE                          = self.PARENT.STORAGE_ROOT+"notebook.file";
        # -------------------------------------------------------------------
        self.TEXT                                   = QTextEdit( "TEST: TEST", self );
        self.TEXT.setGeometry(5, 35, 980, 560);
        self.TEXT.setStyleSheet("QTextEdit{ font: 12px 'monospace'; color: #fff; margin: 5px; padding: 5px; border-style: solid; border-width: 1px; border-color: #FFF; }")
        self.TEXT.setReadOnly( False );
        self.TEXT.setAcceptRichText( False );
        self.TEXT.setUndoRedoEnabled( True );
        self.TEXT.LineWrapMode( self.TEXT.WidgetWidth );

        self.TEXT.textChanged.connect( self.TEXT_CHANGED );


        # -------------------------------------------------------------------
        self.hide();

        self.IS_OPEN                                = False;
        self.KEEP_OPEN                              = False;

        # -------------------------------------------------------------------
        self.UPDATE_TIMER                           = QTimer();
        self.UPDATE_TIMER.singleShot( 1000, self.UPDATE_FRAME );
        
        # -------------------------------------------------------------------
        self.PARENT.SPLASH.STATUS( self.LOG_TAG+": [INIT]" );
        # -------------------------------------------------------------------

    # =======================================================================
    def TEXT_CHANGED( self ):

        # -------------------------------------------------------------------
        pass;
        #self.TEXT.setText( str(self.TEXT.toPlainText() );
        #self.TEXT.setText( str(self.TEXT.text() ) );
        # -------------------------------------------------------------------

    # =======================================================================
    def CMD( self, _CMD ):

        # -------------------------------------------------------------------
        #__exec:notebook:notes:show"
        #__exec:notebook:notes:hide"
        #__exec:notebook:notes:keep_open:(0|1)

        # -------------------------------------------------------------------
        try:
    
            # -----------------------------------------------
            if _CMD[0] == "notes":

                if _CMD[1] == "show":
                    self.SHOW_NOTES( );

                elif _CMD[1] == "hide":
                    self.HIDE_NOTES( );

                elif _CMD[1] == "keep_open":

                    self.KEEP_OPEN = True if _CMD[2] == "1" else False;
                    self.LOCAL_INFO_LOG( "notebook:notes:keep_open:"+_CMD[2] );


                return;
            # -----------------------------------------------
            if _CMD[0] == "cmd":
                pass;
                    
            # -----------------------------------------------

        except Exception as _err:
            self.LOCAL_ERROR_LOG( str(_CMD)+" | "+str(_err) );
    
        # -------------------------------------------------------------------


    # =======================================================================
    def SHOW_NOTES( self ):

        # -------------------------------------------------------------------
        try:
            """
            out = "";
            for _key in self.LAST_PAGE_REQUEST_HEADERS:
                _l = "-----------------------------------------------------------------------\n";
                _l += '["'+_key+'"] => \n["'+self.LAST_PAGE_REQUEST_HEADERS[ _key ]+'"]'+"\n";
                print( "L: "+_l );
                out += _l;

            self.TEXT.setText( out );
            """
            self.show();
            self.IS_OPEN = True;
            self.TEXT.setFocus( True );

        except Exception as _err:
            self.LOCAL_ERROR_LOG( "'Can't show notes: "+str(_err) );


        # -------------------------------------------------------------------

    # =======================================================================
    def HIDE_NOTES( self ):

        # -------------------------------------------------------------------
        self.hide();

        self.IS_OPEN = False;
        self.TEXT.clearFocus();
        # -------------------------------------------------------------------

    # =======================================================================
    def UPDATE_FRAME(self):

        # -------------------------------------------------------------------
        return;
        # -------------------------------------------------------------------
        """
        try:
            _style = "";
            _conf  = [];

            with open( "./ALPHA_FRAME.conf" ) as FS:
                _conf = FS.readline();
                print(_conf );
                _conf = _conf.split("|");

                self.setGeometry( 
                    int(_conf[0]), 
                    int(_conf[1]), 
                    int(_conf[2]), 
                    int(_conf[3])
                );


                for _line in FS:
                    _style += _line;

            self.setStyleSheet( _style );

        except Exception as _err:
            print("ERROR: "+str(_err));
            
        self.UPDATE_TIMER.singleShot( 1000, self.UPDATE_FRAME );
        """
        # -------------------------------------------------------------------

    # =======================================================================
    def LOAD(self):
    
        # -------------------------------------------------------------------
        if self.DEBUG:
            pass;

        # -------------------------------------------------------------------

        try:

            # ---------------------------------------------------
            self.PARENT.SPLASH.STATUS( self.LOG_TAG+": [LOAD]" );
            self.PARENT.LOG_HANDLER.WRITE_LOG( "Doc-Browser: NOTEBOOK: LODE: ");

            self.TEXT.clear();

            with open( self.NOTEBOOK_FILE, "r") as FS:

                for line in FS:
                    self.TEXT.append(line.strip());
                    #self.TEXT.insertPlainText(line);
                    #self.TEXT.insertHtml(line);

            self.PARENT.LOG_HANDLER.WRITE_LOG( "Doc-Browser: NOTEBOOK: LODE: Done");
            # ---------------------------------------------------

        except Exception as _err:
            self.LOCAL_ERROR_LOG( "Can't load notes: "+str(_err) );
        # -------------------------------------------------------------------

    # =======================================================================
    def SAVE(self):

        # -------------------------------------------------------------------
        if self.DEBUG:
            pass;

        # -------------------------------------------------------------------
        try:

            # ---------------------------------------------------
            self.PARENT.LOG_HANDLER.WRITE_LOG( "Doc-Browser: NOTEBOOK: SAVE: ");

            DATA = str(self.TEXT.toPlainText()).split("\n");

            with open( self.NOTEBOOK_FILE, "w") as FS:

                for line in DATA:
                    FS.write( line+"\n" );

            self.PARENT.LOG_HANDLER.WRITE_LOG( "Doc-Browser: NOTEBOOK: SAVE: Done");
            # ---------------------------------------------------

        except Exception as _err:
            self.LOCAL_ERROR_LOG( "Can't save notes: "+str(_err) );

        # -------------------------------------------------------------------

    # =======================================================================
    def LOCAL_INFO_LOG( self, _msg, METHOD=None ):

        # -------------------------------------------------------------------
        if METHOD is None:
            self.PARENT.LOCAL_INFO_LOG( "['"+self.LOG_TAG+"']: ["+_msg+"]" );
        else:
            self.PARENT.LOCAL_INFO_LOG( "['"+self.LOG_TAG+"."+METHOD+"']: ["+_msg+"]" );
        # -------------------------------------------------------------------

    # =======================================================================
    def LOCAL_ERROR_LOG( self, _msg, METHOD=None ):

        # -------------------------------------------------------------------
        if self.DEBUG or self.PARENT.DEBUG_GLOBAL: self.PARENT.DEBUGGER.DEBUG();
        # -------------------------------------------------------------------
        if METHOD is None:
            self.PARENT.LOCAL_ERROR_LOG( "['"+self.LOG_TAG+"']: ["+_msg+"]" );
        else:
            self.PARENT.LOCAL_ERROR_LOG( "['"+self.LOG_TAG+"."+METHOD+"']: ["+_msg+"]" );
        # -------------------------------------------------------------------

    # =======================================================================
    def LOCAL_WARNING_LOG( self, _msg, METHOD=None ):

        # -------------------------------------------------------------------
        if METHOD is None:
            self.PARENT.LOCAL_WARNING_LOG( "['"+self.LOG_TAG+"']: ["+_msg+"]" );
        else:
            self.PARENT.LOCAL_WARNING_LOG( "['"+self.LOG_TAG+"."+METHOD+"']: ["+_msg+"]" );
class SettingsWidget(QWidget):

    DEFAULT_FPS = 60
    DEFAULT_MAX_TICK = 1000
    DEFAULT_WIDTH = 800
    DEFAULT_HEIGHT = 640

    def __init__(self, parent=None, mainWindow=None):
        super(SettingsWidget, self).__init__(parent)
        self.mainWindow = mainWindow

        vbox = QVBoxLayout()

        self._spriteWidgets = []
        self._showSpritesWidgetIndex = 0

        hboxFPSTick = QHBoxLayout()
        self._fpsTE = QLineEdit(self)
        self._maxTickTE = QLineEdit(self)
        
        hboxFPSTick.addWidget(self._fpsTE)
        hboxFPSTick.addWidget(self._maxTickTE)

        hboxSize = QHBoxLayout()
        self._widthTE = QLineEdit(self)
        self._heightTE = QLineEdit(self)

        hboxSize.addWidget(self._widthTE)
        hboxSize.addWidget(self._heightTE)

        vbox.addLayout(hboxFPSTick)
        vbox.addLayout(hboxSize)

        self._initConsequencesTE = QTextEdit(self)
        self._initConsequencesTE.setUndoRedoEnabled(True)

        vbox.addWidget(self._initConsequencesTE)

        self.init()

        self._fpsTE.textChanged.connect(self.window().setModified)
        self._maxTickTE.textChanged.connect(self.window().setModified)
        self._widthTE.textChanged.connect(self.window().setModified)
        self._heightTE.textChanged.connect(self.window().setModified)
        self._initConsequencesTE.textChanged.connect(self.window().setModified)

        self.setLayout(vbox)

    def init(self):
        self._fpsTE.setText(str(SettingsWidget.DEFAULT_FPS))
        self._maxTickTE.setText(str(SettingsWidget.DEFAULT_MAX_TICK))
        self._heightTE.setText(str(SettingsWidget.DEFAULT_HEIGHT))
        self._widthTE.setText(str(SettingsWidget.DEFAULT_WIDTH))

    def getFPS(self):
        try:
            return int(self._fpsTE.text())
        except ValueError:
            return SettingsWidget.DEFAULT_FPS

    def setFPS(self, fps):
        self._fpsTE.setText(str(fps))
    
    def getMaxTick(self):
        try:
            return int(self._maxTickTE.text())
        except ValueError:
            return SettingsWidget.DEFAULT_MAX_TICK

    def setMaxTick(self, maxTick):
        self._maxTickTE.setText(str(maxTick))

    def getWidth(self):
        try:
            return int(self._widthTE.text())
        except ValueError:
            return SettingsWidget.DEFAULT_WIDTH

    def setWidth(self, width):
        self._widthTE.setText(str(width))

    def getHeight(self):
        try:
            return int(self._heightTE.text())
        except ValueError:
            return SettingsWidget.DEFAULT_HEIGHT

    def setHeight(self, height):
        self._heightTE.setText(str(height))

    def setInitConsequences(self, consequences):
        consequencesStr = ';'.join(consequences) + ';'
        self._initConsequencesTE.setText(consequencesStr)

    def getInitConsequences(self):
        consequencesStr = str(self._initConsequencesTE.toPlainText()).strip()
        if consequencesStr == '':
            return []
        else:
            consequences = consequencesStr.split(';')
            if consequences[-1] == '':
                del consequences[-1]
            return consequences
Example #3
0
class Ui_RightWidget(object):
    def setupUi(self, RightWidget, server):
        RightWidget.setMinimumHeight(500)

        main_layout = QVBoxLayout(RightWidget)
        main_layout.setContentsMargins(0, 0, 0, 0)
        main_layout.setSpacing(10)

        # We hide all the main elements, to allow the proper viewer to enable
        # (only) the elements that uses.

        if hasattr(server, 'wild_chars'):
            self.text_map = QTextEdit()
            self.text_map.setObjectName('text_map')
            self.text_map.setVisible(False)
            self.text_map.setFocusPolicy(Qt.NoFocus)
            self.text_map.setAutoFillBackground(True)
            self.text_map.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
            self.text_map.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
            self.text_map.setUndoRedoEnabled(False)
            self.text_map.setReadOnly(True)
            # for some unknown reason, the fontmetrics of the text map is wrong
            # if the font is set with a global stylesheet, so we set it on the
            # specific widget.
            self.text_map.setStyleSheet("QTextEdit { font: 13px \"Courier\";}")
            main_layout.addWidget(self.text_map)

            # We calculate the map area size using the size of the font used. We
            # assume that the font is a monospace ones.
            font_metrics = self.text_map.fontMetrics()
            self.text_map.setFixedWidth(font_metrics.width('#' * server.map_width))
            self.text_map.setFixedHeight(font_metrics.height() * server.map_height)

            # The rightwidget width is determined by the map area size
            RightWidget.setMinimumWidth(self.text_map.width())
        else:
            RightWidget.setMinimumWidth(220)

        self.box_status = QWidget()
        self.box_status.setVisible(False)
        main_layout.addWidget(self.box_status)

        status_layout = QGridLayout(self.box_status)
        status_layout.setContentsMargins(5, 5, 5, 0)
        status_layout.setHorizontalSpacing(0)
        status_layout.setVerticalSpacing(15)

        label_health = QLabel()
        label_health.setMinimumWidth(80)
        label_health.setText(QApplication.translate("RightWidget", "Health"))
        status_layout.addWidget(label_health, 0, 0)

        self.bar_health = QProgressBar()
        self.bar_health.setObjectName("bar_health")
        self.bar_health.setFixedHeight(22)
        self.bar_health.setProperty("value", QVariant(100))
        self.bar_health.setTextVisible(False)
        status_layout.addWidget(self.bar_health, 0, 1)

        label_mana = QLabel()
        label_mana.setMinimumWidth(80)
        label_mana.setText(QApplication.translate("RightWidget", "Mana"))
        status_layout.addWidget(label_mana, 1, 0)

        self.bar_mana = QProgressBar()
        self.bar_mana.setObjectName("bar_mana")
        self.bar_mana.setFixedHeight(22)
        self.bar_mana.setProperty("value", QVariant(100))
        self.bar_mana.setTextVisible(False)
        status_layout.addWidget(self.bar_mana, 1, 1)

        label_movement = QLabel()
        label_movement.setMinimumWidth(80)
        label_movement.setText(QApplication.translate("RightWidget", "Movement"))
        status_layout.addWidget(label_movement, 2, 0)

        self.bar_movement = QProgressBar()
        self.bar_movement.setObjectName("bar_movement")
        self.bar_movement.setFixedHeight(22)
        self.bar_movement.setProperty("value", QVariant(100))
        self.bar_movement.setTextVisible(False)
        status_layout.addWidget(self.bar_movement, 2, 1)

        main_layout.addStretch()
class ArcParamEditorWidget(QWidget):
    def __init__(self, parent=None):
        super(ArcParamEditorWidget, self).__init__(parent)

        hbox = QHBoxLayout()
        vbox = QVBoxLayout()

        hbox2 = QHBoxLayout()
        self._lb1 = QLabel('Arc index : ', self)
        self._indexQCB = QComboBox(self)
        self._indexQCB.setMaxVisibleItems(5)
        hbox2.addWidget(self._lb1)
        hbox2.addWidget(self._indexQCB)

        self._labelTE = QTextEdit(self)
        self._labelTE.setUndoRedoEnabled(True)
        vbox.addLayout(hbox2)
        vbox.addWidget(self._labelTE)

        self._formulaTE = QTextEdit(self)
        self._formulaTE.setUndoRedoEnabled(True)
        self._consequencesTE = QTextEdit(self)
        self._consequencesTE.setUndoRedoEnabled(True)
        hbox.addLayout(vbox)
        hbox.addWidget(self._formulaTE)
        hbox.addWidget(self._consequencesTE)
        self.setLayout(hbox)

        self._selectedArc = None

        self._labelTE.textChanged.connect(self.labelChanged)
        self._formulaTE.textChanged.connect(self.formulaChanged)
        self._consequencesTE.textChanged.connect(self.consequencesChanged)

        self._indexQCB.currentIndexChanged.connect(self.window().setModified)
        self._labelTE.textChanged.connect(self.window().setModified)
        self._formulaTE.textChanged.connect(self.window().setModified)
        self._consequencesTE.textChanged.connect(self.window().setModified)

    def init(self):
        self._indexQCB.clear()
        self.setLabel('Arc label.')
        self.setFormula('Arc boolean formula.')
        self.setConsequences('Arc consequeneces.')

    def setIndexes(self, maxIndex, index):
        self._indexQCB.clear()
        for i in xrange(maxIndex):
            self._indexQCB.addItem(str(i))
        self._indexQCB.setCurrentIndex(index)

    def setLabel(self, label):
        self._labelTE.setText(label)

    def setFormula(self, formula):
        self._formulaTE.setText(formula)

    def setConsequences(self, consequences):
        self._consequencesTE.setText(consequences)

    def labelChanged(self):
        try:
            self._selectedArc.setLabel(str(self._labelTE.toPlainText()))
        except AttributeError:
            pass

    def formulaChanged(self):
        try:
            self._selectedArc.setFormula(str(self._formulaTE.toPlainText()))
        except AttributeError:
            pass

    def consequencesChanged(self):
        try:
            self._selectedArc.setConsequences(str(self._consequencesTE.toPlainText()))
        except AttributeError:
            pass

    def setSelectedArc(self, a):
        try:
            self._indexQCB.currentIndexChanged.disconnect(self._selectedArc.setIndex)
        except (AttributeError, TypeError):
            pass

        self._selectedArc = a
        try:
            self.setIndexes(a.getMaxIndex(), a.getIndex())
            self.setLabel(a.getLabel())
            self.setFormula(a.getFormula())
            self.setConsequences(a.getConsequencesStr())
            self._indexQCB.currentIndexChanged.connect(a.setIndex)
        except AttributeError:
            self.init()
Example #5
0
class Ui_dev_client(object):
    def setupUi(self, dev_client):
        dev_client.resize(935, 660)
        dev_client.setWindowTitle(QApplication.translate("dev_client", "DevClient"))

        self.centralwidget = QWidget(dev_client)
        dev_client.setCentralWidget(self.centralwidget)

        main_layout = QGridLayout(self.centralwidget)
        main_layout.setContentsMargins(5, 5, 5, 3)
        main_layout.setSpacing(3)
        main_layout.setColumnStretch(0, 1)
        main_layout.setRowStretch(1, 1)

        top_layout = QHBoxLayout()
        top_layout.setContentsMargins(0, 0, 0, 0)
        top_layout.setSpacing(5)

        top_label_conn = QLabel()
        top_label_conn.setText(QApplication.translate("dev_client", "Connection"))
        top_layout.addWidget(top_label_conn)

        self.list_conn = QComboBox()
        self.list_conn.setFixedSize(145, 26)
        self.list_conn.setFocusPolicy(Qt.NoFocus)
        top_layout.addWidget(self.list_conn)

        self.list_account = QComboBox()
        self.list_account.setFixedSize(145, 26)
        self.list_account.setFocusPolicy(Qt.NoFocus)
        top_layout.addWidget(self.list_account)

        top_layout.addItem(QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum))
        top_label_account = QLabel()
        top_label_account.setText(QApplication.translate("dev_client", "Account"))
        top_layout.addWidget(top_label_account)

        self.button_connect = QPushButton()
        self.button_connect.setFixedSize(105, 26)
        self.button_connect.setFocusPolicy(Qt.NoFocus)
        self.button_connect.setIcon(QIcon(":/images/connect.png"))
        self.button_connect.setIconSize(QSize(16, 16))
        self.button_connect.setText(QApplication.translate("dev_client", "Connect"))
        top_layout.addWidget(self.button_connect)

        self.button_option = QPushButton()
        self.button_option.setFixedSize(105, 26)
        self.button_option.setFocusPolicy(Qt.NoFocus)
        self.button_option.setIcon(QIcon(":/images/option.png"))
        self.button_option.setIconSize(QSize(16, 16))
        self.button_option.setText(QApplication.translate("dev_client", "Option"))
        top_layout.addWidget(self.button_option)
        main_layout.addLayout(top_layout, 0, 0)

        right_layout = QVBoxLayout()
        right_layout.setContentsMargins(0, 0, 0, 0)
        right_layout.addItem(QSpacerItem(40, 29, QSizePolicy.Minimum, QSizePolicy.Fixed))

        self.rightpanel = QWidget()
        self.rightpanel.setMinimumWidth(225)
        right_layout.addWidget(self.rightpanel)
        main_layout.addLayout(right_layout, 0, 1, 3, 1)

        self.output_splitter = QSplitter(self.centralwidget)
        self.output_splitter.setOrientation(Qt.Vertical)
        self.output_splitter.setHandleWidth(3)
        self.output_splitter.setChildrenCollapsible(False)

        self.text_output = QTextEdit(self.output_splitter)
        self.text_output.setMinimumWidth(690)
        self.text_output.setFocusPolicy(Qt.NoFocus)
        self.text_output.setAutoFillBackground(True)
        self.text_output.setUndoRedoEnabled(False)
        self.text_output.setReadOnly(True)

        self.text_output_noscroll = QTextEdit(self.output_splitter)
        self.text_output_noscroll.setMinimumWidth(690)
        self.text_output_noscroll.setFocusPolicy(Qt.NoFocus)
        self.text_output_noscroll.setAutoFillBackground(True)
        self.text_output_noscroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.text_output_noscroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.text_output_noscroll.setUndoRedoEnabled(False)
        self.text_output_noscroll.setReadOnly(True)
        main_layout.addWidget(self.output_splitter, 1, 0)

        bottom_layout = QHBoxLayout()
        bottom_layout.setContentsMargins(0, 0, 0, 0)
        bottom_layout.setSpacing(5)

        self.text_input = QComboBox()
        self.text_input.setMinimumWidth(660)
        self.text_input.setFixedHeight(25)
        self.text_input.setEditable(True)
        self.text_input.addItem("")
        bottom_layout.addWidget(self.text_input)

        self.toggle_splitter = QPushButton()
        self.toggle_splitter.setFixedSize(25, 25)
        self.toggle_splitter.setFocusPolicy(Qt.NoFocus)
        self.toggle_splitter.setIcon(QIcon(":/images/split-window.png"))
        bottom_layout.addWidget(self.toggle_splitter)
        main_layout.addLayout(bottom_layout, 2, 0)