Exemplo n.º 1
0
    def __init__(self, record, *args, **kwds):
        """
		:param record:
		:type record:
		:param parent: The parent window.
		:type parent: wx.Window
		:param id: An identifier for the panel. wx.ID_ANY is taken to mean a default.
		:type id: wx.WindowID, optional
		:param pos: The panel position. The value wx.DefaultPosition indicates a default position,
		chosen by either the windowing system or wxWidgets, depending on platform.
		:type pos: wx.Point, optional
		:param size: The panel size. The value wx.DefaultSize indicates a default size, chosen by
		either the windowing system or wxWidgets, depending on platform.
		:type size: wx.Size, optional
		:param style: The window style. See wx.Panel.
		:type style: int, optional
		:param name: Window name.
		:type name: str, optional
		"""

        # begin wxGlade: AmmunitionDetailsPanel.__init__
        kwds["style"] = kwds.get("style", 0) | wx.TAB_TRAVERSAL
        wx.Panel.__init__(self, *args, **kwds)
        self.filename_value = wx.TextCtrl(self,
                                          wx.ID_ANY,
                                          "",
                                          style=wx.BORDER_NONE
                                          | wx.TE_MULTILINE | wx.TE_READONLY)
        self.ammo_details_splitter = wx.SplitterWindow(self,
                                                       wx.ID_ANY,
                                                       style=wx.SP_3D
                                                       | wx.SP_LIVE_UPDATE)
        self.ammo_grid_panel = wx.Panel(self.ammo_details_splitter, wx.ID_ANY)
        self.add_propellant_button = wx.Button(self.ammo_grid_panel, wx.ID_ANY,
                                               "Add Propellant Type")
        self.ammo_details_grid = PropertyGrid(self.ammo_grid_panel, wx.ID_ANY)
        self.other_images = ammo_images.OtherImagesCtrl(
            self.ammo_grid_panel, wx.ID_ANY)
        self.ammo_images_splitter = wx.SplitterWindow(
            self.ammo_details_splitter,
            wx.ID_ANY,
            style=wx.SP_3D | wx.SP_LIVE_UPDATE)
        self.propellant_image_panel = wx.Panel(self.ammo_images_splitter,
                                               wx.ID_ANY)
        self.propellant_image = ammo_images.AmmoImagePanel(
            self.propellant_image_panel, None)
        self.headstamp_image_panel = wx.Panel(self.ammo_images_splitter,
                                              wx.ID_ANY)
        self.headstamp_image = ammo_images.AmmoImagePanel(
            self.headstamp_image_panel, None)

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_BUTTON, self.on_add_propellant,
                  self.add_propellant_button)
        # end wxGlade

        self.ammo_details_grid.Bind(wx.propgrid.EVT_PG_CHANGED,
                                    self.on_property_changed)
        self.ammo_details_grid.Bind(wx.propgrid.EVT_PG_SELECTED,
                                    self.on_property_selected)
        self.ammo_details_grid.Bind(wx.propgrid.EVT_PG_RIGHT_CLICK,
                                    self.on_property_rightclick)
        pub.subscribe(self.commit_changes, "SaveProject")

        # Register custom editors for propgrid
        if not getattr(sys, '_PropGridEditorsRegistered', False):
            self.ammo_details_grid.RegisterEditor(ComboBoxEditor,
                                                  "ComboBoxEditor")
            # self.ammo_details_grid.RegisterEditor(CalibreEditor, "CalibreEditor")
            # ensure we only do it once
            sys._PropGridEditorsRegistered = True

        self.fileNotSaved = False

        if record is None:
            self.record = Ammunition.new_empty()
            self.filename = None
        elif isinstance(record, (str, pathlib.Path)):
            self.filename = record
            self.record = Ammunition.load(self.filename)
        elif isinstance(record, Ammunition.AmmunitionDetails):
            self.record = record
            self.filename = record.filename.value
        else:
            raise TypeError("'record' must be a 'str', 'pathlib.Path', or "
                            "'GuiV2.GSMatch2_Core.Ammunition.Details' object, "
                            f"not {type(record)}")

        self.open_record(self.record)

        self.propellant_image.Bind(ammo_images.EVT_IMAGE_PANEL_CHANGED,
                                   self.on_propellant_image_changed)
        self.headstamp_image.Bind(ammo_images.EVT_IMAGE_PANEL_CHANGED,
                                  self.on_headstamp_image_changed)

        self.other_images.Bind(ammo_images.EVT_IMAGE_ADDED,
                               self.on_other_images_changed)
        self.other_images.Bind(ammo_images.EVT_IMAGE_DELETED,
                               self.on_other_images_changed)
        self.other_images.Bind(ammo_images.EVT_IMAGE_RENAMED,
                               self.on_other_images_changed)

        self.other_images.ShowCaptions()
