def gui_layout(self):
        main_layout = QHBoxLayout()
        layout1 = QVBoxLayout()
        right_layout = QHBoxLayout()

        toolbox = ToolBox()

        layout1.addWidget(toolbox)
        layout1.addWidget(Color('pink'))
        layout1.addWidget(Color('blue'))

        main_layout.setContentsMargins(0, 0, 0, 0)
        main_layout.setSpacing(0)
        main_layout.addLayout(layout1)
        table = TabWidget()
        main_layout.addWidget(table)

        right_layout.addWidget(self.right_up_text_edit())
        right_layout.addWidget(self.right_down_text_edit())

        main_layout.addLayout(right_layout)

        widget = QWidget()
        widget.setLayout(main_layout)
        self.setCentralWidget(widget)
    def launch_toolbox(self):
        pid = self.select_text()
        workdir = self.get_submitdir()

        if "ErrorCode_" in pid:
            workdir = "/cluster/home/ambr/projects"
        elif workdir.strip() == "":
            workdir = "/cluster/home/ambr/projects"
        elif "ErrorCode_" in workdir:
            workdir = "/cluster/home/ambr/projects"
        elif self.user.get() not in workdir:
            self.log_update("Suspicious-looking directory...")
            workdir = "/cluster/home/ambr/projects"

        toolbox = ToolBox(self, workdir)
示例#3
0
class LevelEditor:
# * Contains a background.
# * Handles Camera controls.

	#################################
	# PUBLIC

	def __init__(self, window):
		self.Background = Background(window)
		self.ToolBox = ToolBox(*window.size)


	def camera_controls(self, Key, Mouse, Camera):
		Camera.smooth.speed = 3

		if Key.L_CTRL.held(): return

		#Move (per Room)
		if Key.LEFT.pressed(): Camera.smooth.room_x -= 1
		if Key.RIGHT.pressed(): Camera.smooth.room_x += 1
		if Key.UP.pressed(): Camera.smooth.room_y -= 1
		if Key.DOWN.pressed(): Camera.smooth.room_y += 1

		#Move (per Tile)
		amt = 25
		if Key.A.held(): Camera.smooth.x -= amt
		if Key.D.held(): Camera.smooth.x += amt
		if Key.W.held(): Camera.smooth.y -= amt
		if Key.S.held(): Camera.smooth.y += amt

		#Zoom (Toggle)
		if Key.E.pressed():
			if   Camera.smooth.zoom == 1: Camera.smooth.zoom = 2
			elif Camera.smooth.zoom == 2: Camera.smooth.zoom = 1


	def controls(self, Key, Mouse, Camera, WorldMap):
		#toolbox
		self.ToolBox.controls(Key, Mouse, Camera, WorldMap)
		if Key.TAB.pressed(): self.ToolBox.toggle()

		# Toggle grid.
		if Key.Q.pressed():
			WorldMap.enable_grid = not WorldMap.enable_grid

		# Saving/Loading
		if Key.L_CTRL.held():
			if Key.S.pressed():
				self._save(WorldMap)
			if Key.O.pressed():
				self._load(WorldMap)


	#

	def draw_background(self, Window, Camera):
		self.Background.draw(Window, Camera)

	def draw_objects(self, Window, Camera):
		Window.view = Window.default_view
		self.ToolBox.static_draw(Window, None)
		Window.view = Camera
		self.ToolBox.normal_draw(Window, None)


	#################################
	# PRIVATE
	# * WorldMap saving/loading.

	_map_name = "map1"

	def _save(self, WorldMap):
		WorldMap.save(self._map_name)

	def _load(self, WorldMap):
		WorldMap.load(self._map_name)
示例#4
0
	def __init__(self, window):
		self.Background = Background(window)
		self.ToolBox = ToolBox(*window.size)
