Exemplo n.º 1
0
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)

        self.network_access = QNetworkAccessManager()

        # TODO : a better regex that does not need <code></code> tags
        self.level_regex = re.compile('<code>(Hexcells level v1.*?)</code>',
                                      re.IGNORECASE | re.MULTILINE)

        self.setWindowTitle("Open from web page")
        self.setModal(True)
        layout = QVBoxLayout()
        self.setLayout(layout)

        url_selection = QHBoxLayout()
        url_selection.addWidget(QLabel("URL:"))
        self.url_field = QLineEdit(Dialog.current_url)
        self.url_field.setMinimumWidth(400)
        url_selection.addWidget(self.url_field)
        fetch_button = QPushButton("Fetch")
        fetch_button.clicked.connect(self.fetch_url)
        url_selection.addWidget(fetch_button)
        layout.addLayout(url_selection)

        self.fetch_in_progress = QProgressBar()
        layout.addWidget(self.fetch_in_progress)

        def level_selection_changed():
            self.button_box.button(QDialogButtonBox.Ok).setEnabled(True)

        self.levels = QListWidget()
        layout.addWidget(self.levels)
        self.levels.itemSelectionChanged.connect(level_selection_changed)

        def rejected():
            self.selected_level_file = None
            self.reject()

        def accepted():
            self.selected_level_file = self.levels.selectedItems()[0].data(
                qt.UserRole)
            self.accept()

        self.button_box = QDialogButtonBox(QDialogButtonBox.Ok
                                           | QDialogButtonBox.Cancel)
        self.button_box.rejected.connect(rejected)
        self.button_box.accepted.connect(accepted)
        self.button_box.button(QDialogButtonBox.Ok).setEnabled(False)
        layout.addWidget(self.button_box)

        self.webpage_content = Dialog.current_content
        self.find_levels_in_content()
Exemplo n.º 2
0
    def __init__(self,parent=None):
      QDialog.__init__(self,parent)
      
      self.network_access = QNetworkAccessManager()
      
      # TODO : a better regex that does not need <code></code> tags
      self.level_regex = re.compile('<code>(Hexcells level v1.*?)</code>', re.IGNORECASE|re.MULTILINE)

      self.setWindowTitle("Open from web page")
      self.setModal(True)
      layout = QVBoxLayout()
      self.setLayout(layout)
        
      url_selection = QHBoxLayout()
      url_selection.addWidget(QLabel("URL:"))
      self.url_field = QLineEdit(Dialog.current_url)
      self.url_field.setMinimumWidth(400)
      url_selection.addWidget(self.url_field)
      fetch_button = QPushButton("Fetch")
      fetch_button.clicked.connect(self.fetch_url)
      url_selection.addWidget(fetch_button)  
      layout.addLayout(url_selection)
      
      self.fetch_in_progress = QProgressBar()
      layout.addWidget(self.fetch_in_progress)
      
      def level_selection_changed():
        self.button_box.button(QDialogButtonBox.Ok).setEnabled(True)
      self.levels = QListWidget()
      layout.addWidget(self.levels)
      self.levels.itemSelectionChanged.connect(level_selection_changed)
      
      def rejected():
        self.selected_level_file = None
        self.reject()
      def accepted():
        self.selected_level_file = self.levels.selectedItems()[0].data(qt.UserRole)
        self.accept()
      self.button_box = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
      self.button_box.rejected.connect(rejected)
      self.button_box.accepted.connect(accepted)
      self.button_box.button(QDialogButtonBox.Ok).setEnabled(False)
      layout.addWidget(self.button_box)
      
      self.webpage_content = Dialog.current_content
      self.find_levels_in_content()