Exemplo n.º 2
0
 def make_ammo_tab(self):
     self.project_ammo = Ammunition.DetailsPanel(self.project.ammo_data,
                                                 self.notebook, wx.ID_ANY)
     self.project_ammo.filename_value.SetValue(
         self.project.ammo_details.value)
     self.notebook.AddPage(self.project_ammo, "Ammunition Details")
Exemplo n.º 3
0
 def export_pdf(self, input_filename, output_filename):
     Ammunition.AmmoPDFExporter(
         self.record,
         input_filename=input_filename,
         output_filename=output_filename,
     )
Exemplo n.º 4
0
    def open_record(self, record=None):
        """
		Open an Ammunition Details record, either from a filename or from an existing Ammunition object

		:param record: The Ammunition Details record open
		:type record: str or pathlib.Path or GuiV2.GSMatch2_Core.Ammunition.Details, optional
		"""

        # Clear all properties from the grid
        self.ammo_details_grid.Clear()

        self.fileNotSaved = False

        if record is None:
            self.record = Ammunition.new_empty()
            self.filename = None
        elif isinstance(record, (str, pathlib.Path)):
            self.filename = record
            self.record = Ammunition.load(self.filename)
        elif isinstance(record, Ammunition.AmmunitionDetails):
            self.record = record
            self.filename = record.filename.value
        else:
            raise TypeError(
                "'record' must be a 'str', 'pathlib.Path', or "
                "'GuiV2.GSMatch2_Core.Ammunition.AmmunitionDetails.AmmunitionDetails' object, "
                f"not {type(record)}")

        # Add properties to grid
        # Ammunition Information Category
        self.ammo_details_grid.Append(
            wx.propgrid.PropertyCategory("Ammunition Information"))

        # Name
        name_property = wx.propgrid.StringProperty(name="ammo_details_name",
                                                   label="Name",
                                                   value=str(self.record.name))
        name_property.SetHelpString("The name of the Ammunition")
        self.ammo_details_grid.Append(name_property)

        for prop in self.record.ammunition_properties:
            # Add property
            property_item = prop.propgrid
            # print(property_item)
            self.ammo_details_grid.Append(property_item)
            if not prop.editable:
                self.ammo_details_grid.SetPropertyReadOnly(property_item)

        # Projectile Information Category
        self.ammo_details_grid.Append(
            wx.propgrid.PropertyCategory("Projectile Information"))

        for prop in self.record.projectile.all_properties:
            # Add property
            property_item = prop.propgrid
            self.ammo_details_grid.Append(property_item)
            if not prop.editable:
                self.ammo_details_grid.SetPropertyReadOnly(property_item)

        # Propellant Information Category
        self.ammo_details_grid.Append(
            wx.propgrid.PropertyCategory("Propellant Information"))

        for prop in self.record.propellant_granules.all_properties:
            # Add property
            property_item = prop.propgrid
            self.ammo_details_grid.Append(property_item)
            if not prop.editable:
                self.ammo_details_grid.SetPropertyReadOnly(property_item)

        # Add properties to grid
        # File Information Category
        self.ammo_details_grid.Append(
            wx.propgrid.PropertyCategory("File Information"))

        for prop in self.record.file_properties:
            # Add property
            property_item = prop.propgrid
            self.ammo_details_grid.Append(property_item)
            if not prop.editable:
                self.ammo_details_grid.SetPropertyReadOnly(property_item)

        self.ammo_details_grid.Collapse("File Information")

        # Load images
        self.propellant_image.load_image(self.record.propellant_image, True)
        self.headstamp_image.load_image(self.record.headstamp_image, True)

        for image in self.record.other_images:
            if isinstance(image, tuple):
                self.other_images.AppendImage(image[1], image[0])
            else:
                self.other_images.AppendImage(image)

        # if self.record.propellant_image:
        # 	self.other_images.AppendImage(self.record.propellant_image)
        self.other_images.SetBackgroundColour(self.GetBackgroundColour())
        self.other_images.Refresh()

        self.fileNotSaved = False