示例#5
0
class LevelEditor:
    # * Contains a background.
    # * Handles Camera controls.

    #################################
    # PUBLIC

    def __init__(self, window):
        self.Background = Background(window)
        self.ToolBox = ToolBox(*window.size)

    def camera_controls(self, Key, Mouse, Camera):
        Camera.smooth.speed = 3

        if Key.L_CTRL.held(): return

        #Move (per Room)
        if Key.LEFT.pressed(): Camera.smooth.room_x -= 1
        if Key.RIGHT.pressed(): Camera.smooth.room_x += 1
        if Key.UP.pressed(): Camera.smooth.room_y -= 1
        if Key.DOWN.pressed(): Camera.smooth.room_y += 1

        #Move (per Tile)
        amt = 25
        if Key.A.held(): Camera.smooth.x -= amt
        if Key.D.held(): Camera.smooth.x += amt
        if Key.W.held(): Camera.smooth.y -= amt
        if Key.S.held(): Camera.smooth.y += amt

        #Zoom (Toggle)
        if Key.E.pressed():
            if Camera.smooth.zoom == 1: Camera.smooth.zoom = 2
            elif Camera.smooth.zoom == 2: Camera.smooth.zoom = 1

    def controls(self, Key, Mouse, Camera, WorldMap):
        #toolbox
        self.ToolBox.controls(Key, Mouse, Camera, WorldMap)
        if Key.TAB.pressed(): self.ToolBox.toggle()

        # Toggle grid.
        if Key.Q.pressed():
            WorldMap.enable_grid = not WorldMap.enable_grid

        # Saving/Loading
        if Key.L_CTRL.held():
            if Key.S.pressed():
                self._save(WorldMap)
            if Key.O.pressed():
                self._load(WorldMap)

    #

    def draw_background(self, Window, Camera):
        self.Background.draw(Window, Camera)

    def draw_objects(self, Window, Camera):
        Window.view = Window.default_view
        self.ToolBox.static_draw(Window, None)
        Window.view = Camera
        self.ToolBox.normal_draw(Window, None)

    #################################
    # PRIVATE
    # * WorldMap saving/loading.

    _map_name = "map1"

    def _save(self, WorldMap):
        WorldMap.save(self._map_name)

    def _load(self, WorldMap):
        WorldMap.load(self._map_name)
示例#6
0
 def __init__(self, window):
     self.Background = Background(window)
     self.ToolBox = ToolBox(*window.size)
示例#7
0
    def __init__(self):
        self.destroyed = False
        self.t = 0
        self.seq = 1

        self.images = Images(os.path.join(cmdFolder, "images"))
        self.toolicons = Images(os.path.join(cmdFolder, "images", "tools"))

        self.printerList = []
        self.settings = Settings(cmdFolder)

        wx.Frame.__init__(self, None, -1, "Octoprint Monitor", size=(300, 300))
        self.Bind(wx.EVT_CLOSE, self.onClose)

        ico = wx.Icon(os.path.join(cmdFolder, "images", "octomon.png"),
                      wx.BITMAP_TYPE_PNG)
        self.SetIcon(ico)

        sz = wx.BoxSizer(wx.VERTICAL)
        sz.AddSpacer(20)

        box = wx.StaticBox(self, -1, "Printers")
        bsizer = wx.StaticBoxSizer(box, wx.VERTICAL)

        self.buttons = {}
        self.dialogs = {}

        self.plist = self.settings.getSetting("printers")
        for pn in self.plist:
            b = wx.Button(self, wx.ID_ANY, pn)
            self.Bind(wx.EVT_BUTTON, self.pressPrinter, b)
            bsizer.Add(b, 0, wx.ALL, 5)
            self.buttons[pn] = b

        sz.Add(bsizer)
        sz.AddSpacer(10)

        self.tbx = ToolBox(cmdFolder)
        tools = self.tbx.getTools()

        for s in tools.keys():
            box = wx.StaticBox(self, wx.ID_ANY, s)
            bxsz = wx.StaticBoxSizer(box, wx.HORIZONTAL)
            try:
                ordr = tools[s]["order"]
            except KeyError:
                ordr = list(tools[s].keys())
            for t in ordr:
                i = tools[s][t]["icon"]
                png = self.toolicons.getByName(i)

                b = wx.BitmapButton(self, wx.ID_ANY, png, size=BTNDIM)
                bxsz.Add(b, 0, wx.ALL, 5)
                b.SetToolTip(tools[s][t]["helptext"])
                l = lambda evt, section=s, tool=t: self.onToolButton(
                    evt, section, tool)
                self.Bind(wx.EVT_BUTTON, l, b)

            sz.Add(bxsz)
            sz.AddSpacer(10)

        hsz = wx.BoxSizer(wx.HORIZONTAL)
        hsz.AddSpacer(20)
        hsz.Add(sz)
        hsz.AddSpacer(20)

        hsz.Fit(self)
        self.SetSizer(hsz)
        self.Layout()
        self.Fit()

        self.enableButtons()
        self.printerInstances = PrinterInstances(self.plist, self.settings,
                                                 self.registerPrinter)

        self.Bind(EVT_REGISTER, self.printerRegistration)

        self.Show()