Exemplo n.º 3
0
    def __init__(self, playtest=False):
        QMainWindow.__init__(self)

        if not playtest:
            self.resize(1280, 720)
        self.setWindowIcon(QIcon(here('resources', 'player.ico')))

        self.scene = Scene()

        self.central_widget = QWidget()
        self.setCentralWidget(self.central_widget)
        layout = QVBoxLayout()
        layout.setContentsMargins(QMargins())
        layout.setSpacing(0)
        self.central_widget.setLayout(layout)

        top_layout = QHBoxLayout()
        layout.addLayout(top_layout)

        self.author_align_label = QLabel()
        self.author_align_label.setStyleSheet('color: rgba(0,0,0,0%)')
        top_layout.addWidget(self.author_align_label, 0)

        self.title_label = QLabel()
        self.title_label.setAlignment(qt.AlignHCenter)
        font = self.title_label.font()
        multiply_font_size(font, 1.8)
        self.title_label.setFont(font)
        top_layout.addWidget(self.title_label, 1)

        self.author_label = QLabel()
        self.author_label.setAlignment(qt.AlignRight)
        top_layout.addWidget(self.author_label, 0)

        self.view = View(self.scene)
        layout.addWidget(self.view, 1)

        self.information_label = QLabel()
        self.information_label.setAlignment(qt.AlignHCenter)
        self.information_label.setWordWrap(True)
        self.information_label.setContentsMargins(5, 5, 5, 5)
        font = self.information_label.font()
        multiply_font_size(font, 1.5)
        self.information_label.setFont(font)
        layout.addWidget(self.information_label)

        self.scene.playtest = self.playtest = playtest

        menu = self.menuBar().addMenu("&File")

        if not playtest:
            action = menu.addAction("&Open...", self.load_file,
                                    QKeySequence.Open)
            menu.addSeparator()
            action = menu.addAction("&Paste from Clipboard", self.paste,
                                    QKeySequence('Ctrl+V'))
            menu.addSeparator()

        action = menu.addAction(
            "&Quit", self.close,
            QKeySequence('Tab') if playtest else QKeySequence.Quit)
        if playtest:
            QShortcut(QKeySequence.Quit, self, action.trigger)
        else:
            QShortcut(QKeySequence.Close, self, action.trigger)

        menu = self.menuBar().addMenu("&Preferences")

        self.swap_buttons_action = action = make_check_action(
            "&Swap Buttons", self, self.scene, 'swap_buttons')
        menu.addAction(action)

        menu = self.menuBar().addMenu("&Solve")
        menu.setEnabled(solve is not None)

        menu.addAction("&One Step", self.scene.solve_step, QKeySequence("S"))

        menu.addAction("Confirm &Revealed", self.scene.confirm_proven,
                       QKeySequence("C"))

        menu.addAction("&Clear Revealed", self.scene.clear_proven,
                       QKeySequence("X"))

        menu.addSeparator()

        menu.addAction("&Solve Completely", self.scene.solve_complete,
                       QKeySequence("Shift+S"))

        menu = self.menuBar().addMenu("&Help")

        action = menu.addAction("&Instructions", help,
                                QKeySequence.HelpContents)

        action = menu.addAction("&About", lambda: about(self.title))

        self.last_used_folder = None

        self.reset()

        try:
            with open(here('player.cfg')) as cfg_file:
                cfg = cfg_file.read()
        except IOError:
            pass
        else:
            load_config(self, self.config_format, cfg)
Exemplo n.º 4
0
    def set_information(self, desc=None):
        dialog = QDialog()
        dialog.setWindowTitle("Level Information")
        layout = QVBoxLayout()
        dialog.setLayout(layout)
        
        layout.addWidget(QLabel("Title:"))
        title_field = QLineEdit(self.scene.title or '')
        title_field.setMaxLength(50)
        layout.addWidget(title_field)
        
        layout.addWidget(QLabel("Author name:"))
        author_field = QLineEdit(self.scene.author or self.default_author or '')
        author_field.setMaxLength(20)
        layout.addWidget(author_field)
        old_author = author_field.text()
        
        information = (self.scene.information or '').splitlines()
        layout.addWidget(QLabel("Custom text hints:"))
        information1_field = QLineEdit(information[0] if information else '')
        information1_field.setMaxLength(120)
        layout.addWidget(information1_field)
        information2_field = QLineEdit(information[1] if len(information)>1 else '')
        information2_field.setMaxLength(120)
        layout.addWidget(information2_field)

        layout.addWidget(QLabel("This text will be displayed within the level"))
        
        def accepted():
            self.scene.title = title_field.text().strip()
            self.scene.author = author_field.text().strip()
            if self.scene.author and self.scene.author!=old_author:
                self.default_author = self.scene.author
            self.scene.information = '\n'.join(line for line in [information1_field.text().strip(), information2_field.text().strip()] if line)
            self.changed()
            dialog.close()
        
        button_box = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
        button_box.rejected.connect(dialog.close)
        button_box.accepted.connect(accepted)
        layout.addWidget(button_box)
        
        dialog.exec_()