Exemplo n.º 5
0
	def __init__(
			self, name, user, device, date_created, date_modified, version,
			calibre='', year_of_manufacture=0, propellant_granules=None, projectile=None,
			description='', filename=None, manufacturer='', primer_type=PRIMER_TYPE_UNKNOWN,
			propellant_image=None, headstamp_image=None, other_images=None, notes='',
			# legacy projectile properties, if provided add to projectile
			projectile_type='', has_boattail=False, projectile_mass=0,
		):
		"""
		:param name: The name of the Ammunition
		:type name: str
		:param user: The username of the user who created the ``AmmunitionDetails`` object
		:type user: str
		:param device: The device which created the ``AmmunitionDetails`` object
		:type device: str
		:param date_created: The date and time the AmmunitionDetails record was created, in seconds from epoch
		:type date_created: float
		:param date_modified: The date and time the AmmunitionDetails record was last modified, in seconds from epoch
		:type date_modified: float
		:param version: File format version in semver format
		:type version: str
		:param calibre: The calibre of the Ammunition
		:type calibre: str
		:param year_of_manufacture: The year the Ammunition was manufactured
		:type year_of_manufacture: int
		:param propellant_granules: The properties of the propellant
		:type propellant_granules:
		:param projectile: The properties of the projectile
		:type projectile:
		:param description: A description of the Ammunition
		:type description: str
		:param filename:
		:type filename:
		:param manufacturer: The manufacturer of the ammunition
		:type manufacturer: str
		:param primer_type: The type of primer
		:type primer_type: str
		:param propellant_image: Base64 encoded image of propellant
		:type propellant_image:
		:param headstamp_image: Base64 encoded image of headstamp
		:type headstamp_image:
		:param other_images: List of other_images, where each is a tuple containing
		a string for the filename, and a Base64 encoded image
		:type other_images: list
		:param notes: Notes & Remarks about the ammunition
		:type notes: str
		
		Legacy properties
		:param projectile_type:
		:type projectile_type:
		:param has_boattail:
		:type has_boattail:
		:param projectile_mass:
		:type projectile_mass:
		"""
		
		# File Properties
		self.user = Property(
				"ammo_details_user", user, str,
				help="The user who created the Ammunition Details record",
				editable=False, label="User"
				)
		self.device = Property(
				"ammo_details_device", device, str,
				help="The device that created the Ammunition Details record",
				editable=False, label="Device"
				)
		self.date_created = Property(
				"ammo_details_date_created", date_created, datetime,
				help="The date the Ammunition Details record was created",
				editable=False, immutable=True, label="Date Created"
				)
		self.date_modified = Property(
				"ammo_details_date_modified", date_modified, datetime,
				help="The date the Ammunition Details record was last modified",
				editable=False, label="Date Modified"
				)
		self.version = Property(
				"ammo_details_version", version, str,
				help="The Ammunition Details file format version number",
				editable=False, label="Version"
				)
		self.filename = Property(
				"ammo_details_filename", filename, dir,
				help="The name of the Project file", label="Filename"
				)
		
		# Ammunition Information
		self.name = name
		self.description = Property(
				"ammo_details_description", description, longstr,
				help="A description of the Ammunition Details record",
				label="Description"
				)
		self.calibre = Property(
				"ammo_details_calibre", calibre, calibre_type,
				help="The calibre of the ammunition",
				label="Calibre"
				)
		self.manufacturer = Property(
				"ammo_details_manufacturer", manufacturer, str,
				help="The manufacturer of the ammunition",
				label="Manufacturer"
				)
		self.year_of_manufacture = Property(
				"ammo_details_year_of_manufacture", year_of_manufacture, int,
				help="The year the ammunition was manufactured",
				label="Year of Manufacture"
				)
		self.primer_type = Property(
				"ammo_details_primer_type", primer_type, fixed_list,
				help="The type of primer, either Berdan, Boxer or Rimfire. Blank if unknown",
				label="Primer Type", dropdown_choices=[
						PRIMER_TYPE_UNKNOWN,
						PRIMER_TYPE_BERDAN,
						PRIMER_TYPE_BOXER,
						PRIMER_TYPE_RIMFIRE
						])
		self.notes = Property(
				"ammo_details_notes", notes, longstr,
				help="Notes & Remarks about the ammunition", label="Notes & Remarks"
				)
		
		# Propellant
		if propellant_granules:
			self.propellant_granules = Ammunition.Granule.from_dict(propellant_granules)
		else:
			self.propellant_granules = Ammunition.Granule()
		
		# Projectile
		if projectile:
			self.projectile = Ammunition.Projectile.from_dict(projectile)
		else:
			self.projectile = Ammunition.Projectile()
		
		# legacy options
		if projectile_type != '':
			self.projectile.type.value = projectile_type
		if has_boattail:
			self.projectile.has_boattail.value = True
		if projectile_mass != 0:
			self.projectile.mass.value = projectile_mass
		
		# Images
		self.propellant_image = ammo_images.Base642Image(propellant_image)
		self.headstamp_image = ammo_images.Base642Image(headstamp_image)
		self.other_images = []

		if other_images is not None:
			for caption, image in other_images:
				self.other_images.append((caption, ammo_images.Base642Image(image)))
		
		self._panel = None
