def __init__(self, scenario): """ Sets up the graphics view, the toolbar and the tracker rectangle. """ super().__init__() self.setObjectName('minimap-widget') layout = QtWidgets.QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) # the content is a scene self.scene = QtWidgets.QGraphicsScene() # tracker rectangle that tracks the view of the main map self.tracker = QtWidgets.QGraphicsRectItem() print(self.tracker.pen().widthF()) self.tracker.setCursor(QtCore.Qt.PointingHandCursor) self.tracker.setZValue(1000) self.tracker.hide() self.scene.addItem(self.tracker) # the view on the scene (no scroll bars) self.view = QtWidgets.QGraphicsView(self.scene) self.view.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.view.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) layout.addWidget(self.view) # the width and height (fixed width throughout the game) self.view.setFixedWidth(self.VIEW_WIDTH) view_height = math.floor(0.6 * self.VIEW_WIDTH) self.view.setFixedHeight(view_height) # tool bar below the mini map self.toolbar = QtWidgets.QToolBar() self.toolbar.setIconSize(QtCore.QSize(20, 20)) # action group (only one of them can be checked at each time) action_group = QtWidgets.QActionGroup(self.toolbar) # political view in the beginning action_political = qt_graphics.create_action(tools.load_ui_icon('icon.mini.political.png'), 'Show political view', action_group, toggle_connection=self.toggled_political, checkable=True) self.toolbar.addAction(action_political) # geographical view self.toolbar.addAction( qt_graphics.create_action(tools.load_ui_icon('icon.mini.geographical.png'), 'Show geographical view', action_group, toggle_connection=self.toggled_geographical, checkable=True)) # wrap tool bar into horizontal layout with stretch l = QtWidgets.QHBoxLayout() l.setContentsMargins(0, 0, 0, 0) l.addWidget(self.toolbar) l.addStretch() # add layout containing tool bar layout.addLayout(l) # store scenario self.scenario = scenario self.removable_items = []
def __init__(self): """ Create toolbar and invoke pressing of first tab. """ super().__init__() layout = QtGui.QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) # create tool bar toolbar = QtGui.QToolBar() action_group = QtGui.QActionGroup(toolbar) toolbar.addAction(g.create_action(t.load_ui_icon('icon.lobby.single.new.png'), 'Start new single player scenario', action_group, toggle_connection=self.toggled_single_player_scenario_selection, checkable=True)) toolbar.addAction(g.create_action(t.load_ui_icon('icon.lobby.single.load.png'), 'Continue saved single player scenario', action_group, toggle_connection=self.toggled_single_player_load_scenario, checkable=True)) toolbar.addSeparator() toolbar.addAction(g.create_action(t.load_ui_icon('icon.lobby.network.png'), 'Show server lobby', action_group, toggle_connection=self.toggled_server_lobby, checkable=True)) toolbar.addAction(g.create_action(t.load_ui_icon('icon.lobby.multiplayer-game.png'), 'Start or continue multiplayer scenario', action_group, toggle_connection=self.toggled_multiplayer_scenario_selection, checkable=True)) layout.addWidget(toolbar) content = QtGui.QWidget() self.content_layout = QtGui.QVBoxLayout(content) self.content_layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(content)
def __init__(self, client): super().__init__() self.toolbar = QtWidgets.QToolBar() action_help = QtWidgets.QAction(tools.load_ui_icon('icon.help.png'), 'Show help', self) action_help.triggered.connect(client.show_help_browser) # TODO with partial make reference to specific page self.toolbar.addAction(action_help) action_quit = QtWidgets.QAction(tools.load_ui_icon('icon.back.startscreen.png'), 'Exit to main menu', self) action_quit.triggered.connect(client.switch_to_start_screen) self.toolbar.addAction(action_quit) # mini map self.mini_map = MiniMap() # info box self.info_box = InfoBox() # main map self.main_map = MainMap() # layout layout = QtWidgets.QGridLayout(self) layout.addWidget(self.toolbar, 0, 0) layout.addWidget(self.mini_map, 1, 0) layout.addWidget(self.info_box, 2, 0) layout.addWidget(self.main_map, 0, 1, 3, 1) layout.setRowStretch(2, 1) # the info box will take all vertical space left layout.setColumnStretch(1, 1) # the map will take all horizontal space left
def __init__(self, parent, content, title=None, modal=True, delete_on_close=False, help_callback=None, close_callback=None): # no frame but a standalong window super().__init__(parent, flags=QtCore.Qt.FramelessWindowHint | QtCore.Qt.Window) # we need this self.setAttribute(QtCore.Qt.WA_StyledBackground) self.setObjectName('gamedialog') # should be deleted on close if delete_on_close: self.setAttribute(QtCore.Qt.WA_DeleteOnClose) # default state is Qt.NonModal if modal: self.setWindowModality(QtCore.Qt.WindowModal) # title bar title_bar = g.DraggableToolBar() title_bar.setIconSize(QtCore.QSize(20, 20)) title_bar.setObjectName('gamedialog-titlebar') title_bar.setSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Fixed) title_bar.dragged.connect(lambda delta: self.move(self.pos() + delta)) # title in titlebar and close icon title = QtWidgets.QLabel(title) title.setObjectName('gamedialog-title') title_bar.addWidget(title) # spacer between titlebar and help/close icons spacer = QtWidgets.QWidget() spacer.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) title_bar.addWidget(spacer) # if help call back is given, add help icon if help_callback: help_action = QtWidgets.QAction(t.load_ui_icon('icon.help.png'), 'Help', title_bar) help_action.triggered.connect(help_callback) title_bar.addAction(help_action) self.close_callback = close_callback # the close button always calls self.close (but in closeEvent we call the close callback if existing) close_action = QtWidgets.QAction(t.load_ui_icon('icon.close.png'), 'Close', title_bar) close_action.triggered.connect(self.close) title_bar.addAction(close_action) # escape key for close action = QtWidgets.QAction(self) action.setShortcut(QtGui.QKeySequence('Escape')) action.triggered.connect(self.close) self.addAction(action) # layout is 2 pixel contents margin (border), title bar and content widget self.layout = QtWidgets.QVBoxLayout(self) self.layout.setContentsMargins(2, 2, 2, 2) self.layout.addWidget(title_bar) self.layout.addWidget(content)
def __init__(self): """ All the necessary initializations. Is shown at the end. """ super().__init__() # set geometry self.setGeometry(t.get_option(c.O.MW_BOUNDS)) # set icon self.setWindowIcon(t.load_ui_icon('icon.ico')) # set title self.setWindowTitle('Imperialism Remake') # just a layout but nothing else self.layout = QtGui.QHBoxLayout(self) self.layout.setContentsMargins(0, 0, 0, 0) self.content = None # show in full screen, maximized or normal if t.get_option(c.O.FULLSCREEN): self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint) self.showFullScreen() elif t.get_option(c.O.MW_MAXIMIZED): self.showMaximized() else: self.show() # loading animation # TODO animation right and start, stop in client self.animation = QtGui.QMovie(c.extend(c.Graphics_UI_Folder, 'loading.gif')) # self.animation.start() self.loading_label = QtGui.QLabel(self, f=QtCore.Qt.FramelessWindowHint | QtCore.Qt.Window) self.loading_label.setAttribute(QtCore.Qt.WA_TranslucentBackground) self.loading_label.setMovie(self.animation)
def __init__(self): """ Create and add all tabs """ super().__init__() toolbar = QtWidgets.QToolBar() toolbar.setIconSize(QtCore.QSize(32, 32)) action_group = QtWidgets.QActionGroup(toolbar) action_preferences_general = qt_graphics.create_action(tools.load_ui_icon('icon.preferences.general.png'), 'Show general preferences', action_group, toggle_connection=self._toggled_action_preferences_general, checkable=True) toolbar.addAction(action_preferences_general) toolbar.addAction( qt_graphics.create_action(tools.load_ui_icon('icon.preferences.network.png'), 'Show network preferences', action_group, toggle_connection=self._toggled_action_preferences_network, checkable=True)) toolbar.addAction( qt_graphics.create_action(tools.load_ui_icon('icon.preferences.graphics.png'), 'Show graphics preferences', action_group, toggle_connection=self._toggled_action_preferences_graphics, checkable=True)) toolbar.addAction( qt_graphics.create_action(tools.load_ui_icon('icon.preferences.music.png'), 'Show music preferences', action_group, toggle_connection=self._toggled_action_preferences_music, checkable=True)) self.stacked_layout = QtWidgets.QStackedLayout() layout = QtWidgets.QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(toolbar) layout.addLayout(self.stacked_layout) # empty lists self._check_boxes = [] self._line_edits = [] self._sliders = [] # add tabs self._layout_widget_preferences_general() self._layout_widget_preferences_graphics() self._layout_widget_preferences_music() self._layout_widget_preferences_network() # show general preferences action_preferences_general.setChecked(True)
def __init__(self): """ Sets up all the input elements of the create new scenario dialog. """ super().__init__() self.parameters = {} widget_layout = QtWidgets.QVBoxLayout(self) # title box box = QtWidgets.QGroupBox('Title') layout = QtWidgets.QVBoxLayout(box) edit = QtWidgets.QLineEdit() edit.setFixedWidth(300) edit.setPlaceholderText('Unnamed') self.parameters[constants.ScenarioProperties.SCENARIO_TITLE] = edit layout.addWidget(edit) widget_layout.addWidget(box) # map size box = QtWidgets.QGroupBox('Map size') layout = QtWidgets.QHBoxLayout(box) layout.addWidget(QtWidgets.QLabel('Width')) edit = QtWidgets.QLineEdit() edit.setFixedWidth(50) edit.setValidator(QtGui.QIntValidator(1, 1000)) edit.setPlaceholderText('100') self.parameters[constants.ScenarioProperties.MAP_COLUMNS] = edit layout.addWidget(edit) layout.addWidget(QtWidgets.QLabel('Height')) edit = QtWidgets.QLineEdit() edit.setFixedWidth(50) edit.setValidator(QtGui.QIntValidator(1, 1000)) edit.setPlaceholderText('60') self.parameters[constants.ScenarioProperties.MAP_ROWS] = edit layout.addWidget(edit) layout.addStretch() widget_layout.addWidget(box) # vertical stretch widget_layout.addStretch() # add the button layout = QtWidgets.QHBoxLayout() toolbar = QtWidgets.QToolBar() toolbar.addAction( qt_graphics.create_action(tools.load_ui_icon('icon.confirm.png'), 'Create new scenario', toolbar, self.create_scenario_clicked)) layout.addStretch() layout.addWidget(toolbar) widget_layout.addLayout(layout)
def __init__(self, properties): """ Sets up all the input elements of the create new scenario dialog. """ super().__init__() self.properties = properties widget_layout = QtGui.QVBoxLayout(self) # title box box = QtGui.QGroupBox('Title') layout = QtGui.QVBoxLayout(box) edit = QtGui.QLineEdit() edit.setFixedWidth(300) edit.setText(self.properties[k.TITLE]) self.properties[k.TITLE] = edit layout.addWidget(edit) widget_layout.addWidget(box) # map size box = QtGui.QGroupBox('Map size') layout = QtGui.QHBoxLayout(box) layout.addWidget(QtGui.QLabel('Width')) edit = QtGui.QLineEdit() edit.setFixedWidth(50) edit.setValidator(QtGui.QIntValidator(0, 1000)) edit.setText(str(self.properties[k.MAP_COLUMNS])) self.properties[k.MAP_COLUMNS] = edit layout.addWidget(edit) layout.addWidget(QtGui.QLabel('Height')) edit = QtGui.QLineEdit() edit.setFixedWidth(50) edit.setValidator(QtGui.QIntValidator(0, 1000)) edit.setText(str(self.properties[k.MAP_ROWS])) self.properties[k.MAP_ROWS] = edit layout.addWidget(edit) layout.addStretch() widget_layout.addWidget(box) # vertical stretch widget_layout.addStretch() # add the button layout = QtGui.QHBoxLayout() toolbar = QtGui.QToolBar() toolbar.addAction(g.create_action(t.load_ui_icon('icon.confirm.png'), 'Create new scenario', toolbar, self.create_scenario_clicked)) layout.addStretch() layout.addWidget(toolbar) widget_layout.addLayout(layout)
def __init__(self): """ Create and add all tabs """ super().__init__() toolbar = QtGui.QToolBar() toolbar.setIconSize(QtCore.QSize(32, 32)) action_group = QtGui.QActionGroup(toolbar) action_preferences_general = g.create_action(t.load_ui_icon('icon.preferences.general.png'), 'Show general preferences', action_group, toggle_connection=self.toggled_general, checkable=True) toolbar.addAction(action_preferences_general) toolbar.addAction(g.create_action(t.load_ui_icon('icon.preferences.network.png'), 'Show network preferences', action_group, toggle_connection=self.toggled_network, checkable=True)) toolbar.addAction(g.create_action(t.load_ui_icon('icon.preferences.graphics.png'), 'Show graphics preferences', action_group, toggle_connection=self.toggled_graphics, checkable=True)) toolbar.addAction(g.create_action(t.load_ui_icon('icon.preferences.music.png'), 'Show music preferences', action_group, toggle_connection=self.toggled_music, checkable=True)) self.stacked_layout = QtGui.QStackedLayout() layout = QtGui.QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(toolbar) layout.addLayout(self.stacked_layout) # empty lists self.checkboxes = [] self.lineedits = [] # add tabs self.create_options_widget_general() self.create_options_widget_graphics() self.create_options_widget_music() self.create_options_widget_network() # show general preferences action_preferences_general.setChecked(True)
def create_toolbar(self): """ Setup toolbar at the bottom. """ layout = QtGui.QHBoxLayout() toolbar = QtGui.QToolBar() toolbar.setIconSize(QtCore.QSize(20, 20)) toolbar.addAction(g.create_action(t.load_ui_icon('icon.editor.info.terrain.png'), 'Change terrain type', self, self.change_terrain)) layout.addWidget(toolbar) layout.addStretch() return layout
def __init__(self, client): super().__init__() self.toolbar = QtGui.QToolBar() action_help = QtGui.QAction(t.load_ui_icon('icon.help.png'), 'Show help', self) action_help.triggered.connect( client.show_help_browser ) # TODO with partial make reference to specific page self.toolbar.addAction(action_help) action_quit = QtGui.QAction( t.load_ui_icon('icon.back.startscreen.png'), 'Exit to main menu', self) # action_quit.triggered.connect(client.switch_to_start_screen) self.toolbar.addAction(action_quit) # mini map self.mini_map = MiniMap() # info box self.info_box = InfoBox() # main map self.main_map = MainMap() # layout layout = QtGui.QGridLayout(self) layout.addWidget(self.toolbar, 0, 0) layout.addWidget(self.mini_map, 1, 0) layout.addWidget(self.info_box, 2, 0) layout.addWidget(self.main_map, 0, 1, 3, 1) layout.setRowStretch( 2, 1) # the info box will take all vertical space left layout.setColumnStretch( 1, 1) # the map will take all horizontal space left
def create_options_widget_network(self): """ Create network options widget. """ tab = QtGui.QWidget() tab_layout = QtGui.QVBoxLayout(tab) # status label self.network_status_label = QtGui.QLabel('') tab_layout.addWidget(self.network_status_label) # remote server groupbox l = QtGui.QVBoxLayout() # remote server address l2 = QtGui.QHBoxLayout() l2.addWidget(QtGui.QLabel('Remote IP address')) edit = QtGui.QLineEdit() edit.setFixedWidth(300) l2.addWidget(edit) l2.addStretch() l.addLayout(l2) # actions toolbar l2 = QtGui.QHBoxLayout() toolbar = QtGui.QToolBar() toolbar.setIconSize(QtCore.QSize(24, 24)) # connect to remote server toolbar.addAction(g.create_action(t.load_ui_icon('icon.preferences.network.png'), 'Connect/Disconnect to remote server', toolbar, checkable=True)) l2.addWidget(toolbar) l2.addStretch() l.addLayout(l2) tab_layout.addWidget(g.wrap_in_groupbox(l, 'Remote Server')) # local server group box l = QtGui.QVBoxLayout() # accepts incoming connections checkbox checkbox = QtGui.QCheckBox('Accepts incoming connections') self.register_checkbox(checkbox, c.O.LS_OPEN) l.addWidget(checkbox) # alias name edit box l2 = QtGui.QHBoxLayout() l2.addWidget(QtGui.QLabel('Alias')) edit = QtGui.QLineEdit() edit.setFixedWidth(300) l2.addWidget(edit) l2.addStretch() self.register_lineedit(edit, c.O.LS_NAME) l.addLayout(l2) # actions toolbar l2 = QtGui.QHBoxLayout() toolbar = QtGui.QToolBar() toolbar.setIconSize(QtCore.QSize(24, 24)) # show local server monitor toolbar.addAction(g.create_action(t.load_ui_icon('icon.preferences.network.png'), 'Show local server monitor', toolbar)) # local server is on/off toolbar.addAction(g.create_action(t.load_ui_icon('icon.preferences.network.png'), 'Turn local server on/off', toolbar, checkable=True)) l2.addWidget(toolbar) l2.addStretch() l.addLayout(l2) tab_layout.addWidget(g.wrap_in_groupbox(l, 'Local Server')) # vertical stretch tab_layout.addStretch() # add tab self.tab_network = tab self.stacked_layout.addWidget(tab)
def received_preview(self, client, message): """ Populates the widget after the network reply comes from the server with the preview. """ # immediately close the channel, we do not want to get this message twice network_client.remove_channel(self.CH_PREVIEW) # fill the widget with useful stuff layout = QtGui.QGridLayout(self) # selection list for nations self.nations_list = QtGui.QListWidget() self.nations_list.setFixedWidth(200) self.nations_list.setSelectionMode(QtGui.QAbstractItemView.SingleSelection) self.nations_list.itemSelectionChanged.connect(self.nations_list_selection_changed) layout.addWidget(g.wrap_in_groupbox(self.nations_list, 'Nations'), 0, 0) # map view (no scroll bars) self.map_scene = QtGui.QGraphicsScene() self.map_view = g.FitSceneInViewGraphicsView(self.map_scene) self.map_view.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.map_view.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.map_view.setSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.MinimumExpanding) layout.addWidget(g.wrap_in_groupbox(self.map_view, 'Map'), 0, 1) # scenario description self.description = QtGui.QTextEdit() self.description.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.description.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) self.description.setReadOnly(True) self.description.setFixedHeight(60) layout.addWidget(g.wrap_in_groupbox(self.description, 'Description'), 1, 0, 1, 2) # goes over two columns # nation description self.nation_info = QtGui.QTextEdit() self.nation_info.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.nation_info.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) self.nation_info.setReadOnly(True) self.nation_info.setFixedHeight(100) layout.addWidget(g.wrap_in_groupbox(self.nation_info, 'Nation Info'), 2, 0, 1, 2) # stretching of the elements layout.setRowStretch(0, 1) # nation list and map get all the available height layout.setColumnStretch(1, 1) # map gets all the available width # add the start button toolbar = QtGui.QToolBar() toolbar.addAction(g.create_action(t.load_ui_icon('icon.confirm.png'), 'Start selected scenario', toolbar, trigger_connection=self.start_scenario_clicked)) layout.addWidget(toolbar, 3, 0, 1, 2, alignment=QtCore.Qt.AlignRight) # set the content from the message self.description.setText(message[k.DESCRIPTION]) nations = [[message['nations'][key]['name'], key] for key in message['nations']] nations = sorted(nations) # by first element, which is the name nation_names, self.nation_ids = zip(*nations) self.nations_list.addItems(nation_names) # draw the map columns = message[k.MAP_COLUMNS] rows = message[k.MAP_ROWS] self.map_scene.setSceneRect(0, 0, columns, rows) # fill the ground layer with a neutral color item = self.map_scene.addRect(0, 0, columns, rows) item.setBrush(QtCore.Qt.lightGray) item.setPen(g.TRANSPARENT_PEN) item.setZValue(0) # text display self.map_name_item = self.map_scene.addSimpleText('') self.map_name_item.setPen(g.TRANSPARENT_PEN) self.map_name_item.setBrush(QtGui.QBrush(QtCore.Qt.darkRed)) self.map_name_item.setZValue(3) self.map_name_item.setPos(0, 0) # for all nations for nation_id, nation in message['nations'].items(): # get nation color color_string = nation['color'] color = QtGui.QColor() color.setNamedColor(color_string) # get nation name nation_name = nation['name'] # get nation outline path = QtGui.QPainterPath() # TODO traversing everything is quite slow go only once and add to paths for column in range(0, columns): for row in range(0, rows): if nation_id == message['map'][column + row * columns]: path.addRect(column, row, 1, 1) path = path.simplified() item = MiniMapNationItem(path, 1, 2) item.clicked.connect(partial(self.map_selected_nation, u.find_in_list(nation_names, nation_name))) item.entered.connect(partial(self.change_map_name, nation_name)) item.left.connect(partial(self.change_map_name, '')) brush = QtGui.QBrush(color) item.setBrush(brush) self.map_scene.addItem(item) # item = self.map_scene.addPath(path, brush=brush) # will use the default pen for outline self.preview = message
def __init__(self, client): """ Create and setup all the elements. """ super().__init__() self.client = client # create a standard scenario self.scenario = EditorScenario() self.create_new_scenario(NEW_SCENARIO_DEFAULT_PROPERTIES) self.toolbar = QtGui.QToolBar() self.toolbar.setIconSize(QtCore.QSize(32, 32)) self.toolbar.addAction(g.create_action(t.load_ui_icon('icon.scenario.new.png'), 'Create new scenario', self, self.show_new_scenario_dialog)) self.toolbar.addAction(g.create_action(t.load_ui_icon('icon.scenario.load.png'), 'Load scenario', self, self.load_scenario_dialog)) self.toolbar.addAction(g.create_action(t.load_ui_icon('icon.scenario.save.png'), 'Save scenario', self, self.save_scenario_dialog)) self.toolbar.addSeparator() self.toolbar.addAction(g.create_action(t.load_ui_icon('icon.editor.general.png'), 'Edit base properties', self, self.show_general_properties_dialog)) self.toolbar.addAction(g.create_action(t.load_ui_icon('icon.editor.nations.png'), 'Edit nations', self, self.show_nations_dialog)) self.toolbar.addAction(g.create_action(t.load_ui_icon('icon.editor.provinces.png'), 'Edit provinces', self, self.show_provinces_dialog)) spacer = QtGui.QWidget() spacer.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) self.toolbar.addWidget(spacer) clock = g.ClockLabel() self.toolbar.addWidget(clock) action_help = QtGui.QAction(t.load_ui_icon('icon.help.png'), 'Show help', self) action_help.triggered.connect(client.show_help_browser) # TODO with partial make reference to specific page self.toolbar.addAction(action_help) action_quit = QtGui.QAction(t.load_ui_icon('icon.back.startscreen.png'), 'Exit to main menu', self) action_quit.triggered.connect(client.switch_to_start_screen) # TODO ask if something is changed we should save.. (you might loose progress) self.toolbar.addAction(action_quit) # info box self.info_box = InfoBox(self.scenario) # the main map self.map = EditorMainMap(self.scenario) self.map.tile_at_focus_changed.connect(self.info_box.update_tile_information) # the mini map self.mini_map = EditorMiniMap(self.scenario) self.mini_map.focus_moved.connect(self.map.set_position) layout = QtGui.QGridLayout(self) layout.addWidget(self.toolbar, 0, 0, 1, 2) layout.addWidget(self.mini_map, 1, 0) layout.addWidget(self.info_box, 2, 0) layout.addWidget(self.map, 1, 1, 2, 1) layout.setRowStretch(2, 1) # the info box will take all vertical space left layout.setColumnStretch(1, 1) # the map will take all horizontal space left # whenever the scenario changes completely, update the editor self.scenario.everything_changed.connect(self.scenario_change)
def __init__(self, parent, content, title=None, modal=True, delete_on_close=False, help_callback=None, close_callback=None): # no frame but a standalong window super().__init__(parent, f=QtCore.Qt.FramelessWindowHint | QtCore.Qt.Window) # we need this self.setAttribute(QtCore.Qt.WA_StyledBackground) self.setObjectName('gamedialog') # should be deleted on close if delete_on_close: self.setAttribute(QtCore.Qt.WA_DeleteOnClose) # default state is Qt.NonModal if modal: self.setWindowModality(QtCore.Qt.WindowModal) # title bar title_bar = g.DraggableToolBar() title_bar.setIconSize(QtCore.QSize(20, 20)) title_bar.setObjectName('titlebar') title_bar.setSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Fixed) title_bar.dragged.connect(lambda delta: self.move(self.pos() + delta)) # title in titlebar and close icon title = QtGui.QLabel(title) title.setObjectName('gamedialog-title') title_bar.addWidget(title) # spacer between titlebar and help/close icons spacer = QtGui.QWidget() spacer.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) title_bar.addWidget(spacer) # if help call back is given, add help icon if help_callback: help_action = QtGui.QAction(t.load_ui_icon('icon.help.png'), 'Help', title_bar) help_action.triggered.connect(help_callback) title_bar.addAction(help_action) self.close_callback = close_callback # the close button always calls self.close (but in closeEvent we call the close callback if existing) close_action = QtGui.QAction(t.load_ui_icon('icon.close.png'), 'Close', title_bar) close_action.triggered.connect(self.close) title_bar.addAction(close_action) # escape key for close action = QtGui.QAction(self) action.setShortcut(QtGui.QKeySequence('Escape')) action.triggered.connect(self.close) self.addAction(action) # layout is 2 pixel contents margin (border), title bar and content widget self.layout = QtGui.QVBoxLayout(self) self.layout.setContentsMargins(2, 2, 2, 2) self.layout.addWidget(title_bar) self.layout.addWidget(content)