Exemplo n.º 5
0
    def __init__(self, playtest=False):
        common.MainWindow.__init__(self)
        
        if not playtest:
            self.resize(1280, 720)
        self.setWindowIcon(QIcon(here('resources', 'player.ico')))

        self.scene = Scene()

        self.central_widget = QWidget()
        self.setCentralWidget(self.central_widget)
        layout = QVBoxLayout()
        layout.setContentsMargins(QMargins())
        layout.setSpacing(0)
        self.central_widget.setLayout(layout)
        
        self.levels_bar = QTabBar()
        layout.addWidget(self.levels_bar)
        self.levels_bar.currentChanged.connect(self.level_change)
        
        top_layout = QHBoxLayout()
        layout.addLayout(top_layout)
        
        self.author_align_label = QLabel()
        self.author_align_label.setStyleSheet('color: rgba(0,0,0,0%)')
        top_layout.addWidget(self.author_align_label, 0)
        
        self.title_label = QLabel()
        self.title_label.setAlignment(qt.AlignHCenter)
        update_font(self.title_label, lambda f: multiply_font_size(f, 1.8))
        top_layout.addWidget(self.title_label, 1)

        self.author_label = QLabel()
        self.author_label.setAlignment(qt.AlignRight)
        top_layout.addWidget(self.author_label, 0)
        
        
        self.view = View(self.scene)
        layout.addWidget(self.view, 1)

        self.information_label = QLabel()
        self.information_label.setAlignment(qt.AlignHCenter)
        self.information_label.setWordWrap(True)
        self.information_label.setContentsMargins(5, 5, 5, 5)
        update_font(self.information_label, lambda f: multiply_font_size(f, 1.5))
        layout.addWidget(self.information_label)

        self.scene.playtest = self.playtest = playtest
        
        
        menu = self.menuBar().addMenu("&File")
        
        if not playtest:
            action = menu.addAction("&Open...", self.load_file, QKeySequence.Open)
            menu.addSeparator()
        
        self.copy_action = action = menu.addAction("&Copy State to Clipboard", lambda: self.copy(display=True), QKeySequence('Ctrl+C'))
        action.setStatusTip("Copy the current state of the level into clipboard, in a text-based .hexcells format, padded with Tab characters.")
        if not playtest:
            action = menu.addAction("&Paste from Clipboard", self.paste, QKeySequence('Ctrl+V'))
            action.setStatusTip("Load a level in text-based .hexcells format that is currently in the clipboard.")
        menu.addSeparator()

        
        action = menu.addAction("&Quit", self.close, QKeySequence('Tab') if playtest else QKeySequence.Quit)
        if playtest:
            QShortcut(QKeySequence.Quit, self, action.trigger)
        
        
        menu = self.menuBar().addMenu("&Edit")
        
        action = menu.addAction("&Undo", self.scene.undo, QKeySequence.Undo)
        QShortcut(QKeySequence('Z'), self, action.trigger)
        action.setStatusTip("Cover the last uncovered cell.")
        action = menu.addAction("Clear &Progress", self.clear_progress)
        menu.addSeparator()
        
        menu.addAction("&Clear Annotations", self.scene.clear_guesses, QKeySequence("X"))
        menu.addAction("Con&firm Annotated Guesses", self.scene.confirm_guesses, QKeySequence("C"))
        menu.addAction("&Deny Annotated Guesses", self.scene.confirm_opposite_guesses, QKeySequence("D"))
        menu.addSeparator()
        
        menu.addAction("Highlight All C&olumn Hints", self.scene.highlight_all_columns)
        menu.addAction("Highlight All F&lower Hints", self.scene.highlight_all_flowers)

        
        menu = self.menuBar().addMenu("&Solve")
        menu.setEnabled(solve is not None)
        
        menu.addAction("&One Step", self.scene.solve_step, QKeySequence("S"))
        action = menu.addAction("Con&firm Solved", self.scene.confirm_guesses, QKeySequence("C"))
        action.setShortcutContext(qt.WidgetWithChildrenShortcut) # To prevent "ambiguous shortcut"
        action = menu.addAction("&Clear Solved", self.scene.clear_guesses, QKeySequence("X"))
        action.setShortcutContext(qt.WidgetWithChildrenShortcut)
        
        menu.addSeparator()
        
        menu.addAction("&Solve Completely", self.scene.solve_complete)

        
        menu = self.menuBar().addMenu("&Preferences")
        
        self.swap_buttons_action = action = make_check_action("&Swap Buttons", self, self.scene, 'swap_buttons')
        menu.addAction(action)

        
        menu = self.menuBar().addMenu("&Help")
        
        action = menu.addAction("&Instructions", self.help, QKeySequence.HelpContents)
        action = menu.addAction("&About", self.about)
        
        
        self.last_used_folder = None
        
        self.close_file()
        
        load_config_from_file(self, self.config_format, 'sixcells', 'player.cfg')
