Beispiel #1
0
    def init_ui(self):
        r"""UI elements initialization"""

        menubar = wx.MenuBar()

        # File menu
        file_menu = wx.Menu()
        self.add_menu_item(
            menu=file_menu,
            id_=wx.ID_OPEN,
            text='&Open\tCtrl+O',
            handler=self.on_open,
            # icon=p_(__file__, './icons/open.png'),
            icon=path_to_file(__file__, "icons/open.png"),
            enabled=True)

        file_menu.AppendSeparator()

        self.add_menu_item(
            menu=file_menu,
            id_=wx.ID_CLOSE,
            text='&Quit\tCtrl+Q',
            handler=self.on_quit,
            # icon=p_(__file__, './icons/quit.png'))
            icon=path_to_file(__file__, 'icons/quit.png'))
        menubar.Append(file_menu, '&File')

        # Windows menu
        windows_menu = wx.Menu()
        for name in CadracksIdeFrame.PANES:
            self.Bind(wx.EVT_MENU, self.on_window_show,
                      windows_menu.Append(wx.ID_ANY, name, "Show " + name))
        menubar.Append(windows_menu, "&Windows")

        # Refresh menu
        refresh_menu = wx.Menu()
        self.add_menu_item(
            menu=refresh_menu,
            id_=wx.NewId(),
            text="Refresh",
            handler=self.on_refresh,
            # icon=p_(__file__, './icons/refresh.png'))
            icon=path_to_file(__file__, 'icons/refresh.png'))
        menubar.Append(refresh_menu, "&Refresh")

        # Help menu
        help_menu = wx.Menu()
        m_about = help_menu.Append(wx.ID_ABOUT, "&About",
                                   "Information about this program")
        self.Bind(wx.EVT_MENU, self.on_about, m_about)
        menubar.Append(help_menu, "&Help")

        self.SetMenuBar(menubar)

        status_bar = wx.StatusBar(self)
        self.SetStatusBar(status_bar)
Beispiel #2
0
def get_config():
    r"""Get the ConfigObj object from a cadracks-ide.ini file

    Returns
    -------
    configobj.ConfigObj or None

    """
    inifile = path_to_file(__file__, "cadracks-ide.ini")

    if not exists(inifile):
        logger.warning("No cadracks-ide.ini, using default values")
        return None
    else:
        config = configobj.ConfigObj(inifile)
    return config
Beispiel #3
0
    def __init__(self, parent, model):
        wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)

        self.model = model

        self.save_button = wx.Button(self, wx.ID_ANY, "Save")

        # The save_button is initially disabled and will be enabled
        # when a modification has been made for an editable file
        self.save_button.Disable()

        bmp = wx.Image(path_to_file(__file__, 'icons/save.png'),
                       wx.BITMAP_TYPE_PNG).Scale(24, 24).ConvertToBitmap()
        self.save_button.SetBitmap(bmp, wx.LEFT)
        self.Bind(wx.EVT_BUTTON, self.on_save_button, self.save_button)

        # Save with ctrl + S
        randomId = wx.NewId()
        self.Bind(wx.EVT_MENU, self.on_ctrl_s, id=randomId)
        accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('S'), randomId)])
        self.SetAcceleratorTable(accel_tbl)

        # # Sizers
        # controls_panel_sizer = wx.BoxSizer()
        # controls_panel_sizer.Add(self.save_button,
        #                          0,
        #                          wx.ALIGN_CENTER | wx.ALL, 10)

        self.file_editor = Editor(self, model, self.save_button)
        self.file_editor.Disable()
        # self.python_definition_file_editor.EmptyUndoBuffer()

        sizer = wx.BoxSizer(wx.VERTICAL)

        sizer.Add(self.file_editor, 90, wx.EXPAND)
        sizer.Add(self.save_button, 0, wx.ALIGN_RIGHT)

        self.SetSizer(sizer)