示例#8
0
class MyFrame(wx.Frame):
    def __init__(self):
        self.destroyed = False
        self.t = 0
        self.seq = 1

        self.images = Images(os.path.join(cmdFolder, "images"))
        self.toolicons = Images(os.path.join(cmdFolder, "images", "tools"))

        self.printerList = []
        self.settings = Settings(cmdFolder)

        wx.Frame.__init__(self, None, -1, "Octoprint Monitor", size=(300, 300))
        self.Bind(wx.EVT_CLOSE, self.onClose)

        ico = wx.Icon(os.path.join(cmdFolder, "images", "octomon.png"),
                      wx.BITMAP_TYPE_PNG)
        self.SetIcon(ico)

        sz = wx.BoxSizer(wx.VERTICAL)
        sz.AddSpacer(20)

        box = wx.StaticBox(self, -1, "Printers")
        bsizer = wx.StaticBoxSizer(box, wx.VERTICAL)

        self.buttons = {}
        self.dialogs = {}

        self.plist = self.settings.getSetting("printers")
        for pn in self.plist:
            b = wx.Button(self, wx.ID_ANY, pn)
            self.Bind(wx.EVT_BUTTON, self.pressPrinter, b)
            bsizer.Add(b, 0, wx.ALL, 5)
            self.buttons[pn] = b

        sz.Add(bsizer)
        sz.AddSpacer(10)

        self.tbx = ToolBox(cmdFolder)
        tools = self.tbx.getTools()

        for s in tools.keys():
            box = wx.StaticBox(self, wx.ID_ANY, s)
            bxsz = wx.StaticBoxSizer(box, wx.HORIZONTAL)
            try:
                ordr = tools[s]["order"]
            except KeyError:
                ordr = list(tools[s].keys())
            for t in ordr:
                i = tools[s][t]["icon"]
                png = self.toolicons.getByName(i)

                b = wx.BitmapButton(self, wx.ID_ANY, png, size=BTNDIM)
                bxsz.Add(b, 0, wx.ALL, 5)
                b.SetToolTip(tools[s][t]["helptext"])
                l = lambda evt, section=s, tool=t: self.onToolButton(
                    evt, section, tool)
                self.Bind(wx.EVT_BUTTON, l, b)

            sz.Add(bxsz)
            sz.AddSpacer(10)

        hsz = wx.BoxSizer(wx.HORIZONTAL)
        hsz.AddSpacer(20)
        hsz.Add(sz)
        hsz.AddSpacer(20)

        hsz.Fit(self)
        self.SetSizer(hsz)
        self.Layout()
        self.Fit()

        self.enableButtons()
        self.printerInstances = PrinterInstances(self.plist, self.settings,
                                                 self.registerPrinter)

        self.Bind(EVT_REGISTER, self.printerRegistration)

        self.Show()

    def onToolButton(self, _, section, tool):
        self.tbx.execute(section, tool)

    def enableButtons(self):
        for pn in self.plist:
            self.buttons[pn].Enable(pn in self.printerList
                                    and pn not in self.dialogs.keys())

    def pressPrinter(self, evt):
        pName = evt.GetEventObject().GetLabel()
        if pName in self.dialogs.keys():
            return

        try:
            svr = self.printerInstances.getPrinterServer(pName)
        except:
            dlg = wx.MessageDialog(
                self, "Unable to obtain printer server for %s" % pName,
                "Printer Initialization Error", wx.OK | wx.ICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
            return

        try:
            rc, json = svr.state(exclude=["temperature", "sd"])
        except:
            dlg = wx.MessageDialog(
                self, "Unable to obtain initial printer state from %s" % pName,
                "Printer Initialization Error", wx.OK | wx.ICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
            return

        d = PrinterDlg(self, svr, pName, self.settings, self.images)
        self.dialogs[pName] = d
        self.enableButtons()

        d.Show()

    def registerPrinter(self, action, pName):
        if self.destroyed:
            print(
                " printer registration after window has been destroyed - terminating thread"
            )
            exit(0)
        evt = RegisterEvent(action=action, pname=pName)
        wx.PostEvent(self, evt)

    def printerRegistration(self, evt):
        action = evt.action
        pName = evt.pname

        if action == "add":
            if pName in self.printerList:
                pass
            else:
                self.printerList.append(pName)

        elif action == "remove":
            if pName not in self.printerList:
                pass
            else:
                self.printerList.remove(pName)
                if pName in self.dialogs.keys():
                    self.dialogs[pName].sever()
                    self.dialogs[pName].Destroy()
                    del self.dialogs[pName]

        self.enableButtons()

    def onClose(self, _):
        if self.destroyed:
            return

        self.destroyed = True
        for p in self.dialogs.keys():
            self.dialogs[p].sever()
            self.dialogs[p].Destroy()

        self.printerInstances.close()
        self.Destroy()

    def connectionSevered(self, pName):
        if pName in self.dialogs.keys():
            self.dialogs[pName].sever()
            self.dialogs[pName].Destroy()
            del self.dialogs[pName]
            self.enableButtons()