Exemplo n.º 6
0
    def __init__(self, playtest=False):
        QMainWindow.__init__(self)
        
        if not playtest:
            self.resize(1280, 720)
        self.setWindowIcon(QIcon(here('resources', 'player.ico')))

        self.scene = Scene()

        self.central_widget = QWidget()
        self.setCentralWidget(self.central_widget)
        layout = QVBoxLayout()
        layout.setContentsMargins(QMargins())
        layout.setSpacing(0)
        self.central_widget.setLayout(layout)
        
        top_layout = QHBoxLayout()
        layout.addLayout(top_layout)
        
        self.author_align_label = QLabel()
        self.author_align_label.setStyleSheet('color: rgba(0,0,0,0%)')
        top_layout.addWidget(self.author_align_label, 0)
        
        self.title_label = QLabel()
        self.title_label.setAlignment(qt.AlignHCenter)
        font = self.title_label.font()
        multiply_font_size(font, 1.8)
        self.title_label.setFont(font)
        top_layout.addWidget(self.title_label, 1)

        self.author_label = QLabel()
        self.author_label.setAlignment(qt.AlignRight)
        top_layout.addWidget(self.author_label, 0)
        
        
        self.view = View(self.scene)
        layout.addWidget(self.view, 1)

        self.information_label = QLabel()
        self.information_label.setAlignment(qt.AlignHCenter)
        self.information_label.setWordWrap(True)
        self.information_label.setContentsMargins(5, 5, 5, 5)
        font = self.information_label.font()
        multiply_font_size(font, 1.5)
        self.information_label.setFont(font)
        layout.addWidget(self.information_label)

        self.scene.playtest = self.playtest = playtest
        
        
        menu = self.menuBar().addMenu("&File")
        
        if not playtest:
            action = menu.addAction("&Open...", self.load_file, QKeySequence.Open)
            menu.addSeparator()
            action = menu.addAction("&Paste from Clipboard", self.paste, QKeySequence('Ctrl+V'))
            menu.addSeparator()

        
        action = menu.addAction("&Quit", self.close, QKeySequence('Tab') if playtest else QKeySequence.Quit)
        if playtest:
            QShortcut(QKeySequence.Quit, self, action.trigger)
        else:
            QShortcut(QKeySequence.Close, self, action.trigger)
        
        
        menu = self.menuBar().addMenu("&Preferences")
        
        self.swap_buttons_action = action = make_check_action("&Swap Buttons", self, self.scene, 'swap_buttons')
        menu.addAction(action)

        
        menu = self.menuBar().addMenu("&Solve")
        menu.setEnabled(solve is not None)
        
        menu.addAction("&One Step", self.scene.solve_step, QKeySequence("S"))
        
        menu.addAction("Confirm &Revealed", self.scene.confirm_proven, QKeySequence("C"))
        
        menu.addAction("&Clear Revealed", self.scene.clear_proven, QKeySequence("X"))
        
        menu.addSeparator()
        
        menu.addAction("&Solve Completely", self.scene.solve_complete, QKeySequence("Shift+S"))

        
        menu = self.menuBar().addMenu("&Help")
        
        action = menu.addAction("&Instructions", help, QKeySequence.HelpContents)
        
        action = menu.addAction("&About", lambda: about(self.title))
        
        
        self.last_used_folder = None
        
        self.reset()
        
        try:
            with open(here('player.cfg')) as cfg_file:
                cfg = cfg_file.read()
        except IOError:
            pass
        else:
            load_config(self, self.config_format, cfg)
Exemplo n.º 7
0
    def set_information(self, desc=None):
        dialog = QDialog()
        dialog.setWindowTitle("Level Information")
        layout = QVBoxLayout()
        dialog.setLayout(layout)
        
        layout.addWidget(QLabel("Title:"))
        title_field = QLineEdit(self.scene.title or '')
        title_field.setMaxLength(50)
        layout.addWidget(title_field)
        
        layout.addWidget(QLabel("Author name:"))
        author_field = QLineEdit(self.scene.author or self.default_author or '')
        author_field.setMaxLength(20)
        layout.addWidget(author_field)
        old_author = author_field.text()
        
        information = (self.scene.information or '').splitlines()
        layout.addWidget(QLabel("Custom text hints:"))
        information1_field = QLineEdit(information[0] if information else '')
        information1_field.setMaxLength(120)
        layout.addWidget(information1_field)
        information2_field = QLineEdit(information[1] if len(information)>1 else '')
        information2_field.setMaxLength(120)
        layout.addWidget(information2_field)

        layout.addWidget(QLabel("This text will be displayed within the level"))
        
        def accepted():
            self.scene.title = title_field.text().strip()
            self.scene.author = author_field.text().strip()
            if self.scene.author and self.scene.author!=old_author:
                self.default_author = self.scene.author
            self.scene.information = '\n'.join(line for line in [information1_field.text().strip(), information2_field.text().strip()] if line)
            self.changed()
            dialog.close()
        
        button_box = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
        button_box.rejected.connect(dialog.close)
        button_box.accepted.connect(accepted)
        layout.addWidget(button_box)
        
        dialog.exec_()