Exemplo n.º 6
0
    def __init__(self,
                 name,
                 method,
                 user,
                 device,
                 date_created,
                 date_modified,
                 version,
                 description='',
                 experiments=None,
                 filename=None,
                 ammo_details=None,
                 alignment_performed=False,
                 alignment_audit_record=None,
                 consolidate_performed=False,
                 consolidate_audit_record=None,
                 **_):
        """
		
		:param name: The name of the Project
		:type name: str
		:param method:
		:type method:
		:param user: The user who created the Project
		:type user: str
		:param device: The device that created the Project
		:type device: str
		:param date_created: The date and time the Project was created
		:type date_created: datetime.datetime
		:param date_modified: The date and time the Project was last modified
		:type date_modified: datetime.datetime
		:param version: File format version in semver format
		:type version:
		:param description: A description of the Project
		:type description: str
		:param experiments:
		:type experiments:
		:param filename:
		:type filename:
		:param ammo_details:
		:type ammo_details:
		:param alignment_performed: Whether alignment was performed
		:type alignment_performed: bool
		:param alignment_audit_record: If alignment was performed, when and by whom
		:type alignment_audit_record: watchdog.AuditRecord
		:param consolidate_performed: Whether consolidate was performed
		:type consolidate_performed: bool
		:param consolidate_audit_record: If consolidate was performed, when and by whom
		:type consolidate_audit_record: watchdog.AuditRecord
		"""

        Base.GSMBase.__init__(self, name, method, user, device, date_created,
                              date_modified, version, description, filename)

        if experiments:
            self._experiments = experiments  # sorted(experiments, key=lambda experiment: experiment.name)
        else:
            self._experiments = []

        self.ammo_details = Property(
            "Ammunition Details",
            ammo_details,
            dir,
            help="The Ammunition Details file for this Project")

        self._experiment_objects = None

        # Setup Variables
        self.rt_alignment = None
        self.ms_alignment = None
        self.area_alignment = None
        self.consolidated_peaks = None

        self.alignment_performed = alignment_performed
        if self.alignment_performed:
            self.alignment_audit_record = watchdog.AuditRecord(
                record_dict=alignment_audit_record)
        else:
            self.alignment_audit_record = None

        self.consolidate_performed = consolidate_performed
        if self.consolidate_performed:
            self.consolidate_audit_record = watchdog.AuditRecord(
                record_dict=consolidate_audit_record)
        else:
            self.consolidate_audit_record = None

        # Load Data
        self.load_alignment_data()
        self.load_consolidate_results()

        if self.ammo_details.filename:
            self.ammo_data = Ammunition.load(self.ammo_file)

        # TODO: Adding and removing experiments

        self.method_unsaved = False
        self.ammo_details_unsaved = False
        self._unsaved_changes = False
    def __init__(self,
                 parent,
                 filename=None,
                 id=wx.ID_ANY,
                 title='',
                 pos=wx.DefaultPosition,
                 size=wx.DefaultSize,
                 style=wx.DEFAULT_FRAME_STYLE,
                 name="AmmunitionDetailsEditor"):
        """
		:param parent: The window parent. This may be, and often is, None. If it is not None, the frame will be minimized when its parent is minimized and restored when it is restored (although it will still be possible to minimize
		:type parent: wx.Window
		:param filename: AmmunitionDetails file to open, Default None
		:type filename: str, optional
		:param id: The window identifier. It may take a value of -1 to indicate a default value.
		:type id: wx.WindowID, optional
		:param title: The caption to be displayed on the frame’s title bar.
		:type title: str, optional
		:param pos: The window position. The value DefaultPosition indicates a default position, chosen by either the windowing system or wxWidgets, depending on platform.
		:type pos: wx.Point, optional
		:param size: The window size. The value DefaultSize indicates a default size, chosen by either the windowing system or wxWidgets, depending on platform.
		:type size: wx.Size, optional
		:param style: The window style. See wx.Frame class description.
		:type style: int, optional
		:param name: The name of the window. This parameter is used to associate a name with the item, allowing the application user to set Motif resource values for individual windows.
		:type name: str, optional
		"""

        args = (parent, id)
        kwds = {
            "pos": pos,
            "size": size,
            "title": title,
            "style": style,
            "name": name,
        }

        # begin wxGlade: AmmunitionDetailsEditor.__init__
        kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.SetSize((800, 800))

        # Menu Bar
        self.AmmunitionDetails_menubar = wx.MenuBar()
        wxglade_tmp_menu = wx.Menu()
        wxglade_tmp_menu.Append(wx.ID_NEW, "&New Ammunition Record", "")
        self.Bind(wx.EVT_MENU, self.new_record, id=wx.ID_NEW)
        wxglade_tmp_menu.Append(wx.ID_OPEN, "&Open Ammunition Record", "")
        self.Bind(wx.EVT_MENU, self.on_open_record, id=wx.ID_OPEN)
        wxglade_tmp_menu.Append(wx.ID_SAVE, "&Save Ammunition Record", "")
        self.Bind(wx.EVT_MENU, self.on_save_record, id=wx.ID_SAVE)
        wxglade_tmp_menu.Append(wx.ID_SAVEAS, "Save Record As", "")
        self.Bind(wx.EVT_MENU, self.save_as, id=wx.ID_SAVEAS)
        wxglade_tmp_menu.Append(wx.ID_EXIT, "Close", "")
        self.Bind(wx.EVT_MENU, self.exit, id=wx.ID_EXIT)
        self.AmmunitionDetails_menubar.Append(wxglade_tmp_menu, "File")
        wxglade_tmp_menu = wx.Menu()
        wxglade_tmp_menu.Append(wx.ID_HELP, "Help", "")
        self.Bind(wx.EVT_MENU, self.on_help, id=wx.ID_HELP)
        self.AmmunitionDetails_menubar.Append(wxglade_tmp_menu, "Help")
        self.SetMenuBar(self.AmmunitionDetails_menubar)
        # Menu Bar end
        self.AmmunitionDetailsPanel = Ammunition.DetailsPanel(
            None, self, wx.ID_ANY)

        self.__set_properties()
        self.__do_layout()

        # end wxGlade

        self.filename = filename

        if self.filename:
            self.AmmunitionDetailsPanel.open_record(self.filename)
        else:
            self.new_record()

        self.__create_toolbar()

        self.Bind(wx.EVT_CLOSE, self.on_close)
        self.Bind(wx.propgrid.EVT_PG_CHANGED, self.on_property_changed,
                  self.AmmunitionDetailsPanel.ammo_details_grid)