Beispiel #4
0
    def __init__(self,
                 parent,
                 model,
                 root_directory=None,
                 checkable_extensions=None,
                 disabled_extensions=None,
                 excluded_extensions=None,
                 agw_style=wx.TR_DEFAULT_STYLE,
                 context_menu=True):

        wx.lib.agw.customtreectrl.CustomTreeCtrl.__init__(self,
                                                          parent,
                                                          id=-1,
                                                          pos=(-1, -1),
                                                          size=(-1, -1),
                                                          agwStyle=agw_style)

        self.model = model
        self.model.observe("root_folder_changed", self.on_root_folder_changed)

        self.selected_item = None

        if checkable_extensions is None:
            checkable_extensions = []
        if disabled_extensions is None:
            disabled_extensions = []
        if excluded_extensions is None:
            excluded_extensions = []
        self.context_menu = context_menu

        # bind events
        self.Bind(wx.EVT_TREE_ITEM_EXPANDING, self.TreeItemExpanding)
        self.Bind(wx.EVT_TREE_ITEM_COLLAPSING, self.TreeItemCollapsing)
        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnTreeSelChanged)
        # self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.OnEvtTreeItemRightClick)
        # self.Bind(wx.lib.agw.customtreectrl.EVT_TREE_ITEM_CHECKED,
        #           self.OnItemChecked)

        # some hack-ish code here to deal with imagelists
        self.iconentries = {}
        self.imagelist = wx.ImageList(16, 16)

        self.checkable_extensions = checkable_extensions
        self.disabled_extensions = disabled_extensions
        self.excluded_extensions = excluded_extensions

        self.add_icon(path_to_file(__file__, 'icons/folder.png'),
                      wx.BITMAP_TYPE_PNG, 'FOLDER')
        self.add_icon(path_to_file(__file__, 'icons/python_icon.png'),
                      wx.BITMAP_TYPE_PNG, 'python')
        # set default image
        self.add_icon(path_to_file(__file__, 'icons/file_icon.png'),
                      wx.BITMAP_TYPE_PNG, 'default')

        # self.set_root_dir(root_directory)

        pub.subscribe(self.tree_modified_listener, "tree_modified")

        # if root_directory in [None, ""]:
        #     from os import getcwd
        #     root_directory = getcwd()
        # self.model.set_root_folder(root_directory)
        # self.root_directory = root_directory

        self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK,
                  self.on_evt_tree_item_right_click)

        # Store the path corresponding to a right click in the tree
        self.right_click_location = None
Beispiel #5
0
 def __init__(self, parent, label="Close"):
     img = wx.Bitmap(path_to_file(__file__, "icons/dialog-cancel.png"))
     super(CloseBtn, self).__init__(parent, wx.ID_CANCEL, img, label=label)
Beispiel #6
0
 def __init__(self, parent, label="Ok"):
     img = wx.Bitmap(path_to_file(__file__, "icons/dialog-ok-apply.png"))
     super(OkBtn, self).__init__(parent, wx.ID_OK, img, label)
Beispiel #7
0
    def __init__(self, parent, model, config, size=(1200, 800)):
        # logger.debug("Initializing WaterlineUiFrame")
        wx.Frame.__init__(self,
                          parent,
                          -1,
                          "CadRacks IDE",
                          style=wx.DEFAULT_FRAME_STYLE,
                          size=size)

        if platform.system() == "Linux":
            self.Show()

        # Application icon
        ico = path_to_file(__file__, "cadracks-ide.ico")

        self.SetIcon(wx.Icon(wx.IconLocation(filename=ico, num=0)))
        self.Bind(wx.EVT_CLOSE, self.on_close)

        # Config
        self.config = config
        try:
            frame_maximize = True if self.config["frame"][
                "maximize"] == "True" else False
            self.confirm_close = True if self.config["frame"][
                "confirm_close"] == "True" else False
            # self.project_default_dir = self.config["app"]["default_dir"]
            self.viewer_background_colour = tuple([
                float(el)
                for el in self.config["viewer"]["viewer_background_colour"]
            ])
            self.objects_transparency = float(
                self.config["viewer"]["objects_transparency"])
            self.text_height = int(self.config["viewer"]["text_height"])
            self.text_colour = tuple(
                [float(el) for el in self.config["viewer"]["text_colour"]])
        except (TypeError, KeyError):
            frame_maximize = True
            self.confirm_close = True
            # self.project_default_dir = ""
            self.viewer_background_colour = (50., 50., 50.)
            self.objects_transparency = 0.2
            self.text_height = 20
            self.text_colour = (0, 0, 0)
            # Report the problem
            msg = "No config loaded (wrong ini file name or missing key), " \
                  "using program defaults"
            wx.MessageBox(msg, 'Warning', wx.OK | wx.ICON_WARNING)

        self.model = model

        # Panels
        self.log_panel = LogPanel(self,
                                  threadsafe=False,
                                  format_='%(asctime)s :: %(levelname)6s :: '
                                  '%(name)20s :: %(lineno)3d :: '
                                  '%(message)s')
        logger.info("Starting CadRacks IDE ...")
        self.three_d_panel = \
            ThreeDPanel(self,
                        model,
                        viewer_background_color=self.viewer_background_colour,
                        object_transparency=self.objects_transparency,
                        text_height=self.text_height,
                        text_colour=self.text_colour)
        self.code_panel = CodePanel(self, self.model)
        # self.graph_panel = GraphPanel(self, self.model,
        #                               viewer_background_color=self.viewer_background_colour,
        #                               object_transparency=self.objects_transparency,
        #                               text_height=self.text_height,
        #                               text_colour=self.text_colour)
        # self.tree_panel = Tree(self, self.model, root_directory=self.project_default_dir)
        self.tree_panel = Tree(self, self.model)

        # Menus, status bar ...
        self.init_ui()

        # AUI manager
        self._mgr = wx.lib.agw.aui.AuiManager()
        self._mgr.SetManagedWindow(self)  # notify AUI which frame to use

        self._mgr.AddPane(
            self.three_d_panel,
            wx.lib.agw.aui.AuiPaneInfo().Right().Name(
                CadracksIdeFrame.PANE_3D_NAME).Caption("3D").MinSize(
                    wx.Size(400, 200)).MaximizeButton(True).Resizable(True))
        # self._mgr.AddPane(self.graph_panel,
        #                   wx.lib.agw.aui.AuiPaneInfo().Right().
        #                   Name(CadracksIdeFrame.PANE_GRAPH_NAME).Caption("Graph").
        #                   MinSize(wx.Size(400, 100)).MaximizeButton(True).Resizable(True))
        self._mgr.AddPane(
            self.tree_panel,
            wx.lib.agw.aui.AuiPaneInfo().Left().Name(
                CadracksIdeFrame.PANE_TREE_NAME).Caption("Tree").MinSize(
                    wx.Size(400, 100)).MaximizeButton(True).Resizable(True))
        self._mgr.AddPane(
            self.log_panel,
            wx.lib.agw.aui.AuiPaneInfo().Left().Name(
                CadracksIdeFrame.PANE_LOG_NAME).Caption("Log").MinSize(
                    wx.Size(400, 100)).MaximizeButton(True).Resizable(True))
        self._mgr.AddPane(self.code_panel,
                          wx.lib.agw.aui.AuiPaneInfo().CenterPane())

        # tell the manager to "commit" all the changes just made

        self._mgr.Update()
        self.three_d_panel.Layout()

        # self.three_d_panel.viewer.Layout()

        # Show and maximize the frame
        self.Show(True)
        if frame_maximize is True:
            self.Maximize(True)  # Use the full screen
        else:
            self.CenterOnScreen()

        self.Bind(wx.EVT_SIZE, self.OnSize)

        logger.info("... done")